1
0
mirror of https://github.com/golang/go synced 2024-11-24 00:30:15 -07:00

cmd/asm: add support for bdnz/bdz extended mnemonics on PPC64

Support BDNZ and BDZ mnemonics, they are commonly used
POWER instructions. The raw BC mnemonic is not easy
to read.

Likewise, cleanup code surrounding these changes.

Change-Id: I72f1dad5013f7856bd0dd320bfb17b5a9f3c69ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/390696
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Trust: Paul Murphy <murp@ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Paul E. Murphy 2021-10-25 16:51:55 -05:00 committed by Paul Murphy
parent c1f22134f2
commit 7b1ba972dc
5 changed files with 43 additions and 24 deletions

View File

@ -15,7 +15,7 @@ import (
func jumpPPC64(word string) bool { func jumpPPC64(word string) bool {
switch word { switch word {
case "BC", "BCL", "BEQ", "BGE", "BGT", "BL", "BLE", "BLT", "BNE", "BR", "BVC", "BVS", "CALL", "JMP": case "BC", "BCL", "BEQ", "BGE", "BGT", "BL", "BLE", "BLT", "BNE", "BR", "BVC", "BVS", "BDNZ", "BDZ", "CALL", "JMP":
return true return true
} }
return false return false

View File

@ -764,4 +764,10 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0
MOVFL R1, $128 // 7c380120 MOVFL R1, $128 // 7c380120
MOVFL R1, $3 // 7c203120 MOVFL R1, $3 // 7c203120
// Verify supported bdnz/bdz encodings.
BC 16,0,0(PC) // BC $16,R0,0(PC) // 42000000
BDNZ 0(PC) // 42000000
BDZ 0(PC) // 42400000
BC 18,0,0(PC) // BC $18,R0,0(PC) // 42400000
RET RET

View File

@ -362,13 +362,14 @@ const (
BI_LT = 0 BI_LT = 0
BI_GT = 1 BI_GT = 1
BI_EQ = 2 BI_EQ = 2
BI_OVF = 3 BI_FU = 3
) )
// Common values for the BO field. // Common values for the BO field.
const ( const (
BO_BCTR = 16 // decrement ctr, branch on ctr != 0 BO_BCTR = 16 // decrement ctr, branch on ctr != 0
BO_NOTBCTR = 18 // decrement ctr, branch on ctr == 0
BO_BCR = 12 // branch on cr value BO_BCR = 12 // branch on cr value
BO_BCRBCTR = 8 // decrement ctr, branch on ctr != 0 and cr value BO_BCRBCTR = 8 // decrement ctr, branch on ctr != 0 and cr value
BO_NOTBCR = 4 // branch on not cr value BO_NOTBCR = 4 // branch on not cr value
@ -481,8 +482,10 @@ const (
ABLE // not GT = L/E/U ABLE // not GT = L/E/U
ABLT ABLT
ABNE // not EQ = L/G/U ABNE // not EQ = L/G/U
ABVC // Unordered-clear ABVC // Branch if float not unordered (also branch on not summary overflow)
ABVS // Unordered-set ABVS // Branch if float unordered (also branch on summary overflow)
ABDNZ // Decrement CTR, and branch if CTR != 0
ABDZ // Decrement CTR, and branch if CTR == 0
ACMP ACMP
ACMPU ACMPU
ACMPEQB ACMPEQB

View File

@ -42,6 +42,8 @@ var Anames = []string{
"BNE", "BNE",
"BVC", "BVC",
"BVS", "BVS",
"BDNZ",
"BDZ",
"CMP", "CMP",
"CMPU", "CMPU",
"CMPEQB", "CMPEQB",

View File

@ -305,6 +305,7 @@ var optab = []Optab{
{as: ABC, a1: C_SCON, a2: C_REG, a6: C_LR, type_: 18, size: 4}, {as: ABC, a1: C_SCON, a2: C_REG, a6: C_LR, type_: 18, size: 4},
{as: ABC, a1: C_SCON, a2: C_REG, a6: C_CTR, type_: 18, size: 4}, {as: ABC, a1: C_SCON, a2: C_REG, a6: C_CTR, type_: 18, size: 4},
{as: ABC, a6: C_ZOREG, type_: 15, size: 8}, {as: ABC, a6: C_ZOREG, type_: 15, size: 8},
{as: ABDNZ, a6: C_SBRA, type_: 16, size: 4},
{as: ASYNC, type_: 46, size: 4}, {as: ASYNC, type_: 46, size: 4},
{as: AWORD, a1: C_LCON, type_: 40, size: 4}, {as: AWORD, a1: C_LCON, type_: 40, size: 4},
{as: ADWORD, a1: C_64CON, type_: 31, size: 8}, {as: ADWORD, a1: C_64CON, type_: 31, size: 8},
@ -1778,6 +1779,9 @@ func buildop(ctxt *obj.Link) {
case ABC: case ABC:
opset(ABCL, r0) opset(ABCL, r0)
case ABDNZ:
opset(ABDZ, r0)
case AEXTSB: /* op Rs, Ra */ case AEXTSB: /* op Rs, Ra */
opset(AEXTSBCC, r0) opset(AEXTSBCC, r0)
@ -4875,21 +4879,25 @@ func (c *ctxt9) opirr(a obj.As) uint32 {
return OPVCC(16, 0, 0, 0) | 1 return OPVCC(16, 0, 0, 0) | 1
case ABEQ: case ABEQ:
return AOP_RRR(16<<26, 12, 2, 0) return AOP_RRR(16<<26, BO_BCR, BI_EQ, 0)
case ABGE: case ABGE:
return AOP_RRR(16<<26, 4, 0, 0) return AOP_RRR(16<<26, BO_NOTBCR, BI_LT, 0)
case ABGT: case ABGT:
return AOP_RRR(16<<26, 12, 1, 0) return AOP_RRR(16<<26, BO_BCR, BI_GT, 0)
case ABLE: case ABLE:
return AOP_RRR(16<<26, 4, 1, 0) return AOP_RRR(16<<26, BO_NOTBCR, BI_GT, 0)
case ABLT: case ABLT:
return AOP_RRR(16<<26, 12, 0, 0) return AOP_RRR(16<<26, BO_BCR, BI_LT, 0)
case ABNE: case ABNE:
return AOP_RRR(16<<26, 4, 2, 0) return AOP_RRR(16<<26, BO_NOTBCR, BI_EQ, 0)
case ABVC: case ABVC:
return AOP_RRR(16<<26, 4, 3, 0) // apparently unordered-clear return AOP_RRR(16<<26, BO_NOTBCR, BI_FU, 0)
case ABVS: case ABVS:
return AOP_RRR(16<<26, 12, 3, 0) // apparently unordered-set return AOP_RRR(16<<26, BO_BCR, BI_FU, 0)
case ABDZ:
return AOP_RRR(16<<26, BO_NOTBCTR, 0, 0)
case ABDNZ:
return AOP_RRR(16<<26, BO_BCTR, 0, 0)
case ACMP: case ACMP:
return OPVCC(11, 0, 0, 0) | 1<<21 /* L=1 */ return OPVCC(11, 0, 0, 0) | 1<<21 /* L=1 */