Skip to content

Commit

Permalink
all: clean up addition of constants in riscv64 assembly
Browse files Browse the repository at this point in the history
Use ADD with constants, instead of ADDI. Also use SUB with a positive constant
rather than ADD with a negative constant. The resulting assembly is still the
same.

Change-Id: Ife10bf5ae4122e525f0e7d41b5e463e748236a9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/540136
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: M Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
  • Loading branch information
4a6f656c committed Nov 9, 2023
1 parent e816eb5 commit c1a4869
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/crypto/internal/bigmod/nat_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ loop:
MOV X16, 2*8(X5) // z[2]
MOV X19, 3*8(X5) // z[3]

ADDI $32, X5
ADDI $32, X7
ADD $32, X5
ADD $32, X7

ADDI $-4, X30
SUB $4, X30
BNEZ X30, loop

done:
Expand Down
12 changes: 6 additions & 6 deletions src/internal/bytealg/compare_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use_a_len:
ADD $8, X7, X7
SUB X7, X5, X5
align:
ADD $-1, X7
SUB $1, X7
MOVBU 0(X10), X8
MOVBU 0(X12), X9
BNE X8, X9, cmp
Expand All @@ -79,7 +79,7 @@ compare32:
BNE X17, X18, cmp8b
ADD $32, X10
ADD $32, X12
ADD $-32, X5
SUB $32, X5
BGE X5, X6, compare32
BEQZ X5, cmp_len

Expand All @@ -95,7 +95,7 @@ compare16:
BNE X17, X18, cmp8b
ADD $16, X10
ADD $16, X12
ADD $-16, X5
SUB $16, X5
BEQZ X5, cmp_len

check8_unaligned:
Expand Down Expand Up @@ -128,7 +128,7 @@ compare8_unaligned:
BNE X29, X30, cmp1h
ADD $8, X10
ADD $8, X12
ADD $-8, X5
SUB $8, X5
BGE X5, X6, compare8_unaligned
BEQZ X5, cmp_len

Expand All @@ -150,7 +150,7 @@ compare4_unaligned:
BNE X19, X20, cmp1d
ADD $4, X10
ADD $4, X12
ADD $-4, X5
SUB $4, X5
BGE X5, X6, compare4_unaligned

compare1:
Expand All @@ -160,7 +160,7 @@ compare1:
BNE X8, X9, cmp
ADD $1, X10
ADD $1, X12
ADD $-1, X5
SUB $1, X5
JMP compare1

// Compare 8 bytes of memory in X15/X16 that are known to differ.
Expand Down
10 changes: 5 additions & 5 deletions src/internal/bytealg/equal_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEXT memequal<>(SB),NOSPLIT|NOFRAME,$0
ADD $8, X9, X9
SUB X9, X12, X12
align:
ADD $-1, X9
SUB $1, X9
MOVBU 0(X10), X19
MOVBU 0(X11), X20
BNE X19, X20, not_eq
Expand All @@ -67,7 +67,7 @@ loop32:
BNE X16, X17, not_eq
ADD $32, X10
ADD $32, X11
ADD $-32, X12
SUB $32, X12
BGE X12, X9, loop32
BEQZ X12, eq

Expand All @@ -83,7 +83,7 @@ loop16:
BNE X21, X22, not_eq
ADD $16, X10
ADD $16, X11
ADD $-16, X12
SUB $16, X12
BGE X12, X23, loop16
BEQZ X12, eq

Expand All @@ -105,7 +105,7 @@ loop4:
BNE X16, X17, not_eq
ADD $4, X10
ADD $4, X11
ADD $-4, X12
SUB $4, X12
BGE X12, X23, loop4

loop1:
Expand All @@ -115,7 +115,7 @@ loop1:
BNE X19, X20, not_eq
ADD $1, X10
ADD $1, X11
ADD $-1, X12
SUB $1, X12
JMP loop1

not_eq:
Expand Down
4 changes: 2 additions & 2 deletions src/internal/bytealg/indexbyte_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TEXT ·IndexByte<ABIInternal>(SB),NOSPLIT,$0-40
AND $0xff, X13
MOV X10, X12 // store base for later
ADD X10, X11 // end
ADD $-1, X10
SUB $1, X10

loop:
ADD $1, X10
Expand All @@ -35,7 +35,7 @@ TEXT ·IndexByteString<ABIInternal>(SB),NOSPLIT,$0-32
AND $0xff, X12
MOV X10, X13 // store base for later
ADD X10, X11 // end
ADD $-1, X10
SUB $1, X10

loop:
ADD $1, X10
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/asm_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// func rt0_go()
TEXT runtime·rt0_go(SB),NOSPLIT|TOPFRAME,$0
// X2 = stack; A0 = argc; A1 = argv
ADD $-24, X2
SUB $24, X2
MOV A0, 8(X2) // argc
MOV A1, 16(X2) // argv

Expand Down Expand Up @@ -57,7 +57,7 @@ nocgo:

// create a new goroutine to start program
MOV $runtime·mainPC(SB), T0 // entry
ADD $-16, X2
SUB $16, X2
MOV T0, 8(X2)
MOV ZERO, 0(X2)
CALL runtime·newproc(SB)
Expand Down Expand Up @@ -161,7 +161,7 @@ TEXT runtime·switchToCrashStack0<ABIInternal>(SB), NOSPLIT, $0-8

// switch to crashstack
MOV (g_stack+stack_hi)(g), X11
ADD $(-4*8), X11
SUB $(4*8), X11
MOV X11, X2

// call target function
Expand Down Expand Up @@ -219,7 +219,7 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0
MOV (g_sched+gobuf_sp)(g), X2
// Create a stack frame on g0 to call newstack.
MOV ZERO, -8(X2) // Zero saved LR in frame
ADD $-8, X2
SUB $8, X2
CALL runtime·newstack(SB)

// Not reached, but make sure the return PC from the call to newstack
Expand Down Expand Up @@ -304,7 +304,7 @@ TEXT runtime·mcall<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-8
MOV 0(CTXT), T1 // code pointer
MOV (g_sched+gobuf_sp)(g), X2 // sp = m->g0->sched.sp
// we don't need special macro for regabi since arg0(X10) = g
ADD $-16, X2
SUB $16, X2
MOV X10, 8(X2) // setup g
MOV ZERO, 0(X2) // clear return address
JALR RA, T1
Expand Down Expand Up @@ -366,7 +366,7 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20
// Now on a scheduling stack (a pthread-created stack).
g0:
// Save room for two of our pointers.
ADD $-16, X2
SUB $16, X2
MOV X9, 0(X2) // save old g on stack
MOV (g_stack+stack_hi)(X9), X9
SUB X8, X9, X8
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/memclr_riscv64.s
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEXT runtime·memclrNoHeapPointers<ABIInternal>(SB),NOSPLIT,$0-16
SUB X5, X9, X5
SUB X5, X11, X11
align:
ADD $-1, X5
SUB $1, X5
MOVB ZERO, 0(X10)
ADD $1, X10
BNEZ X5, align
Expand All @@ -47,7 +47,7 @@ loop64:
MOV ZERO, 48(X10)
MOV ZERO, 56(X10)
ADD $64, X10
ADD $-64, X11
SUB $64, X11
BGE X11, X9, loop64
BEQZ X11, done

Expand All @@ -60,7 +60,7 @@ zero32:
MOV ZERO, 16(X10)
MOV ZERO, 24(X10)
ADD $32, X10
ADD $-32, X11
SUB $32, X11
BEQZ X11, done

check16:
Expand All @@ -70,7 +70,7 @@ zero16:
MOV ZERO, 0(X10)
MOV ZERO, 8(X10)
ADD $16, X10
ADD $-16, X11
SUB $16, X11
BEQZ X11, done

check8:
Expand All @@ -79,7 +79,7 @@ check8:
zero8:
MOV ZERO, 0(X10)
ADD $8, X10
ADD $-8, X11
SUB $8, X11
BEQZ X11, done

check4:
Expand All @@ -91,13 +91,13 @@ zero4:
MOVB ZERO, 2(X10)
MOVB ZERO, 3(X10)
ADD $4, X10
ADD $-4, X11
SUB $4, X11

loop1:
BEQZ X11, done
MOVB ZERO, 0(X10)
ADD $1, X10
ADD $-1, X11
SUB $1, X11
JMP loop1

done:
Expand Down
Loading

0 comments on commit c1a4869

Please sign in to comment.