//go:build amd64 && !appengine && !noasm && gc
// +build amd64,!appengine,!noasm,gc

package zstd

import (
	
)

type buildDtableAsmContext struct {
	// inputs
	stateTable *uint16
	norm       *int16
	dt         *uint64

	// outputs --- set by the procedure in the case of error;
	// for interpretation please see the error handling part below
	errParam1 uint64
	errParam2 uint64
}

// buildDtable_asm is an x86 assembly implementation of fseDecoder.buildDtable.
// Function returns non-zero exit code on error.
//
//go:noescape
func buildDtable_asm( *fseDecoder,  *buildDtableAsmContext) int

// please keep in sync with _generate/gen_fse.go
const (
	errorCorruptedNormalizedCounter = 1
	errorNewStateTooBig             = 2
	errorNewStateNoBits             = 3
)

// buildDtable will build the decoding table.
func ( *fseDecoder) () error {
	 := buildDtableAsmContext{
		stateTable: &.stateTable[0],
		norm:       &.norm[0],
		dt:         (*uint64)(&.dt[0]),
	}
	 := buildDtable_asm(, &)

	if  != 0 {
		switch  {
		case errorCorruptedNormalizedCounter:
			 := .errParam1
			return fmt.Errorf("corrupted input (position=%d, expected 0)", )

		case errorNewStateTooBig:
			 := decSymbol(.errParam1)
			 := .errParam2
			return fmt.Errorf("newState (%d) outside table size (%d)", , )

		case errorNewStateNoBits:
			 := decSymbol(.errParam1)
			 := decSymbol(.errParam2)
			return fmt.Errorf("newState (%d) == oldState (%d) and no bits", , )

		default:
			return fmt.Errorf("buildDtable_asm returned unhandled nonzero code = %d", )
		}
	}
	return nil
}