fix(asm): materialise RISC-V MOV immediates
Test / vet (push) Successful in 44s
Test / test (push) Failing after 1m56s
Test / build (push) Skipped

This commit is contained in:
2026-08-13 17:41:16 +02:00
parent 3bc7c18bc3
commit 31a2cee382
5 changed files with 85 additions and 25 deletions
+5 -5
View File
@@ -122,7 +122,7 @@ done:
}
func TestRISCV_MOV_imm_small(t *testing.T) {
// MOV $42, rd → ADDI (fits in 12 bits). Not RVC-compressed (treated as MOV, not ADDI).
// MOV $42, rd → ADDI (fits in 12 bits, but not C.LI's 6-bit immediate).
fn := firstTextRISCV(t, `#include "textflag.h"
TEXT ·small(SB), NOSPLIT, $0
MOV $42, X10
@@ -136,16 +136,16 @@ TEXT ·small(SB), NOSPLIT, $0
}
func TestRISCV_MOV_imm_large(t *testing.T) {
// MOV $0x12345, rd → LUI + ADDIW (8 bytes total)
// MOV $0x12345, rd → C.LUI $18 (2B) + ADDIW $837 (4B).
fn := firstTextRISCV(t, `#include "textflag.h"
TEXT ·large(SB), NOSPLIT, $0
MOV $0x12345, X10
RET
`)
code := assembleRISCVHelper(t, fn)
// LUI (4B) + ADDIW (4B) + JALR (4B) = 12
if len(code) != 12 {
t.Errorf("expected 12 bytes, got %d", len(code))
// C.LUI (2B) + ADDIW (4B) + JALR (4B) = 10
if len(code) != 10 {
t.Errorf("expected 10 bytes, got %d", len(code))
}
}