## machine-int.api
# Compiled by:
#
src/lib/compiler/back/low/lib/lowhalf.lib# This module implements 2's complement arithmetic of various widths.
# This api is implemented in:
#
#
src/lib/compiler/back/low/treecode/machine-int.pkg#
api Machine_Int {
#
Machine_Int = multiword_int::Int;
Sz = Int; # width in bits
Div_Rounding_Mode = DIV_TO_ZERO
| DIV_TO_NEGINF;
hash: Machine_Int -> Unt;
# machine_int <-> other types
#
from_int: (Sz, Int) -> Machine_Int;
from_int1: (Sz, one_word_int::Int) -> Machine_Int;
from_unt: (Sz, Unt) -> Machine_Int;
from_unt1: (Sz, one_word_unt::Unt) -> Machine_Int;
to_int: (Sz, Machine_Int) -> Int;
to_unt: (Sz, Machine_Int) -> Unt;
to_unt1: (Sz, Machine_Int) -> one_word_unt::Unt;
to_int1: (Sz, Machine_Int) -> one_word_int::Int;
from_string: (Sz, String) -> Null_Or( Machine_Int );
to_string: (Sz, Machine_Int) -> String;
to_hex_string: (Sz, Machine_Int) -> String;
to_bin_string: (Sz, Machine_Int) -> String;
# When in doubt, use this to narrow to a given width!
#
narrow: (Sz, multiword_int::Int) -> Machine_Int;
# Convert to signed/unsigned representation:
#
signed: (Sz, Machine_Int) -> multiword_int::Int;
unsigned: (Sz, Machine_Int) -> multiword_int::Int;
# Split a machine_int of length size into words of word sizes.
# The least significant word is at the front of the list
#
split: { size: Sz, word_size: Sz, i: Machine_Int } -> List( Machine_Int );
# Two's complement operators:
#
neg: (Sz, Machine_Int) -> Machine_Int;
abs: (Sz, Machine_Int) -> Machine_Int;
add: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
sub: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
muls: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
divs: (Div_Rounding_Mode,
Sz, Machine_Int, Machine_Int) -> Machine_Int;
rems: (Div_Rounding_Mode ,
Sz, Machine_Int, Machine_Int) -> Machine_Int;
# Unsigned operators:
#
mulu: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
divu: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
# my quotu: (Sz, Machine_Int, Machine_Int) -> machine_int
remu: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
# Signed, trapping operators, may raise OVERFLOW
#
abst: (Sz, Machine_Int) -> Machine_Int;
negt: (Sz, Machine_Int) -> Machine_Int;
addt: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
subt: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
mult: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
divt: (Div_Rounding_Mode,
Sz, Machine_Int, Machine_Int) -> Machine_Int;
# Bit operators
#
bitwise_not: (Sz, Machine_Int) -> Machine_Int;
bitwise_and: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
bitwise_or: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
bitwise_xor: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
eqvb: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
sll_x: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
srl_x: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
sra_x: (Sz, Machine_Int, Machine_Int) -> Machine_Int;
bitslice: (Sz, List ((Int, Int)), Machine_Int) -> Machine_Int;
# Other useful operators:
#
sll: (Sz, Machine_Int, Unt) -> Machine_Int;
srl: (Sz, Machine_Int, Unt) -> Machine_Int;
sra: (Sz, Machine_Int, Unt) -> Machine_Int;
pow2: Int -> Machine_Int;
max_of_size: Sz -> Machine_Int;
min_of_size: Sz -> Machine_Int;
is_in_range: (Sz, Machine_Int) -> Bool;
# Indexing:
#
bit_of: (Sz, Machine_Int, Int) -> Unt; # 0w0 or 0w1
byte_of: (Sz, Machine_Int, Int) -> Unt; # 8 bits
half_of: (Sz, Machine_Int, Int) -> Unt; # 16 bits
word_of: (Sz, Machine_Int, Int) -> one_word_unt::Unt; # 32 bits
# Type promotion:
#
sx: (Sz /* to */, Sz /* from */, Machine_Int) -> Machine_Int;
zx: (Sz /* to */, Sz /* from */, Machine_Int) -> Machine_Int;
# Comparisions:
#
eq: (Sz, Machine_Int, Machine_Int) -> Bool;
ne: (Sz, Machine_Int, Machine_Int) -> Bool;
gt: (Sz, Machine_Int, Machine_Int) -> Bool;
ge: (Sz, Machine_Int, Machine_Int) -> Bool;
lt: (Sz, Machine_Int, Machine_Int) -> Bool;
le: (Sz, Machine_Int, Machine_Int) -> Bool;
ltu: (Sz, Machine_Int, Machine_Int) -> Bool;
gtu: (Sz, Machine_Int, Machine_Int) -> Bool;
leu: (Sz, Machine_Int, Machine_Int) -> Bool;
geu: (Sz, Machine_Int, Machine_Int) -> Bool;
};