]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.simd] simd: add emulated Not method
authorDavid Chase <drchase@google.com>
Thu, 9 Oct 2025 18:44:25 +0000 (14:44 -0400)
committerDavid Chase <drchase@google.com>
Fri, 10 Oct 2025 01:09:15 +0000 (18:09 -0700)
this is to help match other SIMD architectures and to
simplify processing of logical expressions for rewriting
to ternary-logical simd instructions.

Change-Id: I3c83afbb399d32ba2ade5f8ef288d4a07e1f3948
Reviewed-on: https://go-review.googlesource.com/c/go/+/710696
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/simd/genfiles.go
src/simd/internal/simd_test/unary_test.go
src/simd/other_gen_amd64.go

index 4d22eaa2336d269cc2b7249c7512e1fc02a0137f..7e904edb107e3be30b4a1cfbee77d6d6e8014346 100644 (file)
@@ -58,6 +58,31 @@ func (sat shapeAndTemplate) shrinkTo(outType string, by int) shapeAndTemplate {
        return newSat
 }
 
+func (s *shapes) forAllShapes(f func(seq int, t, upperT string, w, c int, out io.Writer), out io.Writer) {
+       vecs := s.vecs
+       ints := s.ints
+       uints := s.uints
+       floats := s.floats
+       seq := 0
+       for _, v := range vecs {
+               for _, w := range ints {
+                       c := v / w
+                       f(seq, "int", "Int", w, c, out)
+                       seq++
+               }
+               for _, w := range uints {
+                       c := v / w
+                       f(seq, "uint", "Uint", w, c, out)
+                       seq++
+               }
+               for _, w := range floats {
+                       c := v / w
+                       f(seq, "float", "Float", w, c, out)
+                       seq++
+               }
+       }
+}
+
 var allShapes = &shapes{
        vecs:   []int{128, 256, 512},
        ints:   []int{8, 16, 32, 64},
@@ -65,6 +90,16 @@ var allShapes = &shapes{
        floats: []int{32, 64},
 }
 
+var intShapes = &shapes{
+       vecs: []int{128, 256, 512},
+       ints: []int{8, 16, 32, 64},
+}
+
+var uintShapes = &shapes{
+       vecs:  []int{128, 256, 512},
+       uints: []int{8, 16, 32, 64},
+}
+
 var avx512Shapes = &shapes{
        vecs:   []int{512},
        ints:   []int{8, 16, 32, 64},
@@ -569,6 +604,24 @@ func (x {{.VType}}) NotEqual(y {{.VType}}) Mask{{.WxC}} {
 }
 `)
 
+var bitWiseIntTemplate = shapedTemplateOf(intShapes, "bitwise int complement", `
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature {{.CPUfeature}}
+func (x {{.VType}}) Not() {{.VType}} {
+       return x.Xor(x.Equal(x).As{{.VType}}())
+}
+`)
+
+var bitWiseUintTemplate = shapedTemplateOf(uintShapes, "bitwise uint complement", `
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature {{.CPUfeature}}
+func (x {{.VType}}) Not() {{.VType}} {
+       return x.Xor(x.Equal(x).AsInt{{.WxC}}().As{{.VType}}())
+}
+`)
+
 // CPUfeatureAVX2if8 return AVX2 if the element width is 8,
 // otherwise, it returns CPUfeature.  This is for the cpufeature
 // of unsigned comparison emulation, which uses shifts for all
@@ -781,6 +834,8 @@ func main() {
                one(*op, prologue,
                        broadcastTemplate,
                        maskCvtTemplate,
+                       bitWiseIntTemplate,
+                       bitWiseUintTemplate,
                )
        }
        if *ush != "" {
index 6a1d0fe36981612765904c5e6df81ced2c0a5558..1f89beb78503da1bbd17efdb8976142b702060c9 100644 (file)
@@ -67,6 +67,15 @@ func TestSqrt(t *testing.T) {
        }
 }
 
+func TestNot(t *testing.T) {
+       testInt8x16Unary(t, simd.Int8x16.Not, map1[int8](not))
+       testInt8x32Unary(t, simd.Int8x32.Not, map1[int8](not))
+       testInt16x8Unary(t, simd.Int16x8.Not, map1[int16](not))
+       testInt16x16Unary(t, simd.Int16x16.Not, map1[int16](not))
+       testInt32x4Unary(t, simd.Int32x4.Not, map1[int32](not))
+       testInt32x8Unary(t, simd.Int32x8.Not, map1[int32](not))
+}
+
 func TestAbsolute(t *testing.T) {
        testInt8x16Unary(t, simd.Int8x16.Abs, map1[int8](abs))
        testInt8x32Unary(t, simd.Int8x32.Abs, map1[int8](abs))
index 4a9049a2b9058eae89f2493e5f2e7ad1aca77bb1..76fbe48b203625ede6eda448f92b08bd2ad581e3 100644 (file)
@@ -423,3 +423,171 @@ func (from Float32x16) ToMask() (to Mask32x16) {
 func (from Float64x8) ToMask() (to Mask64x8) {
        return from.NotEqual(Float64x8{})
 }
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Int8x16) Not() Int8x16 {
+       return x.Xor(x.Equal(x).AsInt8x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Int16x8) Not() Int16x8 {
+       return x.Xor(x.Equal(x).AsInt16x8())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Int32x4) Not() Int32x4 {
+       return x.Xor(x.Equal(x).AsInt32x4())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Int64x2) Not() Int64x2 {
+       return x.Xor(x.Equal(x).AsInt64x2())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Int8x32) Not() Int8x32 {
+       return x.Xor(x.Equal(x).AsInt8x32())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Int16x16) Not() Int16x16 {
+       return x.Xor(x.Equal(x).AsInt16x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Int32x8) Not() Int32x8 {
+       return x.Xor(x.Equal(x).AsInt32x8())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Int64x4) Not() Int64x4 {
+       return x.Xor(x.Equal(x).AsInt64x4())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Int8x64) Not() Int8x64 {
+       return x.Xor(x.Equal(x).AsInt8x64())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Int16x32) Not() Int16x32 {
+       return x.Xor(x.Equal(x).AsInt16x32())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Int32x16) Not() Int32x16 {
+       return x.Xor(x.Equal(x).AsInt32x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Int64x8) Not() Int64x8 {
+       return x.Xor(x.Equal(x).AsInt64x8())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Uint8x16) Not() Uint8x16 {
+       return x.Xor(x.Equal(x).AsInt8x16().AsUint8x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Uint16x8) Not() Uint16x8 {
+       return x.Xor(x.Equal(x).AsInt16x8().AsUint16x8())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Uint32x4) Not() Uint32x4 {
+       return x.Xor(x.Equal(x).AsInt32x4().AsUint32x4())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX
+func (x Uint64x2) Not() Uint64x2 {
+       return x.Xor(x.Equal(x).AsInt64x2().AsUint64x2())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Uint8x32) Not() Uint8x32 {
+       return x.Xor(x.Equal(x).AsInt8x32().AsUint8x32())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Uint16x16) Not() Uint16x16 {
+       return x.Xor(x.Equal(x).AsInt16x16().AsUint16x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Uint32x8) Not() Uint32x8 {
+       return x.Xor(x.Equal(x).AsInt32x8().AsUint32x8())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX2
+func (x Uint64x4) Not() Uint64x4 {
+       return x.Xor(x.Equal(x).AsInt64x4().AsUint64x4())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Uint8x64) Not() Uint8x64 {
+       return x.Xor(x.Equal(x).AsInt8x64().AsUint8x64())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Uint16x32) Not() Uint16x32 {
+       return x.Xor(x.Equal(x).AsInt16x32().AsUint16x32())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Uint32x16) Not() Uint32x16 {
+       return x.Xor(x.Equal(x).AsInt32x16().AsUint32x16())
+}
+
+// Not returns the bitwise complement of x
+//
+// Emulated, CPU Feature AVX512
+func (x Uint64x8) Not() Uint64x8 {
+       return x.Xor(x.Equal(x).AsInt64x8().AsUint64x8())
+}