You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2022/04/13 18:15:17 UTC
[arrow] branch master updated: ARROW-16193: [Go] Replace CPU discovery package with golang.org/x/sys/cpu module
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 6240eae218 ARROW-16193: [Go] Replace CPU discovery package with golang.org/x/sys/cpu module
6240eae218 is described below
commit 6240eae2189d938b4f98b8d8235146baed0246c5
Author: Frederic Branczyk <fb...@gmail.com>
AuthorDate: Wed Apr 13 14:14:59 2022 -0400
ARROW-16193: [Go] Replace CPU discovery package with golang.org/x/sys/cpu module
The package deleted in this commit is an outdated copy of a package that
used to be an internal package in the Go standard library, but since
then it has been moved to the publicly accessible golang.org/x/sys
module. Since that module is already used, this commit does not even add
a new dependency.
Other than removing unnecessary code it also makes CPU feature discovery
more consistent with other projects in the Go ecosystem. For example it
is no longer necessary to pass an environment variable to enable usage
of ARM64 NEON SIMD instructions.
Closes #12764 from brancz/go-cpu-discovery
Authored-by: Frederic Branczyk <fb...@gmail.com>
Signed-off-by: Matthew Topol <mt...@factset.com>
---
go/arrow/internal/cpu/README.md | 42 ---------------
go/arrow/internal/cpu/cpu.go | 77 --------------------------
go/arrow/internal/cpu/cpu_arm64.go | 37 -------------
go/arrow/internal/cpu/cpu_s390x.go | 7 ---
go/arrow/internal/cpu/cpu_test.go | 51 ------------------
go/arrow/internal/cpu/cpu_x86.go | 107 -------------------------------------
go/arrow/internal/cpu/cpu_x86.s | 32 -----------
go/arrow/math/math_amd64.go | 2 +-
go/arrow/math/math_arm64.go | 2 +-
go/arrow/memory/memory_amd64.go | 2 +-
go/arrow/memory/memory_arm64.go | 2 +-
11 files changed, 4 insertions(+), 357 deletions(-)
diff --git a/go/arrow/internal/cpu/README.md b/go/arrow/internal/cpu/README.md
deleted file mode 100644
index 2619b38c11..0000000000
--- a/go/arrow/internal/cpu/README.md
+++ /dev/null
@@ -1,42 +0,0 @@
-<!---
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-
-# Package cpu
-
-Copied from Go src/internal/cpu
-
-## Extras
-
-### Intel
-
-The `INTEL_DISABLE_EXT` environment variable can control which CPU extensions are available for
-the running process. It should be a comma-separate list of upper-case strings as follows
-
-| Flag | Description |
-| -------- | ----------- |
-| `ALL` | Disable all CPU extensions and fall back to Go implementation |
-| `AVX2` | Disable AVX2 optimizations |
-| `AVX` | Disable AVX optimizations |
-| `SSE` | Disable all SSE optimizations |
-| `SSE4` | Disable SSE42, SSE41 optimizations |
-| `SSSE3` | Disable supplemental SSE3 optimizations |
-| `SSE3` | Disable SSE3 optimizations |
-| `SSE2` | Disable SSE2 optimizations |
-
-Any unrecognized flags will be ignored and therefore it is possible to leave the environment variable with a bogus value such as `NONE` when experimenting.
\ No newline at end of file
diff --git a/go/arrow/internal/cpu/cpu.go b/go/arrow/internal/cpu/cpu.go
deleted file mode 100644
index 22fc561002..0000000000
--- a/go/arrow/internal/cpu/cpu.go
+++ /dev/null
@@ -1,77 +0,0 @@
-// 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.
-
-// Package cpu implements processor feature detection
-// used by the Go standard library.
-package cpu
-
-var X86 x86
-
-// The booleans in x86 contain the correspondingly named cpuid feature bit.
-// HasAVX and HasAVX2 are only set if the OS does support XMM and YMM registers
-// in addition to the cpuid feature bit being set.
-// The struct is padded to avoid false sharing.
-type x86 struct {
- _ [CacheLineSize]byte
- HasAES bool
- HasADX bool
- HasAVX bool
- HasAVX2 bool
- HasBMI1 bool
- HasBMI2 bool
- HasERMS bool
- HasFMA bool
- HasOSXSAVE bool
- HasPCLMULQDQ bool
- HasPOPCNT bool
- HasSSE2 bool
- HasSSE3 bool
- HasSSSE3 bool
- HasSSE41 bool
- HasSSE42 bool
- _ [CacheLineSize]byte
-}
-
-var PPC64 ppc64
-
-// For ppc64x, it is safe to check only for ISA level starting on ISA v3.00,
-// since there are no optional categories. There are some exceptions that also
-// require kernel support to work (darn, scv), so there are capability bits for
-// those as well. The minimum processor requirement is POWER8 (ISA 2.07), so we
-// maintain some of the old capability checks for optional categories for
-// safety.
-// The struct is padded to avoid false sharing.
-type ppc64 struct {
- _ [CacheLineSize]byte
- HasVMX bool // Vector unit (Altivec)
- HasDFP bool // Decimal Floating Point unit
- HasVSX bool // Vector-scalar unit
- HasHTM bool // Hardware Transactional Memory
- HasISEL bool // Integer select
- HasVCRYPTO bool // Vector cryptography
- HasHTMNOSC bool // HTM: kernel-aborted transaction in syscalls
- HasDARN bool // Hardware random number generator (requires kernel enablement)
- HasSCV bool // Syscall vectored (requires kernel enablement)
- IsPOWER8 bool // ISA v2.07 (POWER8)
- IsPOWER9 bool // ISA v3.00 (POWER9)
- _ [CacheLineSize]byte
-}
-
-var ARM64 arm64
-
-// The booleans in arm64 contain the correspondingly named cpu feature bit.
-// The struct is padded to avoid false sharing.
-type arm64 struct {
- _ [CacheLineSize]byte
- HasFP bool
- HasASIMD bool
- HasEVTSTRM bool
- HasAES bool
- HasPMULL bool
- HasSHA1 bool
- HasSHA2 bool
- HasCRC32 bool
- HasATOMICS bool
- _ [CacheLineSize]byte
-}
diff --git a/go/arrow/internal/cpu/cpu_arm64.go b/go/arrow/internal/cpu/cpu_arm64.go
deleted file mode 100644
index 5d8db435c0..0000000000
--- a/go/arrow/internal/cpu/cpu_arm64.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2020 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.
-
-//go:build arm64
-// +build arm64
-
-package cpu
-
-import (
- "os"
- "strings"
-)
-
-const CacheLineSize = 64
-
-func init() {
- // NOTE(sgc): added ability to enable extension via environment
- if ext, ok := os.LookupEnv("ARM_ENABLE_EXT"); ok {
- exts := strings.Split(ext, ",")
-
- for _, x := range exts {
- switch x {
- case "NEON":
- ARM64.HasASIMD = true
- case "AES":
- ARM64.HasAES = true
- case "PMULL":
- ARM64.HasPMULL = true
- default:
- ARM64.HasASIMD = false
- ARM64.HasAES = false
- ARM64.HasPMULL = false
- }
- }
- }
-}
diff --git a/go/arrow/internal/cpu/cpu_s390x.go b/go/arrow/internal/cpu/cpu_s390x.go
deleted file mode 100644
index 3c1a296424..0000000000
--- a/go/arrow/internal/cpu/cpu_s390x.go
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2020 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.
-
-package cpu
-
-const CacheLineSize = 256
diff --git a/go/arrow/internal/cpu/cpu_test.go b/go/arrow/internal/cpu/cpu_test.go
deleted file mode 100644
index 8975483419..0000000000
--- a/go/arrow/internal/cpu/cpu_test.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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.
-
-package cpu_test
-
-import (
- "runtime"
- "testing"
-
- "github.com/apache/arrow/go/v8/arrow/internal/cpu"
-)
-
-func TestAMD64minimalFeatures(t *testing.T) {
- if runtime.GOARCH == "amd64" {
- if !cpu.X86.HasSSE2 {
- t.Fatalf("HasSSE2 expected true, got false")
- }
- }
-}
-
-func TestAVX2hasAVX(t *testing.T) {
- if runtime.GOARCH == "amd64" {
- if cpu.X86.HasAVX2 && !cpu.X86.HasAVX {
- t.Fatalf("HasAVX expected true, got false")
- }
- }
-}
-
-func TestPPC64minimalFeatures(t *testing.T) {
- if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
- if !cpu.PPC64.IsPOWER8 {
- t.Fatalf("IsPOWER8 expected true, got false")
- }
- if !cpu.PPC64.HasVMX {
- t.Fatalf("HasVMX expected true, got false")
- }
- if !cpu.PPC64.HasDFP {
- t.Fatalf("HasDFP expected true, got false")
- }
- if !cpu.PPC64.HasVSX {
- t.Fatalf("HasVSX expected true, got false")
- }
- if !cpu.PPC64.HasISEL {
- t.Fatalf("HasISEL expected true, got false")
- }
- if !cpu.PPC64.HasVCRYPTO {
- t.Fatalf("HasVCRYPTO expected true, got false")
- }
- }
-}
diff --git a/go/arrow/internal/cpu/cpu_x86.go b/go/arrow/internal/cpu/cpu_x86.go
deleted file mode 100644
index 777269f1a2..0000000000
--- a/go/arrow/internal/cpu/cpu_x86.go
+++ /dev/null
@@ -1,107 +0,0 @@
-// 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.
-
-// +build 386 amd64 amd64p32
-
-package cpu
-
-import (
- "os"
- "strings"
-)
-
-const CacheLineSize = 64
-
-// cpuid is implemented in cpu_x86.s.
-func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
-
-// xgetbv with ecx = 0 is implemented in cpu_x86.s.
-func xgetbv() (eax, edx uint32)
-
-func init() {
- maxID, _, _, _ := cpuid(0, 0)
-
- if maxID < 1 {
- return
- }
-
- _, _, ecx1, edx1 := cpuid(1, 0)
- X86.HasSSE2 = isSet(26, edx1)
-
- X86.HasSSE3 = isSet(0, ecx1)
- X86.HasPCLMULQDQ = isSet(1, ecx1)
- X86.HasSSSE3 = isSet(9, ecx1)
- X86.HasFMA = isSet(12, ecx1)
- X86.HasSSE41 = isSet(19, ecx1)
- X86.HasSSE42 = isSet(20, ecx1)
- X86.HasPOPCNT = isSet(23, ecx1)
- X86.HasAES = isSet(25, ecx1)
- X86.HasOSXSAVE = isSet(27, ecx1)
-
- osSupportsAVX := false
- // For XGETBV, OSXSAVE bit is required and sufficient.
- if X86.HasOSXSAVE {
- eax, _ := xgetbv()
- // Check if XMM and YMM registers have OS support.
- osSupportsAVX = isSet(1, eax) && isSet(2, eax)
- }
-
- X86.HasAVX = isSet(28, ecx1) && osSupportsAVX
-
- if maxID < 7 {
- return
- }
-
- _, ebx7, _, _ := cpuid(7, 0)
- X86.HasBMI1 = isSet(3, ebx7)
- X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX
- X86.HasBMI2 = isSet(8, ebx7)
- X86.HasERMS = isSet(9, ebx7)
- X86.HasADX = isSet(19, ebx7)
-
- // NOTE(sgc): added ability to disable extension via environment
- checkEnvironment()
-}
-func checkEnvironment() {
- if ext, ok := os.LookupEnv("INTEL_DISABLE_EXT"); ok {
- exts := strings.Split(ext, ",")
-
- for _, x := range exts {
- switch x {
- case "ALL":
- X86.HasAVX2 = false
- X86.HasAVX = false
- X86.HasSSE42 = false
- X86.HasSSE41 = false
- X86.HasSSSE3 = false
- X86.HasSSE3 = false
- X86.HasSSE2 = false
-
- case "AVX2":
- X86.HasAVX2 = false
- case "AVX":
- X86.HasAVX = false
- case "SSE":
- X86.HasSSE42 = false
- X86.HasSSE41 = false
- X86.HasSSSE3 = false
- X86.HasSSE3 = false
- X86.HasSSE2 = false
- case "SSE4":
- X86.HasSSE42 = false
- X86.HasSSE41 = false
- case "SSSE3":
- X86.HasSSSE3 = false
- case "SSE3":
- X86.HasSSE3 = false
- case "SSE2":
- X86.HasSSE2 = false
- }
- }
- }
-}
-
-func isSet(bitpos uint, value uint32) bool {
- return value&(1<<bitpos) != 0
-}
diff --git a/go/arrow/internal/cpu/cpu_x86.s b/go/arrow/internal/cpu/cpu_x86.s
deleted file mode 100644
index 228fbcf6d6..0000000000
--- a/go/arrow/internal/cpu/cpu_x86.s
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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.
-
-// +build 386 amd64 amd64p32
-
-#include "textflag.h"
-
-// func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
-TEXT ·cpuid(SB), NOSPLIT, $0-24
- MOVL eaxArg+0(FP), AX
- MOVL ecxArg+4(FP), CX
- CPUID
- MOVL AX, eax+8(FP)
- MOVL BX, ebx+12(FP)
- MOVL CX, ecx+16(FP)
- MOVL DX, edx+20(FP)
- RET
-
-// func xgetbv() (eax, edx uint32)
-TEXT ·xgetbv(SB),NOSPLIT,$0-8
-#ifdef GOOS_nacl
- // nacl does not support XGETBV.
- MOVL $0, eax+0(FP)
- MOVL $0, edx+4(FP)
-#else
- MOVL $0, CX
- XGETBV
- MOVL AX, eax+0(FP)
- MOVL DX, edx+4(FP)
-#endif
- RET
diff --git a/go/arrow/math/math_amd64.go b/go/arrow/math/math_amd64.go
index f09dacd68d..44301dc241 100644
--- a/go/arrow/math/math_amd64.go
+++ b/go/arrow/math/math_amd64.go
@@ -19,7 +19,7 @@
package math
import (
- "github.com/apache/arrow/go/v8/arrow/internal/cpu"
+ "golang.org/x/sys/cpu"
)
func init() {
diff --git a/go/arrow/math/math_arm64.go b/go/arrow/math/math_arm64.go
index ad84c35d37..014664b046 100644
--- a/go/arrow/math/math_arm64.go
+++ b/go/arrow/math/math_arm64.go
@@ -19,7 +19,7 @@
package math
import (
- "github.com/apache/arrow/go/v8/arrow/internal/cpu"
+ "golang.org/x/sys/cpu"
)
func init() {
diff --git a/go/arrow/memory/memory_amd64.go b/go/arrow/memory/memory_amd64.go
index 148caa2ceb..58356d6482 100644
--- a/go/arrow/memory/memory_amd64.go
+++ b/go/arrow/memory/memory_amd64.go
@@ -19,7 +19,7 @@
package memory
import (
- "github.com/apache/arrow/go/v8/arrow/internal/cpu"
+ "golang.org/x/sys/cpu"
)
func init() {
diff --git a/go/arrow/memory/memory_arm64.go b/go/arrow/memory/memory_arm64.go
index fbedd2d4fe..3db5d11013 100755
--- a/go/arrow/memory/memory_arm64.go
+++ b/go/arrow/memory/memory_arm64.go
@@ -19,7 +19,7 @@
package memory
import (
- "github.com/apache/arrow/go/v8/arrow/internal/cpu"
+ "golang.org/x/sys/cpu"
)
func init() {