gfm.bend checks
raw source on the hub · import bend-osdev-gf@0.1.0.0/gfm.bend as Gfm
bend-osdev-gf, GF(2^m) for small m (2 to 16): the fields BCH codes work in (Lin and Costello, "Error Control Coding", chapters 2 and 6).
An element is a number below 2^m held in U32 (bit i the coefficient of x^i; arguments are read modulo 2^m). A GfmField names m and the reduction polynomial with all its bits (x^m included). The named fields use primitive polynomials, so x (2) generates the multiplicative group and Gfm.exp / Gfm.log are to base x.
1 import
import Base
Types
type GfmField source · line 11 · raw
Data
GfmField@m:Nat -> @poly:U32 -> GfmField
Definitions
def Gfm.gf16 source · line 15 · raw
GfmField
x^4 + x + 1
def Gfm.gf32 source · line 19 · raw
GfmField
x^5 + x^2 + 1
def Gfm.bch13 source · line 23 · raw
GfmField
x^13 + x^4 + x^3 + x + 1 (0x201B), for BCH over 8191-bit codewords
def Gfm.bch14 source · line 27 · raw
GfmField
x^14 + x^10 + x^6 + x + 1 (0x4443)
def Gfm.m source · line 30 · raw
@f:GfmField -> Nat
def Gfm.mask source · line 36 · raw
@f:GfmField -> U32
2^m - 1, and the number of nonzero elements
def Gfm.elt source · line 41 · raw
@f:GfmField -> @a:U32 -> U32
def Gfm.add source · line 44 · raw
@+f:GfmField -> @a:U32 -> @b:U32 -> U32
def gfm.mask source · line 48 · raw
@b:U32 -> U32
all ones if the low bit of b is set, else 0
def gfm.x source · line 52 · raw
@+m:Nat -> @+poly:U32 -> @a:U32 -> U32
a * x for a below 2^m: shift, and reduce if x^m appeared
def Gfm.xtime source · line 56 · raw
@+f:GfmField -> @a:U32 -> U32
def gfm.mul.go source · line 62 · raw
@n:Nat -> @+m:Nat -> @+poly:U32 -> @+a:U32 -> @+b:U32 -> @p:U32 -> U32
the product, over the m bits of b from the bottom: p += a * bit; a *= x
def gfm.mul.raw source · line 71 · raw
@f:GfmField -> @a:U32 -> @b:U32 -> U32
the product of a and b, both below 2^m (matching both first, so that the product of unknown values stays a small term for the proof checkers)
def Gfm.mul source · line 76 · raw
@+f:GfmField -> @a:U32 -> @b:U32 -> U32
def gfm.pow.go source · line 80 · raw
@n:Nat -> @+f:GfmField -> @+a:U32 -> @+e:U32 -> @+r:U32 -> U32
a^e by squaring, over the 32 bits of e from the top
def gfm.pow.start source · line 88 · raw
@+f:GfmField -> @x:U32 -> @e:U32 -> U32
def Gfm.pow source · line 94 · raw
@+f:GfmField -> @+a:U32 -> @e:U32 -> U32
a^e (a^0 = 1)
def Gfm.inv source · line 98 · raw
@+f:GfmField -> @+a:U32 -> U32
a^-1 = a^(2^m - 2); the inverse of 0 is 0
def Gfm.div source · line 101 · raw
@+f:GfmField -> @a:U32 -> @+b:U32 -> U32
def Gfm.exp source · line 105 · raw
@+f:GfmField -> @i:U32 -> U32
x^i
def Gfm.log.go source · line 109 · raw
@n:Nat -> @hit:Bool -> @+f:GfmField -> @+a:U32 -> @+cur:U32 -> @+i:U32 -> U32
the least i with x^i = a, searching i below 2^m - 1 (0 for a = 0)
def Gfm.log source · line 119 · raw
@+f:GfmField -> @a:U32 -> U32