X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=3_test%2Fdeepjit.s;h=bf6507bc94da2552d5e9af14e6c3ba5250a9ac22;hb=16e4a5d83c4442b0e642066ea58b238b257e9c37;hp=ae87d687a9732efd0ceec2ce590cc09add53abad;hpb=1a0cc16a34af48c3a1a922bd161cdfe5bb0f6336;p=calu.git diff --git a/3_test/deepjit.s b/3_test/deepjit.s index ae87d68..bf6507b 100644 --- a/3_test/deepjit.s +++ b/3_test/deepjit.s @@ -29,13 +29,12 @@ instrtable: .fill 42, 0 prog_eof: -.ifill ldw r0, 0-4(r3);0xE701FFFC +.ifill pop r0 .ifill ret+ prog_mul: -.ifill subi r3, r3, 4;0xE1998020 -.ifill ldw r6, 0(r3);0xe7318000 -.ifill ldw r7, 0-4(r3);0xe739fffc +.ifill pop r6 +.ifill pop r7 .ifill ldis r8, 0;0xed400004 .ifill mov r0, r7;0xe1038000 .ifill andx r0, 1;0xe2800008 @@ -47,68 +46,60 @@ prog_mul: .ifill adddnz r8, r8, r6;0x00443001 .ifill subi r7, r7, 2;0xe1bb8010 .fill 0x0b7ffe83;brnz+ loop -.ifill stw r8, 0-4(r3);0xe7c1fffc +.ifill push r8 prog_consts: .fill 0xed300004;ldis r6, CONST -.ifill stw r6, 0(r3);0xe7b18000 -.ifill addi r3, r3, 4;0xe1198020 +.ifill push r6 prog_add: -.ifill subi r3, r3, 4;0xe1998020 -.ifill ldw r6, 0(r3);0xe7318000 -.ifill ldw r7, 0-4(r3);0xe739fffc +.ifill pop r6 +.ifill pop r7 .ifill add r7, r7, r6;0xe03bb000 -.ifill stw r7, 0-4(r3);0xe7b9fffc +.ifill push r7 prog_sub: -.ifill subi r3, r3, 4;0xe1998020 -.ifill ldw r6, 0(r3);0xe7318000 -.ifill ldw r7, 0-4(r3);0xe739fffc +.ifill pop r6 +.ifill pop r7 .ifill sub r7, r7, r6;0xe0bbb000 -.ifill stw r7, 0-4(r3);0xe7b9fffc +.ifill push r7 prog_lessthan: -.ifill subi r3, r3, 4;0xe1998020 -.ifill ldw r6, 0(r3);0xe7318000 -.ifill ldw r7, 0-4(r3);0xe739fffc -.ifill ldis r8, 0;0xed400004 +.ifill pop r6 +.ifill pop r7 .ifill cmp r7, r6;0xec3b0000 -.ifill ldislt r8, 0xFF;0xbd4007fc -.ifill stw r8, 0-4(r3);0xe7c1fffc +.ifill pushlt r14 +.ifill pushge r15 prog_dup: -.ifill ldw r6, 0-4(r3);0xe731fffc -.ifill stw r6, 0(r3);0xe7b18000 -.ifill addi r3, r3, 4;0xe1198020 +.ifill fetch r6 +.ifill push r6 prog_jmp: -.ifill subi r3, r3, 4;0xe1998020 -.ifill ldw r6, 0(r3);0xe7318000 +.ifill pop r6 .ifill cmpi r6,0;0xecb00000 ;static calced -.fill 1, 0xbb000103;breq- vm_next +.fill 1, 0x1b000103;breq- vm_next .fill 1, 0xeb000003;br+ CONST prog_imm: .fill 1, 0xed400000;ldil r6, CONST .fill 1, 0xed400002;ldih r6, CONST -.ifill stw r6, 0(r3);0xe7b18000 -.ifill addi r3, r3, 4;0xe1198020 +.ifill push r6 prog_pop: -.ifill subi r3, r3, 4;0xe1998020 +.ifill disc r6 prog_xch: -.ifill ldw r6, 0-4(r3);0xe731fffc -.ifill ldw r7, 0-8(r3);0xe739fff8 -.ifill stw r6, 0-8(r3);0xe7b1fff8 -.ifill stw r7, 0-4(r3);0xe7b9fffc +.ifill pop r6 +.ifill pop r7 +.ifill push r6 +.ifill push r7 prog_not: -.ifill ldw r6, 0-4(r3);0xe731fffc +.ifill pop r6 .ifill not r6;0xe4b7fffa -.ifill stw r6, 0-4(r3);0xe7b1fffc +.ifill push r6 .text main: @@ -125,16 +116,21 @@ main: ldih r3, instrtable@hi ;set address to defer table - ldil r9, instrtable@lo - ldih r9, instrtable@hi + ldil r9, defertable@lo + ldih r9, defertable@hi ;call jit compiler call+ jit ;set address to stack - ldil r3, stack@lo - ldih r3, stack@hi + ;ldil r3, stack@lo + ;ldih r3, stack@hi + + ;make r15 a 0-register + ldis r15, 0 + ;make r14 a 8-bit -1-register + ldis r14, 0xFF ;call jit'ed prog call+ prog_start @@ -152,6 +148,17 @@ jit: ;r9 ... address to actual entry in defer table ;r10... address to defer table + ;load address of program + ldil r13, prog_dup@lo + ldih r13, prog_dup@hi + + ;load address of program + ldil r14, prog_mul@lo + ldih r14, prog_mul@hi + + ldil r15, prog_consts@lo + ldih r15, prog_consts@hi + ;backup defer table address mov r10, r9 ;decrement address to input by 1 @@ -192,7 +199,7 @@ vm_eof: ldil r7, prog_jmp@lo ldih r7, prog_jmp@hi ;load branch template - ldw r7, 16(r7) + ldw r7, 12(r7) ;if actual and base are equal, no entry cmp r9, r10 @@ -209,6 +216,7 @@ vm_defer: ;generate branch sub r11, r6, r8 + lrs r11, r11, 2 ;set the upper 16 bit 0 andx r11, 0xFFFF ;shift to the position of imm in br @@ -224,42 +232,36 @@ vm_defer: ;case * ;42 vm_mul: - ;load address of program - ldil r4, prog_mul@lo - ldih r4, prog_mul@hi - ;program instruction (14) - ldw r0, 0(r4) + ldw r0, 0(r14) stx r0, 0(r2) - ldw r0, 4(r4) + ldw r0, 4(r14) stx r0, 4(r2) - ldw r0, 8(r4) + ldw r0, 8(r14) stx r0, 8(r2) - ldw r0, 12(r4) + ldw r0, 12(r14) stx r0, 12(r2) - ldw r0, 16(r4) + ldw r0, 16(r14) stx r0, 16(r2) - ldw r0, 20(r4) + ldw r0, 20(r14) stx r0, 20(r2) - ldw r0, 24(r4) + ldw r0, 24(r14) stx r0, 24(r2) - ldw r0, 28(r4) + ldw r0, 28(r14) stx r0, 28(r2) - ldw r0, 32(r4) + ldw r0, 32(r14) stx r0, 32(r2) - ldw r0, 36(r4) + ldw r0, 36(r14) stx r0, 36(r2) - ldw r0, 40(r4) + ldw r0, 40(r14) stx r0, 40(r2) - ldw r0, 44(r4) + ldw r0, 44(r14) stx r0, 44(r2) - ldw r0, 48(r4) + ldw r0, 48(r14) stx r0, 48(r2) - ldw r0, 52(r4) - stx r0, 52(r2) ;increment address - addi r2, r2, 56 + addi r2, r2, 52 br+ vm_loop @@ -279,11 +281,9 @@ vm_add: stx r0, 8(r2) ldw r0, 12(r4) stx r0, 12(r2) - ldw r0, 16(r4) - stx r0, 16(r2) ;increment address - addi r2, r2, 20 + addi r2, r2, 16 br+ vm_loop @@ -303,23 +303,17 @@ vm_sub: stx r0, 8(r2) ldw r0, 12(r4) stx r0, 12(r2) - ldw r0, 16(r4) - stx r0, 16(r2) ;increment address - addi r2, r2, 20 + addi r2, r2, 16 br+ vm_loop ;case 0 1 2 3 4 5 6 7 8 9 ;48-57 vm_consts: - ;load address of program - ldil r4, prog_consts@lo - ldih r4, prog_consts@hi - ;program instruction (3) - ldw r0, 0(r4) + ldw r0, 0(r15) ;the first instr. loads r6 with the number ;thus we shall emulate this @@ -333,13 +327,11 @@ vm_consts: ;store this 'dynamic' instruction stx r0, 0(r2) - ldw r0, 4(r4) + ldw r0, 4(r15) stx r0, 4(r2) - ldw r0, 8(r4) - stx r0, 8(r2) ;increment address - addi r2, r2, 12 + addi r2, r2, 8 br+ vm_loop @@ -350,7 +342,7 @@ vm_lessthan: ldil r4, prog_lessthan@lo ldih r4, prog_lessthan@hi - ;program instruction (7) + ;program instruction (6) ldw r0, 0(r4) stx r0, 0(r2) ldw r0, 4(r4) @@ -361,33 +353,24 @@ vm_lessthan: stx r0, 12(r2) ldw r0, 16(r4) stx r0, 16(r2) - ldw r0, 20(r4) - stx r0, 20(r2) - ldw r0, 24(r4) - stx r0, 24(r2) ;increment address - addi r2, r2, 28 + addi r2, r2, 20 br+ vm_loop ;case D ;68 vm_dup: - ;load address of program - ldil r4, prog_dup@lo - ldih r4, prog_dup@hi ;program instruction (3) - ldw r0, 0(r4) + ldw r0, 0(r13) stx r0, 0(r2) - ldw r0, 4(r4) + ldw r0, 4(r13) stx r0, 4(r2) - ldw r0, 8(r4) - stx r0, 8(r2) ;increment address - addi r2, r2, 12 + addi r2, r2, 8 br+ vm_loop @@ -445,11 +428,9 @@ vm_imm: ldw r0, 8(r4) stx r0, 8(r2) - ldw r0, 12(r4) - stx r0, 12(r2) ;increment address - addi r2, r2, 16 + addi r2, r2, 12 ;pc+4 addi r1, r1, 4 @@ -467,29 +448,22 @@ vm_jmp: ldil r4, prog_jmp@lo ldih r4, prog_jmp@hi - ;program instruction (3) - ;decrement sp - ;subi r3, r3, 4 + ;program instruction (2) + ;pop r6 ldw r0, 0(r4) stx r0, 0(r2) - ;load sp - ;ldw r6, 0(r3) - ldw r0, 4(r4) - stx r0, 4(r2) ;compare to 0 ;cmpi r6,0 - ldw r0, 8(r4) - stx r0, 8(r2) + ldw r0, 4(r4) + stx r0, 4(r2) ;breq+ vm_next ;is statically known - ldw r0, 12(r4) - stx r0, 12(r2) + ldw r0, 8(r4) + stx r0, 8(r2) - ;r8 has now the current base - ldw r8, 0(r3) ;we add the offset to this instruction - addi r8, r8, 12 + addi r8, r2, 12 ;we know calculate the jump destination @@ -508,15 +482,16 @@ vm_jmp: ;r6 is now the 'real' negativ number or r6, r6, r7 ;todo: testing showed (at least once) we are off by 2 instr. - addi r6, r6, 2 + ;addi r6, r6, 2 ;multiply by to get the offset lls r6, r6, 2 ;generate address in table add r6, r3, r6 ;r0 now has the target address + ;todo: 0-4? ldw r0, 0(r6) ;we calc the offset - sub r8, r0, r2 + sub r8, r0, r8 ;we shift 2 bits out, because rel. br takes instr. ;count and not address amount ... lrs r8, r8, 2 @@ -525,12 +500,12 @@ vm_jmp: ;shift to the position of imm in br lls r8, r8, 7 ;load template br - ldw r0, 16(r4) + ldw r0, 12(r4) or r0, r0, r8 - stx r0, 16(r2) + stx r0, 12(r2) ;increment address - addi r2, r2, 20 + addi r2, r2, 16 br+ vm_loop @@ -543,7 +518,7 @@ vm_possign: stw r8, 4(r9) ;todo: check if -1 is needed - subi r6, r6, 1 + ;subi r6, r6, 1 ;multiply with 2 to get offset right lls r6, r6, 2 ;add to current base