Remove `OP_EXT[123]` from operands.

parent ce7508e0
...@@ -20,14 +20,6 @@ sign) of operands. ...@@ -20,14 +20,6 @@ sign) of operands.
* sS: signed 16bit * sS: signed 16bit
* W: 24bit * W: 24bit
First two byte operands may be extended to 16bit. When those byte
operands are bigger than 256, the instruction will be prefixed by
`OP_EXT1` (means 1st operand is 16bit) or `OP_EXT2` (means 2nd operand
is 16bit) or `OP_EXT3` (means 1st and 2nd operands are 16bit).
For instructions marked by `'`, `OP_EXT1` can be prefixed. For those
with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
## table.1 Instruction Table ## table.1 Instruction Table
| Instruction Name | Operand type | Semantics | | Instruction Name | Operand type | Semantics |
...@@ -133,8 +125,5 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed. ...@@ -133,8 +125,5 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
| OP_TCLASS' | B | R(a) = target_class | | OP_TCLASS' | B | R(a) = target_class |
| OP_DEBUG" | BBB | print a,b,c | | OP_DEBUG" | BBB | print a,b,c |
| OP_ERR' | B | raise(LocalJumpError, Lit(a)) | | OP_ERR' | B | raise(LocalJumpError, Lit(a)) |
| OP_EXT1 | - | make 1st operand 16bit |
| OP_EXT2 | - | make 2nd operand 16bit |
| OP_EXT3 | - | make 1st and 2nd operands 16bit |
| OP_STOP | - | stop VM | | OP_STOP | - | stop VM |
|------------------|--------------|--------------------------------------------------------| |------------------|--------------|--------------------------------------------------------|
...@@ -39,31 +39,4 @@ enum mrb_insn { ...@@ -39,31 +39,4 @@ enum mrb_insn {
#define FETCH_S() do {a=READ_S();} while (0) #define FETCH_S() do {a=READ_S();} while (0)
#define FETCH_W() do {a=READ_W();} while (0) #define FETCH_W() do {a=READ_W();} while (0)
/* with OP_EXT1 (1st 16bit) */
#define FETCH_Z_1() FETCH_Z()
#define FETCH_B_1() FETCH_S()
#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0)
#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_1() FETCH_S()
#define FETCH_W_1() FETCH_W()
/* with OP_EXT2 (2nd 16bit) */
#define FETCH_Z_2() FETCH_Z()
#define FETCH_B_2() FETCH_B()
#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0)
#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_2() FETCH_BS()
#define FETCH_S_2() FETCH_S()
#define FETCH_W_2() FETCH_W()
/* with OP_EXT3 (1st & 2nd 16bit) */
#define FETCH_Z_3() FETCH_Z()
#define FETCH_B_3() FETCH_B()
#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_3() FETCH_S()
#define FETCH_W_3() FETCH_W()
#endif /* MRUBY_OPCODE_H */ #endif /* MRUBY_OPCODE_H */
...@@ -111,8 +111,5 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */ ...@@ -111,8 +111,5 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */
OPCODE(TCLASS, B) /* R(a) = target_class */ OPCODE(TCLASS, B) /* R(a) = target_class */
OPCODE(DEBUG, BBB) /* print a,b,c */ OPCODE(DEBUG, BBB) /* print a,b,c */
OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */ OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */
OPCODE(EXT1, Z) /* make 1st operand 16bit */
OPCODE(EXT2, Z) /* make 2nd operand 16bit */
OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */
OPCODE(STOP, Z) /* stop VM */ OPCODE(STOP, Z) /* stop VM */
OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */ OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */
...@@ -217,9 +217,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a) ...@@ -217,9 +217,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a)
{ {
s->lastpc = s->pc; s->lastpc = s->pc;
if (a > 0xff) { if (a > 0xff) {
gen_B(s, OP_EXT1); codegen_error(s, "too big operand");
gen_B(s, i);
gen_S(s, a);
} }
else { else {
gen_B(s, i); gen_B(s, i);
...@@ -231,23 +229,8 @@ static void ...@@ -231,23 +229,8 @@ static void
genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b) genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b)
{ {
s->lastpc = s->pc; s->lastpc = s->pc;
if (a > 0xff && b > 0xff) { if (a > 0xff || b > 0xff) {
gen_B(s, OP_EXT3); codegen_error(s, "too big operand");
gen_B(s, i);
gen_S(s, a);
gen_S(s, b);
}
else if (b > 0xff) {
gen_B(s, OP_EXT2);
gen_B(s, i);
gen_B(s, (uint8_t)a);
gen_S(s, b);
}
else if (a > 0xff) {
gen_B(s, OP_EXT1);
gen_B(s, i);
gen_S(s, a);
gen_B(s, (uint8_t)b);
} }
else { else {
gen_B(s, i); gen_B(s, i);
...@@ -309,32 +292,6 @@ mrb_decode_insn(const mrb_code *pc) ...@@ -309,32 +292,6 @@ mrb_decode_insn(const mrb_code *pc)
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break; #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break;
#include "mruby/ops.h" #include "mruby/ops.h"
#undef OPCODE #undef OPCODE
}
switch (insn) {
case OP_EXT1:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
case OP_EXT2:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
case OP_EXT3:
insn = READ_B();
switch (insn) {
#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break;
#include "mruby/ops.h"
#undef OPCODE
}
break;
default: default:
break; break;
} }
...@@ -391,11 +348,8 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val) ...@@ -391,11 +348,8 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val)
s->lastpc = s->pc; s->lastpc = s->pc;
if (a > 0xff) { if (a > 0xff) {
gen_B(s, OP_EXT1); codegen_error(s, "too big operand");
gen_B(s, i); pos = 0;
gen_S(s, a);
pos = s->pc;
gen_S(s, pc);
} }
else { else {
gen_B(s, i); gen_B(s, i);
...@@ -3314,35 +3268,3 @@ uint8_t mrb_insn_size[] = { ...@@ -3314,35 +3268,3 @@ uint8_t mrb_insn_size[] = {
#undef SB #undef SB
#undef BBB #undef BBB
}; };
/* EXT1 instruction sizes */
uint8_t mrb_insn_size1[] = {
#define B 3
#define BB 4
#define BBB 5
#define BS 5
#define SB 5
#define OPCODE(_,x) x,
#include "mruby/ops.h"
#undef OPCODE
#undef B
};
/* EXT2 instruction sizes */
uint8_t mrb_insn_size2[] = {
#define B 2
#define OPCODE(_,x) x,
#include "mruby/ops.h"
#undef OPCODE
#undef BB
#undef BBB
#undef BS
#undef SB
};
/* EXT3 instruction sizes */
#define BB 5
#define BBB 6
#define BS 4
#define SB 5
uint8_t mrb_insn_size3[] = {
#define OPCODE(_,x) x,
#include "mruby/ops.h"
};
This diff is collapsed.
...@@ -901,7 +901,7 @@ argnum_error(mrb_state *mrb, mrb_int num) ...@@ -901,7 +901,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
#ifndef DIRECT_THREADED #ifndef DIRECT_THREADED
#define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) { #define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) {
#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();; L_ ## insn ## _BODY: #define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();
#define NEXT break #define NEXT break
#define JUMP NEXT #define JUMP NEXT
#define END_DISPATCH }} #define END_DISPATCH }}
...@@ -909,7 +909,7 @@ argnum_error(mrb_state *mrb, mrb_int num) ...@@ -909,7 +909,7 @@ argnum_error(mrb_state *mrb, mrb_int num)
#else #else
#define INIT_DISPATCH JUMP; return mrb_nil_value(); #define INIT_DISPATCH JUMP; return mrb_nil_value();
#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); L_ ## insn ## _BODY: #define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops ();
#define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn] #define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn]
#define JUMP NEXT #define JUMP NEXT
...@@ -1512,7 +1512,7 @@ RETRY_TRY_BLOCK: ...@@ -1512,7 +1512,7 @@ RETRY_TRY_BLOCK:
mrb->c->stack[0] = mrb_nil_value(); mrb->c->stack[0] = mrb_nil_value();
a = 0; a = 0;
c = OP_R_NORMAL; c = OP_R_NORMAL;
goto L_OP_RETURN_BODY; goto L_RETURN;
} }
pool = irep->pool; pool = irep->pool;
syms = irep->syms; syms = irep->syms;
...@@ -2733,37 +2733,6 @@ RETRY_TRY_BLOCK: ...@@ -2733,37 +2733,6 @@ RETRY_TRY_BLOCK:
goto L_RAISE; goto L_RAISE;
} }
CASE(OP_EXT1, Z) {
insn = READ_B();
switch (insn) {
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _1(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc--;
NEXT;
}
CASE(OP_EXT2, Z) {
insn = READ_B();
switch (insn) {
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _2(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc--;
NEXT;
}
CASE(OP_EXT3, Z) {
uint8_t insn = READ_B();
switch (insn) {
#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _3(); goto L_OP_ ## insn ## _BODY;
#include "mruby/ops.h"
#undef OPCODE
}
pc--;
NEXT;
}
CASE(OP_STOP, Z) { CASE(OP_STOP, Z) {
/* stop VM */ /* stop VM */
L_STOP: L_STOP:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment