]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm: recognize CR1-CR7 on ppc64x branch instructions
authorLynn Boger <laboger@linux.vnet.ibm.com>
Wed, 12 Oct 2016 12:50:30 +0000 (07:50 -0500)
committerDavid Chase <drchase@google.com>
Wed, 12 Oct 2016 21:17:47 +0000 (21:17 +0000)
Some of the branch instructions (BEQ, BNE, BLT, etc.) accept
all the valid CR values as operands, but the CR register value is
not parsed and not put into the instruction, so that CR0 is always
used regardless of what was specified on the instruction.  For example
BEQ CR2,label becomes beq cr0,label.

This adds the change to the PPC64 assembler to recognize the CR value
and set the approppriate field in the instruction so the correct
CR is used.  This also adds some general comments on the branch
instruction BC and its operand values.

Fixes #17408

Change-Id: I8e956372a42846a4c09a7259e9172eaa29118e71
Reviewed-on: https://go-review.googlesource.com/30930
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/internal/obj/ppc64/a.out.go
src/cmd/internal/obj/ppc64/asm9.go

index 477bc9acd94f067991db8966865d135ca62f1262..556ea3760875c04112b25364faa3083235097652 100644 (file)
@@ -213,6 +213,43 @@ const (
        NOSCHED = 1 << 9
 )
 
+// Values for use in branch instruction BC
+// BC B0,BI,label
+// BO is type of branch + likely bits described below
+// BI is CR value + branch type
+// ex: BEQ CR2,label is BC 12,10,label
+//   12 = BO_BCR
+//   10 = BI_CR2 + BI_EQ
+
+const (
+       BI_CR0 = 0
+       BI_CR1 = 4
+       BI_CR2 = 8
+       BI_CR3 = 12
+       BI_CR4 = 16
+       BI_CR5 = 20
+       BI_CR6 = 24
+       BI_CR7 = 28
+       BI_LT  = 0
+       BI_GT  = 1
+       BI_EQ  = 2
+       BI_OVF = 3
+)
+
+// Values for the BO field.  Add the branch type to
+// the likely bits, if a likely setting is known.
+// If branch likely or unlikely is not known, don't set it.
+// e.g. branch on cr+likely = 15
+
+const (
+       BO_BCTR     = 16 // branch on ctr value
+       BO_BCR      = 12 // branch on cr value
+       BO_BCRBCTR  = 8  // branch on ctr and cr value
+       BO_NOTBCR   = 4  // branch on not cr value
+       BO_UNLIKELY = 2  // value for unlikely
+       BO_LIKELY   = 3  // value for likely
+)
+
 // Bit settings from the CR
 
 const (
index 2a6f1bc5779f33be7c5e6108cf5844901ce13573..d36e32ff0d69745a0f6af71e5874d4a5ed205e6c 100644 (file)
@@ -2137,12 +2137,35 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
                16: /* bc bo,bi,sbra */
                a := 0
 
+               r := int(p.Reg)
+
                if p.From.Type == obj.TYPE_CONST {
                        a = int(regoff(ctxt, &p.From))
-               }
-               r := int(p.Reg)
-               if r == 0 {
-                       r = 0
+               } else if p.From.Type == obj.TYPE_REG {
+                       if r != 0 {
+                               ctxt.Diag("unexpected register setting for branch with CR: %d\n", r)
+                       }
+                       // BI values for the CR
+                       switch p.From.Reg {
+                       case REG_CR0:
+                               r = BI_CR0
+                       case REG_CR1:
+                               r = BI_CR1
+                       case REG_CR2:
+                               r = BI_CR2
+                       case REG_CR3:
+                               r = BI_CR3
+                       case REG_CR4:
+                               r = BI_CR4
+                       case REG_CR5:
+                               r = BI_CR5
+                       case REG_CR6:
+                               r = BI_CR6
+                       case REG_CR7:
+                               r = BI_CR7
+                       default:
+                               ctxt.Diag("unrecognized register: expecting CR\n")
+                       }
                }
                v := int32(0)
                if p.Pcond != nil {