authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-05-17 05:35:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-17 12:03:01-04:00
loge198eec76a478fa9d1cb7b6d7488e273a0d15ff1
tree62a731409597fd709b03004b8605aa6fff144a3d
parent773281c1f47f4e0379d6a3d314c00f752151d89f

Document register functions


2 files changed, 15 insertions(+), 0 deletions(-)

src-self-hosted/backend/x86.zig+4
......@@ -9,6 +9,7 @@ pub const Register = enum(u8) {
99 // 16-23, 8-bit registers. id is int value - 16.
1010 al, bl, cl, dl, ah, ch, dh, bh,
1111
12 /// Returns the bit-width of the register.
1213 pub fn size(self: @This()) u7 {
1314 return switch (@enumToInt(self)) {
1415 0...7 => 32,
......@@ -18,6 +19,9 @@ pub const Register = enum(u8) {
1819 };
1920 }
2021
22 /// Returns the register's id. This is used in practically every opcode the
23 /// x86 has. It is embedded in some instructions, such as the `B8 +rd` move
24 /// instruction, and is used in the R/M byte.
2125 pub fn id(self: @This()) u3 {
2226 return @truncate(u3, @enumToInt(self));
2327 }
src-self-hosted/backend/x86_64.zig+11
......@@ -20,6 +20,7 @@ pub const Register = enum(u8) {
2020 al, bl, cl, dl, ah, ch, dh, bh,
2121 r8b, r9b, r10b, r11b, r12b, r13b, r14b, r15b,
2222
23 /// Returns the bit-width of the register.
2324 pub fn size(self: @This()) u7 {
2425 return switch (@enumToInt(self)) {
2526 0...15 => 64,
......@@ -30,10 +31,20 @@ pub const Register = enum(u8) {
3031 };
3132 }
3233
34 /// Returns whether the register is *extended*. Extended registers are the
35 /// new registers added with amd64, r8 through r15. This also includes any
36 /// other variant of access to those registers, such as r8b, r15d, and so
37 /// on. This is needed because access to these registers requires special
38 /// handling via the REX prefix, via the B or R bits, depending on context.
3339 pub fn isExtended(self: @This()) bool {
3440 return @enumToInt(self) & 0x08 != 0;
3541 }
3642
43 /// This returns the 4-bit register ID, which is used in practically every
44 /// opcode. Note that bit 3 (the highest bit) is *never* used directly in
45 /// an instruction (@see isExtended), and requires special handling. The
46 /// lower three bits are often embedded directly in instructions (such as
47 /// the B8 variant of moves), or used in R/M bytes.
3748 pub fn id(self: @This()) u4 {
3849 return @truncate(u4, @enumToInt(self));
3950 }