Source file src/simd/archsimd/internal/simd_test/arm64_shift_helpers_test.go

     1  // Code generated by 'tmplgen'; DO NOT EDIT.
     2  
     3  //go:build goexperiment.simd && arm64
     4  
     5  // This file contains functions testing shift simd methods.
     6  // Each function in this file is specialized for a
     7  // particular simd type <BaseType><Width>x<Count>.
     8  
     9  package simd_test
    10  
    11  import (
    12  	"simd/archsimd"
    13  	"testing"
    14  )
    15  
    16  // testInt8x16ShiftConst tests a const-shift method (unary + immediate).
    17  func testInt8x16ShiftConst(t *testing.T, f func(_ archsimd.Int8x16, _ uint64) archsimd.Int8x16, want func(_ []int8, _ uint64) []int8) {
    18  	n := 16
    19  	t.Helper()
    20  	forSlice(t, int8s, n, func(x []int8) bool {
    21  		t.Helper()
    22  		for _, amt := range []uint64{0, 1, 3, 8 - 1} {
    23  			a := archsimd.LoadInt8x16(x)
    24  			g := make([]int8, n)
    25  			f(a, amt).Store(g)
    26  			w := want(x, amt)
    27  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
    28  				return false
    29  			}
    30  		}
    31  		return true
    32  	})
    33  }
    34  
    35  // testInt16x8ShiftConst tests a const-shift method (unary + immediate).
    36  func testInt16x8ShiftConst(t *testing.T, f func(_ archsimd.Int16x8, _ uint64) archsimd.Int16x8, want func(_ []int16, _ uint64) []int16) {
    37  	n := 8
    38  	t.Helper()
    39  	forSlice(t, int16s, n, func(x []int16) bool {
    40  		t.Helper()
    41  		for _, amt := range []uint64{0, 1, 3, 16 - 1} {
    42  			a := archsimd.LoadInt16x8(x)
    43  			g := make([]int16, n)
    44  			f(a, amt).Store(g)
    45  			w := want(x, amt)
    46  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
    47  				return false
    48  			}
    49  		}
    50  		return true
    51  	})
    52  }
    53  
    54  // testInt32x4ShiftConst tests a const-shift method (unary + immediate).
    55  func testInt32x4ShiftConst(t *testing.T, f func(_ archsimd.Int32x4, _ uint64) archsimd.Int32x4, want func(_ []int32, _ uint64) []int32) {
    56  	n := 4
    57  	t.Helper()
    58  	forSlice(t, int32s, n, func(x []int32) bool {
    59  		t.Helper()
    60  		for _, amt := range []uint64{0, 1, 3, 32 - 1} {
    61  			a := archsimd.LoadInt32x4(x)
    62  			g := make([]int32, n)
    63  			f(a, amt).Store(g)
    64  			w := want(x, amt)
    65  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
    66  				return false
    67  			}
    68  		}
    69  		return true
    70  	})
    71  }
    72  
    73  // testInt64x2ShiftConst tests a const-shift method (unary + immediate).
    74  func testInt64x2ShiftConst(t *testing.T, f func(_ archsimd.Int64x2, _ uint64) archsimd.Int64x2, want func(_ []int64, _ uint64) []int64) {
    75  	n := 2
    76  	t.Helper()
    77  	forSlice(t, int64s, n, func(x []int64) bool {
    78  		t.Helper()
    79  		for _, amt := range []uint64{0, 1, 3, 64 - 1} {
    80  			a := archsimd.LoadInt64x2(x)
    81  			g := make([]int64, n)
    82  			f(a, amt).Store(g)
    83  			w := want(x, amt)
    84  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
    85  				return false
    86  			}
    87  		}
    88  		return true
    89  	})
    90  }
    91  
    92  // testUint8x16ShiftConst tests a const-shift method (unary + immediate).
    93  func testUint8x16ShiftConst(t *testing.T, f func(_ archsimd.Uint8x16, _ uint64) archsimd.Uint8x16, want func(_ []uint8, _ uint64) []uint8) {
    94  	n := 16
    95  	t.Helper()
    96  	forSlice(t, uint8s, n, func(x []uint8) bool {
    97  		t.Helper()
    98  		for _, amt := range []uint64{0, 1, 3, 8 - 1} {
    99  			a := archsimd.LoadUint8x16(x)
   100  			g := make([]uint8, n)
   101  			f(a, amt).Store(g)
   102  			w := want(x, amt)
   103  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   104  				return false
   105  			}
   106  		}
   107  		return true
   108  	})
   109  }
   110  
   111  // testUint16x8ShiftConst tests a const-shift method (unary + immediate).
   112  func testUint16x8ShiftConst(t *testing.T, f func(_ archsimd.Uint16x8, _ uint64) archsimd.Uint16x8, want func(_ []uint16, _ uint64) []uint16) {
   113  	n := 8
   114  	t.Helper()
   115  	forSlice(t, uint16s, n, func(x []uint16) bool {
   116  		t.Helper()
   117  		for _, amt := range []uint64{0, 1, 3, 16 - 1} {
   118  			a := archsimd.LoadUint16x8(x)
   119  			g := make([]uint16, n)
   120  			f(a, amt).Store(g)
   121  			w := want(x, amt)
   122  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   123  				return false
   124  			}
   125  		}
   126  		return true
   127  	})
   128  }
   129  
   130  // testUint32x4ShiftConst tests a const-shift method (unary + immediate).
   131  func testUint32x4ShiftConst(t *testing.T, f func(_ archsimd.Uint32x4, _ uint64) archsimd.Uint32x4, want func(_ []uint32, _ uint64) []uint32) {
   132  	n := 4
   133  	t.Helper()
   134  	forSlice(t, uint32s, n, func(x []uint32) bool {
   135  		t.Helper()
   136  		for _, amt := range []uint64{0, 1, 3, 32 - 1} {
   137  			a := archsimd.LoadUint32x4(x)
   138  			g := make([]uint32, n)
   139  			f(a, amt).Store(g)
   140  			w := want(x, amt)
   141  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   142  				return false
   143  			}
   144  		}
   145  		return true
   146  	})
   147  }
   148  
   149  // testUint64x2ShiftConst tests a const-shift method (unary + immediate).
   150  func testUint64x2ShiftConst(t *testing.T, f func(_ archsimd.Uint64x2, _ uint64) archsimd.Uint64x2, want func(_ []uint64, _ uint64) []uint64) {
   151  	n := 2
   152  	t.Helper()
   153  	forSlice(t, uint64s, n, func(x []uint64) bool {
   154  		t.Helper()
   155  		for _, amt := range []uint64{0, 1, 3, 64 - 1} {
   156  			a := archsimd.LoadUint64x2(x)
   157  			g := make([]uint64, n)
   158  			f(a, amt).Store(g)
   159  			w := want(x, amt)
   160  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   161  				return false
   162  			}
   163  		}
   164  		return true
   165  	})
   166  }
   167  
   168  // testInt8x16ShiftAll tests a shift-all method (unary + scalar uint64).
   169  func testInt8x16ShiftAll(t *testing.T, f func(_ archsimd.Int8x16, _ uint64) archsimd.Int8x16, want func(_ []int8, _ uint64) []int8) {
   170  	n := 16
   171  	t.Helper()
   172  	forSlice(t, int8s, n, func(x []int8) bool {
   173  		t.Helper()
   174  		for _, amt := range testShiftAllAmts {
   175  			a := archsimd.LoadInt8x16(x)
   176  			g := make([]int8, n)
   177  			f(a, amt).Store(g)
   178  			w := want(x, amt)
   179  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   180  				return false
   181  			}
   182  		}
   183  		return true
   184  	})
   185  }
   186  
   187  // testInt16x8ShiftAll tests a shift-all method (unary + scalar uint64).
   188  func testInt16x8ShiftAll(t *testing.T, f func(_ archsimd.Int16x8, _ uint64) archsimd.Int16x8, want func(_ []int16, _ uint64) []int16) {
   189  	n := 8
   190  	t.Helper()
   191  	forSlice(t, int16s, n, func(x []int16) bool {
   192  		t.Helper()
   193  		for _, amt := range testShiftAllAmts {
   194  			a := archsimd.LoadInt16x8(x)
   195  			g := make([]int16, n)
   196  			f(a, amt).Store(g)
   197  			w := want(x, amt)
   198  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   199  				return false
   200  			}
   201  		}
   202  		return true
   203  	})
   204  }
   205  
   206  // testInt32x4ShiftAll tests a shift-all method (unary + scalar uint64).
   207  func testInt32x4ShiftAll(t *testing.T, f func(_ archsimd.Int32x4, _ uint64) archsimd.Int32x4, want func(_ []int32, _ uint64) []int32) {
   208  	n := 4
   209  	t.Helper()
   210  	forSlice(t, int32s, n, func(x []int32) bool {
   211  		t.Helper()
   212  		for _, amt := range testShiftAllAmts {
   213  			a := archsimd.LoadInt32x4(x)
   214  			g := make([]int32, n)
   215  			f(a, amt).Store(g)
   216  			w := want(x, amt)
   217  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   218  				return false
   219  			}
   220  		}
   221  		return true
   222  	})
   223  }
   224  
   225  // testInt64x2ShiftAll tests a shift-all method (unary + scalar uint64).
   226  func testInt64x2ShiftAll(t *testing.T, f func(_ archsimd.Int64x2, _ uint64) archsimd.Int64x2, want func(_ []int64, _ uint64) []int64) {
   227  	n := 2
   228  	t.Helper()
   229  	forSlice(t, int64s, n, func(x []int64) bool {
   230  		t.Helper()
   231  		for _, amt := range testShiftAllAmts {
   232  			a := archsimd.LoadInt64x2(x)
   233  			g := make([]int64, n)
   234  			f(a, amt).Store(g)
   235  			w := want(x, amt)
   236  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   237  				return false
   238  			}
   239  		}
   240  		return true
   241  	})
   242  }
   243  
   244  // testUint8x16ShiftAll tests a shift-all method (unary + scalar uint64).
   245  func testUint8x16ShiftAll(t *testing.T, f func(_ archsimd.Uint8x16, _ uint64) archsimd.Uint8x16, want func(_ []uint8, _ uint64) []uint8) {
   246  	n := 16
   247  	t.Helper()
   248  	forSlice(t, uint8s, n, func(x []uint8) bool {
   249  		t.Helper()
   250  		for _, amt := range testShiftAllAmts {
   251  			a := archsimd.LoadUint8x16(x)
   252  			g := make([]uint8, n)
   253  			f(a, amt).Store(g)
   254  			w := want(x, amt)
   255  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   256  				return false
   257  			}
   258  		}
   259  		return true
   260  	})
   261  }
   262  
   263  // testUint16x8ShiftAll tests a shift-all method (unary + scalar uint64).
   264  func testUint16x8ShiftAll(t *testing.T, f func(_ archsimd.Uint16x8, _ uint64) archsimd.Uint16x8, want func(_ []uint16, _ uint64) []uint16) {
   265  	n := 8
   266  	t.Helper()
   267  	forSlice(t, uint16s, n, func(x []uint16) bool {
   268  		t.Helper()
   269  		for _, amt := range testShiftAllAmts {
   270  			a := archsimd.LoadUint16x8(x)
   271  			g := make([]uint16, n)
   272  			f(a, amt).Store(g)
   273  			w := want(x, amt)
   274  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   275  				return false
   276  			}
   277  		}
   278  		return true
   279  	})
   280  }
   281  
   282  // testUint32x4ShiftAll tests a shift-all method (unary + scalar uint64).
   283  func testUint32x4ShiftAll(t *testing.T, f func(_ archsimd.Uint32x4, _ uint64) archsimd.Uint32x4, want func(_ []uint32, _ uint64) []uint32) {
   284  	n := 4
   285  	t.Helper()
   286  	forSlice(t, uint32s, n, func(x []uint32) bool {
   287  		t.Helper()
   288  		for _, amt := range testShiftAllAmts {
   289  			a := archsimd.LoadUint32x4(x)
   290  			g := make([]uint32, n)
   291  			f(a, amt).Store(g)
   292  			w := want(x, amt)
   293  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   294  				return false
   295  			}
   296  		}
   297  		return true
   298  	})
   299  }
   300  
   301  // testUint64x2ShiftAll tests a shift-all method (unary + scalar uint64).
   302  func testUint64x2ShiftAll(t *testing.T, f func(_ archsimd.Uint64x2, _ uint64) archsimd.Uint64x2, want func(_ []uint64, _ uint64) []uint64) {
   303  	n := 2
   304  	t.Helper()
   305  	forSlice(t, uint64s, n, func(x []uint64) bool {
   306  		t.Helper()
   307  		for _, amt := range testShiftAllAmts {
   308  			a := archsimd.LoadUint64x2(x)
   309  			g := make([]uint64, n)
   310  			f(a, amt).Store(g)
   311  			w := want(x, amt)
   312  			if !checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v, amt=%d", x, amt) }) {
   313  				return false
   314  			}
   315  		}
   316  		return true
   317  	})
   318  }
   319  
   320  // testUint8x16Shift tests a shift-like method where the first operand is Uint8x16
   321  // and the second operand is Int8x16 (mixed-type shift).
   322  func testUint8x16Shift(t *testing.T, f func(_ archsimd.Uint8x16, _ archsimd.Int8x16) archsimd.Uint8x16, want func(_ []uint8, _ []int8) []uint8) {
   323  	n := 16
   324  	t.Helper()
   325  	forSliceMixed(t, uint8s, int8s, n, func(x []uint8, y []int8) bool {
   326  		t.Helper()
   327  		a := archsimd.LoadUint8x16(x)
   328  		b := archsimd.LoadInt8x16(y)
   329  		g := make([]uint8, n)
   330  		f(a, b).Store(g)
   331  		w := want(x, y)
   332  		return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
   333  	})
   334  }
   335  
   336  // testUint16x8Shift tests a shift-like method where the first operand is Uint16x8
   337  // and the second operand is Int16x8 (mixed-type shift).
   338  func testUint16x8Shift(t *testing.T, f func(_ archsimd.Uint16x8, _ archsimd.Int16x8) archsimd.Uint16x8, want func(_ []uint16, _ []int16) []uint16) {
   339  	n := 8
   340  	t.Helper()
   341  	forSliceMixed(t, uint16s, int16s, n, func(x []uint16, y []int16) bool {
   342  		t.Helper()
   343  		a := archsimd.LoadUint16x8(x)
   344  		b := archsimd.LoadInt16x8(y)
   345  		g := make([]uint16, n)
   346  		f(a, b).Store(g)
   347  		w := want(x, y)
   348  		return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
   349  	})
   350  }
   351  
   352  // testUint32x4Shift tests a shift-like method where the first operand is Uint32x4
   353  // and the second operand is Int32x4 (mixed-type shift).
   354  func testUint32x4Shift(t *testing.T, f func(_ archsimd.Uint32x4, _ archsimd.Int32x4) archsimd.Uint32x4, want func(_ []uint32, _ []int32) []uint32) {
   355  	n := 4
   356  	t.Helper()
   357  	forSliceMixed(t, uint32s, int32s, n, func(x []uint32, y []int32) bool {
   358  		t.Helper()
   359  		a := archsimd.LoadUint32x4(x)
   360  		b := archsimd.LoadInt32x4(y)
   361  		g := make([]uint32, n)
   362  		f(a, b).Store(g)
   363  		w := want(x, y)
   364  		return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
   365  	})
   366  }
   367  
   368  // testUint64x2Shift tests a shift-like method where the first operand is Uint64x2
   369  // and the second operand is Int64x2 (mixed-type shift).
   370  func testUint64x2Shift(t *testing.T, f func(_ archsimd.Uint64x2, _ archsimd.Int64x2) archsimd.Uint64x2, want func(_ []uint64, _ []int64) []uint64) {
   371  	n := 2
   372  	t.Helper()
   373  	forSliceMixed(t, uint64s, int64s, n, func(x []uint64, y []int64) bool {
   374  		t.Helper()
   375  		a := archsimd.LoadUint64x2(x)
   376  		b := archsimd.LoadInt64x2(y)
   377  		g := make([]uint64, n)
   378  		f(a, b).Store(g)
   379  		w := want(x, y)
   380  		return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
   381  	})
   382  }
   383  

View as plain text