func InitTables() {
intrinsics = map[intrinsicKey]intrinsicBuilder{}
- var all []*sys.Arch
var p4 []*sys.Arch
var p8 []*sys.Arch
var lwatomics []*sys.Arch
- for _, a := range &sys.Archs {
- all = append(all, a)
+ for _, a := range sys.Archs {
if a.PtrSize == 4 {
p4 = append(p4, a)
} else {
lwatomics = append(lwatomics, a)
}
}
+ all := sys.Archs[:]
// add adds the intrinsic b for pkg.fn for the given list of architectures.
add := func(pkg, fn string, b intrinsicBuilder, archs ...*sys.Arch) {
}
// addF does the same as add but operates on architecture families.
addF := func(pkg, fn string, b intrinsicBuilder, archFamilies ...sys.ArchFamily) {
- m := 0
- for _, f := range archFamilies {
- if f >= 32 {
- panic("too many architecture families")
- }
- m |= 1 << uint(f)
- }
- for _, a := range all {
- if m>>uint(a.Family)&1 != 0 {
+ for _, a := range sys.Archs {
+ if a.InFamily(archFamilies...) {
intrinsics[intrinsicKey{a, pkg, fn}] = b
}
}
--- /dev/null
+// Copyright 2024 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 sys
+
+import (
+ "testing"
+)
+
+func TestArchInFamily(t *testing.T) {
+ if got, want := ArchPPC64LE.InFamily(AMD64), false; got != want {
+ t.Errorf("Got ArchPPC64LE.InFamily(AMD64) = %v, want %v", got, want)
+ }
+ if got, want := ArchPPC64LE.InFamily(PPC64), true; got != want {
+ t.Errorf("Got ArchPPC64LE.InFamily(PPC64) = %v, want %v", got, want)
+ }
+ if got, want := ArchPPC64LE.InFamily(AMD64, RISCV64), false; got != want {
+ t.Errorf("Got ArchPPC64LE.InFamily(AMD64, RISCV64) = %v, want %v", got, want)
+ }
+ if got, want := ArchPPC64LE.InFamily(AMD64, PPC64), true; got != want {
+ t.Errorf("Got ArchPPC64LE.InFamily(AMD64, PPC64) = %v, want %v", got, want)
+ }
+}