// AppendX87Reg appends a 80 bit float register to regs.
969300
func AppendX87Reg(regs []Register, index int, exponent uint16, mantissa uint64) []Register {
	var f float64
	fset := false

	const (
		_SIGNBIT    = 1 << 15
		_EXP_BIAS   = (1 << 14) - 1 // 2^(n-1) - 1 = 16383
		_SPECIALEXP = (1 << 15) - 1 // all bits set
		_HIGHBIT    = 1 << 63
		_QUIETBIT   = 1 << 62
	)

	sign := 1.0
	if exponent&_SIGNBIT != 0 {
		sign = -1.0
	}
	exponent &= ^uint16(_SIGNBIT)

	NaN := math.NaN()
	Inf := math.Inf(+1)

	switch exponent {
	case 0:
		switch {
		case mantissa == 0:
			f = sign * 0.0
			fset = true
		case mantissa&_HIGHBIT != 0:
			f = NaN
			fset = true
		}
	case _SPECIALEXP:
		switch {
		case mantissa&_HIGHBIT == 0:
			f = sign * Inf
			fset = true
		default:
			f = NaN // signaling NaN
			fset = true
		}
	default:
		if mantissa&_HIGHBIT == 0 {
			f = NaN
			fset = true
		}
	}

	if !fset {
		significand := float64(mantissa) / (1 << 63)
		f = sign * math.Ldexp(significand, int(exponent-_EXP_BIAS))
	}

	var buf bytes.Buffer
	binary.Write(&buf, binary.LittleEndian, exponent)
	binary.Write(&buf, binary.LittleEndian, mantissa)

	return append(regs, Register{fmt.Sprintf("ST(%d)", index), buf.Bytes(), fmt.Sprintf("%#04x%016x\t%g", exponent, mantissa, f)})
}
1363748
func MovImmReg(ctx context, imm int64, size uint, dst *register, spill bool) string {
	if dst.width < 8*size {
		ice("Invalid register width")
	}
	switch size {
	case 1:
		imm = int64(int8(imm))
	case 2:
		imm = int64(int16(imm))
	case 4:
		imm = int64(int32(imm))
	}
	data := OpDataType{OP_DATA, InstrData{signed: true, size: size}, XMM_INVALID}
	mov := GetInstr(I_MOV, data)
	return instrImmReg(ctx, mov, imm, size, dst, spill)
}
851720
func (l *Lexer) indexRegexp(r *regexp.Regexp) int {
	loc := r.FindStringIndex(l.input[l.pos:])
	if loc == nil {
		return -1
	}
	return loc[0]
}
1356765
func MulRegReg(ctx context, datatype OpDataType, src, dst *register, spill bool) string {
	if dst.width != src.width {
		ice("Invalid register width")
	}
	asm := ""
	if datatype.op == OP_DATA {
		rax := getRegister(REG_AX)
		rdx := getRegister(REG_DX)
		if rax.width != 64 || rdx.width != 64 {
			ice("Invalid rax or rdx register width")
		}
		// rax is the implicit destination for MULQ
		asm = MovRegReg(ctx, datatype, dst, rax, false)
		// the low order part of the result is stored in rax and the high order part
		// is stored in rdx
		var tinstr InstructionType
		if datatype.signed {
			tinstr = I_IMUL
		} else {
			tinstr = I_MUL
		}
		mul := GetInstr(tinstr, datatype)
		asm += instrReg(ctx, mul, src, false)
		asm += MovRegReg(ctx, datatype, rax, dst, spill)
		return asm
	}
	if datatype.op == OP_XMM {
		asm += instrRegReg(ctx, GetInstr(I_MUL, datatype), src, dst, spill)
	}
	return asm
}
343440
func (c *Chunk) AppendFloat64(colIdx int, f float64) {
	c.columns[colIdx].appendFloat64(f)
}
928927
func (a *AdvPacket) AppendFlags(f byte) *AdvPacket {
	return a.AppendField(typeFlags, []byte{f})
}
678155
func (msg *MsgTx) AddTxOut(to *TxOut) {
	msg.TxOut = append(msg.TxOut, to)
}
930135
func (Encoder) AppendHex(dst, s []byte) []byte {
	dst = append(dst, '"')
	for _, v := range s {
		dst = append(dst, hex[v>>4], hex[v&0x0f])
	}
	return append(dst, '"')
}
1031338
func (Encoder) AppendUints8(dst []byte, vals []uint8) []byte {
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = strconv.AppendUint(dst, uint64(vals[0]), 10)
	if len(vals) > 1 {
		for _, val := range vals[1:] {
			dst = strconv.AppendUint(append(dst, ','), uint64(val), 10)
		}
	}
	dst = append(dst, ']')
	return dst
}
741156
func (c *Chunk) AppendInt64(colIdx int, i int64) {
	c.columns[colIdx].appendInt64(i)
}
311968
func (e Encoder) AppendUints32(dst []byte, vals []uint32) []byte {
	major := majorTypeArray
	l := len(vals)
	if l == 0 {
		return e.AppendArrayEnd(e.AppendArrayStart(dst))
	}
	if l <= additionalMax {
		lb := byte(l)
		dst = append(dst, byte(major|lb))
	} else {
		dst = appendCborTypePrefix(dst, major, uint64(l))
	}
	for _, v := range vals {
		dst = e.AppendUint32(dst, v)
	}
	return dst
}
1316664
func (Encoder) AppendFloat32(dst []byte, val float32) []byte {
	switch {
	case math.IsNaN(float64(val)):
		return append(dst, "\xfa\x7f\xc0\x00\x00"...)
	case math.IsInf(float64(val), 1):
		return append(dst, "\xfa\x7f\x80\x00\x00"...)
	case math.IsInf(float64(val), -1):
		return append(dst, "\xfa\xff\x80\x00\x00"...)
	}
	major := majorTypeSimpleAndFloat
	subType := additionalTypeFloat32
	n := math.Float32bits(val)
	var buf [4]byte
	for i := uint(0); i < 4; i++ {
		buf[i] = byte(n >> ((3 - i) * 8))
	}
	return append(append(dst, byte(major|subType)), buf[0], buf[1], buf[2], buf[3])
}
1053913
func (c Context) addBig(z *Big, X *big.Int, Xsign form, Y *big.Int, Ysign form, shift uint64) form {
	// Guard the call so we don't allocate (via alias) if we don't need to.
	if shift != 0 {
		X = arith.MulBigPow10(alias(&z.unscaled, Y), X, shift)
	}

	if Xsign == Ysign {
		z.unscaled.Add(X, Y)
		z.compact = cst.Inflated
		z.precision = arith.BigLength(&z.unscaled)
		return Xsign
	}

	sign := Xsign
	// X + (-Y) == X - Y == -(Y - X)
	// (-X) + Y == Y - X == -(X - Y)
	if X.Cmp(Y) >= 0 {
		z.unscaled.Sub(X, Y)
	} else {
		sign ^= signbit
		z.unscaled.Sub(Y, X)
	}

	if z.unscaled.Sign() == 0 {
		z.compact = 0
		z.precision = 1
		if c.RoundingMode == ToNegativeInf {
			sign = Xsign ^ Ysign // either 0 or 1
		}
		return sign | Xsign&Ysign
	}

	z.norm()
	return sign
}
192257
func (slocs SegmentLocs) AddRef() {
	for _, sloc := range slocs {
		if sloc.mref != nil {
			sloc.mref.AddRef()
		}
	}
}
594721
func NewDefaultDxWithSrcLen(sourceLength uint) (indicator *Dx, err error) {
	ind, err := NewDefaultDx()

	// only initialise the storage if there is enough source data to require it
	if sourceLength-uint(ind.GetLookbackPeriod()) > 1 {
		ind.Data = make([]float64, 0, sourceLength-uint(ind.GetLookbackPeriod()))
	}

	return ind, err
}
1135399
func GetDwarfRegister(regs Registers, i int) []byte {
	if asmreg, ok := dwarfToAsm[i]; ok {
		x, _ := regs.Get(int(asmreg))
		var buf bytes.Buffer
		binary.Write(&buf, binary.LittleEndian, x)
		return buf.Bytes()
	}
	if regname, ok := dwarfToName[i]; ok {
		regslice := regs.Slice(true)
		for _, reg := range regslice {
			if reg.Name == regname {
				return reg.Bytes
			}
		}
	}
	return []byte{}
}
847022
func (r *Registry) AppendReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref ...types.ManagedObjectReference) {
	r.WithLock(obj, func() {
		*field = append(*field, ref...)
	})
}