Igor's patch for simpler extended atom indexing (365608, tweaks and r=me).
This commit is contained in:
@@ -84,9 +84,8 @@ typedef enum JSOpLength {
|
||||
#define JOF_TABLESWITCHX 10 /* extended (32-bit offset) table switch */
|
||||
#define JOF_LOOKUPSWITCHX 11 /* extended (32-bit offset) lookup switch */
|
||||
#define JOF_UINT24 12 /* extended unsigned 24-bit literal (index) */
|
||||
#define JOF_LITOPX 13 /* JOF_UINT24 followed by op being extended,
|
||||
where op if JOF_CONST has no unsigned 16-
|
||||
bit immediate operand */
|
||||
#define JOF_2BYTE 13 /* 2-byte opcode, e.g., upper 8 bits of 24-bit
|
||||
atom index */
|
||||
#define JOF_LOCAL 14 /* block-local operand stack variable */
|
||||
#define JOF_TYPEMASK 0x000f /* mask for above immediate types */
|
||||
#define JOF_NAME 0x0010 /* name operation */
|
||||
@@ -109,6 +108,7 @@ typedef enum JSOpLength {
|
||||
#define JOF_BACKPATCH 0x8000 /* backpatch placeholder during codegen */
|
||||
#define JOF_LEFTASSOC 0x10000 /* left-associative operator */
|
||||
#define JOF_DECLARING 0x20000 /* var, const, or function declaration op */
|
||||
#define JOF_ATOMBASE 0x40000 /* atom segment base setting prefix op */
|
||||
|
||||
#define JOF_TYPE_IS_EXTENDED_JUMP(t) \
|
||||
((unsigned)((t) - JOF_JUMPX) <= (unsigned)(JOF_LOOKUPSWITCHX - JOF_JUMPX))
|
||||
@@ -117,11 +117,19 @@ typedef enum JSOpLength {
|
||||
* Immediate operand getters, setters, and bounds.
|
||||
*/
|
||||
|
||||
/* Common uint16 immediate format helpers. */
|
||||
#define UINT16_LEN 2
|
||||
#define UINT16_HI(i) ((jsbytecode)((i) >> 8))
|
||||
#define UINT16_LO(i) ((jsbytecode)(i))
|
||||
#define GET_UINT16(pc) ((uintN)(((pc)[1] << 8) | (pc)[2]))
|
||||
#define SET_UINT16(pc,i) ((pc)[1] = UINT16_HI(i), (pc)[2] = UINT16_LO(i))
|
||||
#define UINT16_LIMIT ((uintN)1 << 16)
|
||||
|
||||
/* Short (2-byte signed offset) relative jump macros. */
|
||||
#define JUMP_OFFSET_LEN 2
|
||||
#define JUMP_OFFSET_HI(off) ((jsbytecode)((off) >> 8))
|
||||
#define JUMP_OFFSET_LO(off) ((jsbytecode)(off))
|
||||
#define GET_JUMP_OFFSET(pc) ((int16)(((pc)[1] << 8) | (pc)[2]))
|
||||
#define GET_JUMP_OFFSET(pc) ((int16)GET_UINT16(pc))
|
||||
#define SET_JUMP_OFFSET(pc,off) ((pc)[1] = JUMP_OFFSET_HI(off), \
|
||||
(pc)[2] = JUMP_OFFSET_LO(off))
|
||||
#define JUMP_OFFSET_MIN ((int16)0x8000)
|
||||
@@ -138,7 +146,7 @@ typedef enum JSOpLength {
|
||||
* found (via binary search) by its "before span-dependency optimization" pc
|
||||
* offset (from script main entry point).
|
||||
*/
|
||||
#define GET_SPANDEP_INDEX(pc) ((uint16)(((pc)[1] << 8) | (pc)[2]))
|
||||
#define GET_SPANDEP_INDEX(pc) ((uint16)GET_UINT16(pc))
|
||||
#define SET_SPANDEP_INDEX(pc,i) ((pc)[1] = JUMP_OFFSET_HI(i), \
|
||||
(pc)[2] = JUMP_OFFSET_LO(i))
|
||||
#define SPANDEP_INDEX_MAX ((uint16)0xfffe)
|
||||
@@ -162,18 +170,20 @@ typedef enum JSOpLength {
|
||||
/*
|
||||
* A literal is indexed by a per-script atom map. Most scripts have relatively
|
||||
* few literals, so the standard JOF_CONST format specifies a fixed 16 bits of
|
||||
* immediate operand index. A script with more than 64K literals must push all
|
||||
* high-indexed literals on the stack using JSOP_LITERAL, then use JOF_ELEM ops
|
||||
* instead of JOF_PROP, etc.
|
||||
* immediate operand index. A script with more than 64K literals must wrap the
|
||||
* bytecode into JSOP_ATOMBASE and JSOP_RESETBASE pair.
|
||||
*/
|
||||
#define ATOM_INDEX_LEN 2
|
||||
#define ATOM_INDEX_HI(i) ((jsbytecode)((i) >> 8))
|
||||
#define ATOM_INDEX_LO(i) ((jsbytecode)(i))
|
||||
#define GET_ATOM_INDEX(pc) ((jsatomid)(((pc)[1] << 8) | (pc)[2]))
|
||||
#define GET_ATOM_INDEX(pc) GET_UINT16(pc)
|
||||
#define SET_ATOM_INDEX(pc,i) ((pc)[1] = ATOM_INDEX_HI(i), \
|
||||
(pc)[2] = ATOM_INDEX_LO(i))
|
||||
#define GET_ATOM(cx,script,pc) js_GetAtom((cx), &(script)->atomMap, \
|
||||
GET_ATOM_INDEX(pc))
|
||||
#define GET_ATOM(cx,atoms,pc) ((atoms)[GET_ATOM_INDEX(pc)])
|
||||
|
||||
#define GET_ATOMBASE(pc) (JS_ASSERT(*(pc) == JSOP_ATOMBASE), \
|
||||
((uintN)((pc)[1])) << 16)
|
||||
#define ATOMBASE_LEN 1
|
||||
|
||||
/* A full atom index for JSOP_UINT24 uses 24 bits of immediate operand. */
|
||||
#define UINT24_HI(i) ((jsbytecode)((i) >> 16))
|
||||
@@ -186,14 +196,6 @@ typedef enum JSOpLength {
|
||||
(pc)[2] = UINT24_MID(i), \
|
||||
(pc)[3] = UINT24_LO(i))
|
||||
|
||||
/* Same format for JSOP_LITERAL, etc., but future-proof with different names. */
|
||||
#define LITERAL_INDEX_LEN 3
|
||||
#define LITERAL_INDEX_HI(i) UINT24_HI(i)
|
||||
#define LITERAL_INDEX_MID(i) UINT24_MID(i)
|
||||
#define LITERAL_INDEX_LO(i) UINT24_LO(i)
|
||||
#define GET_LITERAL_INDEX(pc) GET_UINT24(pc)
|
||||
#define SET_LITERAL_INDEX(pc,i) SET_UINT24(pc,i)
|
||||
|
||||
/* Atom index limit is determined by SN_3BYTE_OFFSET_FLAG, see jsemit.h. */
|
||||
#define ATOM_INDEX_LIMIT_LOG2 23
|
||||
#define ATOM_INDEX_LIMIT ((uint32)1 << ATOM_INDEX_LIMIT_LOG2)
|
||||
@@ -201,13 +203,6 @@ typedef enum JSOpLength {
|
||||
JS_STATIC_ASSERT(sizeof(jsatomid) * JS_BITS_PER_BYTE >=
|
||||
ATOM_INDEX_LIMIT_LOG2 + 1);
|
||||
|
||||
/* Common uint16 immediate format helpers. */
|
||||
#define UINT16_HI(i) ((jsbytecode)((i) >> 8))
|
||||
#define UINT16_LO(i) ((jsbytecode)(i))
|
||||
#define GET_UINT16(pc) ((uintN)(((pc)[1] << 8) | (pc)[2]))
|
||||
#define SET_UINT16(pc,i) ((pc)[1] = UINT16_HI(i), (pc)[2] = UINT16_LO(i))
|
||||
#define UINT16_LIMIT ((uintN)1 << 16)
|
||||
|
||||
/* Actual argument count operand format helpers. */
|
||||
#define ARGC_HI(argc) UINT16_HI(argc)
|
||||
#define ARGC_LO(argc) UINT16_LO(argc)
|
||||
@@ -267,6 +262,14 @@ js_printf(JSPrinter *jp, const char *format, ...);
|
||||
extern JSBool
|
||||
js_puts(JSPrinter *jp, const char *s);
|
||||
|
||||
/*
|
||||
* A slower version of GET_ATOM when the caller does not want to maintain
|
||||
* atoms table offset itself.
|
||||
*/
|
||||
extern JSAtom*
|
||||
js_GetAtomFromBytecode(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
ptrdiff_t pcoff);
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* Disassemblers, for debugging only.
|
||||
|
||||
Reference in New Issue
Block a user