Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1111. #1112

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ retract (
v1.0.0-beta.2
v1.0.0-beta.1
)

require github.com/zcalusic/sysinfo v0.9.5
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/zcalusic/sysinfo v0.9.5 h1:ivoHyj9aIAYkwzo1+8QgJ5s4oeE6Etx9FmZtqa4wJjQ=
github.com/zcalusic/sysinfo v0.9.5/go.mod h1:Z/gPVufBrFc8X5sef3m6kkw3r3nlNFp+I6bvASfvBZQ=
19 changes: 16 additions & 3 deletions internal/engine/compiler/impl_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"bytes"
"fmt"
"math"
"runtime"

"github.com/zcalusic/sysinfo/cpuid"

"github.com/tetratelabs/wazero/internal/asm"
"github.com/tetratelabs/wazero/internal/asm/amd64"
Expand Down Expand Up @@ -1151,14 +1152,26 @@ func (c *amd64Compiler) compileMulForFloats(instruction asm.Instruction) error {
return nil
}

func hasLZCNT() bool {
// https://www.amd.com/system/files/TechDocs/25481.pdf
const (
Fn8000_0001 = 0x8000_0001
ABM = 0x0400_0000 // ABM is the 5th bit, from the left, zero based, EDX register
EDX = 3
)
var out [4]uint32
cpuid.CPUID(&out, Fn8000_0001)
return out[EDX]&ABM != 0
}

// compileClz implements compiler.compileClz for the amd64 architecture.
func (c *amd64Compiler) compileClz(o *wazeroir.OperationClz) error {
target := c.locationStack.pop()
if err := c.compileEnsureOnRegister(target); err != nil {
return err
}

if runtime.GOOS != "darwin" && runtime.GOOS != "freebsd" {
if hasLZCNT() {
if o.Type == wazeroir.UnsignedInt32 {
c.assembler.CompileRegisterToRegister(amd64.LZCNTL, target.register, target.register)
} else {
Expand Down Expand Up @@ -1221,7 +1234,7 @@ func (c *amd64Compiler) compileCtz(o *wazeroir.OperationCtz) error {
return err
}

if runtime.GOOS != "darwin" && runtime.GOOS != "freebsd" {
if hasLZCNT() {
if o.Type == wazeroir.UnsignedInt32 {
c.assembler.CompileRegisterToRegister(amd64.TZCNTL, target.register, target.register)
} else {
Expand Down