Add vnsra instruction and test.
* Add softrvv implementation.
* Add sorfrvv test.
* Add v-ext test.
Change-Id: I97b059c3b4315c8e8d1bb04806edf77c399e142a
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h
index e3a245a..75a4017 100644
--- a/softrvv/include/softrvv.h
+++ b/softrvv/include/softrvv.h
@@ -10,6 +10,7 @@
#include "softrvv_vmax.h"
#include "softrvv_vmin.h"
#include "softrvv_vmul_vmulh.h"
+#include "softrvv_vnsra.h"
#include "softrvv_vnsrl.h"
#include "softrvv_vor.h"
#include "softrvv_vrem.h"
diff --git a/softrvv/include/softrvv_vnsra.h b/softrvv/include/softrvv_vnsra.h
new file mode 100644
index 0000000..7c81a14
--- /dev/null
+++ b/softrvv/include/softrvv_vnsra.h
@@ -0,0 +1,31 @@
+#ifndef SOFTRVV_VNSRA_H
+#define SOFTRVV_VNSRA_H
+
+#include <stddef.h>
+
+namespace softrvv {
+
+template <typename T1, typename T2>
+void vnsra_vx(T1 *dest, T2 *src1, const T1 *src2, int32_t avl) {
+ // Only low lg2(SEW*2) bits are used for shift
+ static_assert(sizeof(T1) * 2 == sizeof(T2));
+ const T1 low_bits_mask = sizeof(T2) * 8 - 1;
+ const T1 shift = *src2 & low_bits_mask;
+ for (int32_t idx = 0; idx < avl; idx++) {
+ dest[idx] = static_cast<T1>(src1[idx] >> shift);
+ }
+}
+
+template <typename T1, typename T2>
+void vnsra_vv(T1 *dest, T2 *src1, T1 *src2, int32_t avl) {
+ // Only low lg2(SEW*2) bits are used for shift
+ static_assert(sizeof(T1) * 2 == sizeof(T2));
+ const T1 low_bits_mask = sizeof(T2) * 8 - 1;
+ for (int32_t idx = 0; idx < avl; idx++) {
+ dest[idx] = static_cast<T1>(src1[idx] >> (src2[idx] & low_bits_mask));
+ }
+}
+
+} // namespace softrvv
+
+#endif // SOFTRVV_VNSRA_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt
index ac55038..f788d8c 100644
--- a/softrvv/tests/CMakeLists.txt
+++ b/softrvv/tests/CMakeLists.txt
@@ -197,6 +197,15 @@
-Xlinker --defsym=__itcm_length__=128K
)
+softrvv_vec_cc_generated_test(
+ NAME
+ vnsra
+ TEMPLATE
+ softrvv_vnsra_test.tpl.cpp
+ LINKOPTS
+ -Xlinker --defsym=__itcm_length__=128K
+)
+
vec_cc_test(
NAME
softrvv_vmax
diff --git a/softrvv/tests/templates/softrvv_vnsra_test.tpl.cpp b/softrvv/tests/templates/softrvv_vnsra_test.tpl.cpp
new file mode 100644
index 0000000..fcd6e67
--- /dev/null
+++ b/softrvv/tests/templates/softrvv_vnsra_test.tpl.cpp
@@ -0,0 +1,15 @@
+<%inherit file="base.tpl.cpp"/>\
+<%namespace name="tests" file="opivv_opivx_test.tpl.cpp"/>
+<%
+import numpy as np
+import vec_test_helpers
+template_helper = vec_test_helpers.VecTemplateHelper(op, 16)
+N = 5
+src2, src1, rs1 = template_helper.get_test_inputs(n=N)
+src2_type = template_helper.get_np_src2_type()
+tmp_src1 = src1 & (src2_type(0).itemsize * 8 -1)
+ref_vv = np.right_shift(src2, tmp_src1).astype(np.int16)
+tmp_rs1 = rs1 & (src2_type(0).itemsize * 8 - 1)
+ref_vx = np.right_shift(src2, tmp_rs1).astype(np.int16)
+%>\
+${tests.test_opivv_opivx(template_helper, src2, src1, rs1, ref_vv, ref_vx)}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e1de24d..9564552 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -255,6 +255,15 @@
-Xlinker --defsym=__itcm_length__=192K
)
+vec_cc_generated_test(
+ NAME
+ vnsra
+ TEMPLATE
+ opivv_opivx_opivi_test.tpl.cpp
+ LINKOPTS
+ -Xlinker --defsym=__itcm_length__=192K
+)
+
vec_cc_test(
NAME
vsetvl_test