Skip to content

Commit a40188c

Browse files
authored
compiler: fix ARMv8 regression introduced in #2345 (#2365)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
1 parent 4231c48 commit a40188c

File tree

11 files changed

+44
-83
lines changed

11 files changed

+44
-83
lines changed

config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212

1313
"github.com/tetratelabs/wazero/api"
1414
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
15-
"github.com/tetratelabs/wazero/internal/engine/interpreter"
16-
"github.com/tetratelabs/wazero/internal/engine/wazevo"
1715
"github.com/tetratelabs/wazero/internal/filecache"
1816
"github.com/tetratelabs/wazero/internal/internalapi"
1917
"github.com/tetratelabs/wazero/internal/platform"
@@ -175,7 +173,9 @@ type RuntimeConfig interface {
175173
// NewRuntimeConfig returns a RuntimeConfig using the compiler if it is supported in this environment,
176174
// or the interpreter otherwise.
177175
func NewRuntimeConfig() RuntimeConfig {
178-
return newRuntimeConfig()
176+
ret := engineLessConfig.clone()
177+
ret.engineKind = engineKindAuto
178+
return ret
179179
}
180180

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

205205
const (
206-
engineKindCompiler engineKind = iota
206+
engineKindAuto engineKind = iota - 1
207+
engineKindCompiler
207208
engineKindInterpreter
208209
engineKindCount
209210
)
@@ -234,15 +235,13 @@ const (
234235
func NewRuntimeConfigCompiler() RuntimeConfig {
235236
ret := engineLessConfig.clone()
236237
ret.engineKind = engineKindCompiler
237-
ret.newEngine = wazevo.NewEngine
238238
return ret
239239
}
240240

241241
// NewRuntimeConfigInterpreter interprets WebAssembly modules instead of compiling them into assembly.
242242
func NewRuntimeConfigInterpreter() RuntimeConfig {
243243
ret := engineLessConfig.clone()
244244
ret.engineKind = engineKindInterpreter
245-
ret.newEngine = interpreter.NewEngine
246245
return ret
247246
}
248247

config_supported.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

config_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,5 @@ func TestNewRuntimeConfig(t *testing.T) {
670670
// Should be cloned from the source.
671671
require.NotEqual(t, engineLessConfig, c)
672672
// Ensures if the correct engine is selected.
673-
if platform.CompilerSupported() {
674-
require.Equal(t, engineKindCompiler, c.engineKind)
675-
} else {
676-
require.Equal(t, engineKindInterpreter, c.engineKind)
677-
}
673+
require.Equal(t, engineKindAuto, c.engineKind)
678674
}

config_unsupported.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

internal/engine/wazevo/backend/backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func TestMain(m *testing.M) {
25-
if !platform.CompilerSupported() {
25+
if !platform.CompilerSupports(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads) {
2626
os.Exit(0)
2727
}
2828
os.Exit(m.Run())

internal/integration_test/engine/threads_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestThreadsNotEnabled(t *testing.T) {
5454
}
5555

5656
func TestThreadsCompiler_hammer(t *testing.T) {
57-
if !platform.CompilerSupported() {
57+
if !platform.CompilerSupports(api.CoreFeaturesV2 | experimental.CoreFeaturesThreads) {
5858
t.Skip()
5959
}
6060
runAllTests(t, threadTests, wazero.NewRuntimeConfigCompiler().WithCoreFeatures(api.CoreFeaturesV2|experimental.CoreFeaturesThreads), false)

internal/platform/platform.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ package platform
66

77
import (
88
"runtime"
9-
)
109

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

1414
// CompilerSupported includes constraints here and also the assembler.
1515
func CompilerSupported() bool {
16+
return CompilerSupports(api.CoreFeaturesV2)
17+
}
18+
19+
func CompilerSupports(features api.CoreFeatures) bool {
1620
switch runtime.GOOS {
1721
case "linux", "darwin", "freebsd", "netbsd", "dragonfly", "windows":
18-
return archRequirementsVerified
22+
if runtime.GOARCH == "arm64" {
23+
if features.IsEnabled(experimental.CoreFeaturesThreads) {
24+
return CpuFeatures.Has(CpuFeatureArm64Atomic)
25+
}
26+
return true
27+
}
28+
fallthrough
1929
case "solaris", "illumos":
20-
return runtime.GOARCH == "amd64" && archRequirementsVerified
30+
return runtime.GOARCH == "amd64" && CpuFeatures.Has(CpuFeatureAmd64SSE4_1)
2131
default:
2232
return false
2333
}

internal/platform/platform_amd64.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/platform/platform_arm64.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/platform/platform_test.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

runtime.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77

88
"github.com/tetratelabs/wazero/api"
99
experimentalapi "github.com/tetratelabs/wazero/experimental"
10+
"github.com/tetratelabs/wazero/internal/engine/interpreter"
11+
"github.com/tetratelabs/wazero/internal/engine/wazevo"
1012
"github.com/tetratelabs/wazero/internal/expctxkeys"
13+
"github.com/tetratelabs/wazero/internal/platform"
1114
internalsock "github.com/tetratelabs/wazero/internal/sock"
1215
internalsys "github.com/tetratelabs/wazero/internal/sys"
1316
"github.com/tetratelabs/wazero/internal/wasm"
@@ -148,15 +151,31 @@ func NewRuntime(ctx context.Context) Runtime {
148151
// NewRuntimeWithConfig returns a runtime with the given configuration.
149152
func NewRuntimeWithConfig(ctx context.Context, rConfig RuntimeConfig) Runtime {
150153
config := rConfig.(*runtimeConfig)
154+
configKind := config.engineKind
155+
configEngine := config.newEngine
156+
if configKind == engineKindAuto {
157+
if platform.CompilerSupports(config.enabledFeatures) {
158+
configKind = engineKindCompiler
159+
} else {
160+
configKind = engineKindInterpreter
161+
}
162+
}
163+
if configEngine == nil {
164+
if configKind == engineKindCompiler {
165+
configEngine = wazevo.NewEngine
166+
} else {
167+
configEngine = interpreter.NewEngine
168+
}
169+
}
151170
var engine wasm.Engine
152171
var cacheImpl *cache
153172
if c := config.cache; c != nil {
154173
// If the Cache is configured, we share the engine.
155174
cacheImpl = c.(*cache)
156-
engine = cacheImpl.initEngine(config.engineKind, config.newEngine, ctx, config.enabledFeatures)
175+
engine = cacheImpl.initEngine(configKind, configEngine, ctx, config.enabledFeatures)
157176
} else {
158177
// Otherwise, we create a new engine.
159-
engine = config.newEngine(ctx, config.enabledFeatures, nil)
178+
engine = configEngine(ctx, config.enabledFeatures, nil)
160179
}
161180
store := wasm.NewStore(config.enabledFeatures, engine)
162181
return &runtime{

0 commit comments

Comments
 (0)