1

I'm learning (slowly and painfully) about x86-64 instructions, and found this chart in the documentation I'm reading:

enter image description here

I think "GP" in this context refers to the GPR (General Purpose Registers) I "understand" the register structure for x86-64 is like so:

enter image description here

And so my first comprehension of this was that a 64 bit system has 64 bits of cache allocated to the GPR in a CPU and can handle larger register values, and the 32 bit registers act as a fall-back for compatibility with processors that only allocate 32 bits to the GPRs, and so on and so forth down to a theoretical 8 bit processor (or perhaps one exists).

But I was also wondering if it's alternatively a way of writing fewer bits to the registers when more precision isn't needed, and therefore operate more efficiently or faster.

But looking at that top table, it seems like since the xReg column assigns a single binary value to each category of GPR segment (0000=> AL, AX, EAX, RAX, ...) makes it seem like there's a specific mode of operation decided ahead of time and the developer doesn't work with all the different register sizes. or maybe there's other bits in the instruction that define which mode is being used?

What's the purpose of the multiple register sizes? Is it compatibility with various CPU GPR sizes where a 64 bit CPU only uses 64 bit registers? or is it about writing smaller register values for efficiency?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
J.Todd
  • 707
  • 1
  • 12
  • 34
  • *where a 64 bit CPU only uses 64 bit registers* Nope. Look at compiler-generated asm sometime for code using `char` (8-bit) or `int` (32-bit). All four operand-sizes are usable with most instructions in 64-bit mode, and 32-bit is the "default" with no prefixes. (Or 8-bit for those opcodes.) – Peter Cordes Oct 22 '20 at 12:52
  • 3
    The "duplicates" I linked aren't really exact duplicates, but for a conceptual question like this based on false premises, I think pointing you (and future readers) in the direction of stuff you should understand will clear up this question. Correct me if I'm wrong. – Peter Cordes Oct 22 '20 at 12:59
  • 1
    @PeterCordes That's fair – J.Todd Oct 22 '20 at 13:04
  • @PeterCordes This is a resource request and therefore off topic I believe so I'll ask you in a comment: Is there an official standard documentation for x86-64, like the W3C spec documentation? I'm trying to write a very minimal, simple emulator where my code simulates the processing of machine code and all of the sources I'm reading, various wikis and documents, seems to explain one little component of the subject, but I need something that covers *everything* (or just about). Instead of the big picture I keep finding little pieces. – J.Todd Oct 22 '20 at 13:17
  • 3
    Yes, Intel and AMD both publish architecture manuals. Links in https://stackoverflow.com/tags/x86/info. They're *very* long, but most of the complexity is in privileged instructions and the semantics of control registers, page tables, and all that stuff. vol.2 of Intel's manuals is the instruction-set reference, including intro sections. vol.1 includes some more introductory material and might be good, IDK I haven't really read it because I already knew asm for another ISA before learning x86, and I don't write OSes. – Peter Cordes Oct 22 '20 at 13:37
  • 2
    https://agner.org/optimize/ is good for example of how the pieces fit together to get stuff actually done, as is looking at compiler output. [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116). is good, especially Matt Godbolt's talk is a good intro to asm in general for beginners. (asm, not machine code, but knowing what you're "supposed" to do with asm makes the machine code design choices make more sense.) – Peter Cordes Oct 22 '20 at 13:39

0 Answers0