Skip to content

Commit

Permalink
Use operations exported by PRIM_SEQUENCE
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewFluet committed Oct 7, 2017
1 parent 1c0b24e commit 5e4b00d
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions basis-library/integer/int-inf0.sml
Expand Up @@ -452,33 +452,33 @@ structure IntInf =
(* sign limb + magnitude limb(s) *)
S.>= (l, 2) andalso
(* sign limb is 0w0 (positive) or 0w1 (negative) *)
MPLimb.<= (V.subUnsafe (v, 0), 0w1) andalso
MPLimb.<= (V.unsafeSub (v, 0), 0w1) andalso
(* most-significant magnitude limb is non-zero *)
MPLimb.> (V.subUnsafe (v, S.- (l, 1)), 0w0) andalso
MPLimb.> (V.unsafeSub (v, S.- (l, 1)), 0w0) andalso
(* value exceeds Small representation;
* if positive, then mag in [1, 2^(ObjptrWord.sizeInBits - 2)].
* if negative, then mag in [0, 2^(ObjptrWord.sizeInBits - 2) - 1].
*)
(S.> (l, S.+ (1, limbsPerObjptr)) orelse
if Int32.<= (ObjptrWord.sizeInBits, MPLimb.sizeInBits)
then let
val mag = V.subUnsafe (v, 1)
val mag = V.unsafeSub (v, 1)
in
MPLimb.>=
(if MPLimb.>= (V.subUnsafe (v, 0), 0w1) then MPLimb.- (mag, 0w1) else mag,
(if MPLimb.>= (V.unsafeSub (v, 0), 0w1) then MPLimb.- (mag, 0w1) else mag,
MPLimb.<<? (0w1, Word32.- (ObjptrWord.sizeInBitsWord, 0w2)))
end
else let
fun loop (i, mag) =
if S.< (i, l)
then ObjptrWord.andb
(ObjptrWord.<<? (mag, MPLimb.sizeInBitsWord),
W.castFromMPLimb (V.subUnsafe (v, i)))
W.castFromMPLimb (V.unsafeSub (v, i)))
else mag
val mag = loop (2, W.castFromMPLimb (V.subUnsafe (v, 1)))
val mag = loop (2, W.castFromMPLimb (V.unsafeSub (v, 1)))
in
ObjptrWord.>=
(if MPLimb.>= (V.subUnsafe (v, 0), 0w1) then ObjptrWord.- (mag, 0w1) else mag,
(if MPLimb.>= (V.unsafeSub (v, 0), 0w1) then ObjptrWord.- (mag, 0w1) else mag,
ObjptrWord.<<? (0w1, Word32.- (ObjptrWord.sizeInBitsWord, 0w2)))
end)
in
Expand Down Expand Up @@ -542,15 +542,15 @@ structure IntInf =
if sextd andalso (#isNeg other) w
then loop ((#neg other) w, 1, [(0,0w1)])
else loop (w, 1, [(0,0w0)])
val a = A.allocUnsafe n
val a = A.unsafeAlloc n
fun loop acc =
case acc of
[] => ()
| (i, v) :: acc => (A.updateUnsafe (a, i, v)
| (i, v) :: acc => (A.unsafeUpdate (a, i, v)
; loop acc)
val () = loop acc
in
Prim.fromVector (V.fromArrayUnsafe a)
Prim.fromVector (V.unsafeFromArray a)
end
in
fun extdFromWord8 (sextd, w) =
Expand Down Expand Up @@ -683,12 +683,12 @@ structure IntInf =
else let
val v = Prim.toVector i
val n = V.length v
val isneg = V.subUnsafe (v, 0) <> 0w0
val isneg = V.unsafeSub (v, 0) <> 0w0
in
if Int32.>= (MPLimb.sizeInBits, #sizeInBits other)
then let
val limbsPer : S.t = 1
val limb = V.subUnsafe (v, 1)
val limb = V.unsafeSub (v, 1)
val extra =
S.> (n, S.+ (limbsPer, 1))
orelse
Expand All @@ -708,7 +708,7 @@ structure IntInf =
fun loop (i, ans) =
if S.> (i, 0)
then let
val limb = V.subUnsafe (v, i)
val limb = V.unsafeSub (v, i)
val ans =
(#orb other)
((#lshift other)
Expand Down Expand Up @@ -993,7 +993,7 @@ structure IntInf =
(* Given a bignum bigint, test if it is (strictly) negative.
*)
fun bigIsNeg (arg: bigInt): bool =
V.subUnsafe (Prim.toVector arg, 0) <> 0w0
V.unsafeSub (Prim.toVector arg, 0) <> 0w0

local
fun make (smallOp, bigOp, limbsFn, extra)
Expand Down Expand Up @@ -1316,7 +1316,7 @@ structure IntInf =
else let
val v = Prim.toVector arg
val n = V.length v
val w = MPLimb.log2 (V.subUnsafe (v, S.- (n, 1)))
val w = MPLimb.log2 (V.unsafeSub (v, S.- (n, 1)))
in
fromLarge {numLimbsMinusOne = S.- (n, 2),
mostSigLimbLog2 = w}
Expand Down

0 comments on commit 5e4b00d

Please sign in to comment.