MCPcopy
hub / github.com/klauspost/compress / buildDtableRef

Function buildDtableRef

zstd/fse_decoder_arm64_test.go:16–71  ·  view source on GitHub ↗

buildDtableRef is a copy of the pure-Go reference algorithm (fse_decoder_generic.go), kept here so the arm64 asm implementation can be differentially tested against it even though the generic file is not compiled on arm64.

(s *fseDecoder)

Source from the content-addressed store, hash-verified

14// differentially tested against it even though the generic file is not
15// compiled on arm64.
16func buildDtableRef(s *fseDecoder) error {
17 tableSize := uint32(1 << s.actualTableLog)
18 highThreshold := tableSize - 1
19 symbolNext := s.stateTable[:256]
20
21 {
22 for i, v := range s.norm[:s.symbolLen] {
23 if v == -1 {
24 s.dt[highThreshold].setAddBits(uint8(i))
25 highThreshold--
26 v = 1
27 }
28 symbolNext[i] = uint16(v)
29 }
30 }
31
32 {
33 tableMask := tableSize - 1
34 step := tableStep(tableSize)
35 position := uint32(0)
36 for ss, v := range s.norm[:s.symbolLen] {
37 for i := 0; i < int(v); i++ {
38 s.dt[position].setAddBits(uint8(ss))
39 for {
40 position = (position + step) & tableMask
41 if position <= highThreshold {
42 break
43 }
44 }
45 }
46 }
47 if position != 0 {
48 return errors.New("corrupted input (position != 0)")
49 }
50 }
51
52 {
53 tableSize := uint16(1 << s.actualTableLog)
54 for u, v := range s.dt[:tableSize] {
55 symbol := v.addBits()
56 nextState := symbolNext[symbol]
57 symbolNext[symbol] = nextState + 1
58 nBits := s.actualTableLog - byte(highBits(uint32(nextState)))
59 s.dt[u&maxTableMask].setNBits(nBits)
60 newState := (nextState << nBits) - tableSize
61 if newState > tableSize {
62 return fmt.Errorf("newState (%d) outside table size (%d)", newState, tableSize)
63 }
64 if newState == uint16(u) && nBits == 0 {
65 return fmt.Errorf("newState (%d) == oldState (%d) and no bits", newState, u)
66 }
67 s.dt[u&maxTableMask].setNewState(newState)
68 }
69 }
70 return nil
71}
72
73func TestBuildDtableARM64MatchesReference(t *testing.T) {

Callers 1

Calls 6

setAddBitsMethod · 0.80
addBitsMethod · 0.80
setNBitsMethod · 0.80
setNewStateMethod · 0.80
tableStepFunction · 0.70
highBitsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…