Skip to content

Commit

Permalink
compiler: fix ARMv8 regression introduced in #2345
Browse files Browse the repository at this point in the history
Signed-off-by: Nuno Cruces <[email protected]>
  • Loading branch information
ncruces committed Jan 16, 2025
1 parent edb3c73 commit 70425b8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 81 deletions.
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.

17 changes: 17 additions & 0 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,6 +151,20 @@ 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)
if config.engineKind == engineKindAuto {
if platform.CompilerSupports(config.enabledFeatures) {
config.engineKind = engineKindCompiler
} else {
config.engineKind = engineKindInterpreter
}
}
if config.newEngine == nil {
if config.engineKind == engineKindCompiler {
config.newEngine = wazevo.NewEngine
} else {
config.newEngine = interpreter.NewEngine
}
}
var engine wasm.Engine
var cacheImpl *cache
if c := config.cache; c != nil {
Expand Down

0 comments on commit 70425b8

Please sign in to comment.