Common — library colibrilib.bddbitv — module Modulo

The modulo of the rotations: it has a precondition, its only callers are the rotations of Export, which check sz

5174
module Modulo
5175
use colibrilib.spec.Value
5176
use int.Int
5177
use int.EuclideanDivision as E
5178
use int.ComputerDivision as C
5179
use colibrilib.int63.Int63

off modulo sz (Int.(%) of Base)

  Valid (1.0s) (colibri2 9) (cvc4) (split_vc 2) (depth 2)
5182
let
bv_modulo
(off sz: int63) : int63
5183
requires { 0 < sz }
5184
ensures { value_is (E.mod off sz) (to_int result) }
5185
ensures { 0 <= result < sz }
5186
=
5187
let o = off % sz in
5188
let o' = if o < 0 then o + sz else o in
5189
let ghost q = if o < 0 then C.div (to_int off) (to_int sz) - 1 else C.div (to_int off) (to_int sz) in
5190
assert { to_int off = q * to_int sz + to_int o' };
5191
assert { E.div off sz = q };
5192
o'
5193
end