summaryrefslogtreecommitdiff
path: root/lib/sail.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sail.c')
-rw-r--r--lib/sail.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/sail.c b/lib/sail.c
index 5c83690d..c66c057c 100644
--- a/lib/sail.c
+++ b/lib/sail.c
@@ -680,6 +680,11 @@ void zero_extend(lbits *rop, const lbits op, const sail_int len)
mpz_set(*rop->bits, *op.bits);
}
+fbits fast_zero_extend(const sbits op, const uint64_t n)
+{
+ return op.bits;
+}
+
void sign_extend(lbits *rop, const lbits op, const sail_int len)
{
assert(op.len <= mpz_get_ui(len));
@@ -694,6 +699,32 @@ void sign_extend(lbits *rop, const lbits op, const sail_int len)
}
}
+fbits fast_sign_extend(const fbits op, const uint64_t n, const uint64_t m)
+{
+ uint64_t rop = op;
+ if (op & (UINT64_C(1) << (n - 1))) {
+ for (uint64_t i = m - 1; i >= n; i--) {
+ rop = rop | (UINT64_C(1) << i);
+ }
+ return rop;
+ } else {
+ return rop;
+ }
+}
+
+fbits fast_sign_extend2(const sbits op, const uint64_t m)
+{
+ uint64_t rop = op.bits;
+ if (op.bits & (UINT64_C(1) << (op.len - 1))) {
+ for (uint64_t i = m - 1; i >= op.len; i--) {
+ rop = rop | (UINT64_C(1) << i);
+ }
+ return rop;
+ } else {
+ return rop;
+ }
+}
+
void length_lbits(sail_int *rop, const lbits op)
{
mpz_set_ui(*rop, op.len);
@@ -783,12 +814,21 @@ void sail_signed(sail_int *rop, const lbits op)
}
}
-inline
mach_int fast_unsigned(const fbits op)
{
return (mach_int) op;
}
+mach_int fast_signed(const fbits op, const uint64_t n)
+{
+ if (op & (UINT64_C(1) << (n - 1))) {
+ uint64_t rop = op & ~(UINT64_C(1) << (n - 1));
+ return (mach_int) (rop - (UINT64_C(1) << (n - 1)));
+ } else {
+ return (mach_int) op;
+ }
+}
+
void append(lbits *rop, const lbits op1, const lbits op2)
{
rop->len = op1.len + op2.len;
@@ -911,6 +951,23 @@ void vector_update_subrange_lbits(lbits *rop,
}
}
+fbits fast_update_subrange(const fbits op,
+ const mach_int n,
+ const mach_int m,
+ const fbits slice)
+{
+ fbits rop = op;
+ for (mach_int i = 0; i < n - (m - UINT64_C(1)); i++) {
+ uint64_t bit = UINT64_C(1) << ((uint64_t) i);
+ if (slice & bit) {
+ rop |= (bit << m);
+ } else {
+ rop &= ~(bit << m);
+ }
+ }
+ return rop;
+}
+
void slice(lbits *rop, const lbits op, const sail_int start_mpz, const sail_int len_mpz)
{
assert(mpz_get_ui(start_mpz) + mpz_get_ui(len_mpz) <= op.len);