feat(riscv64,loong64): PCALIGN, branch relaxation and operand shapes

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-20 14:25:47 +02:00
parent 9b238a525a
commit 9dc3987e02
8 changed files with 3230 additions and 100 deletions
File diff suppressed because it is too large Load Diff
+51
View File
@@ -0,0 +1,51 @@
// The subtract-immediate fold, the TEQ/TNE trap pseudos, PRELDX, the FP
// condition branches and the N(PC) branch spellings, against the toolchain.
#include "textflag.h"
// func SubFold(x int64) int64
TEXT ·SubFold(SB), NOSPLIT, $0-16
MOVV x+0(FP), R8
SUBV $0, R8
SUBV $4, R9, R10
SUBV $4096, R11
SUBV $-4, R12
SUB $1, R13
SUBVU $4, R14
SUBV $1048576, R15
MOVV R8, ret+8(FP)
RET
// func Traps(x int64) int64
TEXT ·Traps(SB), NOSPLIT, $0-16
MOVV x+0(FP), R4
TEQ $4, R4, R5
TEQ $4, R4
TNE $6, R5, R6
MOVV R4, ret+8(FP)
RET
// func Prefetch(x int64) int64
TEXT ·Prefetch(SB), NOSPLIT, $0-16
MOVV x+0(FP), R7
PRELDX 0(R7), $0x80001021, $0
PRELDX -1(R7), $0x1021, $2
MOVV R7, ret+8(FP)
RET
// func BranchForms(x int64) int64
TEXT ·BranchForms(SB), NOSPLIT, $0-16
MOVV x+0(FP), R4
l1:
BFPT l1
BFPT FCC3, l1
BFPF l1
JMP -4(PC)
JAL 1(PC)
JAL (R4)
loop:
ADDV $1, R4
BEQ R4, R5, loop
BNE R4, l1
RET
+33
View File
@@ -0,0 +1,33 @@
// PCALIGN padding on loong64: andi $0, $0, 0 (the architecture's NOP), plus
// the automatic loop-head alignment to a 16-byte boundary.
#include "textflag.h"
// func Pad16(x int64) int64
TEXT ·Pad16(SB), NOSPLIT, $0-16
MOVV x+0(FP), R4
PCALIGN $16
ADDV $1, R4
MOVV R4, ret+8(FP)
RET
// func Pad32(x int64) int64
TEXT ·Pad32(SB), NOSPLIT, $0-16
MOVV x+0(FP), R4
PCALIGN $32
ADDV $1, R4
MOVV R4, ret+8(FP)
RET
// func LoopAlign(x int64) int64
TEXT ·LoopAlign(SB), NOSPLIT, $0-16
MOVV x+0(FP), R4
MOVV $10, R5
loop:
BEQ R4, R5, done
ADDV $1, R4
JMP loop
done:
MOVV R4, ret+8(FP)
RET
+35
View File
@@ -0,0 +1,35 @@
// PCALIGN padding on riscv64: 4-byte NOPs with a 2-byte compressed NOP when
// the pad is 2 mod 4, exactly as the toolchain lays the bytes down.
#include "textflag.h"
// func Pad8(x int64) int64
TEXT ·Pad8(SB), NOSPLIT, $0-16
MOV x+0(FP), X5
PCALIGN $8
ADD $1, X5
MOV X5, ret+8(FP)
RET
// func Pad16(x int64) int64
TEXT ·Pad16(SB), NOSPLIT, $0-16
MOV x+0(FP), X5
PCALIGN $16
ADD $1, X5
MOV X5, ret+8(FP)
RET
// func Pad32(x int64) int64
TEXT ·Pad32(SB), NOSPLIT, $0-16
MOV x+0(FP), X5
PCALIGN $32
ADD $1, X5
MOV X5, ret+8(FP)
RET
// func PadAfterOdd(x int64) int64
TEXT ·PadAfterOdd(SB), NOSPLIT, $0-16
MOV x+0(FP), X5
PCALIGN $8
ADD $1, X5
MOV X5, ret+8(FP)
RET