aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2013-05-13 19:49:46 +0200
committerMike Pall <mike>2013-05-13 19:49:46 +0200
commitacda75ad2cc30cff0a390ae0d232a098296e517e (patch)
tree2aa351a4f6c1c2b8ff60b46c3974c148ed135d24
parent23e47f2913623063936d8c8d8b25ee25a5db2070 (diff)
downloadluajit-acda75ad2cc30cff0a390ae0d232a098296e517e.tar.gz
luajit-acda75ad2cc30cff0a390ae0d232a098296e517e.tar.bz2
luajit-acda75ad2cc30cff0a390ae0d232a098296e517e.zip
Refactor CCallInfo representation for split arguments.
-rw-r--r--src/lj_asm.c2
-rw-r--r--src/lj_asm_arm.h4
-rw-r--r--src/lj_asm_mips.h4
-rw-r--r--src/lj_asm_ppc.h4
-rw-r--r--src/lj_asm_x86.h4
-rw-r--r--src/lj_ircall.h115
6 files changed, 74 insertions, 59 deletions
diff --git a/src/lj_asm.c b/src/lj_asm.c
index 9d874ddb..a1e92003 100644
--- a/src/lj_asm.c
+++ b/src/lj_asm.c
@@ -1197,7 +1197,7 @@ static void asm_newref(ASMState *as, IRIns *ir)
1197static void asm_collectargs(ASMState *as, IRIns *ir, 1197static void asm_collectargs(ASMState *as, IRIns *ir,
1198 const CCallInfo *ci, IRRef *args) 1198 const CCallInfo *ci, IRRef *args)
1199{ 1199{
1200 uint32_t n = CCI_NARGS(ci); 1200 uint32_t n = CCI_XNARGS(ci);
1201 lua_assert(n <= CCI_NARGS_MAX); 1201 lua_assert(n <= CCI_NARGS_MAX);
1202 if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; } 1202 if ((ci->flags & CCI_L)) { *args++ = ASMREF_L; n--; }
1203 while (n-- > 1) { 1203 while (n-- > 1) {
diff --git a/src/lj_asm_arm.h b/src/lj_asm_arm.h
index 039a2a9a..1e024dcd 100644
--- a/src/lj_asm_arm.h
+++ b/src/lj_asm_arm.h
@@ -338,7 +338,7 @@ static int asm_fusemadd(ASMState *as, IRIns *ir, ARMIns ai, ARMIns air)
338/* Generate a call to a C function. */ 338/* Generate a call to a C function. */
339static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) 339static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
340{ 340{
341 uint32_t n, nargs = CCI_NARGS(ci); 341 uint32_t n, nargs = CCI_XNARGS(ci);
342 int32_t ofs = 0; 342 int32_t ofs = 0;
343#if LJ_SOFTFP 343#if LJ_SOFTFP
344 Reg gpr = REGARG_FIRSTGPR; 344 Reg gpr = REGARG_FIRSTGPR;
@@ -2133,7 +2133,7 @@ static void asm_tail_prep(ASMState *as)
2133static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) 2133static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
2134{ 2134{
2135 IRRef args[CCI_NARGS_MAX]; 2135 IRRef args[CCI_NARGS_MAX];
2136 uint32_t i, nargs = (int)CCI_NARGS(ci); 2136 uint32_t i, nargs = CCI_XNARGS(ci);
2137 int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0; 2137 int nslots = 0, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR, fprodd = 0;
2138 asm_collectargs(as, ir, ci, args); 2138 asm_collectargs(as, ir, ci, args);
2139 for (i = 0; i < nargs; i++) { 2139 for (i = 0; i < nargs; i++) {
diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h
index 122e5ecd..5070a7a2 100644
--- a/src/lj_asm_mips.h
+++ b/src/lj_asm_mips.h
@@ -226,7 +226,7 @@ static void asm_fusexref(ASMState *as, MIPSIns mi, Reg rt, IRRef ref,
226/* Generate a call to a C function. */ 226/* Generate a call to a C function. */
227static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) 227static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
228{ 228{
229 uint32_t n, nargs = CCI_NARGS(ci); 229 uint32_t n, nargs = CCI_XNARGS(ci);
230 int32_t ofs = 16; 230 int32_t ofs = 16;
231 Reg gpr, fpr = REGARG_FIRSTFPR; 231 Reg gpr, fpr = REGARG_FIRSTFPR;
232 if ((void *)ci->func) 232 if ((void *)ci->func)
@@ -1726,7 +1726,7 @@ static void asm_tail_prep(ASMState *as)
1726static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) 1726static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
1727{ 1727{
1728 IRRef args[CCI_NARGS_MAX]; 1728 IRRef args[CCI_NARGS_MAX];
1729 uint32_t i, nargs = (int)CCI_NARGS(ci); 1729 uint32_t i, nargs = CCI_XNARGS(ci);
1730 int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; 1730 int nslots = 4, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
1731 asm_collectargs(as, ir, ci, args); 1731 asm_collectargs(as, ir, ci, args);
1732 for (i = 0; i < nargs; i++) { 1732 for (i = 0; i < nargs; i++) {
diff --git a/src/lj_asm_ppc.h b/src/lj_asm_ppc.h
index d9174e7d..a4a35547 100644
--- a/src/lj_asm_ppc.h
+++ b/src/lj_asm_ppc.h
@@ -249,7 +249,7 @@ static int asm_fusemadd(ASMState *as, IRIns *ir, PPCIns pi, PPCIns pir)
249/* Generate a call to a C function. */ 249/* Generate a call to a C function. */
250static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) 250static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
251{ 251{
252 uint32_t n, nargs = CCI_NARGS(ci); 252 uint32_t n, nargs = CCI_XNARGS(ci);
253 int32_t ofs = 8; 253 int32_t ofs = 8;
254 Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR; 254 Reg gpr = REGARG_FIRSTGPR, fpr = REGARG_FIRSTFPR;
255 if ((void *)ci->func) 255 if ((void *)ci->func)
@@ -1917,7 +1917,7 @@ static void asm_tail_prep(ASMState *as)
1917static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci) 1917static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
1918{ 1918{
1919 IRRef args[CCI_NARGS_MAX]; 1919 IRRef args[CCI_NARGS_MAX];
1920 uint32_t i, nargs = (int)CCI_NARGS(ci); 1920 uint32_t i, nargs = CCI_XNARGS(ci);
1921 int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; 1921 int nslots = 2, ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
1922 asm_collectargs(as, ir, ci, args); 1922 asm_collectargs(as, ir, ci, args);
1923 for (i = 0; i < nargs; i++) 1923 for (i = 0; i < nargs; i++)
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
index 2ab1dbf5..3a029970 100644
--- a/src/lj_asm_x86.h
+++ b/src/lj_asm_x86.h
@@ -384,7 +384,7 @@ static Reg asm_fuseloadm(ASMState *as, IRRef ref, RegSet allow, int is64)
384/* Count the required number of stack slots for a call. */ 384/* Count the required number of stack slots for a call. */
385static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args) 385static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)
386{ 386{
387 uint32_t i, nargs = CCI_NARGS(ci); 387 uint32_t i, nargs = CCI_XNARGS(ci);
388 int nslots = 0; 388 int nslots = 0;
389#if LJ_64 389#if LJ_64
390 if (LJ_ABI_WIN) { 390 if (LJ_ABI_WIN) {
@@ -417,7 +417,7 @@ static int asm_count_call_slots(ASMState *as, const CCallInfo *ci, IRRef *args)
417/* Generate a call to a C function. */ 417/* Generate a call to a C function. */
418static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args) 418static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
419{ 419{
420 uint32_t n, nargs = CCI_NARGS(ci); 420 uint32_t n, nargs = CCI_XNARGS(ci);
421 int32_t ofs = STACKARG_OFS; 421 int32_t ofs = STACKARG_OFS;
422#if LJ_64 422#if LJ_64
423 uint32_t gprs = REGARG_GPRS; 423 uint32_t gprs = REGARG_GPRS;
diff --git a/src/lj_ircall.h b/src/lj_ircall.h
index bf83a3b3..43bd25d9 100644
--- a/src/lj_ircall.h
+++ b/src/lj_ircall.h
@@ -16,7 +16,7 @@ typedef struct CCallInfo {
16 uint32_t flags; /* Number of arguments and flags. */ 16 uint32_t flags; /* Number of arguments and flags. */
17} CCallInfo; 17} CCallInfo;
18 18
19#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */ 19#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* # of args. */
20#define CCI_NARGS_MAX 32 /* Max. # of args. */ 20#define CCI_NARGS_MAX 32 /* Max. # of args. */
21 21
22#define CCI_OTSHIFT 16 22#define CCI_OTSHIFT 16
@@ -45,6 +45,17 @@ typedef struct CCallInfo {
45#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */ 45#define CCI_CC_FASTCALL 0x2000 /* Fastcall calling convention. */
46#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */ 46#define CCI_CC_STDCALL 0x3000 /* Stdcall calling convention. */
47 47
48/* Extra args for SOFTFP, SPLIT 64 bit. */
49#define CCI_XARGS_SHIFT 14
50#define CCI_XARGS(ci) (((ci)->flags >> CCI_XARGS_SHIFT) & 3)
51#define CCI_XA (1u << CCI_XARGS_SHIFT)
52
53#if LJ_SOFTFP || (LJ_32 && LJ_HASFFI)
54#define CCI_XNARGS(ci) (CCI_NARGS((ci)) + CCI_XARGS((ci)))
55#else
56#define CCI_XNARGS(ci) CCI_NARGS((ci))
57#endif
58
48/* Helpers for conditional function definitions. */ 59/* Helpers for conditional function definitions. */
49#define IRCALLCOND_ANY(x) x 60#define IRCALLCOND_ANY(x) x
50 61
@@ -87,15 +98,19 @@ typedef struct CCallInfo {
87#endif 98#endif
88 99
89#if LJ_SOFTFP 100#if LJ_SOFTFP
90#define ARG1_FP 2 /* Treat as 2 32 bit arguments. */ 101#define XA_FP CCI_XA
102#define XA2_FP (CCI_XA+CCI_XA)
91#else 103#else
92#define ARG1_FP 1 104#define XA_FP 0
105#define XA2_FP 0
93#endif 106#endif
94 107
95#if LJ_32 108#if LJ_32
96#define ARG2_64 4 /* Treat as 4 32 bit arguments. */ 109#define XA_64 CCI_XA
110#define XA2_64 (CCI_XA+CCI_XA)
97#else 111#else
98#define ARG2_64 2 112#define XA_64 0
113#define XA2_64 0
99#endif 114#endif
100 115
101/* Function definitions for CALL* instructions. */ 116/* Function definitions for CALL* instructions. */
@@ -127,29 +142,29 @@ typedef struct CCallInfo {
127 _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \ 142 _(ANY, lj_mem_newgco, 2, FS, P32, CCI_L) \
128 _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \ 143 _(ANY, lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \
129 _(ANY, lj_vm_modi, 2, FN, INT, 0) \ 144 _(ANY, lj_vm_modi, 2, FN, INT, 0) \
130 _(ANY, sinh, ARG1_FP, N, NUM, 0) \ 145 _(ANY, sinh, 1, N, NUM, XA_FP) \
131 _(ANY, cosh, ARG1_FP, N, NUM, 0) \ 146 _(ANY, cosh, 1, N, NUM, XA_FP) \
132 _(ANY, tanh, ARG1_FP, N, NUM, 0) \ 147 _(ANY, tanh, 1, N, NUM, XA_FP) \
133 _(ANY, fputc, 2, S, INT, 0) \ 148 _(ANY, fputc, 2, S, INT, 0) \
134 _(ANY, fwrite, 4, S, INT, 0) \ 149 _(ANY, fwrite, 4, S, INT, 0) \
135 _(ANY, fflush, 1, S, INT, 0) \ 150 _(ANY, fflush, 1, S, INT, 0) \
136 /* ORDER FPM */ \ 151 /* ORDER FPM */ \
137 _(FPMATH, lj_vm_floor, ARG1_FP, N, NUM, 0) \ 152 _(FPMATH, lj_vm_floor, 1, N, NUM, XA_FP) \
138 _(FPMATH, lj_vm_ceil, ARG1_FP, N, NUM, 0) \ 153 _(FPMATH, lj_vm_ceil, 1, N, NUM, XA_FP) \
139 _(FPMATH, lj_vm_trunc, ARG1_FP, N, NUM, 0) \ 154 _(FPMATH, lj_vm_trunc, 1, N, NUM, XA_FP) \
140 _(FPMATH, sqrt, ARG1_FP, N, NUM, 0) \ 155 _(FPMATH, sqrt, 1, N, NUM, XA_FP) \
141 _(FPMATH, exp, ARG1_FP, N, NUM, 0) \ 156 _(FPMATH, exp, 1, N, NUM, XA_FP) \
142 _(FPMATH, lj_vm_exp2, ARG1_FP, N, NUM, 0) \ 157 _(FPMATH, lj_vm_exp2, 1, N, NUM, XA_FP) \
143 _(FPMATH, log, ARG1_FP, N, NUM, 0) \ 158 _(FPMATH, log, 1, N, NUM, XA_FP) \
144 _(FPMATH, lj_vm_log2, ARG1_FP, N, NUM, 0) \ 159 _(FPMATH, lj_vm_log2, 1, N, NUM, XA_FP) \
145 _(FPMATH, log10, ARG1_FP, N, NUM, 0) \ 160 _(FPMATH, log10, 1, N, NUM, XA_FP) \
146 _(FPMATH, sin, ARG1_FP, N, NUM, 0) \ 161 _(FPMATH, sin, 1, N, NUM, XA_FP) \
147 _(FPMATH, cos, ARG1_FP, N, NUM, 0) \ 162 _(FPMATH, cos, 1, N, NUM, XA_FP) \
148 _(FPMATH, tan, ARG1_FP, N, NUM, 0) \ 163 _(FPMATH, tan, 1, N, NUM, XA_FP) \
149 _(FPMATH, lj_vm_powi, ARG1_FP+1, N, NUM, 0) \ 164 _(FPMATH, lj_vm_powi, 2, N, NUM, XA_FP) \
150 _(FPMATH, pow, ARG1_FP*2, N, NUM, 0) \ 165 _(FPMATH, pow, 2, N, NUM, XA2_FP) \
151 _(FPMATH, atan2, ARG1_FP*2, N, NUM, 0) \ 166 _(FPMATH, atan2, 2, N, NUM, XA2_FP) \
152 _(FPMATH, ldexp, ARG1_FP+1, N, NUM, 0) \ 167 _(FPMATH, ldexp, 2, N, NUM, XA_FP) \
153 _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \ 168 _(SOFTFP, lj_vm_tobit, 2, N, INT, 0) \
154 _(SOFTFP, softfp_add, 4, N, NUM, 0) \ 169 _(SOFTFP, softfp_add, 4, N, NUM, 0) \
155 _(SOFTFP, softfp_sub, 4, N, NUM, 0) \ 170 _(SOFTFP, softfp_sub, 4, N, NUM, 0) \
@@ -166,31 +181,31 @@ typedef struct CCallInfo {
166 _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \ 181 _(SOFTFP_FFI, softfp_ui2f, 1, N, FLOAT, 0) \
167 _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \ 182 _(SOFTFP_FFI, softfp_f2i, 1, N, INT, 0) \
168 _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \ 183 _(SOFTFP_FFI, softfp_f2ui, 1, N, INT, 0) \
169 _(FP64_FFI, fp64_l2d, 2, N, NUM, 0) \ 184 _(FP64_FFI, fp64_l2d, 1, N, NUM, XA_64) \
170 _(FP64_FFI, fp64_ul2d, 2, N, NUM, 0) \ 185 _(FP64_FFI, fp64_ul2d, 1, N, NUM, XA_64) \
171 _(FP64_FFI, fp64_l2f, 2, N, FLOAT, 0) \ 186 _(FP64_FFI, fp64_l2f, 1, N, FLOAT, XA_64) \
172 _(FP64_FFI, fp64_ul2f, 2, N, FLOAT, 0) \ 187 _(FP64_FFI, fp64_ul2f, 1, N, FLOAT, XA_64) \
173 _(FP64_FFI, fp64_d2l, ARG1_FP, N, I64, 0) \ 188 _(FP64_FFI, fp64_d2l, 1, N, I64, XA_FP) \
174 _(FP64_FFI, fp64_d2ul, ARG1_FP, N, U64, 0) \ 189 _(FP64_FFI, fp64_d2ul, 1, N, U64, XA_FP) \
175 _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \ 190 _(FP64_FFI, fp64_f2l, 1, N, I64, 0) \
176 _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \ 191 _(FP64_FFI, fp64_f2ul, 1, N, U64, 0) \
177 _(FFI, lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ 192 _(FFI, lj_carith_divi64, 2, N, I64, XA2_64|CCI_NOFPRCLOBBER) \
178 _(FFI, lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ 193 _(FFI, lj_carith_divu64, 2, N, U64, XA2_64|CCI_NOFPRCLOBBER) \
179 _(FFI, lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ 194 _(FFI, lj_carith_modi64, 2, N, I64, XA2_64|CCI_NOFPRCLOBBER) \
180 _(FFI, lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ 195 _(FFI, lj_carith_modu64, 2, N, U64, XA2_64|CCI_NOFPRCLOBBER) \
181 _(FFI, lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ 196 _(FFI, lj_carith_powi64, 2, N, I64, XA2_64|CCI_NOFPRCLOBBER) \
182 _(FFI, lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \ 197 _(FFI, lj_carith_powu64, 2, N, U64, XA2_64|CCI_NOFPRCLOBBER) \
183 _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \ 198 _(FFI, lj_cdata_setfin, 2, FN, P32, CCI_L) \
184 _(FFI, strlen, 1, L, INTP, 0) \ 199 _(FFI, strlen, 1, L, INTP, 0) \
185 _(FFI, memcpy, 3, S, PTR, 0) \ 200 _(FFI, memcpy, 3, S, PTR, 0) \
186 _(FFI, memset, 3, S, PTR, 0) \ 201 _(FFI, memset, 3, S, PTR, 0) \
187 _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \ 202 _(FFI, lj_vm_errno, 0, S, INT, CCI_NOFPRCLOBBER) \
188 _(FFI32, lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \ 203 _(FFI32, lj_carith_mul64, 2, N, I64, XA2_64|CCI_NOFPRCLOBBER) \
189 _(FFI32, lj_carith_shl64, 3, N, U64, CCI_NOFPRCLOBBER) \ 204 _(FFI32, lj_carith_shl64, 2, N, U64, XA_64|CCI_NOFPRCLOBBER) \
190 _(FFI32, lj_carith_shr64, 3, N, U64, CCI_NOFPRCLOBBER) \ 205 _(FFI32, lj_carith_shr64, 2, N, U64, XA_64|CCI_NOFPRCLOBBER) \
191 _(FFI32, lj_carith_sar64, 3, N, U64, CCI_NOFPRCLOBBER) \ 206 _(FFI32, lj_carith_sar64, 2, N, U64, XA_64|CCI_NOFPRCLOBBER) \
192 _(FFI32, lj_carith_rol64, 3, N, U64, CCI_NOFPRCLOBBER) \ 207 _(FFI32, lj_carith_rol64, 2, N, U64, XA_64|CCI_NOFPRCLOBBER) \
193 _(FFI32, lj_carith_ror64, 3, N, U64, CCI_NOFPRCLOBBER) \ 208 _(FFI32, lj_carith_ror64, 2, N, U64, XA_64|CCI_NOFPRCLOBBER) \
194 \ 209 \
195 /* End of list. */ 210 /* End of list. */
196 211