Debian Codegraph @

internal/regmask/regmask.go

raw
1 //go:build !386
2
3 // Package regmask provides masks for variable shift counts.
4 //
5 // Go defines a shift by more than the width of the shifted value as producing
6 // zero, so the compiler has to guard every variable shift against that: on
7 // amd64 with a CMP and an SBB, on arm64 with a CMP and a CSEL, and so on. When
8 // the count is known to be smaller than the width anyway, masking it with the
9 // width minus one lets the compiler drop the guard. The mask itself costs
10 // nothing on the architectures whose shift instructions already use only the
11 // low bits of the count, which the compiler knows about.
12 //
13 // Each constant is named for the width of the value being shifted and the type
14 // of the shift count, and may only be used where the count is always smaller
15 // than that width:
16 //
17 // x := y >> (n & regmask.Shift64ByUint) // y is 64 bits, n is a uint below 64
18 package regmask
19
20 const (
21 // ShiftNByUint8 - shifting an N bit value by a uint8
22 Shift8ByUint8 = 7
23 Shift16ByUint8 = 15
24 Shift32ByUint8 = 31
25 Shift64ByUint8 = 63
26
27 // ShiftNByUint16 - shifting an N bit value by a uint16
28 Shift8ByUint16 = Shift8ByUint8
29 Shift16ByUint16 = Shift16ByUint8
30 Shift32ByUint16 = Shift32ByUint8
31 Shift64ByUint16 = Shift64ByUint8
32
33 // ShiftNByUint32 - shifting an N bit value by a uint32
34 Shift8ByUint32 = Shift8ByUint8
35 Shift16ByUint32 = Shift16ByUint8
36 Shift32ByUint32 = Shift32ByUint8
37 Shift64ByUint32 = Shift64ByUint8
38
39 // ShiftNByUint64 - shifting an N bit value by a uint64
40 Shift8ByUint64 = Shift8ByUint8
41 Shift16ByUint64 = Shift16ByUint8
42 Shift32ByUint64 = Shift32ByUint8
43 Shift64ByUint64 = Shift64ByUint8
44
45 // ShiftNByUint - shifting an N bit value by a uint
46 Shift8ByUint = Shift8ByUint8
47 Shift16ByUint = Shift16ByUint8
48 Shift32ByUint = Shift32ByUint8
49 Shift64ByUint = Shift64ByUint8
50 )