Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
The Basic theory of bitvector machines.
The Basic theory could be derived from the Minimal
theory using the Basic functor.
include Minimal
include Init
val unk : 'a Value.sort -> 'a pure
unk s
an unknown value of sort s
.
This term explicitly denotes a term with undefined or unknown value.
include Bitv
val int : 's Bitv.t Value.sort -> word -> 's bitv
int s x
is a bitvector constant x
of sort s
.
div x y
unsigned division modulo 2^'s
truncating towards 0.
The division by zero is defined to be a vector of all ones of size 's
.
sdiv x y
is signed division of x
by y
modulo 2^'s
,
The signed division operator is defined in terms of the div
operator as follows:
/ | div x y : if not mx /\ not my | neg (div (neg x) y) if mx /\ not my x sdiv y = < | neg (div x (neg y)) if not mx /\ my | div (neg x) (neg y) if mx /\ my \ where mx = msb x, and my = msb y.
smodulo x y
is the signed remainder of div x y
modulo 2^'s
.
This version of the signed remainder where the sign follows the dividend, and is defined via the % = modulo
operation as follows
/ | x % y : if not mx /\ not my | neg (neg x % y) if mx /\ not my x smodulo y = < | neg (x % (neg y)) if not mx /\ my | neg (neg x % neg y) mod m if mx /\ my \ where mx = msb x and my = msb y.
shiftr s x m
shifts x
right by m
bits filling with s
.
shiftl s x m
shifts x
left by m
bits filling with s
.
val cast : 'a Bitv.t Value.sort -> bool -> 'b bitv -> 'a bitv
cast s b x
casts x
to sort s
filling with b
.
If m = size s - size (sort b) > 0
then m
bits b
are prepended to the most significant part of the vector.
Otherwise, if m <= 0
, i.e., it is a narrowing cast, then the value of b
doesn't affect the result of evaluation.
val concat : 'a Bitv.t Value.sort -> 'b bitv list -> 'a bitv
concat s xs
concatenates a list of vectors xs
.
All vectors are concatenated from left to right (so that the most significant bits of the resulting vector are defined by the first element of the list and so on).
The result of concatenation are then casted to sort s
with all extra bits (if any) set to zero
.
val append : 'a Bitv.t Value.sort -> 'b bitv -> 'c bitv -> 'a bitv
append s x y
appends x
and y
and casts to s
.
Appends x
and y
so that in the resulting vector the vector x
occupies the most significant part and y
the least significant part. The resulting vector is then casted to the sort s
with extra bits (if any) set to zero.
include Effect
val perform : 'a Effect.sort -> 'a eff
perform s
performs a generic effect of sort s
.
repeat c data
repeats data effects until the condition c
holds.
val zero : 'a Bitv.t Value.sort -> 'a bitv
zero s
creates a bitvector of all zeros of sort s
.
val high : 'a Bitv.t Value.sort -> 'b bitv -> 'a bitv
high s x
is the high cast of x
to sort s
.
if m = size (sort x) - size s > 0
then high s x
evaluates to m
most significant bits of x
; else if m = 0
then high s x
evaluates to the value of x
; else m
zeros are prepended to the most significant part of x
.
val low : 'a Bitv.t Value.sort -> 'b bitv -> 'a bitv
low s x = cast s b0 x
is the low cast of x
to sort s
.
if m = size (sort x) - size s < 0
then low s x
evaluates to size s
least significant bits of x
; else if m = 0
then high s x
evaluates to the value of x
; else m
zeros are prepended to the most significant part of x
.
val signed : 'a Bitv.t Value.sort -> 'b bitv -> 'a bitv
signed s x = cast s (msb x) x
is the signed cast of x
to sort s
.
if m = size s - (size (sort x)) > 0
then extends x
on its most significant side with m
bits equal to msb x
; else if m = 0
then signed s x
evaluates to x
else it evaluates to size s
least significant bits of x
.
val unsigned : 'a Bitv.t Value.sort -> 'b bitv -> 'a bitv
unsigned s x = cast s b0 x
is the unsigned cast of x
to sort s
.
if m = size s - (size (sort x)) > 0
then extends x
on its most significant side with m
zeros; else if m = 0
then unsigned s x
evaluates to x
else it evaluates to size s
least significant bits of x
.
extract s hi lo x
extracts bits of x
between hi
and lo
.
Extracts hi-lo+1
consecutive bits of x
from hi
to lo
, and casts them to sort s
with any excessive bits set to zero.
Note that hi-lo+1
is taken modulo 2^'b
, so this operation is defined even if lo
is greater or equal to hi
.
loadw s e m k
loads a word from the memory m
.
if e
evaluates to b1
(big endian case), then the term evaluates to low s (m[k] @ m[k+1] @ ... @ m[k+n] )
, else the term evaluates to low s (m[k+n] @ m[k+n-1] @ ... @ m[k] )
where x @ y
is append (vals m) x y
, and n
is the smallest natural number such that n * size (vals (sort m)) >= size s
, an m[i]
is the i
'th value of memory m
. .
This is a generic function that loads words using specified endianess (e
could be read as is_big_endian
) with arbitrary byte size.
storew e m k x
stores a word in the memory m
.
Splits the word x
into chunks of size equal to the size of memory elements and lays them out in the big endian order, if e
evaluates to b1
, or little endian order otherwise.
arshift x m = shiftr (msb x) m
arithmetically shifts x
right by m
bits.