Skip to content

Commit

Permalink
fix darwin cpu feature detect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Jan 24, 2024
1 parent 5cf5e34 commit 8198f2a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/cpuid/cpuid_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cpuid

import "golang.org/x/sys/cpu"

var HasAES = cpu.X86.HasAES
var HasGFMUL = cpu.X86.HasPCLMULQDQ
6 changes: 6 additions & 0 deletions internal/cpuid/cpuid_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cpuid

import "golang.org/x/sys/cpu"

var HasAES = cpu.ARM64.HasAES
var HasGFMUL = cpu.ARM64.HasPMULL
10 changes: 10 additions & 0 deletions internal/cpuid/cpuid_arm64_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build arm64 && darwin && !ios

package cpuid

// There are no hw.optional sysctl values for the below features on Mac OS 11.0
// to detect their supported state dynamically. Assume the CPU features that
// Apple Silicon M1 supports to be available as a minimal set of features
// to all Go programs running on darwin/arm64.
var HasAES = true
var HasGFMUL = true
5 changes: 3 additions & 2 deletions sm4/cipher_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"os"

"github.com/emmansun/gmsm/internal/alias"
"github.com/emmansun/gmsm/internal/cpuid"
"golang.org/x/sys/cpu"
)

var supportSM4 = cpu.ARM64.HasSM4 && os.Getenv("DISABLE_SM4NI") != "1"
var supportsAES = cpu.X86.HasAES || cpu.ARM64.HasAES
var supportsGFMUL = cpu.X86.HasPCLMULQDQ || cpu.ARM64.HasPMULL
var supportsAES = cpuid.HasAES
var supportsGFMUL = cpuid.HasGFMUL
var useAVX2 = cpu.X86.HasAVX2
var useAVX = cpu.X86.HasAVX

Expand Down
9 changes: 6 additions & 3 deletions zuc/eia_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

package zuc

import "golang.org/x/sys/cpu"
import (
"github.com/emmansun/gmsm/internal/cpuid"
"golang.org/x/sys/cpu"
)

var supportsAES = cpu.X86.HasAES || cpu.ARM64.HasAES
var supportsAES = cpuid.HasAES
var supportsGFMUL = cpuid.HasGFMUL
var useAVX = cpu.X86.HasAVX
var supportsGFMUL = cpu.X86.HasPCLMULQDQ || cpu.ARM64.HasPMULL

//go:noescape
func eia3Round16B(t *uint32, keyStream *uint32, p *byte, tagSize int)
Expand Down

0 comments on commit 8198f2a

Please sign in to comment.