summaryrefslogtreecommitdiff
path: root/src/lj_ircall.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_ircall.h')
-rw-r--r--src/lj_ircall.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/lj_ircall.h b/src/lj_ircall.h
new file mode 100644
index 00000000..3131b15d
--- /dev/null
+++ b/src/lj_ircall.h
@@ -0,0 +1,100 @@
1/*
2** IR CALL* instruction definitions.
3** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
4*/
5
6#ifndef _LJ_IRCALL_H
7#define _LJ_IRCALL_H
8
9#include "lj_obj.h"
10#include "lj_ir.h"
11#include "lj_jit.h"
12
13/* C call info for CALL* instructions. */
14typedef struct CCallInfo {
15 ASMFunction func; /* Function pointer. */
16 uint32_t flags; /* Number of arguments and flags. */
17} CCallInfo;
18
19#define CCI_NARGS(ci) ((ci)->flags & 0xff) /* Extract # of args. */
20#define CCI_NARGS_MAX 32 /* Max. # of args. */
21
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. */
26
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)
33
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. */
39
40/* Function definitions for CALL* instructions. */
41#if LJ_HASFFI
42#if LJ_32
43#define ARG2_64 4 /* Treat as 4 32 bit arguments. */
44#define IRCALLDEF_FFI32(_) \
45 _(lj_carith_mul64, ARG2_64, N, I64, CCI_NOFPRCLOBBER)
46#else
47#define ARG2_64 2
48#define IRCALLDEF_FFI32(_)
49#endif
50#define IRCALLDEF_FFI(_) \
51 IRCALLDEF_FFI32(_) \
52 _(lj_carith_divi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
53 _(lj_carith_divu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
54 _(lj_carith_modi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
55 _(lj_carith_modu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
56 _(lj_carith_powi64, ARG2_64, N, I64, CCI_NOFPRCLOBBER) \
57 _(lj_carith_powu64, ARG2_64, N, U64, CCI_NOFPRCLOBBER) \
58 _(lj_cdata_setfin, 2, FN, P32, CCI_L) \
59 _(strlen, 1, N, INTP, 0) \
60 _(memcpy, 3, S, PTR, 0) \
61 _(memset, 3, S, PTR, 0)
62#else
63#define IRCALLDEF_FFI(_)
64#endif
65#define IRCALLDEF(_) \
66 _(lj_str_cmp, 2, FN, INT, CCI_NOFPRCLOBBER) \
67 _(lj_str_new, 3, S, STR, CCI_L) \
68 _(lj_str_tonum, 2, FN, INT, 0) \
69 _(lj_str_fromint, 2, FN, STR, CCI_L) \
70 _(lj_str_fromnum, 2, FN, STR, CCI_L) \
71 _(lj_tab_new1, 2, FS, TAB, CCI_L) \
72 _(lj_tab_dup, 2, FS, TAB, CCI_L) \
73 _(lj_tab_newkey, 3, S, P32, CCI_L) \
74 _(lj_tab_len, 1, FL, INT, 0) \
75 _(lj_gc_step_jit, 2, FS, NIL, CCI_L) \
76 _(lj_gc_barrieruv, 2, FS, NIL, 0) \
77 _(lj_mem_newgco, 2, FS, P32, CCI_L) \
78 _(lj_math_random_step, 1, FS, NUM, CCI_CASTU64|CCI_NOFPRCLOBBER) \
79 IRCALLDEF_FFI(_) \
80 _(sinh, 1, N, NUM, 0) \
81 _(cosh, 1, N, NUM, 0) \
82 _(tanh, 1, N, NUM, 0) \
83 _(fputc, 2, S, INT, 0) \
84 _(fwrite, 4, S, INT, 0) \
85 _(fflush, 1, S, INT, 0) \
86 \
87 /* End of list. */
88
89typedef enum {
90#define IRCALLENUM(name, nargs, kind, type, flags) IRCALL_##name,
91IRCALLDEF(IRCALLENUM)
92#undef IRCALLENUM
93 IRCALL__MAX
94} IRCallID;
95
96LJ_FUNC TRef lj_ir_call(jit_State *J, IRCallID id, ...);
97
98LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
99
100#endif