Add optimization for arbitrary aligned values

Any value with 16 or less significant bits but larger than 64k is loaded
in one fewer cycle
This commit is contained in:
PleegWat
2026-09-05 15:39:55 +02:00
parent 8e7441fdb3
commit 2f09320fa5
+7 -4
View File
@@ -332,11 +332,12 @@ ret
li %r(register), %a:S33(immediate | label) li %r(register), %a:S33(immediate | label)
; assert(0 - 0x80000000 <= %a, "%a is too low") ; assert(0 - 0x80000000 <= %a, "%a is too low")
; assert(%a <= 0xffffffff, "%a is too high") ; assert(%a <= 0xffffffff, "%a is too high")
%s = trailing_zeros(%a)
%sa = %a >> %s
%nota = ~%a %nota = ~%a
when 0x0000 <= %a && %a <= 0xffff: 00110001 rrrr0000 %a[15:0] ; First 64k 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 %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 %sa < 0xffff : 00110001 rrrr0000 %sa[15:0] 00100011 rrrrrrrr 00000000 %s[7:0] ; Aligned
when !(%a & 0x03) && %a < 0x3fffc: 00110001 rrrr0000 %a[17:2] 00100111 rrrrrrrr 00000000 00000010 ; 4-byte aligned
00110001 rrrr0000 %a[31:16] 00100111 rrrrrrrr 00000000 00010000 00110001 rrrrrrrr %a[15:0] ; Any 32-bit 00110001 rrrr0000 %a[31:16] 00100111 rrrrrrrr 00000000 00010000 00110001 rrrrrrrr %a[15:0] ; Any 32-bit
# Load 32-bit immediate %a into %r # Load 32-bit immediate %a into %r
@@ -345,14 +346,16 @@ qcall %a:U32(label)
; assert(%a <= 0xffffffff, "%a is too high") ; assert(%a <= 0xffffffff, "%a is too high")
%r = 13 %r = 13
%f = 15 %f = 15
%s = trailing_zeros(%a)
%sa = %a >> %s
%nota = ~%a %nota = ~%a
when 0x0000 <= %a && %a <= 0xffff: 01011000 rrrrffff %a[15:0] ; First 64k 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 %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 %sa < 0xffff : 00110001 rrrr0000 %sa[15:0] 00100011 rrrrrrrr 00000000 %s[7:0] 01001000 rrrrffff 0000rrrr 00000000 ; Aligned
when !(%a & 0x03) && %a < 0x3fffc: 00110001 rrrr0000 %a[17:2] 00100111 rrrrrrrr 00000000 00000010 01001000 rrrrffff 0000rrrr 00000000 ; 4-byte aligned
00110001 rrrr0000 %a[31:16] 00100111 rrrrrrrr 00000000 00010000 00110001 rrrrrrrr %a[15:0] 01001000 rrrrffff 0000rrrr 00000000 ; Any 32-bit 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 # Jump and link to 32-bit label
halt%c(condition) halt%c(condition)
1000cccc 00001111 00000000 00000000 1000cccc 00001111 00000000 00000000
# Halt on condition %c # Halt on condition %c