diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-08 21:19:22 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-08 21:19:22 -0300 |
| commit | 88b306f495fa7034c708c6b75a355a6deee51c58 (patch) | |
| tree | 7d8faaacd1f5c753ed9e77f0e2c8e27b9a002635 /lopcodes.h | |
| parent | 563de491be90601f23a735aede89ea9a3ef86ee9 (diff) | |
| download | lua-88b306f495fa7034c708c6b75a355a6deee51c58.tar.gz lua-88b306f495fa7034c708c6b75a355a6deee51c58.tar.bz2 lua-88b306f495fa7034c708c6b75a355a6deee51c58.zip | |
some optimizations
Diffstat (limited to 'lopcodes.h')
| -rw-r--r-- | lopcodes.h | 57 |
1 files changed, 37 insertions, 20 deletions
| @@ -24,34 +24,51 @@ | |||
| 24 | is the usigned value minus 2^23. | 24 | is the usigned value minus 2^23. |
| 25 | ===========================================================================*/ | 25 | ===========================================================================*/ |
| 26 | 26 | ||
| 27 | #define EXCESS_S (1<<23) /* == 2^23 */ | 27 | #define SIZE_OP 8 |
| 28 | #define SIZE_U 24 | ||
| 29 | #define POS_U 8 | ||
| 30 | #define SIZE_S 24 | ||
| 31 | #define POS_S 8 | ||
| 32 | #define SIZE_A 16 | ||
| 33 | #define POS_A 16 | ||
| 34 | #define SIZE_B 8 | ||
| 35 | #define POS_B 8 | ||
| 36 | |||
| 37 | #define EXCESS_S (1<<(SIZE_S-1)) /* == 2^23 */ | ||
| 38 | |||
| 39 | |||
| 40 | /* creates a mask with `n' 1 bits at position `p' */ | ||
| 41 | #define MASK1(n,p) ((~((~0ul)<<n))<<p) | ||
| 42 | |||
| 43 | /* creates a mask with `n' 0 bits at position `p' */ | ||
| 44 | #define MASK0(n,p) (~MASK1(n,p)) | ||
| 28 | 45 | ||
| 29 | /* | 46 | /* |
| 30 | ** the following macros help to manipulate instructions | 47 | ** the following macros help to manipulate instructions |
| 31 | */ | 48 | */ |
| 32 | 49 | ||
| 33 | #define MAXARG_U ((1<<24)-1) | 50 | #define MAXARG_U ((1<<SIZE_U)-1) |
| 34 | #define MAXARG_S ((1<<23)-1) | 51 | #define MAXARG_S ((1<<(SIZE_S-1))-1) /* `S' is signed */ |
| 35 | #define MAXARG_A ((1<<16)-1) | 52 | #define MAXARG_A ((1<<SIZE_A)-1) |
| 36 | #define MAXARG_B ((1<<8)-1) | 53 | #define MAXARG_B ((1<<SIZE_B)-1) |
| 37 | 54 | ||
| 38 | #define GET_OPCODE(i) ((OpCode)((i)&0xFF)) | 55 | #define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) |
| 39 | #define GETARG_U(i) ((int)((i)>>8)) | 56 | #define GETARG_U(i) ((int)((i)>>POS_U)) |
| 40 | #define GETARG_S(i) ((int)((i)>>8)-EXCESS_S) | 57 | #define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S) |
| 41 | #define GETARG_A(i) ((int)((i)>>16)) | 58 | #define GETARG_A(i) ((int)((i)>>POS_A)) |
| 42 | #define GETARG_B(i) ((int)(((i)>>8) & 0xFF)) | 59 | #define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0))) |
| 43 | 60 | ||
| 44 | #define SET_OPCODE(i,o) (((i)&0xFFFFFF00u) | (Instruction)(o)) | 61 | #define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)) |
| 45 | #define SETARG_U(i,u) (((i)&0x000000FFu) | ((Instruction)(u)<<8)) | 62 | #define SETARG_U(i,u) (((i)&MASK0(SIZE_U,POS_U)) | ((Instruction)(u)<<POS_U)) |
| 46 | #define SETARG_S(i,s) (((i)&0x000000FFu) | ((Instruction)((s)+EXCESS_S)<<8)) | 63 | #define SETARG_S(i,s) (((i)&MASK0(SIZE_S,POS_S)) | ((Instruction)((s)+EXCESS_S)<<POS_S)) |
| 47 | #define SETARG_A(i,a) (((i)&0x0000FFFFu) | ((Instruction)(a)<<16)) | 64 | #define SETARG_A(i,a) (((i)&MASK0(SIZE_A,POS_A)) | ((Instruction)(a)<<POS_A)) |
| 48 | #define SETARG_B(i,b) (((i)&0xFFFF00FFu) | ((Instruction)(b)<<8)) | 65 | #define SETARG_B(i,b) (((i)&MASK0(SIZE_B,POS_B)) | ((Instruction)(b)<<POS_B)) |
| 49 | 66 | ||
| 50 | #define CREATE_0(o) ((Instruction)(o)) | 67 | #define CREATE_0(o) ((Instruction)(o)) |
| 51 | #define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<8) | 68 | #define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<POS_U) |
| 52 | #define CREATE_S(o,s) ((Instruction)(o) | ((Instruction)(s)+EXCESS_S)<<8) | 69 | #define CREATE_S(o,s) ((Instruction)(o) | ((Instruction)(s)+EXCESS_S)<<POS_S) |
| 53 | #define CREATE_AB(o,a,b) ((Instruction)(o) | ((Instruction)(a)<<16) \ | 70 | #define CREATE_AB(o,a,b) ((Instruction)(o) | ((Instruction)(a)<<POS_A) \ |
| 54 | | ((Instruction)(b)<<8)) | 71 | | ((Instruction)(b)<<POS_B)) |
| 55 | 72 | ||
| 56 | 73 | ||
| 57 | /* | 74 | /* |
| @@ -111,7 +128,7 @@ SUBOP,/* - y x x-y */ | |||
| 111 | MULTOP,/* - y x x*y */ | 128 | MULTOP,/* - y x x*y */ |
| 112 | DIVOP,/* - y x x/y */ | 129 | DIVOP,/* - y x x/y */ |
| 113 | POWOP,/* - y x x^y */ | 130 | POWOP,/* - y x x^y */ |
| 114 | CONCOP,/* - y x x..y */ | 131 | CONCOP,/* U v_u-v_1 v1..-..v_u */ |
| 115 | MINUSOP,/* - x -x */ | 132 | MINUSOP,/* - x -x */ |
| 116 | NOTOP,/* - x (x==nil)? 1 : nil */ | 133 | NOTOP,/* - x (x==nil)? 1 : nil */ |
| 117 | 134 | ||
