fix(asm): carry the riscv64 U-type immediate raw
The toolchain writes the source immediate straight into imm[31:12] (riscv64.s: AUIPC 24287, X10 encodes 7ffff517), and rejects values beyond the signed 20-bit span; the encoder divided by 4096 instead and truncated silently, so the high bits of every large AUIPC and LUI were lost. Assisted-by: GLM 5.3 Flash
This commit is contained in:
1 parent
a829b8f321
commit
0cfed5516c
2 files changed
+36
-2
No files matched your search
@@ -109,6 +109,34 @@ TEXT ·imm(SB), NOSPLIT, $0
|
||||
}
|
||||
}
|
||||
|
||||
// TestRISCV_utypeImmediate pins the U-type immediate semantics byte for byte
|
||||
// against go tool asm (riscv64.s lines 76 to 85): the source immediate is the
|
||||
// raw 20-bit field, not a byte address to divide, and both sign extremes
|
||||
// encode. The range beyond the signed 20 bits is the toolchain's own error.
|
||||
func TestRISCV_utypeImmediate(t *testing.T) {
|
||||
fn := firstTextRISCV(t, `#include "textflag.h"
|
||||
TEXT ·utype(SB), NOSPLIT, $0
|
||||
AUIPC $524287, X10
|
||||
LUI $524287, X15
|
||||
LUI $167, X15
|
||||
AUIPC $-524288, X15
|
||||
RET
|
||||
`)
|
||||
code := assembleRISCVHelper(t, fn)
|
||||
want := "17f5ff7f" + "b7f7ff7f" + "b7770a00" + "97070080"
|
||||
if got := hex.EncodeToString(code[:16]); got != want {
|
||||
t.Errorf("U-type immediates: %s, want %s", got, want)
|
||||
}
|
||||
fn = firstTextRISCV(t, `#include "textflag.h"
|
||||
TEXT ·wide(SB), NOSPLIT, $0
|
||||
AUIPC $524288, X10
|
||||
RET
|
||||
`)
|
||||
if _, _, _, _, _, _, err := assembleRISCV(fn); err == nil {
|
||||
t.Error("AUIPC $524288: expected the 20-bit range error, got none")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRISCV_branches(t *testing.T) {
|
||||
fn := firstTextRISCV(t, `#include "textflag.h"
|
||||
TEXT ·br(SB), NOSPLIT, $0
|
||||
|
||||
Reference in new issue
Block a user