summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sail.c14
-rw-r--r--lib/sail.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/sail.c b/lib/sail.c
index 5530b462..e9c6ca37 100644
--- a/lib/sail.c
+++ b/lib/sail.c
@@ -1091,6 +1091,20 @@ void shift_bits_right_arith(lbits *rop, const lbits op1, const lbits op2)
}
}
+void arith_shiftr(lbits *rop, const lbits op1, const sail_int op2)
+{
+ rop->len = op1.len;
+ mp_bitcnt_t shift_amt = mpz_get_ui(op2);
+ mp_bitcnt_t sign_bit = op1.len - 1;
+ mpz_fdiv_q_2exp(*rop->bits, *op1.bits, shift_amt);
+ if(mpz_tstbit(*op1.bits, sign_bit) != 0) {
+ /* */
+ for(; shift_amt > 0; shift_amt--) {
+ mpz_setbit(*rop->bits, sign_bit - shift_amt + 1);
+ }
+ }
+}
+
void shiftl(lbits *rop, const lbits op1, const sail_int op2)
{
rop->len = op1.len;
diff --git a/lib/sail.h b/lib/sail.h
index b50a5a4c..1a123cf4 100644
--- a/lib/sail.h
+++ b/lib/sail.h
@@ -330,6 +330,7 @@ void shift_bits_right_arith(lbits *rop, const lbits op1, const lbits op2);
void shiftl(lbits *rop, const lbits op1, const sail_int op2);
void shiftr(lbits *rop, const lbits op1, const sail_int op2);
+void arith_shiftr(lbits *rop, const lbits op1, const sail_int op2);
void reverse_endianness(lbits*, lbits);