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