Move math helpers to lj_vmmath.c. Add missing log2/exp2 for Symbian.
[luajit-2.0.git] / src / lj_ircall.h
blob1cbee91c67449e0c3a1d76a9f40dc66d2f0845c5
1 /*
2 ** IR CALL* instruction definitions.
3 ** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #ifndef _LJ_IRCALL_H
7 #define _LJ_IRCALL_H
9 #include "lj_obj.h"
10 #include "lj_ir.h"
11 #include "lj_jit.h"
13 /* C call info for CALL* instructions. */
14 typedef struct CCallInfo {
15 ASMFunction func; /* Function pointer. */
16 uint32_t flags; /* Number of arguments and flags. */
17 } CCallInfo;
19 #define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */
20 #define CCI_NARGS_MAX 32 /* Max. # of args. */
22 #define CCI_OTSHIFT 16
23 #define CCI_OPTYPE(ci) ((ci)->flags >> CCI_OTSHIFT) /* Get op/type. */
24 #define CCI_OPSHIFT 24
25 #define CCI_OP(ci) ((ci)->flags >> CCI_OPSHIFT) /* Get op. */
27 #define CCI_CALL_N (IR_CALLN << CCI_OPSHIFT)
28 #define CCI_CALL_L (IR_CALLL << CCI_OPSHIFT)
29 #define CCI_CALL_S (IR_CALLS << CCI_OPSHIFT)
30 #define CCI_CALL_FN (CCI_CALL_N|CCI_FASTCALL)
31 #define CCI_CALL_FL (CCI_CALL_L|CCI_FASTCALL)
32 #define CCI_CALL_FS (CCI_CALL_S|CCI_FASTCALL)
34 /* C call info flags. */
35 #define CCI_L 0x0100 /* Implicit L arg. */
36 #define CCI_CASTU64 0x0200 /* Cast u64 result to number. */
37 #define CCI_NOFPRCLOBBER 0x0400 /* Does not clobber any FPRs. */
38 #define CCI_FASTCALL 0x0800 /* Fastcall convention. */
40 /* Function definitions for CALL* instructions. */
41 #if LJ_SOFTFP
42 #if LJ_HASFFI
43 #define IRCALLDEF_SOFTFP_FFI(_) \
44 _(softfp_ui2d, 1, N, NUM, 0) \
45 _(softfp_l2d, 2, N, NUM, 0) \
46 _(softfp_ul2d, 2, N, NUM, 0) \
47 _(softfp_f2d, 1, N, NUM, 0) \
48 _(softfp_d2ui, 2, N, INT, 0) \
49 _(softfp_d2l, 2, N, I64, 0) \
50 _(softfp_d2ul, 2, N, U64, 0) \
51 _(softfp_d2f, 2, N, FLOAT, 0) \
52 _(softfp_i2f, 1, N, FLOAT, 0) \
53 _(softfp_ui2f, 1, N, FLOAT, 0) \
54 _(softfp_l2f, 2, N, FLOAT, 0) \
55 _(softfp_ul2f, 2, N, FLOAT, 0) \
56 _(softfp_f2i, 1, N, INT, 0) \
57 _(softfp_f2ui, 1, N, INT, 0) \
58 _(softfp_f2l, 1, N, I64, 0) \
59 _(softfp_f2ul, 1, N, U64, 0)
60 #else
61 #define IRCALLDEF_SOFTFP_FFI(_)
62 #endif
63 #define IRCALLDEF_SOFTFP(_) \
64 _(lj_vm_tobit, 2, N, INT, 0) \
65 _(softfp_add, 4, N, NUM, 0) \
66 _(softfp_sub, 4, N, NUM, 0) \
67 _(softfp_mul, 4, N, NUM, 0) \
68 _(softfp_div, 4, N, NUM, 0) \
69 _(softfp_cmp, 4, N, NIL, 0) \
70 _(softfp_i2d, 1, N, NUM, 0) \
71 _(softfp_d2i, 2, N, INT, 0) \
72 IRCALLDEF_SOFTFP_FFI(_)
73 #else
74 #define IRCALLDEF_SOFTFP(_)
75 #endif
77 #if LJ_TARGET_X86ORX64
78 /* Use lj_vm_* helpers and x87 ops. */
79 #define IRCALLDEF_FPMATH(_)
80 #else
81 /* Use standard math library calls. */
82 #if LJ_SOFTFP
83 #define ARG1_FP 2 /* Treat as 2 32 bit arguments. */
84 #else
85 #define ARG1_FP 1
86 #endif
87 /* ORDER FPM */
88 #define IRCALLDEF_FPMATH(_) \
89 _(lj_vm_floor, ARG1_FP, N, NUM, 0) \
90 _(lj_vm_ceil, ARG1_FP, N, NUM, 0) \
91 _(lj_vm_trunc, ARG1_FP, N, NUM, 0) \
92 _(sqrt, ARG1_FP, N, NUM, 0) \
93 _(exp, ARG1_FP, N, NUM, 0) \
94 _(lj_vm_exp2, ARG1_FP, N, NUM, 0) \
95 _(log, ARG1_FP, N, NUM, 0) \
96 _(lj_vm_log2, ARG1_FP, N, NUM, 0) \
97 _(log10, ARG1_FP, N, NUM, 0) \
98 _(sin, ARG1_FP, N, NUM, 0) \
99 _(cos, ARG1_FP, N, NUM, 0) \
100 _(tan, ARG1_FP, N, NUM, 0) \
101 _(lj_vm_powi, ARG1_FP+1, N, NUM, 0) \
102 _(pow, ARG1_FP*2, N, NUM, 0) \
103 _(atan2, ARG1_FP*2, N, NUM, 0) \
104 _(ldexp, ARG1_FP+1, N, NUM, 0)
105 #endif
107 #if LJ_HASFFI
108 #if LJ_32
109 #define ARG2_64 4 /* Treat as 4 32 bit arguments. */
110 #define IRCALLDEF_FFI32(_) \
111 _(lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER)
112 #else
113 #define ARG2_64 2
114 #define IRCALLDEF_FFI32(_)
115 #endif
116 #define IRCALLDEF_FFI(_) \
117 IRCALLDEF_FFI32(_) \
118 _(lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
119 _(lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
120 _(lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
121 _(lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
122 _(lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
123 _(lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
124 _(lj_cdata_setfin, 2, FN, P32, CCI_L) \
125 _(strlen, 1, N, INTP, 0) \
126 _(memcpy, 3, S, PTR, 0) \
127 _(memset, 3, S, PTR, 0)
128 #else
129 #define IRCALLDEF_FFI(_)
130 #endif
132 #define IRCALLDEF(_) \
133 _(lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \
134 _(lj_str_new, 3, S, STR, CCI_L) \
135 _(lj_str_tonum, 2, FN, INT, 0) \
136 _(lj_str_fromint, 2, FN, STR, CCI_L) \
137 _(lj_str_fromnum, 2, FN, STR, CCI_L) \
138 _(lj_tab_new1, 2, FS, TAB, CCI_L) \
139 _(lj_tab_dup, 2, FS, TAB, CCI_L) \
140 _(lj_tab_newkey, 3, S, P32, CCI_L) \
141 _(lj_tab_len, 1, FL, INT, 0) \
142 _(lj_gc_step_jit, 2, FS, NIL, CCI_L) \
143 _(lj_gc_barrieruv, 2, FS, NIL, 0) \
144 _(lj_mem_newgco, 2, FS, P32, CCI_L) \
145 _(lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \
146 IRCALLDEF_SOFTFP(_) \
147 IRCALLDEF_FPMATH(_) \
148 IRCALLDEF_FFI(_) \
149 _(sinh, 1, N, NUM, 0) \
150 _(cosh, 1, N, NUM, 0) \
151 _(tanh, 1, N, NUM, 0) \
152 _(fputc, 2, S, INT, 0) \
153 _(fwrite, 4, S, INT, 0) \
154 _(fflush, 1, S, INT, 0) \
156 /* End of list. */
158 typedef enum {
159 #define IRCALLENUM(name, nargs, kind, type, flags) IRCALL_##name,
160 IRCALLDEF(IRCALLENUM)
161 #undef IRCALLENUM
162 IRCALL__MAX
163 } IRCallID;
165 LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);
167 LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
169 /* Soft-float declarations. */
170 #if LJ_SOFTFP
171 #if LJ_TARGET_ARM
172 #define softfp_add __aeabi_dadd
173 #define softfp_sub __aeabi_dsub
174 #define softfp_mul __aeabi_dmul
175 #define softfp_div __aeabi_ddiv
176 #define softfp_cmp __aeabi_cdcmple
177 #define softfp_i2d __aeabi_i2d
178 #define softfp_ui2d __aeabi_ui2d
179 #define softfp_l2d __aeabi_l2d
180 #define softfp_ul2d __aeabi_ul2d
181 #define softfp_f2d __aeabi_f2d
182 #define softfp_d2i __aeabi_d2iz
183 #define softfp_d2ui __aeabi_d2uiz
184 #define softfp_d2l __aeabi_d2lz
185 #define softfp_d2ul __aeabi_d2ulz
186 #define softfp_d2f __aeabi_d2f
187 #define softfp_i2f __aeabi_i2f
188 #define softfp_ui2f __aeabi_ui2f
189 #define softfp_l2f __aeabi_l2f
190 #define softfp_ul2f __aeabi_ul2f
191 #define softfp_f2i __aeabi_f2iz
192 #define softfp_f2ui __aeabi_f2uiz
193 #define softfp_f2l __aeabi_f2lz
194 #define softfp_f2ul __aeabi_f2ulz
195 #else
196 #error "Missing soft-float definitions for target architecture"
197 #endif
198 extern double softfp_add(double a, double b);
199 extern double softfp_sub(double a, double b);
200 extern double softfp_mul(double a, double b);
201 extern double softfp_div(double a, double b);
202 extern void softfp_cmp(double a, double b);
203 extern double softfp_i2d(int32_t a);
204 extern double softfp_ui2d(uint32_t a);
205 extern double softfp_l2d(int64_t a);
206 extern double softfp_ul2d(uint64_t a);
207 extern double softfp_f2d(float a);
208 extern int32_t softfp_d2i(double a);
209 extern uint32_t softfp_d2ui(double a);
210 extern int64_t softfp_d2l(double a);
211 extern uint64_t softfp_d2ul(double a);
212 extern float softfp_d2f(double a);
213 extern float softfp_i2f(int32_t a);
214 extern float softfp_ui2f(uint32_t a);
215 extern float softfp_l2f(int64_t a);
216 extern float softfp_ul2f(uint64_t a);
217 extern int32_t softfp_f2i(float a);
218 extern uint32_t softfp_f2ui(float a);
219 extern int64_t softfp_f2l(float a);
220 extern uint64_t softfp_f2ul(float a);
221 #endif
223 #endif