add shaddw
[libreriscv.git] / openpower / sv / bitmanip.mdwn
index c839655904175a58073174978f25efe97957ee93..59688e12932e507f74616e8d6a7a6fad9521e57a 100644 (file)
@@ -270,6 +270,12 @@ Pseudo-code (shadd):
     m <- sm + 1
     RT <- (n[m:XLEN-1] || [0]*m) + (RA)
 
+Pseudo-code (shaddw):
+
+    shift <- sm + 1                # Shift is between 1-4
+    n <- EXTS((RB)[XLEN/2:XLEN-1]) # Only use lower XLEN/2-bits of RB
+    RT <- (n << shift) + (RA)      # Shift n, add RA
+
 Pseudo-code (shadduw):
 
     n <- ([0]*(XLEN/2)) || (RB)[XLEN/2:XLEN-1]
@@ -282,6 +288,12 @@ uint_xlen_t shadd(uint_xlen_t RA, uint_xlen_t RB, uint8_t sm) {
     return (RB << (sm+1)) + RA;
 }
 
+uint_xlen_t shaddw(uint_xlen_t RA, uint_xlen_t RB, uint8_t sm) {
+    uint_xlen_t n = (int_xlen_t)(RB << XLEN / 2) >> XLEN / 2;
+    sm = sm & 0x3;
+    return (n << (sm+1)) + RA;
+}
+
 uint_xlen_t shadduw(uint_xlen_t RA, uint_xlen_t RB, uint8_t sm) {
     uint_xlen_t n = RB & 0xFFFFFFFF;
     sm = sm & 0x3;