[go/dev.simd] [dev.simd] simd/_gen: parse SHA features from XED

0 views
Skip to first unread message

Junyang Shao (Gerrit)

unread,
3:19 PM (9 hours ago) 3:19 PM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Junyang Shao has uploaded the change for review

Commit message

[dev.simd] simd/_gen: parse SHA features from XED

To parse SHA feature instructions from XED, this CL added some utility
to decode fixed reg operands.

SHA512 parsing will be in next CL as we don't have SHA512 cpu features
in src/internal/cpu/cpu.go yet.
Change-Id: Id14cced57eab2ca9e75693a201f4ce7c04981587

Change diff

diff --git a/src/simd/_gen/simdgen/xed.go b/src/simd/_gen/simdgen/xed.go
index c3eb478..76bd584 100644
--- a/src/simd/_gen/simdgen/xed.go
+++ b/src/simd/_gen/simdgen/xed.go
@@ -22,9 +22,10 @@
)

const (
- NOT_REG_CLASS = 0 // not a register
- VREG_CLASS = 1 // classify as a vector register; see
- GREG_CLASS = 2 // classify as a general register
+ NOT_REG_CLASS = iota // not a register
+ VREG_CLASS // classify as a vector register; see
+ GREG_CLASS // classify as a general register
+ REG_FIXED // classify as a fixed register
)

// instVariant is a bitmap indicating a variant of an instruction that has
@@ -78,8 +79,8 @@
switch {
case inst.RealOpcode == "N":
return // Skip unstable instructions
- case !strings.HasPrefix(inst.Extension, "AVX"):
- // We're only interested in AVX instructions.
+ case !(strings.HasPrefix(inst.Extension, "AVX") || strings.HasPrefix(inst.Extension, "SHA")):
+ // We're only interested in AVX and SHA instructions.
return
}

@@ -283,8 +284,9 @@
}

type vecShape struct {
- elemBits int // Element size in bits
- bits int // Register width in bits (total vector bits)
+ elemBits int // Element size in bits
+ bits int // Register width in bits (total vector bits)
+ fixedName string // the fixed register name
}

type operandVReg struct { // Vector register
@@ -364,6 +366,9 @@
if o.elemBits != o.bits {
b.Add("elemBits", strVal(o.elemBits))
}
+ if o.fixedName != "" {
+ b.Add("fixedReg", strVal(o.fixedName))
+ }
}

func (o operandGReg) addToDef(b *unify.DefBuilder) {
@@ -377,6 +382,9 @@
if o.elemBits != o.bits {
b.Add("elemBits", strVal(o.elemBits))
}
+ if o.fixedName != "" {
+ b.Add("fixedReg", strVal(o.fixedName))
+ }
}

func (o operandMask) addToDef(b *unify.DefBuilder) {
@@ -387,6 +395,9 @@
}
b.Add("elemBits", strVal(o.elemBits))
b.Add("bits", strVal(o.bits))
+ if o.fixedName != "" {
+ b.Add("fixedReg", strVal(o.fixedName))
+ }
}

func (o operandImm) addToDef(b *unify.DefBuilder) {
@@ -470,7 +481,7 @@
optional: op.Attributes["TXT=ZEROSTR"],
}, nil
} else {
- class, regBits := decodeReg(op)
+ class, regBits, fixedReg := decodeReg(op)
if class == NOT_REG_CLASS {
return nil, fmt.Errorf("failed to decode register %q", operand)
}
@@ -478,7 +489,7 @@
if !ok {
return nil, fmt.Errorf("failed to decode register width %q", operand)
}
- shape := vecShape{elemBits: elemBits, bits: regBits}
+ shape := vecShape{elemBits: elemBits, bits: regBits, fixedName: fixedReg}
if class == VREG_CLASS {
return operandVReg{
operandCommon: common,
@@ -782,6 +793,8 @@
// cpuFeatureMap maps from XED's "EXTENSION" and "ISA_SET" to a CPU feature name
// that can be used in the SIMD API.
var cpuFeatureMap = map[cpuFeatureKey]string{
+ {"SHA", "SHA"}: "SHA",
+
{"AVX", ""}: "AVX",
{"AVX_VNNI", "AVX_VNNI"}: "AVXVNNI",
{"AVX2", ""}: "AVX2",
@@ -832,10 +845,20 @@
return xs[0], true
}

-// decodeReg returns class (NOT_REG_CLASS, VREG_CLASS, GREG_CLASS),
-// and width in bits. If the operand cannot be decided as a register,
-// then the clas is NOT_REG_CLASS.
-func decodeReg(op *xeddata.Operand) (class, width int) {
+type fixedReg struct {
+ class int
+ name string
+ width int
+}
+
+var fixedRegMap = map[string]fixedReg{
+ "XED_REG_XMM0": {REG_FIXED, "XMM0", 128},
+}
+
+// decodeReg returns class (NOT_REG_CLASS, VREG_CLASS, GREG_CLASS, VREG_CLASS_FIXED,
+// GREG_CLASS_FIXED), width in bits and reg name(if fixed).
+// If the operand cannot be decided as a register, then the clas is NOT_REG_CLASS.
+func decodeReg(op *xeddata.Operand) (class, width int, name string) {
// op.Width tells us the total width, e.g.,:
//
// dq => 128 bits (XMM)
@@ -848,27 +871,30 @@
// Hence, we dig into the register sets themselves.

if !strings.HasPrefix(op.NameLHS(), "REG") {
- return NOT_REG_CLASS, 0
+ return NOT_REG_CLASS, 0, ""
}
// TODO: We shouldn't be relying on the macro naming conventions. We should
// use all-dec-patterns.txt, but xeddata doesn't support that table right now.
rhs := op.NameRHS()
if !strings.HasSuffix(rhs, "()") {
- return NOT_REG_CLASS, 0
+ if fixedReg, ok := fixedRegMap[rhs]; ok {
+ return fixedReg.class, fixedReg.width, fixedReg.name
+ }
+ return NOT_REG_CLASS, 0, ""
}
switch {
case strings.HasPrefix(rhs, "XMM_"):
- return VREG_CLASS, 128
+ return VREG_CLASS, 128, ""
case strings.HasPrefix(rhs, "YMM_"):
- return VREG_CLASS, 256
+ return VREG_CLASS, 256, ""
case strings.HasPrefix(rhs, "ZMM_"):
- return VREG_CLASS, 512
+ return VREG_CLASS, 512, ""
case strings.HasPrefix(rhs, "GPR64_"), strings.HasPrefix(rhs, "VGPR64_"):
- return GREG_CLASS, 64
+ return GREG_CLASS, 64, ""
case strings.HasPrefix(rhs, "GPR32_"), strings.HasPrefix(rhs, "VGPR32_"):
- return GREG_CLASS, 32
+ return GREG_CLASS, 32, ""
}
- return NOT_REG_CLASS, 0
+ return NOT_REG_CLASS, 0, ""
}

var xtypeRe = regexp.MustCompile(`^([iuf])([0-9]+)$`)

Change information

Files:
  • M src/simd/_gen/simdgen/xed.go
Change size: M
Delta: 1 file changed, 47 insertions(+), 21 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: dev.simd
Gerrit-Change-Id: Id14cced57eab2ca9e75693a201f4ce7c04981587
Gerrit-Change-Number: 712181
Gerrit-PatchSet: 1
Gerrit-Owner: Junyang Shao <shaoj...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Junyang Shao (Gerrit)

unread,
3:19 PM (8 hours ago) 3:19 PM
to goph...@pubsubhelper.golang.org, David Chase, golang-co...@googlegroups.com
Attention needed from David Chase

Junyang Shao voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • David Chase
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: dev.simd
Gerrit-Change-Id: Id14cced57eab2ca9e75693a201f4ce7c04981587
Gerrit-Change-Number: 712181
Gerrit-PatchSet: 1
Gerrit-Owner: Junyang Shao <shaoj...@google.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
Gerrit-Attention: David Chase <drc...@google.com>
Gerrit-Comment-Date: Wed, 15 Oct 2025 19:19:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

David Chase (Gerrit)

unread,
5:09 PM (7 hours ago) 5:09 PM
to Junyang Shao, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Junyang Shao

David Chase voted and added 1 comment

Votes added by David Chase

Code-Review+2
Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
David Chase . resolved

Failure looks flaky, will try again anyway. Maybe we need to re-sync with master.

Open in Gerrit

Related details

Attention is currently required from:
  • Junyang Shao
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: dev.simd
Gerrit-Change-Id: Id14cced57eab2ca9e75693a201f4ce7c04981587
Gerrit-Change-Number: 712181
Gerrit-PatchSet: 1
Gerrit-Owner: Junyang Shao <shaoj...@google.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Junyang Shao <shaoj...@google.com>
Gerrit-Attention: Junyang Shao <shaoj...@google.com>
Gerrit-Comment-Date: Wed, 15 Oct 2025 21:09:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages