~/bend-docscommunity

tables.bend checks

raw source on the hub · import bend-osdev-gf@0.1.1.0/tables.bend as Tables

bend-osdev-gf, the table-driven fast path for GF(2^8): exponential (antilog) and logarithm tables to the field's generator, and multiplication, inversion and division through them.

exp[i] = gen^i for i from 0 to 509 (two periods of 255), so exp[log a + log b] needs no reduction modulo 255; log[a] is the i < 255 with gen^i = a, for a nonzero (log[0] is 0 and never read). The tables are built from gf.bend's reference multiplication; they are correct only when gen generates the field (it does for the named fields).

A Gf8Tab holds two Arrays, so it has one owner: every operation hands it back beside its result. Build it once (Gf8Tab.new) and thread it through.

2 imports
import Base
import ./gf.bend as G

Types

type Gf8Tab source · line 16 · raw

Type

Definitions

def gf8tab.fill.exp source · line 20 · raw

@n:Nat -> @a:Array<U32> -> @+f:0x783d0fad62351acb750d929ab748bb90/gf.Gf8Field -> @+cur:U32 -> @+i:U32 -> Array<U32>

exp[i] for i from i0, n entries, with cur = gen^i0

def gf8tab.fill.log source · line 28 · raw

@n:Nat -> @a:Array<U32> -> @+f:0x783d0fad62351acb750d929ab748bb90/gf.Gf8Field -> @+cur:U32 -> @+i:U32 -> Array<U32>

log[gen^i] = i for i from i0, n entries

def Gf8Tab.exp_table source · line 35 · raw

@+f:0x783d0fad62351acb750d929ab748bb90/gf.Gf8Field -> Array<U32>

def Gf8Tab.log_table source · line 38 · raw

@+f:0x783d0fad62351acb750d929ab748bb90/gf.Gf8Field -> Array<U32>

def Gf8Tab.new source · line 41 · raw

@+f:0x783d0fad62351acb750d929ab748bb90/gf.Gf8Field -> Gf8Tab

def gf8tab.exp.fin source · line 46 · raw

@r:Pair(Array<U32>, U32) -> @l:Array<U32> -> Pair(Gf8Tab, U32)

def gf8tab.log.fin source · line 50 · raw

@e:Array<U32> -> @r:Pair(Array<U32>, U32) -> Pair(Gf8Tab, U32)

def Gf8Tab.exp source · line 55 · raw

@t:Gf8Tab -> @i:U32 -> Pair(Gf8Tab, U32)

gen^i, for i below 510

def Gf8Tab.log source · line 61 · raw

@t:Gf8Tab -> @a:U32 -> Pair(Gf8Tab, U32)

the logarithm of a nonzero a (0 for a = 0)

def gf8tab.two.idx source · line 66 · raw

@div:Bool -> @+lx:U32 -> @+ly:U32 -> U32

def gf8tab.two.fin source · line 75 · raw

@e:Array<U32> -> @ry:Pair(Array<U32>, U32) -> @+lx:U32 -> @div:Bool -> Pair(Gf8Tab, U32)

exp[log x + log y + k], where k is 0 (multiplying) or 255 - 2 log y (dividing: log x + 255 - log y)

def gf8tab.two.mid source · line 79 · raw

@e:Array<U32> -> @rx:Pair(Array<U32>, U32) -> @+y:U32 -> @div:Bool -> Pair(Gf8Tab, U32)

def gf8tab.two.pick source · line 83 · raw

@z:Bool -> @t:Gf8Tab -> @+x:U32 -> @+y:U32 -> @div:Bool -> Pair(Gf8Tab, U32)

def Gf8Tab.mul source · line 93 · raw

@t:Gf8Tab -> @a:U32 -> @b:U32 -> Pair(Gf8Tab, U32)

a * b = exp[log a + log b], or 0 if either is 0

def Gf8Tab.div source · line 99 · raw

@t:Gf8Tab -> @a:U32 -> @b:U32 -> Pair(Gf8Tab, U32)

a / b = exp[log a + 255 - log b], or 0 if either is 0 (as Gf8.div)

def gf8tab.inv.fin source · line 104 · raw

@e:Array<U32> -> @rx:Pair(Array<U32>, U32) -> Pair(Gf8Tab, U32)

def gf8tab.inv.pick source · line 108 · raw

@z:Bool -> @t:Gf8Tab -> @+x:U32 -> Pair(Gf8Tab, U32)

def Gf8Tab.inv source · line 118 · raw

@t:Gf8Tab -> @a:U32 -> Pair(Gf8Tab, U32)

a^-1 = exp[255 - log a], and the inverse of 0 is 0