From 71e11e17c68bfcb815c76ebda4d20e8a6b89b746 Mon Sep 17 00:00:00 2001 From: Vincent St-Amour Date: Thu, 24 Jul 2008 18:00:56 -0400 Subject: [PATCH] Push-long now uses a 4-bit opcode. Reduces size a bit. Now we have a lot of free opcodes. I'll try to add some "short" versions to the label instrs, with only 8 bit of address. --- picobit-vm.c | 54 +++++++++++++++++++++++++++--------------------------- picobit.scm | 5 ++--- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/picobit-vm.c b/picobit-vm.c index 4d00a03..2a80701 100644 --- a/picobit-vm.c +++ b/picobit-vm.c @@ -1979,24 +1979,25 @@ int read_hex_file (char *filename) #define bytecode_hi4 WREG #endif -#define PUSH_CONSTANT1 0x00 -#define PUSH_CONSTANT2 0x10 -#define PUSH_STACK1 0x20 -#define PUSH_STACK2 0x30 -#define PUSH_GLOBAL 0x40 -#define SET_GLOBAL 0x50 -#define CALL 0x60 -#define JUMP 0x70 -#define BRANCHES 0x80 - -#define CALL_TOPLEVEL 0x80 -#define JUMP_TOPLEVEL 0x90 -#define GOTO 0xa0 -#define GOTO_IF_FALSE 0xb0 -#define CLOSURE 0xc0 -#define PRIM1 0xd0 -#define PRIM2 0xe0 -#define PRIM3 0xf0 +#define PUSH_CONSTANT1 0x00 +#define PUSH_CONSTANT2 0x10 +#define PUSH_STACK1 0x20 +#define PUSH_STACK2 0x30 +#define PUSH_GLOBAL 0x40 +#define SET_GLOBAL 0x50 +#define CALL 0x60 +#define JUMP 0x70 +#define LABEL_INSTR 0x80 +#define PUSH_CONSTANT_LONG 0x90 + +// TODO these are free +#define GOTO 0xa0 +#define GOTO_IF_FALSE 0xb0 +#define CLOSURE 0xc0 + +#define PRIM1 0xd0 +#define PRIM2 0xe0 +#define PRIM3 0xf0 #ifdef WORKSTATION @@ -2282,7 +2283,7 @@ void interpreter (void) DISPATCH(); /***************************************************************************/ - CASE(BRANCHES); + CASE(LABEL_INSTR); switch (bytecode_lo4) { @@ -2415,8 +2416,13 @@ void interpreter (void) DISPATCH(); /***************************************************************************/ - CASE(JUMP_TOPLEVEL); // BREGG move, have push long here + CASE(PUSH_CONSTANT_LONG); + /* push-constant [long] */ + FETCH_NEXT_BYTECODE(); + arg1 = (bytecode_lo4 << 8) | bytecode; + PUSH_ARG1(); + DISPATCH(); /***************************************************************************/ @@ -2610,13 +2616,7 @@ void interpreter (void) /* prim #%u8vector-length */ arg1 = POP(); prim_u8vector_length (); PUSH_ARG1(); break; case 12: - /* push-constant [long] */ // BREGG move to a 4-bit opcode - FETCH_NEXT_BYTECODE(); // TODO BREGG this is a test, the compiler only knows what's in rom or lower, so we only need a byte, unless we change the number of rom addresses OOPS, 8 bits is not enough even for fixnums, we'd probably be ok with 12, though (actually 9, but that's harder to have and 12 gives us more room should we increase the number of rom addresses) - arg2 = bytecode; - FETCH_NEXT_BYTECODE(); - arg1 = (arg2 << 8) | bytecode; - PUSH_ARG1(); - arg2 = OBJ_FALSE; + // FREE find something to do with this break; case 13: /* shift */ diff --git a/picobit.scm b/picobit.scm index 4ff9b12..0014e8e 100644 --- a/picobit.scm +++ b/picobit.scm @@ -2662,9 +2662,8 @@ (if (<= n 31) (asm-8 (+ #x00 n)) (begin - (asm-8 #xfc) - (asm-8 (quotient n 256)) ;; BREGG this is a test, the compiler cannot know about anything over 256 (as long as no rom goes higher, which might change, watch out for this), so no need for 13 bits OOPS, actually, 8 is not enough for fixnums and rom, revert to 12 and use some of the free instrs ? - (asm-8 (modulo n 256))))) ;; TODO with 13-bit objects, we need 2 bytes, maybe limit to 12, so we could use a byte and a half, but we'd need to use an opcode with only 4 bits, maybe the call/jump stuff can be combined ? FOOBAR + (asm-8 (+ #x90 (quotient n 256))) + (asm-8 (modulo n 256))))) (define (push-stack n) (if (> n 31) -- 2.11.4.GIT