From 2f09320fa56c3eca48810371c39e66f925f14c9b Mon Sep 17 00:00:00 2001 From: PleegWat Date: Sat, 5 Sep 2026 15:39:55 +0200 Subject: [PATCH] Add optimization for arbitrary aligned values Any value with 16 or less significant bits but larger than 64k is loaded in one fewer cycle --- isa/test.isa | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/isa/test.isa b/isa/test.isa index 5aca729..f030f08 100644 --- a/isa/test.isa +++ b/isa/test.isa @@ -332,11 +332,12 @@ ret li %r(register), %a:S33(immediate | label) ; assert(0 - 0x80000000 <= %a, "%a is too low") ; assert(%a <= 0xffffffff, "%a is too high") +%s = trailing_zeros(%a) +%sa = %a >> %s %nota = ~%a when 0x0000 <= %a && %a <= 0xffff: 00110001 rrrr0000 %a[15:0] ; First 64k when %nota <= 0xffff : 00110001 rrrr0000 %nota[15:0] 00100011 rrrr0000 0000rrrr 00000000 ; Last 64k -when !(%a & 0x0f) && %a < 0xffff0: 00110001 rrrr0000 %a[19:4] 00100111 rrrrrrrr 00000000 00000100 ; 16-byte aligned -when !(%a & 0x03) && %a < 0x3fffc: 00110001 rrrr0000 %a[17:2] 00100111 rrrrrrrr 00000000 00000010 ; 4-byte aligned +when %sa < 0xffff : 00110001 rrrr0000 %sa[15:0] 00100011 rrrrrrrr 00000000 %s[7:0] ; Aligned 00110001 rrrr0000 %a[31:16] 00100111 rrrrrrrr 00000000 00010000 00110001 rrrrrrrr %a[15:0] ; Any 32-bit # Load 32-bit immediate %a into %r @@ -345,14 +346,16 @@ qcall %a:U32(label) ; assert(%a <= 0xffffffff, "%a is too high") %r = 13 %f = 15 +%s = trailing_zeros(%a) +%sa = %a >> %s %nota = ~%a when 0x0000 <= %a && %a <= 0xffff: 01011000 rrrrffff %a[15:0] ; First 64k when %nota <= 0xffff : 00110001 rrrr0000 %nota[15:0] 00100011 rrrr0000 0000rrrr 00000000 01001000 rrrrffff 0000rrrr 00000000 ; Last 64k -when !(%a & 0x0f) && %a < 0xffff0: 00110001 rrrr0000 %a[19:4] 00100111 rrrrrrrr 00000000 00000100 01001000 rrrrffff 0000rrrr 00000000 ; 16-byte aligned -when !(%a & 0x03) && %a < 0x3fffc: 00110001 rrrr0000 %a[17:2] 00100111 rrrrrrrr 00000000 00000010 01001000 rrrrffff 0000rrrr 00000000 ; 4-byte aligned +when %sa < 0xffff : 00110001 rrrr0000 %sa[15:0] 00100011 rrrrrrrr 00000000 %s[7:0] 01001000 rrrrffff 0000rrrr 00000000 ; Aligned 00110001 rrrr0000 %a[31:16] 00100111 rrrrrrrr 00000000 00010000 00110001 rrrrrrrr %a[15:0] 01001000 rrrrffff 0000rrrr 00000000 ; Any 32-bit # Jump and link to 32-bit label halt%c(condition) 1000cccc 00001111 00000000 00000000 # Halt on condition %c +