summaryrefslogtreecommitdiff
path: root/src/lj_dispatch.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_dispatch.h')
-rw-r--r--src/lj_dispatch.h64
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. */
17typedef 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. */
26typedef 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. */
58LJ_FUNC void lj_dispatch_init(GG_State *GG);
59LJ_FUNC void lj_dispatch_update(global_State *g);
60
61/* Instruction dispatch callback for instr/line hooks or when recording. */
62LJ_FUNCA void lj_dispatch_ins(lua_State *L, const BCIns *pc, uint32_t nres);
63
64#endif