- tarval *bits_minus_1 = new_tarval_from_long(bits - 1, mode);
- tarval *two_bits_1 = SHL(get_mode_one(mode), bits_minus_1);
- tarval *seven_ff = SUB(two_bits_1, ONE(mode));
+ tarval_int_overflow_mode_t rem = tarval_get_integer_overflow_mode();
+
+ /* we need overflow mode to work correctly */
+ tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
+
+ bits_minus_1 = new_tarval_from_long(bits - 1, mode);
+ two_bits_1 = SHL(get_mode_one(mode), bits_minus_1);
+ seven_ff = SUB(two_bits_1, ONE(mode));