// calculateIntBithDepth looks at the int values in the buffer and returns
// the required lowest bit depth.
486533
func (b *PCMBuffer) calculateIntBitDepth() uint8 {
	if b == nil {
		return 0
	}
	bitDepth := b.SourceBitDepth
	if bitDepth != 0 {
		return bitDepth
	}
	var max int64
	switch b.DataType {
	case DataTypeI8:
		var i8max int8
		for _, s := range b.I8 {
			if s > i8max {
				i8max = s
			}
		}
		max = int64(i8max)
	case DataTypeI16:
		var i16max int16
		for _, s := range b.I16 {
			if s > i16max {
				i16max = s
			}
		}
		max = int64(i16max)
	case DataTypeI32:
		var i32max int32
		for _, s := range b.I32 {
			if s > i32max {
				i32max = s
			}
		}
		max = int64(i32max)
	default:
		// This method is only meant to be used on int buffers.
		return bitDepth
	}
	bitDepth = 8
	if max > 127 {
		bitDepth = 16
	}
	// greater than int16, expecting int24
	if max > 32767 {
		bitDepth = 24
	}
	// int 32
	if max > 8388607 {
		bitDepth = 32
	}
	// int 64
	if max > 4294967295 {
		bitDepth = 64
	}

	return bitDepth
}
807313
func (b *bsiGroup) BitDepth() uint {
	for i := uint(0); i < 63; i++ {
		if b.Max-b.Min < (1 << i) {
			return i
		}
	}
	return 63
}
833244
func Int(v interface{}, err error) (int64, error) {
	if err != nil {
		return 0, err
	}
	vi, ok := v.(int64)
	if ok {
		return vi, nil
	}

	vbi, ok := v.(*big.Int)
	if ok {
		if vbi.BitLen() <= 63 {
			return vbi.Int64(), nil
		}
	}

	return 0, newWrongTypeError(v, vi)

}
1059738
func (bitmap *bitmap) Bit(index int) int {
	if index >= bitmap.Size {
		panic("index out of range")
	}

	div, mod := index>>3, index&0x07
	return int((uint(bitmap.data[div]) & (1 << uint(7-mod))) >> uint(7-mod))
}
145720
func EqualDepth(x, y Value, depth int) (bool, error) {
	return CompareDepth(syntax.EQL, x, y, depth)
}
1074518
func IntBytes(n uint32, base uint) []byte {
	mask := uint32(1<<base - 1)
	bytes := make([]byte, BytesPerInt)

	for i, _ := range bytes {
		bytes[len(bytes)-i-1] = byte(n & mask)
		n >>= base
	}

	return bytes
}
57239
func SubUintWithInt(a uint64, b int64) (uint64, error) {
	if b < 0 {
		return AddUint64(a, uint64(-b))
	}
	return SubUint64(a, uint64(b))
}
189440
func CountBitsUintPopCnt(x uint) int {
	if strconv.IntSize == 64 {
		return CountBitsUint64PopCnt(uint64(x))
	} else if strconv.IntSize == 32 {
		return CountBitsUint32PopCnt(uint32(x))
	}
	panic("strconv.IntSize must be 32 or 64")
}
615007
func CountBitsUint32s(b []uint32) int {
	c := 0
	for _, x := range b {
		c += CountBitsUint32(x)
	}
	return c
}
1043196
func (s *AiffSettings) SetBitDepth(v int64) *AiffSettings {
	s.BitDepth = &v
	return s
}
349752
func (s *AudioCodecOptions) SetBitDepth(v string) *AudioCodecOptions {
	s.BitDepth = &v
	return s
}
246065
func BitIn(index int, bitset uint) uint {
	if index < 0 {
		return 0
	}

	var idx uint = 1 << uint(index)
	if idx&bitset != 0 {
		return idx
	}

	return 0
}
9758
func IntAtLeast(min int) schema.SchemaValidateFunc {
	return func(i interface{}, k string) (s []string, es []error) {
		v, ok := i.(int)
		if !ok {
			es = append(es, fmt.Errorf("expected type of %s to be int", k))
			return
		}

		if v < min {
			es = append(es, fmt.Errorf("expected %s to be at least (%d), got %d", k, min, v))
			return
		}

		return
	}
}
654175
func ComputeBitNeg(sc *variable.StatementContext, a Datum) (d Datum, err error) {
	aKind := a.Kind()
	if aKind == KindInt64 || aKind == KindUint64 {
		d.SetUint64(^a.GetUint64())
		return
	}
	// If either is not integer, we round the operands and then use uint64 to calculate.
	x, err := convertNonInt2RoundUint64(sc, a)
	if err != nil {
		return d, errors.Trace(err)
	}

	d.SetUint64(^x)
	return d, nil
}
693068
func (rb *Bitmap) ContainsInt(x int) bool {
	return rb.Contains(uint32(x))
}
748339
func (r *BitReader) ReadBitFast() bool {
	v := (r.buf.v&(1<<63) != 0)
	r.buf.v <<= 1
	r.buf.n -= 1
	return v
}
622418
func (m *Monitor) BitDepth() (red, green, blue int) {
	var mode *glfw.VidMode
	mainthread.Call(func() {
		mode = m.monitor.GetVideoMode()
	})
	red = mode.RedBits
	green = mode.GreenBits
	blue = mode.BlueBits
	return
}