| •1 |
package reedsolomon |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
// Enabling an instruction set must never exceed what the CPU actually supports, |
| 6 |
// or the generated assembly will fault. AVX512 and GFNI in particular are |
| 7 |
// separate CPU features; CPUs with AVX512 but no GFNI exist (e.g. Skylake-SP). |
| 8 |
func TestOptionsCannotForceUnsupported(t *testing.T) { |
| 9 |
var o options |
| 10 |
for _, opt := range []Option{ |
| 11 |
WithSSE2(true), WithSSSE3(true), WithAVX2(true), |
| 12 |
WithAVX512(true), WithGFNI(true), WithAVXGFNI(true), |
| 13 |
WithNEON(true), WithSVE(true), |
| 14 |
} { |
| 15 |
opt(&o) |
| 16 |
} |
| 17 |
for _, tt := range []struct { |
| 18 |
name string |
| 19 |
enabled, have bool |
| 20 |
}{ |
| 21 |
{"useSSE2", o.useSSE2, defaultOptions.useSSE2}, |
| 22 |
{"useSSSE3", o.useSSSE3, defaultOptions.useSSSE3}, |
| 23 |
{"useAVX2", o.useAVX2, defaultOptions.useAVX2}, |
| 24 |
{"useAVX512", o.useAVX512, defaultOptions.useAVX512}, |
| 25 |
{"useAvx512GFNI", o.useAvx512GFNI, defaultOptions.useAvx512GFNI}, |
| 26 |
{"useAvxGNFI", o.useAvxGNFI, defaultOptions.useAvxGNFI}, |
| 27 |
{"useNEON", o.useNEON, defaultOptions.useNEON}, |
| 28 |
{"useSVE", o.useSVE, defaultOptions.useSVE}, |
| 29 |
} { |
| 30 |
if tt.enabled && !tt.have { |
| 31 |
t.Errorf("%s was enabled, but CPU does not support it", tt.name) |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// The NEON kernels read fixed 32 byte tables, while SVE uses the hardware vector |
| 37 |
// length - 16 bytes on a 128 bit core, as set by the galois_arm64.go init. Turning |
| 38 |
// SVE off must restore the table size, or NEON silently reads the wrong layout. |
| 39 |
func TestSVEVectorLength(t *testing.T) { |
| 40 |
for _, tt := range []struct { |
| 41 |
name string |
| 42 |
opt Option |
| 43 |
}{ |
| 44 |
{"WithSVE(false)", WithSVE(false)}, |
| 45 |
{"WithNEON(false)", WithNEON(false)}, |
| 46 |
} { |
| 47 |
o := defaultOptions |
| 48 |
o.useSVE, o.vectorLength = true, 16 |
| 49 |
tt.opt(&o) |
| 50 |
if o.useSVE { |
| 51 |
t.Errorf("%s: SVE still enabled", tt.name) |
| 52 |
} |
| 53 |
if o.vectorLength != 32 { |
| 54 |
t.Errorf("%s: vectorLength = %d, want 32", tt.name, o.vectorLength) |
| 55 |
} |
| 56 |
} |
| 57 |
} |