chore: use the compile-time GOAMD64 flag in the updater

This commit is contained in:
wwqgtxx
2025-07-23 18:02:46 +08:00
parent 63ad95e10f
commit 9f1da11792
6 changed files with 56 additions and 4 deletions

View File

@@ -0,0 +1,4 @@
package updater
// getGOAMD64level is implemented in cpu_amd64.s. Returns number in [1,4].
func getGOAMD64level() int32

View File

@@ -0,0 +1,22 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "textflag.h"
// func getGOAMD64level() int32
TEXT ·getGOAMD64level(SB),NOSPLIT,$0-4
#ifdef GOAMD64_v4
MOVL $4, ret+0(FP)
#else
#ifdef GOAMD64_v3
MOVL $3, ret+0(FP)
#else
#ifdef GOAMD64_v2
MOVL $2, ret+0(FP)
#else
MOVL $1, ret+0(FP)
#endif
#endif
#endif
RET

View File

@@ -0,0 +1,8 @@
//go:build !amd64
package updater
// getGOAMD64level is always return 0 when not in amd64 platfrom.
func getGOAMD64level() int32 {
return 0
}

View File

@@ -0,0 +1,20 @@
package updater
import (
"fmt"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGOAMD64level(t *testing.T) {
level := getGOAMD64level()
fmt.Printf("GOAMD64=%d\n", level)
if runtime.GOARCH == "amd64" {
assert.True(t, level > 0)
assert.True(t, level <= 4)
} else {
assert.Equal(t, level, int32(0))
}
}

View File

@@ -18,8 +18,6 @@ import (
mihomoHttp "github.com/metacubex/mihomo/component/http"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/log"
"github.com/klauspost/cpuid/v2"
)
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/updater/updater.go
@@ -48,7 +46,7 @@ var (
)
func init() {
if runtime.GOARCH == "amd64" && cpuid.CPU.X64Level() < 3 {
if runtime.GOARCH == "amd64" && getGOAMD64level() < 3 {
amd64Compatible = "-compatible"
}
if !strings.HasPrefix(C.Version, "alpha") {