crc32.bend relies on unsafe/foreign
raw source on the hub · import gralha-crc32@0.1.0.0/crc32.bend as Crc32
gralha-crc32: the IEEE CRC-32 (gzip's, zip's, PNG's) over bytes packed four to a U32 word, little-endian, in an Array<U32>. update_raw is a foreign effect (ARM CRC instructions where the C target has them, a table elsewhere); pure is the same function in Bend, for proofs and for code that must not do IO. prior is the finished CRC of the bytes before start, 0 for none, so a long input is checked in pieces.
1 import
import Base
Types
type St source · line 53 · raw
Type
St@a:Array<U32> -> @c:U32 -> St
Definitions
def update_got source · line 14 · raw
@what:String -> @r:Pair(Array<U32>, Result<&1, &1, Pair(U32, String), U32>) -> IO(Pair(Array<U32>, U32))
def update source · line 24 · raw
@+what:String -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> @+prior:U32 -> IO(Pair(Array<U32>, U32))
update_raw, exiting with what and the error on a failure
def bit_odd source · line 33 · raw
@+c:U32 -> @odd:Bool -> U32
one bit of the reflected polynomial 0xEDB88320
def bit source · line 40 · raw
@+c:U32 -> U32
def bits source · line 43 · raw
@n:Nat -> @+c:U32 -> U32
def byte source · line 50 · raw
@+c:U32 -> @+b:U32 -> U32
def pure_at source · line 56 · raw
@r:Pair(Array<U32>, U32) -> @+c:U32 -> @+sh:U32 -> St
def pure_go source · line 60 · raw
@n:Nat -> @st:St -> @+j:U32 -> St
def pure_fin source · line 68 · raw
@st:St -> Pair(Array<U32>, U32)
def pure source · line 74 · raw
@a:Array<U32> -> @+start:U32 -> @+n:U32 -> @+prior:U32 -> Pair(Array<U32>, U32)
update_raw in Bend: a bit at a time, so slow, but total and pure
Effects (foreign code)
effect update_raw source · line 10 · raw
@a:Array<U32> -> @+start:U32 -> @+n:U32 -> @+prior:U32 -> IO(Pair(Array<U32>, Result<&1, &1, Pair(U32, String), U32>))
n bytes of a from byte start, after prior; the Array comes back
foreign: effs/words_crc32.c, effs/words_crc32.js