fse_decoder_amd64.go 1.6 KB

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