fse_decoder_amd64.go 1.6 KB

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