summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/_simd/_simd.dispatch.c.src26
-rw-r--r--numpy/core/tests/test_simd.py21
2 files changed, 44 insertions, 3 deletions
diff --git a/numpy/core/src/_simd/_simd.dispatch.c.src b/numpy/core/src/_simd/_simd.dispatch.c.src
index fabec069c..ab48db5b1 100644
--- a/numpy/core/src/_simd/_simd.dispatch.c.src
+++ b/numpy/core/src/_simd/_simd.dispatch.c.src
@@ -15,7 +15,8 @@
/**begin repeat
* #sfx = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #bsfx = b8, b8, b16, b16, b32, b32, b64, b64, b32, b64#
- * #esfx = u16, s8, u32,s16, u32, s32, u64, s64, f32, f64#
+ * #esfx = u16,s8, u32, s16, u32, s32, u64, s64, f32, f64#
+ * #size = 8, 8, 16, 16, 32, 32, 64, 64, 32, 64#
* #expand_sup= 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #simd_sup = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
* #fp_only = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
@@ -232,6 +233,15 @@ err:
/**end repeat1**/
#endif // @ncont_sup@
+/****************************
+ * Lookup tables
+ ****************************/
+#if @size@ == 32
+SIMD_IMPL_INTRIN_2(lut32_@sfx@, v@sfx@, q@sfx@, vu@size@)
+#endif
+#if @size@ == 64
+SIMD_IMPL_INTRIN_2(lut16_@sfx@, v@sfx@, q@sfx@, vu@size@)
+#endif
/***************************
* Misc
***************************/
@@ -470,8 +480,9 @@ static PyMethodDef simd__intrinsics_methods[] = {
/**begin repeat
* #sfx = u8, s8, u16, s16, u32, s32, u64, s64, f32, f64#
* #bsfx = b8, b8, b16, b16, b32, b32, b64, b64, b32, b64#
- * #esfx = u16, s8, u32,s16, u32, s32, u64, s64, f32, f64#
- * #expand_sup =1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
+ * #esfx = u16,s8, u32, s16, u32, s32, u64, s64, f32, f64#
+ * #size = 8, 8, 16, 16, 32, 32, 64, 64, 32, 64#
+ * #expand_sup= 1, 0, 1, 0, 0, 0, 0, 0, 0, 0#
* #simd_sup = 1, 1, 1, 1, 1, 1, 1, 1, 1, NPY_SIMD_F64#
* #fp_only = 0, 0, 0, 0, 0, 0, 0, 0, 1, 1#
* #sat_sup = 1, 1, 1, 1, 0, 0, 0, 0, 0, 0#
@@ -509,6 +520,15 @@ SIMD_INTRIN_DEF(@intrin@_@sfx@)
/**end repeat1**/
#endif // ncont_sup
+/****************************
+ * Lookup tables
+ ****************************/
+#if @size@ == 32
+SIMD_INTRIN_DEF(lut32_@sfx@)
+#endif
+#if @size@ == 64
+SIMD_INTRIN_DEF(lut16_@sfx@)
+#endif
/***************************
* Misc
***************************/
diff --git a/numpy/core/tests/test_simd.py b/numpy/core/tests/test_simd.py
index 605baefe6..e4b5e0c8f 100644
--- a/numpy/core/tests/test_simd.py
+++ b/numpy/core/tests/test_simd.py
@@ -627,6 +627,27 @@ class _SIMD_ALL(_Test_Utility):
assert storen_till[64:] == data_till
assert storen_till[:64] == [127]*64 # detect overflow
+ @pytest.mark.parametrize("intrin, table_size, elsize", [
+ ("self.lut32", 32, 32),
+ ("self.lut16", 16, 64)
+ ])
+ def test_lut(self, intrin, table_size, elsize):
+ """
+ Test lookup table intrinsics:
+ npyv_lut32_##sfx
+ npyv_lut16_##sfx
+ """
+ if elsize != self._scalar_size():
+ return
+ intrin = eval(intrin)
+ idx_itrin = getattr(self.npyv, f"setall_u{elsize}")
+ table = range(0, table_size)
+ for i in table:
+ broadi = self.setall(i)
+ idx = idx_itrin(i)
+ lut = intrin(table, idx)
+ assert lut == broadi
+
def test_misc(self):
broadcast_zero = self.zero()
assert broadcast_zero == [0] * self.nlanes