## bitop-g.pkg
## Author: Matthias Blume (blume@tti-c.org)
# Compiled by:
#
src/lib/c-glue-lib/ram/memory.lib# Bit operations on integers as if they were words
# (based on suggestions from Allen Leung).
generic package integer_bitops_g (
package i: Int; # Int is from
src/lib/std/src/int.api package w: Unt; # Unt is from
src/lib/std/src/unt.api)
: (weak)
api {
# We use a generic to express this stuff generically.
# If efficiency is a concern, it may be necessary to
# expand this "by hand"....
Int = i::Int;
# unsigned arithmetic.
# non-overflow trapping
+++ : (Int, Int) -> Int;
--- : (Int, Int) -> Int;
*** : (Int, Int) -> Int;
udiv: (Int, Int) -> Int;
umod: (Int, Int) -> Int;
umin: (Int, Int) -> Int;
umax: (Int, Int) -> Int;
# Bit ops
bitwise_not: Int -> Int;
bitwise_and: (Int, Int) -> Int;
bitwise_or: (Int, Int) -> Int;
bitwise_xor: (Int, Int) -> Int;
<< : (Int, unt::Unt) -> Int;
>> : (Int, unt::Unt) -> Int;
>>> : (Int, unt::Unt) -> Int;
# unsigned comparisons
ule: (Int, Int) -> Bool;
ulg: (Int, Int) -> Bool;
ugt: (Int, Int) -> Bool;
uge: (Int, Int) -> Bool;
ucompare: (Int, Int) -> Order;
}
{
Int = i::Int;
stipulate
to = w::from_multiword_int
o i::to_multiword_int;
from = i::from_multiword_int
o w::to_multiword_int_x;
fun bop f (x, y) = from (f (to x, to y)); # Binary op
fun uop f x = from (f (to x)); # unary op
fun sop f (x, y) = from (f (to x, y)); # shift-like op
fun cop f (x, y) = f (to x, to y); # Comparison-like op
herein
my +++ = bop w::(+) ;
my --- = bop w::(-) ;
my *** = bop w::(*) ;
udiv = bop w::(/) ;
umod = bop w::(%) ;
bitwise_and = bop w::bitwise_and ;
bitwise_or = bop w::bitwise_or ;
bitwise_xor = bop w::bitwise_xor ;
bitwise_not = uop w::bitwise_not ;
umax = bop w::max ;
umin = bop w::min ;
my (<<) = sop w::(<<) ;
my (>>) = sop w::(>>) ;
my (>>>) = sop w::(>>>) ;
ulg = cop w::(<) ;
ule = cop w::(<=) ;
ugt = cop w::(>) ;
uge = cop w::(>=) ;
ucompare = cop w::compare ;
end;
};
## Copyright (c) 2004 by The Fellowship of SML/NJ
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.