]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/internal/obj/riscv: support subtraction with a constant
authorJoel Sing <joel@sing.id.au>
Fri, 25 Aug 2023 18:19:40 +0000 (04:19 +1000)
committerJoel Sing <joel@sing.id.au>
Tue, 7 Nov 2023 10:37:24 +0000 (10:37 +0000)
Allow SUB and SUBW to be specified with a constant, which are mapped
to ADDI and ADDIW with negated values.

Change-Id: I7dc55692febc81ea87393b0a3a7d23a43c30313b
Reviewed-on: https://go-review.googlesource.com/c/go/+/538915
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: M Zhuo <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
Reviewed-by: Wang Yaduo <wangyaduo@linux.alibaba.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
src/cmd/asm/internal/asm/testdata/riscv64.s
src/cmd/internal/obj/riscv/obj.go

index 2afa45710517dd81d33f6f9d338b10bbf515cdeb..072302b2257d72029c274d3d6458bf4dc866e073 100644 (file)
@@ -94,6 +94,10 @@ start:
 
        SUB     X6, X5, X7                              // b3836240
        SUB     X5, X6                                  // 33035340
+       SUB     $-2047, X5, X6                          // 1383f27f
+       SUB     $2048, X5, X6                           // 13830280
+       SUB     $-2047, X5                              // 9382f27f
+       SUB     $2048, X5                               // 93820280
 
        SRA     X6, X5, X7                              // b3d36240
        SRA     X5, X6                                  // 33535340
@@ -157,6 +161,7 @@ start:
        ADDW    $1, X6                                  // 1b031300
        SLLW    $1, X6                                  // 1b131300
        SRLW    $1, X6                                  // 1b531300
+       SUBW    $1, X6                                  // 1b03f3ff
        SRAW    $1, X6                                  // 1b531340
 
        // 5.3: Load and Store Instructions (RV64I)
index 279c8678a782a3eff292c952c4c2f0244ab0b704..4ff1d910ce3aa8f1c514173b3d33130efd183721 100644 (file)
@@ -69,6 +69,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
                switch p.As {
                case AADD:
                        p.As = AADDI
+               case ASUB:
+                       p.As, p.From.Offset = AADDI, -p.From.Offset
                case ASLT:
                        p.As = ASLTI
                case ASLTU:
@@ -87,6 +89,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
                        p.As = ASRAI
                case AADDW:
                        p.As = AADDIW
+               case ASUBW:
+                       p.As, p.From.Offset = AADDIW, -p.From.Offset
                case ASLLW:
                        p.As = ASLLIW
                case ASRLW: