clean up shift instruction implementation
authorAndrew Waterman <waterman@cs.berkeley.edu>
Fri, 2 Oct 2015 18:39:09 +0000 (11:39 -0700)
committerAndrew Waterman <waterman@cs.berkeley.edu>
Fri, 2 Oct 2015 18:39:09 +0000 (11:39 -0700)
riscv/insns/slli.h
riscv/insns/srai.h
riscv/insns/srl.h
riscv/insns/srli.h

index dfe7168193f9dac8848aa32ce5173b9cbf9caa8e..26782fda3d1a00f0d44d4e17cc5f661eec055873 100644 (file)
@@ -1,3 +1,2 @@
-if (SHAMT >= xlen)
-  throw trap_illegal_instruction();
+require(SHAMT < xlen);
 WRITE_RD(sext_xlen(RS1 << SHAMT));
index 69066efb4d4fad0c4845eb56ff4a06c7c8f07161..7ae1d4e5af36affad7c319225e89508b8bbce504 100644 (file)
@@ -1,8 +1,2 @@
-if (xlen == 64)
-  WRITE_RD(sreg_t(RS1) >> SHAMT);
-else
-{
-  if(SHAMT & 0x20)
-    throw trap_illegal_instruction();
-  WRITE_RD(sext32(int32_t(RS1) >> SHAMT));
-}
+require(SHAMT < xlen);
+WRITE_RD(sext_xlen(sext_xlen(RS1) >> SHAMT));
index 0eb948b7454e48962d4234304ccb7e17a4aea684..0dabe9ecde160c95c58e72248cd78b22918d5d3d 100644 (file)
@@ -1,4 +1 @@
-if (xlen == 64)
-  WRITE_RD(RS1 >> (RS2 & 0x3F));
-else
-  WRITE_RD(sext32((uint32_t)RS1 >> (RS2 & 0x1F)));
+WRITE_RD(sext_xlen(zext_xlen(RS1) >> (RS2 & (xlen-1))));
index 0cdc853b0483f68021ef101f607a7e71da7288c7..ea0b40d6549b5f1f9ea51b1d8d5988e514ac0ef4 100644 (file)
@@ -1,8 +1,2 @@
-if (xlen == 64)
-  WRITE_RD(RS1 >> SHAMT);
-else
-{
-  if(SHAMT & 0x20)
-    throw trap_illegal_instruction();
-  WRITE_RD(sext32((uint32_t)RS1 >> SHAMT));
-}
+require(SHAMT < xlen);
+WRITE_RD(sext_xlen(zext_xlen(RS1) >> SHAMT));