aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/luajit-2.0/src/lj_dispatch.h
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-23 23:36:30 +1000
committerDavid Walter Seikel2012-01-23 23:36:30 +1000
commit6523585c66c04cea54df50013df8886b589847d8 (patch)
tree0b22aee7064166d88595eda260ca2d17c0773da5 /libraries/luajit-2.0/src/lj_dispatch.h
parentUpdate the EFL to what I'm actually using, coz I'm using some stuff not yet r... (diff)
downloadSledjHamr-6523585c66c04cea54df50013df8886b589847d8.zip
SledjHamr-6523585c66c04cea54df50013df8886b589847d8.tar.gz
SledjHamr-6523585c66c04cea54df50013df8886b589847d8.tar.bz2
SledjHamr-6523585c66c04cea54df50013df8886b589847d8.tar.xz
Add luaproc and LuaJIT libraries.
Two versions of LuaJIT, the stable release, and the dev version. Try the dev version first, until ih fails badly.
Diffstat (limited to 'libraries/luajit-2.0/src/lj_dispatch.h')
-rw-r--r--libraries/luajit-2.0/src/lj_dispatch.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/libraries/luajit-2.0/src/lj_dispatch.h b/libraries/luajit-2.0/src/lj_dispatch.h
new file mode 100644
index 0000000..c50d33a
--- /dev/null
+++ b/libraries/luajit-2.0/src/lj_dispatch.h
@@ -0,0 +1,93 @@
1/*
2** Instruction dispatch handling.
3** Copyright (C) 2005-2011 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
23/* Hotcount decrements. */
24#define HOTCOUNT_LOOP 2
25#define HOTCOUNT_CALL 1
26
27/* This solves a circular dependency problem -- bump as needed. Sigh. */
28#define GG_NUM_ASMFF 62
29
30#define GG_LEN_DDISP (BC__MAX + GG_NUM_ASMFF)
31#define GG_LEN_SDISP BC_FUNCF
32#define GG_LEN_DISP (GG_LEN_DDISP + GG_LEN_SDISP)
33
34/* Global state, main thread and extra fields are allocated together. */
35typedef struct GG_State {
36 lua_State L; /* Main thread. */
37 global_State g; /* Global state. */
38#if LJ_HASJIT
39 jit_State J; /* JIT state. */
40 HotCount hotcount[HOTCOUNT_SIZE]; /* Hot counters. */
41#endif
42 ASMFunction dispatch[GG_LEN_DISP]; /* Instruction dispatch tables. */
43 BCIns bcff[GG_NUM_ASMFF]; /* Bytecode for ASM fast functions. */
44} GG_State;
45
46#define GG_OFS(field) ((int)offsetof(GG_State, field))
47#define G2GG(gl) ((GG_State *)((char *)(gl) - GG_OFS(g)))
48#define J2GG(j) ((GG_State *)((char *)(j) - GG_OFS(J)))
49#define L2GG(L) (G2GG(G(L)))
50#define J2G(J) (&J2GG(J)->g)
51#define G2J(gl) (&G2GG(gl)->J)
52#define L2J(L) (&L2GG(L)->J)
53#define GG_G2DISP (GG_OFS(dispatch) - GG_OFS(g))
54#define GG_DISP2G (GG_OFS(g) - GG_OFS(dispatch))
55#define GG_DISP2J (GG_OFS(J) - GG_OFS(dispatch))
56#define GG_DISP2HOT (GG_OFS(hotcount) - GG_OFS(dispatch))
57#define GG_DISP2STATIC (GG_LEN_DDISP*(int)sizeof(ASMFunction))
58
59#define hotcount_get(gg, pc) \
60 (gg)->hotcount[(u32ptr(pc)>>2) & (HOTCOUNT_SIZE-1)]
61#define hotcount_set(gg, pc, val) \
62 (hotcount_get((gg), (pc)) = (HotCount)(val))
63
64/* Dispatch table management. */
65LJ_FUNC void lj_dispatch_init(GG_State *GG);
66#if LJ_HASJIT
67LJ_FUNC void lj_dispatch_init_hotcount(global_State *g);
68#endif
69LJ_FUNC void lj_dispatch_update(global_State *g);
70
71/* Instruction dispatch callback for hooks or when recording. */
72LJ_FUNCA void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc);
73LJ_FUNCA ASMFunction LJ_FASTCALL lj_dispatch_call(lua_State *L, const BCIns*pc);
74LJ_FUNCA void LJ_FASTCALL lj_dispatch_return(lua_State *L, const BCIns *pc);
75
76#if LJ_HASFFI && !defined(_BUILDVM_H)
77/* Save/restore errno and GetLastError() around hooks, exits and recording. */
78#include <errno.h>
79#if LJ_TARGET_WINDOWS
80#define WIN32_LEAN_AND_MEAN
81#include <windows.h>
82#define ERRNO_SAVE int olderr = errno; DWORD oldwerr = GetLastError();
83#define ERRNO_RESTORE errno = olderr; SetLastError(oldwerr);
84#else
85#define ERRNO_SAVE int olderr = errno;
86#define ERRNO_RESTORE errno = olderr;
87#endif
88#else
89#define ERRNO_SAVE
90#define ERRNO_RESTORE
91#endif
92
93#endif