add operators test class
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 10 Oct 2018 14:01:42 +0000 (15:01 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 10 Oct 2018 14:01:42 +0000 (15:01 +0100)
operators/operators.cc
operators/operators.h
operators/operators.t.cc
operators/operators_test.h [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..79f74a580617c63977a7a3a4f30f55b124145475 100644 (file)
@@ -0,0 +1 @@
+#include "operators.h"
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b9abb3e4a1505af262559c38b895f4dd1f93ca65 100644 (file)
@@ -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); }
+};
index 75bd379a1c91b37ea4d513f66a8004116306999b..24b20da9e9805917652e62e014a9476035f9c30d 100644 (file)
@@ -1,6 +1,19 @@
 #include <stdio.h>
 
+#include "operators.h"
+#include "operators_test.h"
+#include "decode.h"
+
 int main(int argc, char *argv[])
 {
-    printf("hello\n");
+    /*op2<uint16_t, uint16_t, uint32_t> 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 (file)
index 0000000..e9a8d31
--- /dev/null
@@ -0,0 +1 @@
+#define require_rv64