diff options
author | Mike Pall <mike> | 2009-12-08 19:46:35 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-08 19:46:35 +0100 |
commit | 55b16959717084884fd4a0cbae6d19e3786c20c7 (patch) | |
tree | c8a07a43c13679751ed25a9d06796e9e7b2134a6 /src/lj_dispatch.h | |
download | luajit-2.0.0-beta1.tar.gz luajit-2.0.0-beta1.tar.bz2 luajit-2.0.0-beta1.zip |
RELEASE LuaJIT-2.0.0-beta1v2.0.0-beta1
Diffstat (limited to 'src/lj_dispatch.h')
-rw-r--r-- | src/lj_dispatch.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h new file mode 100644 index 00000000..298aa166 --- /dev/null +++ b/src/lj_dispatch.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | ** Instruction dispatch handling. | ||
3 | ** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_DISPATCH_H | ||
7 | #define _LJ_DISPATCH_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | #include "lj_bc.h" | ||
11 | #if LJ_HASJIT | ||
12 | #include "lj_jit.h" | ||
13 | #endif | ||
14 | |||
15 | /* Type of hot counter. Must match the code in the assembler VM. */ | ||
16 | /* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */ | ||
17 | typedef uint16_t HotCount; | ||
18 | |||
19 | /* Number of hot counter hash table entries (must be a power of two). */ | ||
20 | #define HOTCOUNT_SIZE 64 | ||
21 | #define HOTCOUNT_PCMASK ((HOTCOUNT_SIZE-1)*sizeof(HotCount)) | ||
22 | #define HOTCOUNT_MIN_PENALTY 103 | ||
23 | #define HOTCOUNT_MAX_PENALTY 60000 | ||
24 | |||
25 | /* Global state, main thread and extra fields are allocated together. */ | ||
26 | typedef struct GG_State { | ||
27 | lua_State L; /* Main thread. */ | ||
28 | global_State g; /* Global state. */ | ||
29 | #if LJ_HASJIT | ||
30 | jit_State J; /* JIT state. */ | ||
31 | HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */ | ||
32 | #endif | ||
33 | ASMFunction dispatch[2*BC__MAX]; /* Instruction dispatch tables. */ | ||
34 | } GG_State; | ||
35 | |||
36 | #define GG_DISP_STATIC BC__MAX | ||
37 | |||
38 | #define GG_OFS(field) ((int)offsetof(GG_State, field)) | ||
39 | #define G2GG(gl) \ | ||
40 | ((GG_State *)(((char *)(gl))-((char *)(&((GG_State *)0)->g)))) | ||
41 | #define J2GG(j) \ | ||
42 | ((GG_State *)(((char *)(j))-((char *)(&((GG_State *)0)->J)))) | ||
43 | #define L2GG(L) G2GG(G(L)) | ||
44 | #define J2G(J) (&J2GG(J)->g) | ||
45 | #define G2J(gl) (&G2GG(gl)->J) | ||
46 | #define L2J(L) (&L2GG(L)->J) | ||
47 | #define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g)) | ||
48 | #define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch)) | ||
49 | #define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch)) | ||
50 | #define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch)) | ||
51 | |||
52 | #define hotcount_get(gg, pc) \ | ||
53 | (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)] | ||
54 | #define hotcount_set(gg, pc, val) \ | ||
55 | (hotcount_get((gg), (pc)) = (HotCount)(val)) | ||
56 | |||
57 | /* Dispatch table management. */ | ||
58 | LJ_FUNC void lj_dispatch_init(GG_State *GG); | ||
59 | LJ_FUNC void lj_dispatch_update(global_State *g); | ||
60 | |||
61 | /* Instruction dispatch callback for instr/line hooks or when recording. */ | ||
62 | LJ_FUNCA void lj_dispatch_ins(lua_State *L, const BCIns *pc, uint32_t nres); | ||
63 | |||
64 | #endif | ||