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

compiler: fix ARMv8 regression introduced in #2345 #2365

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (

"github.com/tetratelabs/wazero/api"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/engine/interpreter"
"github.com/tetratelabs/wazero/internal/engine/wazevo"
"github.com/tetratelabs/wazero/internal/filecache"
"github.com/tetratelabs/wazero/internal/internalapi"
"github.com/tetratelabs/wazero/internal/platform"
Expand Down Expand Up @@ -175,7 +173,9 @@ type RuntimeConfig interface {
// NewRuntimeConfig returns a RuntimeConfig using the compiler if it is supported in this environment,
// or the interpreter otherwise.
func NewRuntimeConfig() RuntimeConfig {
return newRuntimeConfig()
ret := engineLessConfig.clone()
ret.engineKind = engineKindAuto
return ret
}

type newEngine func(context.Context, api.CoreFeatures, filecache.Cache) wasm.Engine
Expand Down Expand Up @@ -203,7 +203,8 @@ var engineLessConfig = &runtimeConfig{
type engineKind int

const (
engineKindCompiler engineKind = iota
engineKindAuto engineKind = iota - 1
engineKindCompiler
engineKindInterpreter
engineKindCount
)
Expand Down Expand Up @@ -234,15 +235,13 @@ const (
func NewRuntimeConfigCompiler() RuntimeConfig {
ret := engineLessConfig.clone()
ret.engineKind = engineKindCompiler
ret.newEngine = wazevo.NewEngine
return ret
}

// NewRuntimeConfigInterpreter interprets WebAssembly modules instead of compiling them into assembly.
func NewRuntimeConfigInterpreter() RuntimeConfig {
ret := engineLessConfig.clone()
ret.engineKind = engineKindInterpreter
ret.newEngine = interpreter.NewEngine
return ret
}

Expand Down
19 changes: 0 additions & 19 deletions config_supported.go

This file was deleted.

6 changes: 1 addition & 5 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,5 @@ func TestNewRuntimeConfig(t *testing.T) {
// Should be cloned from the source.
require.NotEqual(t, engineLessConfig, c)
// Ensures if the correct engine is selected.
if platform.CompilerSupported() {
require.Equal(t, engineKindCompiler, c.engineKind)
} else {
require.Equal(t, engineKindInterpreter, c.engineKind)
}
require.Equal(t, engineKindAuto, c.engineKind)
}
8 changes: 0 additions & 8 deletions config_unsupported.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/engine/wazevo/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func TestMain(m *testing.M) {
if !platform.CompilerSupported() {
if !platform.CompilerSupports(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads) {
os.Exit(0)
}
os.Exit(m.Run())
Expand Down
2 changes: 1 addition & 1 deletion internal/integration_test/engine/threads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestThreadsNotEnabled(t *testing.T) {
}

func TestThreadsCompiler_hammer(t *testing.T) {
if !platform.CompilerSupported() {
if !platform.CompilerSupports(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads) {
t.Skip()
}
runAllTests(t, threadTests, wazero.NewRuntimeConfigCompiler().WithCoreFeatures(api.CoreFeaturesV2|experimental.CoreFeaturesThreads), false)
Expand Down
20 changes: 15 additions & 5 deletions internal/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ package platform

import (
"runtime"
)

// archRequirementsVerified is set by platform-specific init to true if the platform is supported
var archRequirementsVerified bool
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
)

// CompilerSupported includes constraints here and also the assembler.
func CompilerSupported() bool {
return CompilerSupports(api.CoreFeaturesV2)
}

func CompilerSupports(features api.CoreFeatures) bool {
switch runtime.GOOS {
case "linux", "darwin", "freebsd", "netbsd", "dragonfly", "windows":
return archRequirementsVerified
if runtime.GOARCH == "arm64" {
if features.IsEnabled(experimental.CoreFeaturesThreads) {
return CpuFeatures.Has(CpuFeatureArm64Atomic)
}
return true
}
fallthrough
case "solaris", "illumos":
return runtime.GOARCH == "amd64" && archRequirementsVerified
return runtime.GOARCH == "amd64" && CpuFeatures.Has(CpuFeatureAmd64SSE4_1)
default:
return false
}
Expand Down
7 changes: 0 additions & 7 deletions internal/platform/platform_amd64.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/platform/platform_arm64.go

This file was deleted.

22 changes: 0 additions & 22 deletions internal/platform/platform_test.go

This file was deleted.

23 changes: 21 additions & 2 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (

"github.com/tetratelabs/wazero/api"
experimentalapi "github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/internal/engine/interpreter"
"github.com/tetratelabs/wazero/internal/engine/wazevo"
"github.com/tetratelabs/wazero/internal/expctxkeys"
"github.com/tetratelabs/wazero/internal/platform"
internalsock "github.com/tetratelabs/wazero/internal/sock"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/wasm"
Expand Down Expand Up @@ -148,15 +151,31 @@ func NewRuntime(ctx context.Context) Runtime {
// NewRuntimeWithConfig returns a runtime with the given configuration.
func NewRuntimeWithConfig(ctx context.Context, rConfig RuntimeConfig) Runtime {
config := rConfig.(*runtimeConfig)
configKind := config.engineKind
configEngine := config.newEngine
if configKind == engineKindAuto {
if platform.CompilerSupports(config.enabledFeatures) {
configKind = engineKindCompiler
} else {
configKind = engineKindInterpreter
}
}
if configEngine == nil {
if configKind == engineKindCompiler {
configEngine = wazevo.NewEngine
} else {
configEngine = interpreter.NewEngine
}
}
var engine wasm.Engine
var cacheImpl *cache
if c := config.cache; c != nil {
// If the Cache is configured, we share the engine.
cacheImpl = c.(*cache)
engine = cacheImpl.initEngine(config.engineKind, config.newEngine, ctx, config.enabledFeatures)
engine = cacheImpl.initEngine(configKind, configEngine, ctx, config.enabledFeatures)
} else {
// Otherwise, we create a new engine.
engine = config.newEngine(ctx, config.enabledFeatures, nil)
engine = configEngine(ctx, config.enabledFeatures, nil)
}
store := wasm.NewStore(config.enabledFeatures, engine)
return &runtime{
Expand Down
Loading