Skip to content

Commit

Permalink
cmd/compile: intrinsify math/bits/ReverseBytes{32|64} for 386
Browse files Browse the repository at this point in the history
The BSWAPL instruction is supported in i486 and newer.
https://github.com/golang/go/wiki/MinimumRequirements#386 says we
support "All Pentium MMX or later". The Pentium is also referred to as
i586, so that we are safe with these instructions.

Change-Id: I6dea1f9d864a45bb07c8f8f35a81cfe16cca216c
Reviewed-on: https://go-review.googlesource.com/c/go/+/465515
Run-TryBot: Wayne Zuo <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
wdvxdr1123 committed Feb 8, 2023
1 parent abd55d8 commit d7ac5d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/ssagen/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4000,10 +4000,10 @@ func InitTables() {
},
sys.ARM64, sys.PPC64)

/* Use only on Power10 as the new byte reverse instructions that Power10 provide
make it worthwhile as an intrinsic */
brev_arch := []sys.ArchFamily{sys.AMD64, sys.ARM64, sys.ARM, sys.S390X}
brev_arch := []sys.ArchFamily{sys.AMD64, sys.I386, sys.ARM64, sys.ARM, sys.S390X}
if buildcfg.GOPPC64 >= 10 {
// Use only on Power10 as the new byte reverse instructions that Power10 provide
// make it worthwhile as an intrinsic
brev_arch = append(brev_arch, sys.PPC64)
}
/******** runtime/internal/sys ********/
Expand Down
3 changes: 3 additions & 0 deletions test/codegen/mathbits.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,15 @@ func OnesCount8(n uint8) int {

func ReverseBytes(n uint) uint {
// amd64:"BSWAPQ"
// 386:"BSWAPL"
// s390x:"MOVDBR"
// arm64:"REV"
return bits.ReverseBytes(n)
}

func ReverseBytes64(n uint64) uint64 {
// amd64:"BSWAPQ"
// 386:"BSWAPL"
// s390x:"MOVDBR"
// arm64:"REV"
// ppc64x/power10: "BRD"
Expand All @@ -204,6 +206,7 @@ func ReverseBytes64(n uint64) uint64 {

func ReverseBytes32(n uint32) uint32 {
// amd64:"BSWAPL"
// 386:"BSWAPL"
// s390x:"MOVWBR"
// arm64:"REVW"
// ppc64x/power10: "BRW"
Expand Down

0 comments on commit d7ac5d1

Please sign in to comment.