| 1 |
//go:build (amd64 || arm64) && !appengine && !noasm && gc |
| 2 |
|
| 3 |
package zstd |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
) |
| 8 |
|
| 9 |
// buildDtable_asm is generated by _generate/gen_fse.go and lowered to each |
| 10 |
// architecture (amd64 by goasm, arm64 by the avo arm64 lowering printer). The |
| 11 |
// Go side is identical across architectures, so it lives here. |
| 12 |
|
| 13 |
type buildDtableAsmContext struct { |
| 14 |
// inputs |
| 15 |
stateTable *uint16 |
| 16 |
norm *int16 |
| 17 |
dt *uint64 |
| 18 |
|
| 19 |
// outputs --- set by the procedure in the case of error; |
| 20 |
// for interpretation please see the error handling part below |
| 21 |
errParam1 uint64 |
| 22 |
errParam2 uint64 |
| 23 |
} |
| 24 |
|
| 25 |
// buildDtable_asm is an assembly implementation of fseDecoder.buildDtable. |
| 26 |
// Function returns non-zero exit code on error. |
| 27 |
// |
| 28 |
//go:noescape |
| 29 |
func buildDtable_asm(s *fseDecoder, ctx *buildDtableAsmContext) int |
| 30 |
|
| 31 |
// please keep in sync with _generate/gen_fse.go |
| 32 |
const ( |
| 33 |
errorCorruptedNormalizedCounter = 1 |
| 34 |
errorNewStateTooBig = 2 |
| 35 |
errorNewStateNoBits = 3 |
| 36 |
) |
| 37 |
|
| 38 |
// buildDtable will build the decoding table. |
| 39 |
func (s *fseDecoder) buildDtable() error { |
| 40 |
ctx := buildDtableAsmContext{ |
| 41 |
stateTable: &s.stateTable[0], |
| 42 |
norm: &s.norm[0], |
| 43 |
dt: (*uint64)(&s.dt[0]), |
| 44 |
} |
| 45 |
code := buildDtable_asm(s, &ctx) |
| 46 |
|
| 47 |
if code != 0 { |
| 48 |
switch code { |
| 49 |
case errorCorruptedNormalizedCounter: |
| 50 |
position := ctx.errParam1 |
| 51 |
return fmt.Errorf("corrupted input (position=%d, expected 0)", position) |
| 52 |
|
| 53 |
case errorNewStateTooBig: |
| 54 |
newState := decSymbol(ctx.errParam1) |
| 55 |
size := ctx.errParam2 |
| 56 |
return fmt.Errorf("newState (%d) outside table size (%d)", newState, size) |
| 57 |
|
| 58 |
case errorNewStateNoBits: |
| 59 |
newState := decSymbol(ctx.errParam1) |
| 60 |
oldState := decSymbol(ctx.errParam2) |
| 61 |
return fmt.Errorf("newState (%d) == oldState (%d) and no bits", newState, oldState) |
| 62 |
|
| 63 |
default: |
| 64 |
return fmt.Errorf("buildDtable_asm returned unhandled nonzero code = %d", code) |
| 65 |
} |
| 66 |
} |
| 67 |
return nil |
| 68 |
} |