]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/internal/obj/ppc64: add support for pcalign 32 on ppc64x
authorLynn Boger <laboger@linux.vnet.ibm.com>
Tue, 31 Mar 2020 14:08:29 +0000 (10:08 -0400)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Fri, 10 Apr 2020 18:45:24 +0000 (18:45 +0000)
Previous PCALIGN support on ppc64x only accepted 8 and 16 byte
alignment since the default function alignment was 16. Now that
the function's alignment can be set to a larger value when needed,
PCALIGN can accept 32. When this happens then the function's
alignment will be changed to 32.

Test has been updated to recognized this new value.

Change-Id: If82c3cd50d7c686fcf8a9e819708b15660cdfa63
Reviewed-on: https://go-review.googlesource.com/c/go/+/227775
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/ppc64/asm_test.go

index 288e5f336064517bfa4131a4d7bc7b105765586b..69ff75349b86f9a42244baa71e652eb809725ed8 100644 (file)
@@ -620,7 +620,7 @@ var oprange [ALAST & obj.AMask][]Optab
 var xcmp [C_NCLASS][C_NCLASS]bool
 
 // padding bytes to add to align code as requested
-func addpad(pc, a int64, ctxt *obj.Link) int {
+func addpad(pc, a int64, ctxt *obj.Link, cursym *obj.LSym) int {
        switch a {
        case 8:
                if pc&7 != 0 {
@@ -633,6 +633,21 @@ func addpad(pc, a int64, ctxt *obj.Link) int {
                case 8:
                        return 8
                }
+       case 32:
+               switch pc & 31 {
+               case 4, 20:
+                       return 12
+               case 8, 24:
+                       return 8
+               case 12, 28:
+                       return 4
+               }
+               // The default function alignment is 16, but
+               // if 32 byte alignment is requested then the
+               // function needs to be aligned to 32.
+               if cursym.Func.Align < 32 {
+                       cursym.Func.Align = 32
+               }
        default:
                ctxt.Diag("Unexpected alignment: %d for PCALIGN directive\n", a)
        }
@@ -663,7 +678,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                if m == 0 {
                        if p.As == obj.APCALIGN {
                                a := c.vregoff(&p.From)
-                               m = addpad(pc, a, ctxt)
+                               m = addpad(pc, a, ctxt, cursym)
                        } else {
                                if p.As != obj.ANOP && p.As != obj.AFUNCDATA && p.As != obj.APCDATA {
                                        ctxt.Diag("zero-width instruction\n%v", p)
@@ -721,7 +736,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                        if m == 0 {
                                if p.As == obj.APCALIGN {
                                        a := c.vregoff(&p.From)
-                                       m = addpad(pc, a, ctxt)
+                                       m = addpad(pc, a, ctxt, cursym)
                                } else {
                                        if p.As != obj.ANOP && p.As != obj.AFUNCDATA && p.As != obj.APCDATA {
                                                ctxt.Diag("zero-width instruction\n%v", p)
@@ -736,10 +751,6 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                c.cursym.Size = pc
        }
 
-       if r := pc & funcAlignMask; r != 0 {
-               pc += funcAlign - r
-       }
-
        c.cursym.Size = pc
 
        /*
@@ -761,7 +772,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                if o.type_ == 0 && p.As == obj.APCALIGN {
                        pad := LOP_RRR(OP_OR, REGZERO, REGZERO, REGZERO)
                        aln := c.vregoff(&p.From)
-                       v := addpad(p.Pc, aln, c.ctxt)
+                       v := addpad(p.Pc, aln, c.ctxt, c.cursym)
                        if v > 0 {
                                // Same padding instruction for all
                                for i = 0; i < int32(v/4); i++ {
index fff478e552941882579cccb6ab7bdca11d37fe26..70dabc20175a61ffddb75683b8056b3f6cfe6d0a 100644 (file)
@@ -10,6 +10,7 @@ import (
        "os"
        "os/exec"
        "path/filepath"
+       "regexp"
        "strings"
        "testing"
 )
@@ -17,21 +18,20 @@ import (
 var invalidPCAlignSrc = `
 TEXT test(SB),0,$0-0
 ADD $2, R3
-PCALIGN $32
+PCALIGN $64
 RET
 `
+
 var validPCAlignSrc = `
 TEXT test(SB),0,$0-0
 ADD $2, R3
 PCALIGN $16
-MOVD $8, R4
-ADD $8, R4
-PCALIGN $16
+MOVD $8, R16
 ADD $8, R4
+PCALIGN $32
+ADD $8, R3
 PCALIGN $8
-ADD $4, R6
-PCALIGN $16
-ADD R2, R3, R4
+ADD $4, R8
 RET
 `
 
@@ -39,6 +39,10 @@ RET
 // PCALIGN directive, to verify correct values are and
 // accepted, and incorrect values are flagged in error.
 func TestPCalign(t *testing.T) {
+       var pattern8 = `0x...8\s.*ADD\s..,\sR8`
+       var pattern16 = `0x...[80]\s.*MOVD\s..,\sR16`
+       var pattern32 = `0x...0\s.*ADD\s..,\sR3`
+
        testenv.MustHaveGoBuild(t)
 
        dir, err := ioutil.TempDir("", "testpcalign")
@@ -63,6 +67,30 @@ func TestPCalign(t *testing.T) {
                t.Errorf("Build failed: %v, output: %s", err, out)
        }
 
+       matched, err := regexp.MatchString(pattern8, string(out))
+       if err != nil {
+               t.Fatal(err)
+       }
+       if !matched {
+               t.Errorf("The 8 byte alignment is not correct: %t, output:%s\n", matched, out)
+       }
+
+       matched, err = regexp.MatchString(pattern16, string(out))
+       if err != nil {
+               t.Fatal(err)
+       }
+       if !matched {
+               t.Errorf("The 16 byte alignment is not correct: %t, output:%s\n", matched, out)
+       }
+
+       matched, err = regexp.MatchString(pattern32, string(out))
+       if err != nil {
+               t.Fatal(err)
+       }
+       if !matched {
+               t.Errorf("The 32 byte alignment is not correct: %t, output:%s\n", matched, out)
+       }
+
        // generate a test with invalid use of PCALIGN
 
        tmpfile = filepath.Join(dir, "xi.s")