@@ -2033,6 +2033,70 @@ btorsim_bv_srem (const BtorSimBitVector *a, const BtorSimBitVector *b)
2033
2033
return res ;
2034
2034
}
2035
2035
2036
+ BtorSimBitVector *
2037
+ btorsim_bv_smod (const BtorSimBitVector * a , const BtorSimBitVector * b )
2038
+ {
2039
+ assert (a );
2040
+ assert (b );
2041
+ assert (a -> len == b -> len );
2042
+ assert (a -> width == b -> width );
2043
+
2044
+ BtorSimBitVector * res = 0 , * not_b , * sign_a , * sign_b , * neg_a , * neg_b , * add ;
2045
+ BtorSimBitVector * cond_a , * cond_b , * urem , * neg_urem , * add_urem , * add_neg_urem ;
2046
+ bool a_positive , b_positive ;
2047
+
2048
+ if (a -> width == 1 )
2049
+ {
2050
+ not_b = btorsim_bv_not (b );
2051
+ res = btorsim_bv_and (a , not_b );
2052
+ btorsim_bv_free (not_b );
2053
+ }
2054
+ else
2055
+ {
2056
+ sign_a = btorsim_bv_slice (a , a -> width - 1 , a -> width - 1 );
2057
+ sign_b = btorsim_bv_slice (b , b -> width - 1 , b -> width - 1 );
2058
+ a_positive = !btorsim_bv_is_true (sign_a );
2059
+ b_positive = !btorsim_bv_is_true (sign_b );
2060
+
2061
+ neg_a = btorsim_bv_neg (a );
2062
+ neg_b = btorsim_bv_neg (b );
2063
+ cond_a = a_positive ? btorsim_bv_copy (a )
2064
+ : btorsim_bv_copy (neg_a );
2065
+ cond_b = b_positive ? btorsim_bv_copy (b )
2066
+ : btorsim_bv_copy (neg_b );
2067
+
2068
+
2069
+ urem = btorsim_bv_urem (cond_a , cond_b );
2070
+ add = btorsim_bv_is_zero (urem ) ? btorsim_bv_zero (b -> width )
2071
+ : btorsim_bv_copy (b );
2072
+
2073
+ neg_urem = btorsim_bv_neg (urem );
2074
+ add_urem = btorsim_bv_add (urem , add );
2075
+ add_neg_urem = btorsim_bv_add (neg_urem , add );
2076
+
2077
+ res = a_positive && b_positive ? btorsim_bv_copy (urem )
2078
+ : !a_positive && b_positive ? btorsim_bv_copy (add_neg_urem )
2079
+ : a_positive && !b_positive ? btorsim_bv_copy (add_urem )
2080
+ : btorsim_bv_copy (neg_urem );
2081
+
2082
+ btorsim_bv_free (sign_a );
2083
+ btorsim_bv_free (sign_b );
2084
+ btorsim_bv_free (neg_a );
2085
+ btorsim_bv_free (neg_b );
2086
+ btorsim_bv_free (cond_a );
2087
+ btorsim_bv_free (cond_b );
2088
+ btorsim_bv_free (urem );
2089
+ btorsim_bv_free (add );
2090
+ btorsim_bv_free (neg_urem );
2091
+ btorsim_bv_free (add_urem );
2092
+ btorsim_bv_free (add_neg_urem );
2093
+ }
2094
+
2095
+ assert (res );
2096
+ assert (rem_bits_zero_dbg (res ));
2097
+ return res ;
2098
+ }
2099
+
2036
2100
BtorSimBitVector *
2037
2101
btorsim_bv_concat (const BtorSimBitVector * a , const BtorSimBitVector * b )
2038
2102
{
0 commit comments