Revert "reflects reviews"
Revert submission 11560
Reason for revert: Revert this and all related CLs to review the changes again. I will create a new CL by cherry-picking the CL that contains the up-to-date version.
Reverted Changes:
Id487b5bd4:1. Modify template files for vector tests with flo...
I13979c48c:Merge branch 'master' of https://spacebeaker.googl...
I7b24a230b:reflects reviews
Change-Id: I76c2cae9629c14f97fb7f3e1517be77c7811765b
diff --git a/scripts/vec_test_helpers/__init__.py b/scripts/vec_test_helpers/__init__.py
index 8f000eb..4aa284e 100644
--- a/scripts/vec_test_helpers/__init__.py
+++ b/scripts/vec_test_helpers/__init__.py
@@ -129,9 +129,8 @@
return [8, 16, 32]
def get_sew_sizes(self):
- """Return size of types.
- imm is not used for floating point op codes.
- """
+ """Return size of types."""
+ """imm is not used for floating point op codes."""
dest_sew = self.sew
src2_sew = self.sew
src1_sew = self.sew
@@ -143,44 +142,37 @@
return dest_sew, src2_sew, src1_sew, imm_sew
def get_var_types(self):
- """Return types for an op_code and element width.
- imm_type won't be used for floating point values.
- """
+ """Return types for an op_code and element width."""
+ """imm_type won't be used for floating point values."""
VarTypes = collections.namedtuple(
"VarTypes",
('dest_type', 'src2_type', 'src1_type', 'imm_type'))
- if self.is_floating():
- var_types = VarTypes("float", "float", "float", "float")
- else:
- type_fmt = "%sint%d_t"
- sign_type = "u" if self.is_unsigned() or self.force_unsigned else ""
- dest_sew, src2_sew, src1_sew, imm_sew = self.get_sew_sizes()
- dest_type = type_fmt % (sign_type, dest_sew)
- src1_type = type_fmt % (sign_type, src1_sew)
- src2_type = type_fmt % (sign_type, src2_sew)
- imm_type = type_fmt % (sign_type, imm_sew)
- var_types = VarTypes(dest_type, src2_type, src1_type, imm_type)
+ type_fmt = "%sfloat%d_t" if self.is_floating() else "%sint%d_t"
+ sign_type = "u" if (not self.is_floating()) and (self.is_unsigned() or self.force_unsigned) else ""
+ dest_sew, src2_sew, src1_sew, imm_sew = self.get_sew_sizes()
+ dest_type = type_fmt % (sign_type, dest_sew)
+ src1_type = type_fmt % (sign_type, src1_sew)
+ src2_type = type_fmt % (sign_type, src2_sew)
+ imm_type = type_fmt % (sign_type, imm_sew)
+ var_types = VarTypes(dest_type, src2_type, src1_type, imm_type)
return var_types
def get_mnemonic(self, operand_type):
"""Generate the correct mnemonic given a opcode and operand type."""
operand_width = self.OperandWidth.STANDARD
- if self.is_floating():
- if operand_type == self.OperandType.SCALAR:
- operand_type = self.OperandType.FLOATSCALAR
- else:
- if self.is_narrowing():
- operand_width = self.OperandWidth.NARROWING
- elif self.is_widening():
- operand_width = self.OperandWidth.WIDENING
+ if (not self.is_floating()) and self.is_narrowing():
+ operand_width = self.OperandWidth.NARROWING
+ elif (not self.is_floating()) and self.is_widening():
+ operand_width = self.OperandWidth.WIDENING
+ if self.is_floating() and operand_type == self.OperandType.SCALAR:
+ operand_type = self.OperandType.FLOATSCALAR
op_suffix = self.mnemonic_suffix[operand_type][operand_width]
return "%s.%s" % (self.op_code, op_suffix)
def get_lmuls(self):
"""Given an op_code return an iterable of valid lmuls."""
- if not self.is_floating():
- if self.is_widening() or self.is_narrowing():
- return [1, 2, 4]
+ if (not self.is_floating()) and (self.is_widening() or self.is_narrowing()):
+ return [1, 2, 4]
return [1, 2, 4, 8]
@staticmethod
@@ -192,9 +184,8 @@
def get_softrvv_template_data_type(self):
"""Return types """
var_types = self.get_var_types()
- if not self.is_floating():
- if self.is_narrowing() or self.is_widening():
- return "%s, %s" % (var_types.dest_type, var_types.src2_type)
+ if (not self.is_floating()) and (self.is_narrowing() or self.is_widening()):
+ return "%s, %s" % (var_types.dest_type, var_types.src2_type)
return var_types.src1_type
def get_ref_opcode(self):
@@ -252,7 +243,7 @@
src1_np_type = self.get_np_src1_type()
src2_np_type = self.get_np_src2_type()
src2_np_type = self.get_np_src2_type()
- # Return test inputs for floating points.
+ """Return test inputs for floating points."""
if self.is_floating():
type_info = np.finfo(src1_np_type)
src1_data = np.random.uniform(
@@ -267,7 +258,7 @@
rs1 = 1.0 if rs1 == 0.0 else rs1
return src2_data, src1_data, rs1
- # Return test inputs for integers.
+ """Return test inputs for integers."""
type_info = np.iinfo(src1_np_type)
src1_data = np.random.randint(
type_info.min, type_info.max, n).astype(src1_np_type)
@@ -287,9 +278,8 @@
return np.packbits(dest_type(values), bitorder='little')
def cast_to_unsigned(arr):
- """Cast a signed array to an unsigned array.
- This should not be called with floating point values.
- """
+ """Cast a signed array to an unsigned array."""
+ """This should not be called with floating point values."""
udtypes = {np.int8:np.uint8,
np.int16:np.uint16,
np.int32:np.uint32,
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h
index 76f1313..1046aba 100644
--- a/softrvv/include/softrvv.h
+++ b/softrvv/include/softrvv.h
@@ -2,7 +2,6 @@
#define SOFTRVV_H
#include <stddef.h>
-#include <stdint.h>
#include "encoding.h"
#include "softrvv_internal.h"
@@ -32,8 +31,8 @@
#include "softrvv_vwsub.h"
#include "softrvv_vxor.h"
-#include "softrvv_vfsub.h"
#include "softrvv_vfadd.h"
+#include "softrvv_vfsub.h"
namespace softrvv {
diff --git a/softrvv/include/softrvv_vfadd.h b/softrvv/include/softrvv_vfadd.h
index 0a6633d..86009c8 100644
--- a/softrvv/include/softrvv_vfadd.h
+++ b/softrvv/include/softrvv_vfadd.h
@@ -5,13 +5,15 @@
namespace softrvv {
-void vfadd_vf(float *dest, float *src1, const float *src2, int32_t avl) {
+template <typename T>
+void vfadd_vf(T *dest, T *src1, const T *src2, int32_t avl) {
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = src1[idx] + *src2;
}
}
-void vfadd_vv(float *dest, float *src1, float *src2, int32_t avl) {
+template <typename T>
+void vfadd_vv(T *dest, T *src1, T *src2, int32_t avl) {
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = src1[idx] + src2[idx];
}
diff --git a/softrvv/include/softrvv_vfsub.h b/softrvv/include/softrvv_vfsub.h
index aff1f52..eea2f26 100644
--- a/softrvv/include/softrvv_vfsub.h
+++ b/softrvv/include/softrvv_vfsub.h
@@ -5,19 +5,22 @@
namespace softrvv {
-void vfsub_vf(float *dest, float *src1, const float *src2, int32_t avl) {
+template <typename T>
+void vfsub_vf(T *dest, T *src1, const T *src2, int32_t avl) {
for (int idx = 0; idx < avl; idx++) {
dest[idx] = src1[idx] - *src2;
}
}
-void vfsub_vv(float *dest, float *src1, float *src2, int32_t avl) {
+template <typename T>
+void vfsub_vv(T *dest, T *src1, T *src2, int32_t avl) {
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = src1[idx] - src2[idx];
}
}
-void vfrsub_vx(float *dest, float *src1, const float *src2, int32_t avl) {
+template <typename T>
+void vfrsub_vx(T *dest, T *src1, const T *src2, int32_t avl) {
for (int32_t idx = 0; idx < avl; idx++) {
dest[idx] = *src2 - src1[idx];
}
diff --git a/softrvv/tests/templates/opivf_test.tpl.cpp b/softrvv/tests/templates/opivf_test.tpl.cpp
index a32bc0d..87c04c1 100644
--- a/softrvv/tests/templates/opivf_test.tpl.cpp
+++ b/softrvv/tests/templates/opivf_test.tpl.cpp
@@ -38,7 +38,7 @@
%>\
TEST_F(SoftRvv${template_helper.op_code.capitalize()}Test, VF) {
- softrvv::${template_helper.op_code}_vf(dest, src2, &rs1, kAVL);\
+ softrvv::${template_helper.op_code}_vf<${datatypes}>(dest, src2, &rs1, kAVL);\
${insert_check(template_helper, var_types.dest_type, "ref_vf")}\
}
</%def>\
diff --git a/softrvv/tests/templates/opivv_test.tpl.cpp b/softrvv/tests/templates/opivv_test.tpl.cpp
index ab54161..08bd2e7 100644
--- a/softrvv/tests/templates/opivv_test.tpl.cpp
+++ b/softrvv/tests/templates/opivv_test.tpl.cpp
@@ -38,11 +38,7 @@
datatypes = template_helper.get_softrvv_template_data_type()
%>\
TEST_F(SoftRvv${template_helper.op_code.capitalize()}Test, VV) {
- % if template_helper.is_floating():
- softrvv::${template_helper.op_code}_vv(dest, src2, src1, kAVL);\
- % else:
- softrvv::${template_helper.op_code}_vv<${datatypes}>(dest, src2, src1, kAVL);\
- % endif
+ softrvv::${template_helper.op_code}_vv<${datatypes}>(dest, src2, src1, kAVL);\
${insert_check(template_helper, var_types.dest_type, "ref_vv")}\
}
diff --git a/test_v_helpers/include/test_v_helpers.h b/test_v_helpers/include/test_v_helpers.h
index ba28e43..66760c0 100644
--- a/test_v_helpers/include/test_v_helpers.h
+++ b/test_v_helpers/include/test_v_helpers.h
@@ -8,6 +8,20 @@
#include "pw_unit_test/framework.h"
+#ifdef __cplusplus
+
+using float32_t = float;
+using float64_t = double;
+using float128_t = long double;
+
+#else
+
+typedef float float32_t;
+typedef double float64_t;
+typedef long double float128_t;
+
+#endif // __cplusplus
+
namespace test_v_helpers {
const int LMUL_MAX = 8;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5acd28c..e2f55ff 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,3 +1,12 @@
+# vec_cc_generated_test(
+# NAME
+# vfadd
+# TEMPLATE
+# opivv_test.tpl.cpp
+# LINKOPTS
+# -Xlinker --defsym=__itcm_length__=128K
+# )
+
vec_cc_generated_test(
NAME
vsub
@@ -399,5 +408,4 @@
vector_vfadd_test.cpp
LINKOPTS
-Xlinker --defsym=__itcm_length__=128K
-)
-
+)
\ No newline at end of file
diff --git a/tests/vector_vfadd_test.cpp b/tests/vector_vfadd_test.cpp
index a6abfa1..9ec1eac 100644
--- a/tests/vector_vfadd_test.cpp
+++ b/tests/vector_vfadd_test.cpp
@@ -1,29 +1,48 @@
+#include <limits.h>
+#include <riscv_vector.h>
#include <softrvv.h>
#include <springbok.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <bit>
#include <tuple>
#include "pw_unit_test/framework.h"
#include "test_v_helpers.h"
+#ifdef __cplusplus
+
+using float32_t = float;
+using float64_t = double;
+using float128_t = long double;
+
+#else
+
+typedef float float32_t;
+typedef double float64_t;
+typedef long double float128_t;
+
+#endif // __cplusplus
+
namespace vfadd_vv_test
{
namespace
{
using namespace test_v_helpers;
-
+
float src_vector_1[MAXVL_BYTES];
float src_vector_2[MAXVL_BYTES];
float dest_vector[MAXVL_BYTES];
float ref_dest_vector[MAXVL_BYTES];
-
+
class VfaddTest : public ::testing::Test {
protected:
void SetUp() override { zero_vector_registers(); }
void TearDown() override { zero_vector_registers(); }
};
-
+
TEST_F(VfaddTest, vfadd_vv32m1) {
for (int i = 0; i < AVL_COUNT; i++) {
int32_t avl = AVLS[i];
@@ -33,12 +52,12 @@
/* For non narrowing instructions all vectors have same type*/
std::tie(vlmax, vl) = vector_test_setup<int32_t>(
VLMUL::LMUL_M1, avl,
- {dest_vector, ref_dest_vector, src_vector_1, src_vector_2});
-
+ {dest_vector, ref_dest_vector, src_vector_1});
+
if (avl > vlmax) {
continue;
}
-
+
float *ptr_vec_1 = reinterpret_cast<float *>(src_vector_1);
float *ptr_vec_2 = reinterpret_cast<float *>(src_vector_2);
float *ptr_dest_vec = reinterpret_cast<float *>(dest_vector);
@@ -47,9 +66,11 @@
// set up values to test up to index of the AVL
fill_random_vector<float>(ptr_vec_1, avl);
fill_random_vector<float>(ptr_vec_2, avl);
+ memset(dest_vector, 0, MAXVL_BYTES);
+ memset(ref_dest_vector, 0, MAXVL_BYTES);
// Generate reference vector
- softrvv::vfadd_vv(ptr_ref_dest_vec, ptr_vec_2, ptr_vec_1, avl);
+ softrvv::vfadd_vv<float>(ptr_ref_dest_vec, ptr_vec_2, ptr_vec_1, avl);
// Load vector registers
__asm__ volatile("vle32.v v8, (%0)" : : "r"(ptr_vec_1));
__asm__ volatile("vle32.v v16, (%0)" : : "r"(ptr_vec_2));