forked from modern-go/amd64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefix.go
42 lines (36 loc) · 883 Bytes
/
prefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package amd64
// If a 66H override is used with REX and REX.W = 0, the operand size is 16 bits.
const Prefix16Bit = 0x66
// In 64-bit mode, the instruction’s default address size is 64 bits, 32 bit address size is supported using the prefix 67H.
const Prefix32Bit = 0x67
func REX(w, r, x, b bool) byte {
bits := byte(0x40)
if w {
bits |= 0x08
}
if r {
bits |= 0x04
}
if x {
bits |= 0x02
}
if b {
bits |= 0x01
}
return bits
}
func VEX2(r, vvvv, l, pp byte) byte {
r = (^(r << 7)) & 0x80 // 10000000
vvvv = (^(vvvv << 3)) & 0x78 // 01111000
return r | vvvv | l<<2 | pp
}
func VEX31(r, x, b, m byte) byte {
r = (^(r << 7)) & 0x80 // 10000000
x = (^(x << 6)) & 0x40 // 01000000
b = (^(x << 5)) & 0x20 // 00100000
return r | x | b | m
}
func VEX32(w, vvvv, l, pp byte) byte {
vvvv = (^(vvvv << 3)) & 0x78 // 01111000
return w | vvvv | l<<2 | pp
}