Source/Packages

Model.Word32

packages/foundation/standard/src/Model/Word32.alpha

508 lines41 declarations18.3 KiBSHA-256 7f230128ec8c

def · lines 285–298

modelWord32ShiftRight

Full file
A logical shift is division/multiplication by 2^amount followed by the word conversion, rather than amount separate carry traversals. The width guard is lazy: amounts >= 32 return zero without computing their power. On the bounded u64 runtime lane the largest admitted multiplication is (2^32 - 1) * 2^31 < 2^63, so no host overflow precedes truncation. Keeping the one-bit operations independent also leaves a byte-lane reference for the full shift tests. The Baguette realize profile run-430189202 motivated this change; equality of emitted bytes still needs artifact qualification.
285def modelWord32ShiftRight =
286  (lambda unrestricted value : (family ModelWord32) .
287    (lambda unrestricted amount : Nat .
288      (app
289        (nat-eliminate
290          (lambda unrestricted current : Nat . (pi unrestricted unit : Nat . (family ModelWord32)))
291          (lambda unrestricted unit : Nat . modelWord32Zero)
292          (lambda unrestricted predecessor : Nat .
293            (lambda unrestricted induction : (pi unrestricted unit : Nat . (family ModelWord32)) .
294              (lambda unrestricted unit : Nat .
295                (modelWord32FromNaturalTruncated
296                  (naturalDivideUnchecked (modelWord32ToNatural value) (naturalPowerOfTwo amount))))))
297          (naturalLess amount modelWord32NaturalThirtyTwo))
298        zero)))

The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.