Merge "Vector extension test with floating point values"
diff --git a/scripts/test_runner.py b/scripts/test_runner.py index 983de9c..5941830 100755 --- a/scripts/test_runner.py +++ b/scripts/test_runner.py
@@ -55,19 +55,23 @@ class RenodeSimulation(Simulation): # pylint: disable=too-few-public-methods """ Renode Simulation """ def __init__(self, path, elf): - # TODO(henryherman): Look at using repl platform file. + # Get the ROOTDIR path if it exists + self.rootdir = os.environ.get('ROOTDIR', default=None) + if self.rootdir is None: + parser.error("ROOTDIR environment variable not set.") renode_script = """ -mach create "springbok" -machine LoadPlatformDescriptionFromString "cpu: CPU.SpringbokRiscV32 @ sysbus" -machine LoadPlatformDescriptionFromString "ram_vec_imem: Memory.MappedMemory @ sysbus 0x30000000 {size: 0x00040000}" -machine LoadPlatformDescriptionFromString "ram_vec_dmem: Memory.MappedMemory @ sysbus 0x34000000 {size: 0x00400000}" -sysbus LoadELF @%s -sysbus.cpu PC 0x30000000 -sysbus.cpu PerformanceInMips 2000 +path set @%(rootdir)s +$bin=@%(elf)s +include @sim/config/springbok.resc +sysbus.cpu2 PerformanceInMips 2000 emulation SetGlobalQuantum "1" -sysbus.cpu IsHalted False -start""" - self.renode_script = renode_script % elf +start +sysbus.vec_controlblock WriteDoubleWord 0xc 0""" + self.script_params = { + "rootdir": self.rootdir, + "elf":elf + } + self.renode_script = renode_script % self.script_params self.renode_args = [ "mono",
diff --git a/softrvv/include/softrvv.h b/softrvv/include/softrvv.h index 18c2c21..bfc0f54 100644 --- a/softrvv/include/softrvv.h +++ b/softrvv/include/softrvv.h
@@ -24,6 +24,7 @@ #include "softrvv_vnsra.h" #include "softrvv_vnsrl.h" #include "softrvv_vor.h" +#include "softrvv_vredsum.h" #include "softrvv_vrem.h" #include "softrvv_vsext_vzext.h" #include "softrvv_vsll.h"
diff --git a/softrvv/include/softrvv_vredsum.h b/softrvv/include/softrvv_vredsum.h new file mode 100644 index 0000000..7f96886 --- /dev/null +++ b/softrvv/include/softrvv_vredsum.h
@@ -0,0 +1,18 @@ +#ifndef SOFTRVV_VREDSUM_H +#define SOFTRVV_VREDSUM_H + +#include <stddef.h> + +namespace softrvv { + +template <typename T> +void vredsum_vs(T *dest, T *src2, T *src1, int32_t avl) { + dest[0] = src1[0]; + for (int32_t idx = 0; idx < avl; idx++) { + dest[0] += src2[idx]; + } +} + +} // namespace softrvv + +#endif // SOFTRVV_VREDSUM_H
diff --git a/softrvv/tests/CMakeLists.txt b/softrvv/tests/CMakeLists.txt index 62cbc9a..9614eb4 100644 --- a/softrvv/tests/CMakeLists.txt +++ b/softrvv/tests/CMakeLists.txt
@@ -260,6 +260,15 @@ -Xlinker --defsym=__itcm_length__=128K ) +softrvv_vec_cc_generated_test( + NAME + vredsum + TEMPLATE + softrvv_vredsum_test.tpl.cpp + LINKOPTS + -Xlinker --defsym=__itcm_length__=128K +) + vec_cc_test( NAME softrvv_vmax
diff --git a/softrvv/tests/templates/opmvv_vred_test.tpl.cpp b/softrvv/tests/templates/opmvv_vred_test.tpl.cpp new file mode 100644 index 0000000..c40f1c1 --- /dev/null +++ b/softrvv/tests/templates/opmvv_vred_test.tpl.cpp
@@ -0,0 +1,44 @@ +<%! +import vec_test_helpers +%>\ +<%def name="test_opmvv_vred(template_helper, src2, src1, ref_vv)"> +<% +src1 = vec_test_helpers.to_carr_str(src1) +src2 = vec_test_helpers.to_carr_str(src2) +ref_vv = vec_test_helpers.to_carr_str(ref_vv) +%>\ +namespace softrvv_${template_helper.op_code}_test { +namespace { +${insert_variable_init(template_helper, src2, src1, ref_vv)} + +class SoftRvv${template_helper.op_code.capitalize()}Test : public ::testing::Test { + protected: + void SetUp() override { memset(dest, 0, sizeof(dest)); } +}; +${insert_test(template_helper)}\ +} // namespace +} // namespace softrvv_${op}_test\ +</%def>\ + +<%def name="insert_variable_init(template_helper, src2, src1, ref_vv)"> +<% + var_types = template_helper.get_var_types() +%>\ +${var_types.src1_type} src1[] = {${src1}}; +${var_types.src2_type} src2[] = {${src2}}; +const int kAVL = sizeof(src1)/sizeof(src1[0]); +${var_types.dest_type} dest[kAVL]; + +${var_types.dest_type} ref_vv[kAVL] = {${ref_vv}}; +</%def>\ + +<%def name="insert_test(template_helper)"> +<% +var_types = template_helper.get_var_types() +datatypes = template_helper.get_softrvv_template_data_type() +%>\ +TEST_F(SoftRvv${template_helper.op_code.capitalize()}Test, VS) { + softrvv::${template_helper.op_code}_vs<${datatypes}>(dest, src2, src1, kAVL);\ + assert_vec_elem_eq<${var_types.dest_type}>(kAVL, dest, ref_vv); +} +</%def>\
diff --git a/softrvv/tests/templates/softrvv_vredsum_test.tpl.cpp b/softrvv/tests/templates/softrvv_vredsum_test.tpl.cpp new file mode 100644 index 0000000..7eced1a --- /dev/null +++ b/softrvv/tests/templates/softrvv_vredsum_test.tpl.cpp
@@ -0,0 +1,12 @@ +<%inherit file="base.tpl.cpp"/>\ +<%namespace name="tests" file="opmvv_vred_test.tpl.cpp"/> +<% +import numpy as np +import vec_test_helpers +template_helper = vec_test_helpers.VecTemplateHelper(op, 32) +src2, src1, rs1 = template_helper.get_test_inputs(n=5) +dest_type = template_helper.get_np_dest_type() +ref_vv = np.zeros(src2.shape, dtype=dest_type) +ref_vv[0] = src2.sum() + src1[0] +%>\ +${tests.test_opmvv_vred(template_helper, src2, src1, ref_vv)}
diff --git a/springbok/crt0.S b/springbok/crt0.S index f9e46f6..d4ce006 100644 --- a/springbok/crt0.S +++ b/springbok/crt0.S
@@ -246,13 +246,27 @@ .weak exception_handler exception_handler: - li t4, 0 # ERROR logging level - la a0, exception_msg - csrr t5, mcause - .word 0x001E50EFB # simprint t4, a0, t5 (encoded as custom3<func3=0>) + # Exception occurred + li t0, 0x65637845 # "Exce" + li t1, 0x6f697470 # "ptio" + li t2, 0x636f206e # "n oc" + li t3, 0x72727563 # "curr" + li t4, 0x00006465 # "ed\0\0" + addi sp, sp, -20 + sw t0, 0(sp) + sw t1, 4(sp) + sw t2, 8(sp) + sw t3, 12(sp) + sw t4, 16(sp) + csrr a0, mcause + li t6, 0 # ERROR logging level + .word 0x00A10FFB # simprint t6, sp, a0 (encoded as custom3<func3=0>) + addi sp, sp, 20 + # Store mcause as the reture value + mv s0, a0 call print_csrs - # Store the return value as mcause to be used in _finish - mv a0, t5 + # Restore the return value to be used in _finish + mv a0, s0 # Clear the stack la sp, _stack_ptr j _finish @@ -260,7 +274,3 @@ .weak print_csrs print_csrs: mret - -.section ".rodata","a",@progbits -exception_msg: - .string "Exception occurred\0"