From: Luke Kenneth Casson Leighton Date: Wed, 10 Oct 2018 14:01:42 +0000 (+0100) Subject: add operators test class X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1e33219bc00f9d93832ce7d057cdbc280c512e9c;p=riscv-isa-sim.git add operators test class --- diff --git a/operators/operators.cc b/operators/operators.cc index e69de29..79f74a5 100644 --- a/operators/operators.cc +++ b/operators/operators.cc @@ -0,0 +1 @@ +#include "operators.h" diff --git a/operators/operators.h b/operators/operators.h index e69de29..b9abb3e 100644 --- a/operators/operators.h +++ b/operators/operators.h @@ -0,0 +1,25 @@ +#include "stdint.h" +#include "decode.h" + +typedef uint64_t (*cvt)(uint64_t r); + +uint64_t u64_u64_cvt(reg_t r) { return r; } +uint64_t u64_u16_cvt(reg_t r) { return (uint64_t)(uint16_t)r; } + +uint64_t (sext32)(reg_t r) { return sext32(r); } + +class opcvt +{ +public: + cvt cv_rd; + cvt cv_rs1; + cvt cv_rs2; + opcvt(cvt _cv_rd, cvt _cv_rs1, cvt _cv_rs2) : + cv_rd(_cv_rd), cv_rs1(_cv_rs1), cv_rs2(_cv_rs2) {} + + void add(reg_t &rd, const reg_t &rs1, const reg_t &rs2) + { rd = cv_rd(cv_rs1(rs1) + cv_rs2(rs2)); } + + //R operator+ (op2 &s2) { return typecvt(s1 + typecvt(s2)); } + //operator R() { return typecvt(s1); } +}; diff --git a/operators/operators.t.cc b/operators/operators.t.cc index 75bd379..24b20da 100644 --- a/operators/operators.t.cc +++ b/operators/operators.t.cc @@ -1,6 +1,19 @@ #include +#include "operators.h" +#include "operators_test.h" +#include "decode.h" + int main(int argc, char *argv[]) { - printf("hello\n"); + /*op2 o(0xfff0); + uint32_t p = 0xfffffef; + o = o + p; + */ + opcvt cvt(u64_u64_cvt, u64_u64_cvt, sext32); + uint64_t o = 0xff00; + uint64_t s1 = 0x1ff01; + uint64_t s2 = 0x2ff01; + cvt.add(o, s1, s2); + printf("hello %lx\n", o); } diff --git a/operators/operators_test.h b/operators/operators_test.h new file mode 100644 index 0000000..e9a8d31 --- /dev/null +++ b/operators/operators_test.h @@ -0,0 +1 @@ +#define require_rv64