Source/Packages

Model.Word32

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

481 lines41 declarations16.9 KiBSHA-256 56a6cf48ff83

def · lines 273–285

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.
273def modelWord32ShiftRight =
274  (lambda unrestricted value : (family ModelWord32) . unrestricted amount : Nat .
275    app
276      (nat-eliminate
277        (lambda unrestricted current : Nat . pi unrestricted unit : Nat . family ModelWord32)
278        (lambda unrestricted unit : Nat . modelWord32Zero)
279        (lambda unrestricted predecessor : Nat .
280          unrestricted induction : (pi unrestricted unit : Nat . family ModelWord32) .
281          unrestricted unit : Nat .
282          modelWord32FromNaturalTruncated
283            (naturalDivideUnchecked (modelWord32ToNatural value) (naturalPowerOfTwo amount)))
284        (naturalLess amount modelWord32NaturalThirtyTwo))
285      0)

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.