Module Asllib.Bitvector
Source This module provide an interface to ASL bitvector, and main operations on it.
The length of the bitvector.
ConstructorsA length 1 bitvector with a 1 bit inside.
A length 1 bitvector with a 0 bit inside.
ones n
is a bitvector of length n
with every bit set.
zeros n
is a bitvector of length n
without any bit set.
of_string s
interpretes s
as a right-indexed representation of a bitvector. Characters others than '0' or '1' are ignored. The length of of_string s
is equal to the number of such characters in s
.
of_int i
is the bitvector of length Sys.int_size
(e.g. 63) that corresponds to i
in little-endian, i.e. index 0 (for slicing operations corresponds to i mod 2
.
Source val of_int_sized : int -> int -> t
of_int n i
is the bitvector of length n
that corresponds to i
in little-endian, i.e. index 0 (for slicing operations corresponds to i mod 2
.
of_int i
is the bitvector of length 64 that corresponds to i
in little-endian, i.e. index 0 (for slicing operations corresponds to i mod 2
.
of_int sz i
is the bitvector of length sz
that corresponds to i
in little-endian.
ExportsPrint the bitvector, indexed from the right, as a serie of '0' and '1', delimited by apostrophes. Inside a horizontal box.
Returns a string representing the bitvector, indexed from the right and delimited by apostrophes.
Source val to_string_hexa : t -> string
Returns a string representing the bitvector in hexadecimal, indexed from the right and preceded by '0x'.
Returns an integer representing the bitvector, little-endian. Result unspecified if length > Sys.int_size
.
Returns a signed integer representing the bitvector.
Source val to_int64_unsigned : t -> int64
Returns an integer representing the bitvector, little-endian. Result unspecified if length > 64
.
Source val to_int64_signed : t -> int64
Returns an integer representing the bitvector, little-endian. Result unspecified if length > 64
.
Operations on bitvectorsequal b1 b2
is true
if and only if b1
and b2
are bitwise equal.
The comparison function for bitvectors, with the same specification as Stdlib.compare
.
sign_extend nbytes bv
returns a copy of bv of length 8*nbytes
, left-padded with bv
's bit-sign.
Returns the number of bits set to 1.
Source val highest_set_bit : t -> int
Returns the index of the highest set bit.
prefix src len
returns the prefix of size len
of bitvector src
. Will crash if len
is strictly more then the size of src
.
extract_slice src positions
returns a bitvector whose i
-th bit is the bit of src
whose index is the i
-th element of positions
.
Source val write_slice : t -> t -> int list -> t
write_slice dst src positions
is a copy of dst
where each bit at index i
in src
has been written in dst
at the index given by the i
-th element of positions
.
concat [bv2; bv1; bv0]
is the concatenation of bv0
, bv1
, and bv2
, in this order, i.e. if bv0
is not empty, the following is true:
equal (extract_slice (concat [bv1; bv0]) [ 0 ]) (extract_slice bv0 [ 0 ])
is_zeros bv
is true if every bit of bv is unset.
is_ones bv
is true if every bit of bv is set.
Bitvector masksBitvector in ASL can be matched against masks, that have the same syntax than bitvectors, with an extra possible bit: 'x'
. This bits indicates that the mask would match against any bit at this position.
For example:
assert ('01' IN {'01'}) == TRUE;
assert ('01' IN {'0x'}) == TRUE;
assert ('10' IN {'0x'}) == FALSE;
Internal representation of a mask.
Returns the length of bitvectors matched by this mask.
Build a mask from its ASL representation.
Build a mask that matches a bitvector.
matches mask bv
is true iff bv
matches mask
.
Returns an ASL string matching its value.
Source val mask_to_canonical_string : mask -> string
Returns a unique ASL string matching its value.
mask_set m
's set bits are those required set by m
.
mask_unset m
's set bits are those required unset by m
.
mask_specified m
's set bits are those require set or unset by m
.