diff options
author | Mike Pall <mike> | 2009-12-27 18:44:12 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-27 18:44:12 +0100 |
commit | 3a15e46b79b0c58c59fd841654560ff0b301e37e (patch) | |
tree | e5e8f5750dbaf88d6bc9546ee2b480f763d615c7 /src/buildvm_x86.dasc | |
parent | e5438daffe4b7451fd888294521aacd226f53c06 (diff) | |
download | luajit-3a15e46b79b0c58c59fd841654560ff0b301e37e.tar.gz luajit-3a15e46b79b0c58c59fd841654560ff0b301e37e.tar.bz2 luajit-3a15e46b79b0c58c59fd841654560ff0b301e37e.zip |
More calling convention cleanups for x64 interpreter.
Diffstat (limited to 'src/buildvm_x86.dasc')
-rw-r--r-- | src/buildvm_x86.dasc | 107 |
1 files changed, 94 insertions, 13 deletions
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index eadd8d57..7167ffb1 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
@@ -863,12 +863,32 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse) | |||
863 | | je ->cont_ra | 863 | | je ->cont_ra |
864 | | neg RA | 864 | | neg RA |
865 | | shr RA, 3 | 865 | | shr RA, 3 |
866 | |.if X64WIN | ||
867 | | mov CARG3d, RA | ||
868 | | mov L:CARG1d, SAVE_L | ||
869 | | mov L:CARG1d->base, BASE | ||
870 | | mov CARG2d, [RC+4] | ||
871 | | mov RC, [RC] | ||
872 | | mov [RB+4], CARG2d | ||
873 | | mov [RB], RC | ||
874 | | mov CARG2d, RB | ||
875 | |.elif X64 | ||
876 | | mov L:CARG1d, SAVE_L | ||
877 | | mov L:CARG1d->base, BASE | ||
878 | | mov CARG3d, RA | ||
879 | | mov RA, [RC+4] | ||
880 | | mov RC, [RC] | ||
881 | | mov [RB+4], RA | ||
882 | | mov [RB], RC | ||
883 | | mov CARG2d, RB | ||
884 | |.else | ||
866 | | mov ARG3, RA | 885 | | mov ARG3, RA |
867 | | mov RA, [RC+4] | 886 | | mov RA, [RC+4] |
868 | | mov RC, [RC] | 887 | | mov RC, [RC] |
869 | | mov [RB+4], RA | 888 | | mov [RB+4], RA |
870 | | mov [RB], RC | 889 | | mov [RB], RC |
871 | | mov ARG2, RB | 890 | | mov ARG2, RB |
891 | |.endif | ||
872 | | jmp ->BC_CAT_Z | 892 | | jmp ->BC_CAT_Z |
873 | | | 893 | | |
874 | |//-- Table indexing metamethods ----------------------------------------- | 894 | |//-- Table indexing metamethods ----------------------------------------- |
@@ -3624,6 +3644,15 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
3624 | 3644 | ||
3625 | case BC_CAT: | 3645 | case BC_CAT: |
3626 | | ins_ABC // RA = dst, RB = src_start, RC = src_end | 3646 | | ins_ABC // RA = dst, RB = src_start, RC = src_end |
3647 | |.if X64 | ||
3648 | | mov L:CARG1d, SAVE_L | ||
3649 | | mov L:CARG1d->base, BASE | ||
3650 | | lea CARG2d, [BASE+RC*8] | ||
3651 | | mov CARG3d, RC | ||
3652 | | sub CARG3d, RB | ||
3653 | |->BC_CAT_Z: | ||
3654 | | mov L:RB, L:CARG1d | ||
3655 | |.else | ||
3627 | | lea RA, [BASE+RC*8] | 3656 | | lea RA, [BASE+RC*8] |
3628 | | sub RC, RB | 3657 | | sub RC, RB |
3629 | | mov ARG2, RA | 3658 | | mov ARG2, RA |
@@ -3631,8 +3660,9 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
3631 | |->BC_CAT_Z: | 3660 | |->BC_CAT_Z: |
3632 | | mov L:RB, SAVE_L | 3661 | | mov L:RB, SAVE_L |
3633 | | mov ARG1, L:RB | 3662 | | mov ARG1, L:RB |
3634 | | mov SAVE_PC, PC | ||
3635 | | mov L:RB->base, BASE | 3663 | | mov L:RB->base, BASE |
3664 | |.endif | ||
3665 | | mov SAVE_PC, PC | ||
3636 | | call extern lj_meta_cat // (lua_State *L, TValue *top, int left) | 3666 | | call extern lj_meta_cat // (lua_State *L, TValue *top, int left) |
3637 | | // NULL (finished) or TValue * (metamethod) returned in eax (RC). | 3667 | | // NULL (finished) or TValue * (metamethod) returned in eax (RC). |
3638 | | mov BASE, L:RB->base | 3668 | | mov BASE, L:RB->base |
@@ -3817,14 +3847,22 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
3817 | 3847 | ||
3818 | case BC_FNEW: | 3848 | case BC_FNEW: |
3819 | | ins_AND // RA = dst, RD = proto const (~) (holding function prototype) | 3849 | | ins_AND // RA = dst, RD = proto const (~) (holding function prototype) |
3850 | |.if X64 | ||
3851 | | mov L:RB, SAVE_L | ||
3852 | | mov L:RB->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | ||
3853 | | mov CARG3d, [BASE-8] | ||
3854 | | mov CARG2d, [KBASE+RD*4] // Fetch GCproto *. | ||
3855 | | mov CARG1d, L:RB | ||
3856 | |.else | ||
3820 | | mov LFUNC:RA, [BASE-8] | 3857 | | mov LFUNC:RA, [BASE-8] |
3821 | | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *. | 3858 | | mov PROTO:RD, [KBASE+RD*4] // Fetch GCproto *. |
3822 | | mov L:RB, SAVE_L | 3859 | | mov L:RB, SAVE_L |
3823 | | mov ARG3, LFUNC:RA | 3860 | | mov ARG3, LFUNC:RA |
3824 | | mov ARG2, PROTO:RD | 3861 | | mov ARG2, PROTO:RD |
3825 | | mov SAVE_PC, PC | ||
3826 | | mov ARG1, L:RB | 3862 | | mov ARG1, L:RB |
3827 | | mov L:RB->base, BASE | 3863 | | mov L:RB->base, BASE |
3864 | |.endif | ||
3865 | | mov SAVE_PC, PC | ||
3828 | | // (lua_State *L, GCproto *pt, GCfuncL *parent) | 3866 | | // (lua_State *L, GCproto *pt, GCfuncL *parent) |
3829 | | call extern lj_func_newL_gc | 3867 | | call extern lj_func_newL_gc |
3830 | | // GCfuncL * returned in eax (RC). | 3868 | | // GCfuncL * returned in eax (RC). |
@@ -3839,23 +3877,40 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
3839 | 3877 | ||
3840 | case BC_TNEW: | 3878 | case BC_TNEW: |
3841 | | ins_AD // RA = dst, RD = hbits|asize | 3879 | | ins_AD // RA = dst, RD = hbits|asize |
3880 | |.if X64 | ||
3881 | | mov L:CARG1d, SAVE_L | ||
3882 | |1: | ||
3883 | | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | ||
3884 | | mov CARG3d, RD | ||
3885 | | and RD, 0x7ff | ||
3886 | | shr CARG3d, 11 | ||
3887 | | cmp RD, 0x7ff | ||
3888 | | je >3 | ||
3889 | |2: | ||
3890 | | mov CARG2d, RD | ||
3891 | | mov RD, [DISPATCH+DISPATCH_GL(gc.total)] | ||
3892 | | mov L:RB, L:CARG1d | ||
3893 | | cmp RD, [DISPATCH+DISPATCH_GL(gc.threshold)] | ||
3894 | | mov SAVE_PC, PC | ||
3895 | | jae >5 | ||
3896 | |.else | ||
3842 | | mov RB, RD | 3897 | | mov RB, RD |
3843 | | and RD, 0x7ff | 3898 | | and RD, 0x7ff |
3844 | | shr RB, 11 | 3899 | | shr RB, 11 |
3845 | | cmp RD, 0x7ff // Turn 0x7ff into 0x801. | 3900 | | cmp RD, 0x7ff |
3846 | | sete RAL | 3901 | | je >3 |
3902 | |2: | ||
3847 | | mov ARG3, RB | 3903 | | mov ARG3, RB |
3848 | | add RD, RA | ||
3849 | | mov L:RB, SAVE_L | 3904 | | mov L:RB, SAVE_L |
3850 | | add RD, RA | ||
3851 | | mov ARG2, RD | 3905 | | mov ARG2, RD |
3852 | | mov SAVE_PC, PC | 3906 | | mov SAVE_PC, PC |
3853 | | mov RA, [DISPATCH+DISPATCH_GL(gc.total)] | 3907 | | mov RD, [DISPATCH+DISPATCH_GL(gc.total)] |
3854 | | mov ARG1, L:RB | 3908 | | mov ARG1, L:RB |
3855 | | cmp RA, [DISPATCH+DISPATCH_GL(gc.threshold)] | 3909 | | cmp RD, [DISPATCH+DISPATCH_GL(gc.threshold)] |
3856 | | mov L:RB->base, BASE | 3910 | | mov L:RB->base, BASE |
3857 | | jae >2 | 3911 | | jae >5 |
3858 | |1: | 3912 | |1: |
3913 | |.endif | ||
3859 | | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) | 3914 | | call extern lj_tab_new // (lua_State *L, int32_t asize, uint32_t hbits) |
3860 | | // Table * returned in eax (RC). | 3915 | | // Table * returned in eax (RC). |
3861 | | mov BASE, L:RB->base | 3916 | | mov BASE, L:RB->base |
@@ -3863,10 +3918,20 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
3863 | | mov [BASE+RA*8], TAB:RC | 3918 | | mov [BASE+RA*8], TAB:RC |
3864 | | mov dword [BASE+RA*8+4], LJ_TTAB | 3919 | | mov dword [BASE+RA*8+4], LJ_TTAB |
3865 | | ins_next | 3920 | | ins_next |
3866 | |2: | 3921 | |3: // Turn 0x7ff into 0x801. |
3922 | | mov RD, 0x801 | ||
3923 | | jmp <2 | ||
3924 | |5: | ||
3925 | |.if X64 | ||
3926 | | call extern lj_gc_step_fixtop@4 // (lua_State *L) | ||
3927 | | movzx RD, PC_RD | ||
3928 | | mov L:CARG1d, L:RB | ||
3929 | | jmp <1 | ||
3930 | |.else | ||
3867 | | mov L:FCARG1, L:RB | 3931 | | mov L:FCARG1, L:RB |
3868 | | call extern lj_gc_step_fixtop@4 // (lua_State *L) | 3932 | | call extern lj_gc_step_fixtop@4 // (lua_State *L) |
3869 | | jmp <1 | 3933 | | jmp <1 |
3934 | |.endif | ||
3870 | break; | 3935 | break; |
3871 | case BC_TDUP: | 3936 | case BC_TDUP: |
3872 | | ins_AND // RA = dst, RD = table const (~) (holding template table) | 3937 | | ins_AND // RA = dst, RD = table const (~) (holding template table) |
@@ -4144,14 +4209,22 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
4144 | |6: | 4209 | |6: |
4145 | | mov TMP1, STR:RC | 4210 | | mov TMP1, STR:RC |
4146 | | mov TMP2, LJ_TSTR | 4211 | | mov TMP2, LJ_TSTR |
4147 | | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | ||
4148 | | mov TMP3, TAB:RB // Save TAB:RB for us. | 4212 | | mov TMP3, TAB:RB // Save TAB:RB for us. |
4213 | |.if X64 | ||
4214 | | mov L:CARG1d, SAVE_L | ||
4215 | | mov L:CARG1d->base, BASE | ||
4216 | | lea CARG3, TMP1 | ||
4217 | | mov CARG2d, TAB:RB | ||
4218 | | mov L:RB, L:CARG1d | ||
4219 | |.else | ||
4220 | | lea RC, TMP1 // Store temp. TValue in TMP1/TMP2. | ||
4149 | | mov ARG2, TAB:RB | 4221 | | mov ARG2, TAB:RB |
4150 | | mov L:RB, SAVE_L | 4222 | | mov L:RB, SAVE_L |
4151 | | mov ARG3, RC | 4223 | | mov ARG3, RC |
4152 | | mov ARG1, L:RB | 4224 | | mov ARG1, L:RB |
4153 | | mov SAVE_PC, PC | ||
4154 | | mov L:RB->base, BASE | 4225 | | mov L:RB->base, BASE |
4226 | |.endif | ||
4227 | | mov SAVE_PC, PC | ||
4155 | | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) | 4228 | | call extern lj_tab_newkey // (lua_State *L, GCtab *t, TValue *k) |
4156 | | // Handles write barrier for the new key. TValue * returned in eax (RC). | 4229 | | // Handles write barrier for the new key. TValue * returned in eax (RC). |
4157 | | mov BASE, L:RB->base | 4230 | | mov BASE, L:RB->base |
@@ -4245,12 +4318,20 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop, int cmov, int sse) | |||
4245 | | ins_next | 4318 | | ins_next |
4246 | | | 4319 | | |
4247 | |5: // Need to resize array part. | 4320 | |5: // Need to resize array part. |
4321 | |.if X64 | ||
4322 | | mov L:CARG1d, SAVE_L | ||
4323 | | mov L:CARG1d->base, BASE // Caveat: CARG2d/CARG3d may be BASE. | ||
4324 | | mov CARG2d, TAB:RB | ||
4325 | | mov CARG3d, RD | ||
4326 | | mov L:RB, L:CARG1d | ||
4327 | |.else | ||
4248 | | mov ARG2, TAB:RB | 4328 | | mov ARG2, TAB:RB |
4249 | | mov L:RB, SAVE_L | 4329 | | mov L:RB, SAVE_L |
4330 | | mov L:RB->base, BASE | ||
4250 | | mov ARG3, RD | 4331 | | mov ARG3, RD |
4251 | | mov ARG1, L:RB | 4332 | | mov ARG1, L:RB |
4333 | |.endif | ||
4252 | | mov SAVE_PC, PC | 4334 | | mov SAVE_PC, PC |
4253 | | mov L:RB->base, BASE | ||
4254 | | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) | 4335 | | call extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize) |
4255 | | mov BASE, L:RB->base | 4336 | | mov BASE, L:RB->base |
4256 | | movzx RA, PC_RA // Restore RA. | 4337 | | movzx RA, PC_RA // Restore RA. |