9 ms·
How many registers does an x86-64 CPU have?
- hollymolly86 6y agoHow about removing obsolete stuff from 86x CPUs to make the platform perform better? If someone need to execute old programs/OSes they can use emulators for that...
- ppg677 6y agoAll that stuff is emulated in microcode. And while counting architectural registers is something, in reality modern out-of-order processors do something called "register renaming" so that more registers can be used on-the-fly as it dynamically creates a data flow dependency graph. Yes, inside each processor.
- colejohnson66 6y agoThere have been attempts to move the register renaming out of the processor and into the program through VLIW architectures such as the Itanium, but it failed because (1) they require “sufficiently smart compilers” that weren’t available in the day, and (2) putting it in the silicon allows new architecture revisions to benefit older programs (putting it in code means it can’t benefit from newer register renaming algorithms without a recompile). Also, if it’s in the silicon and there’s a bug in the algorithm, a microcode update can fix it for everyone. If the bug was in the compiler, you’d need to recompile everything to fix it.
- imtringued 6y agoThe only successful VLIW architectures run JIT compilers on an existing ISA. Transmeta did this for x86 but Intel brought them to court them which gave Intel time to release superior chips (through superior manufacturing). The other example is Nvidia's Project Denver.
- kllrnohj 6y agoA very debatable level of "successful" on that. It shipped in a product, yes, but it wasn't very good either. It ran ARM code, but not very well, and was a horrible nightmare to work on. The JIT'd aspect completely breaks profilers. ie, what do you mean this simple field access took 20ms?? Oh, because the CPU wasn't running my code, it just silently went out to lunch to JIT some random shit, cool, thanks. There's then also the questionable security design of a globally read/write/executable chunk of memory where security is "enforced" by the JIT which is a complex bit of microcode, totally nothing can go wrong there... It's only noteworthy "feature" was that it was able to ship ARMv8 support before ARM had a proper ARMv8 CPU design. Time to market for a new ISA was fast, but that's about it.
- tambre 6y agoProject Denver lives on in NVIDIA's Carmel cores shipping in Tegra 194 (Xavier) chips today. Though they seem to be giving up on it, as they'll be using Cortex "Hercules" A78 cores in the successor named Orin.
- SomeoneFromCA 6y agoRussian Elbrus machines (VLIW afaik) run Linux natively.
- simion314 6y agoI think if something is trully obsolete is already removed from hardware and emulated by the CPU with microcode.
- SomeoneFromCA 6y agoIf you remove the obsolete stuff from x86, there will be no point to keep this old ISA altogether. One of the selling point of x86 is legacy support.
- colejohnson66 6y agoYou mean remove backwards compatibility and ruin the whole reason people use x86? Not to mention that when AMD64 (“long mode”) was introduced, a big amount of cruft was disabled in the new mode (but is still available in 16-bit (“real mode”) and 32-bit (“protected mode”) for compatibility).
- wolfgke 6y ago> (but is still available in 16-bit (“real mode”) and 32-bit (“protected mode”) for compatibility). There exists both 16 bit protected mode (available since the 80286) and 32 bit protected mode (available since the 80386).
- colejohnson66 6y agoI thought the 80286 had 32-bit protected mode, but it was badly implemented (the only way to get back to real mode was a reboot), so they fixed it with the 80386. Unless, are you referring to “unreal mode”?
- cesarb 6y agoNo, most people forget about it (I had to be reminded by the above comment), but the 80286 did have a 16-bit protected mode. Quoting Wikipedia (https://en.wikipedia.org/wiki/Protected_mode https://en.wikipedia.org/wiki/Protected_mode): "[...] Acceptance was additionally hampered by the fact that the 286 only allowed memory access in 16 bit segments via each of four segment registers, meaning only 4*2^16 bytes, equivalent to 256 kilobytes, could be accessed at a time. [...]"
- userbinator 6y agoThere is also "32 bit realmode", which is not mentioned in the official documentation but simply a combination of existing states. Ditto for real mode paging and the like --- which finds more applications as emulator acid-tests than anything else.
- sroussey 6y agoYeah, but what about servers and data enters?
- szatkus 6y agoThere are a lot of x86 software out there. Even games switched to x64 binary relatively recently. That alone means that you would want to emulate with performance of, let's say i5-2500, if you want a decent framerate, which would be quite chellanging given that modern CPUs are 80% faster at best.
- pjc50 6y agoYes, it's called Apple A1. Once you remove a single opcode, it's not really x86 any more, and you need emulation at OS level. But then, once you've done that, why not remove more instructions? Why not remove all of them and start again on a much more power-efficient platform? Why not remove the memory model? One of the brilliant ideas in the A1 is a flag for whether the current process insists on the slower but more comprehensible x86 memory ordering.
- colejohnson66 6y agoYou mean M1? The A series started at A4 (S5L8930) with the iPhone 4.
- The_Colonel 6y agoThat's pretty misleading. You can remove many instructions while keeping CPU x86 compatible. You can e.g. remove all MMX instructions and signal this fact through CPUID. Very few apps require MMX (as in can't work without it). Another option is to remove the instructions from hardware and emulate them in microcode.
- saagarjha 6y agoA lot of software will ignore cpuid and assume features like MMX.
- rbanffy 6y agoThis is a bug.
- jcranmer 6y agoSeveral CPU features require other ones--for example, AVX requires the XSAVE feature. Additionally, x86-64 implicitly requires several features (most notably SSE2), and the glibc folks have been working on a proposed ABI for x86-64 that groups the feature sets into levels--roughly base (≤SSE2), ≤SSE4.2, ≤AVX2, current skylake-server (a clutch of AVX-512 features), with the BMI and FMA features scattered in there somewhere. That said, the MMX instructions in particular are so problematic to use (and SSE ubiquitous and strictly better) that I suspect you could introduce a processor that lacks MMX support and break almost nobody, certainly far fewer people than removing x87. I don't know if there is an implicit or explicit actual dependency on MMX anywhere.
- jcranmer 6y agoWhat obsolete stuff could you remove? If you want to actually meaningfully cut out a large amount of space on the processor, you'll have to cut into the actual instruction space and remove instructions that take up space in your execution units. Removing the 16-bit and 32-bit modes don't actually remove any instructions from the platform (save the binary-coded decimal instructions)--you're largely saving only a few bits of decoder table entries at best. Furthermore, processors reset into 16-bit mode on startup for compatibility reasons, so killing 16-bit and 32-bit mode would introduce major compatibility headaches. ISA extensions can be more easily removed since there's already a CPUID bit that tells operating systems and applications whether or not they are used. The MPX extension for bounds checking is now regarded as a mistake, and Intel has already confirmed that they are removing it from future processor generations. The TSX extension for transactional memory is apparently on the hit list because of Spectre, and was removed from some processor generations. The only significant processor execution unit space that is truly obsolete I can think is the x87 floating-point execution unit logic, with the concomitant MMX execution unit logic--SSE is just strictly better for everything here, except if you're trying to actually get the 80-bit precision. But the existence of 80-bit floating point in the 64-bit ABI (i.e., long double) means you'd have a hard ABI break that would potentially break software even written today, and the pain of breaking that ABI is probably not worth whatever savings you get out of it.
- wtallis 6y ago> Furthermore, processors reset into 16-bit mode on startup for compatibility reasons, so killing 16-bit and 32-bit mode would introduce major compatibility headaches. Didn't the switch to UEFI effectively reduce the scope of this problem to only apply to motherboard firmware? Operating systems no longer need 16-bit code to boot.
- msla 6y agoPeople always get the idea that removing the cruft will make the design faster, and yet most of the top 500 supercomputers use x86-64 chips: https://en.wikipedia.org/wiki/TOP500 https://en.wikipedia.org/wiki/TOP500 > As of November 2020, all supercomputers on TOP500 are 64-bit, mostly based on CPUs using the x86-64 instruction set architecture (of which 459 are Intel EMT64-based and 22 are AMD AMD64-based. The few exceptions are all based on RISC architectures). Thirteen supercomputers, including the no 2. and no. 3 are based on the Power ISA used by IBM POWER microprocessors, three on Fujitsu-designed SPARC64 chips. One computer uses another non-US design, the Japanese PEZY-SC (based on the British ARM[8]) as an accelerator paired with Intel's Xeon. There are non-x86 architectures in the TOP500, including ones which have less cruft than x86, but the x86 chips keep on being used in some of the fastest machines on the planet. My hypothesis is that x86 cruft doesn't really matter, and you'd need to go to a cruft level that was orders-of-magnitude worse for the ISA choice to dominate performance.
- imtringued 6y agoIt really doesn't matter. The biggest benefit of ARM are the fixed length instructions and only Apple is actually taking advantage of this by decoding 8 instructions at once. The big question is whether decoding that many instructions is actually a benefit. It's entirely possible that branch prediction and other factors are greater bottlenecks that have to be tackled first to take advantage of the faster instruction decoding. Intel's Pentium processors (the original ones) were doing pretty badly because they made the pipeline too deep at the expense of other things.
- hajile 6y agoAnandtech's article indicates they have an out-of-order buffer of around 630 entries (Zen 3 is only 256 entries). The M1 has 7 integer math ports and 4 FP/SIMD math ports plus several bunch of load/store/branch ports . It seems like they could completely saturate those decoders given the right code.
- gpderetta 6y agoI think the original Pentium had the pretty much canonical 5 stage pipeline. It did pretty well. Its successor, the Pentium Pro, an OoO design, was deeper but also did amazingly well. You are probably thinking of the Pentium 4 which was designed as a speed demon with a very deep pipeline and failed to reach its target frequency.
- VLM 6y agoEssentially every device that does not use a x86 cpu did that. There's no point in waiting an entire development cycle to get a new smaller x86-alike when you could solder an ARM chip or similar to the board today. The vast majority of CPUs shipped are not x86 compatible. Statista claims 23.5 billion microcontrollers are shipped annually. I know microchip (the PIC people) made press releases roughly annually as they shipped another billion flash microcontrollers. Google found the one from 2011 when they shipped their tenth billion PIC chip. I find it difficult to get x86 sales figures. Intel gross revenue is high because they have their fingers in everything. AMD financial statements claim about $2B/quarter total revenue, so if you figure the average shipped price of a AMD cpu is $200 and they made all their revenue off CPUs, that would be 40 million CPUs shipped per year, which seems both ridiculously high AND about a 25th the quantity of microchip PICs shipped. One way to look at the number of ARM CPUs shipped is the licensing / holding company has made enough licensing fees to pay for about "a hundred and fifty billion" ARM chips in its lifetime.
- imtringued 6y agoIt doesn't matter. The only meaningful change would be to go with fixed length instructions and maybe get rid of the memory ordering guarantees. If you do that you might as well switch to any other ISA that has these properties. But since Intel has an inferior manufacturing process the new ISA would still suffer from inferior CPUs. However, AMD has shown that x86_64 is still viable so the benefits of switching are miniscule anyway.
- wpietri 6y agoWhy are people downvoting this? It's a reasonable question. And it has some very helpful answers.
- userbinator 6y agoMSRs are interesting. There are a lot more than are documented, and since they came into existence, people have been exploring them: http://archive.gamedev.net/archive/reference/articles/article213.html http://archive.gamedev.net/archive/reference/articles/articl... http://www.rcollins.org/Errata/Jan97/Bugs.html http://www.rcollins.org/Errata/Jan97/Bugs.html
- TonyTrapp 6y agoFunny to think that once x86 was the platform that had too few general-purpose registers, so people sacrificed the frame pointer register in their highly-optimized assembly routines...
- varispeed 6y agoI still remember programming on paper mapping U and V pipelines to get as much done in parallel...
- jandrese 6y agoI still remember benchmarking the various optimization options in GCC and the only one that consistently and significantly improved performance on real code was -fomit-frame-pointer.
- nwmcsween 6y agoIt still is limited, this isn't general purpose registers which is 16, I semi regularly see register spills on x86_64 while looking at compiler output
- my123 6y ago> I will count sub-registers (e.g., EAX for RAX) as distinct registers. My justification: they have different instruction encodings, and both Intel and AMD optimize/pessimize particular sub-register use patterns in their microcode. I disagree strongly with that characterisation. Just no.
- thesuitonym 6y agoCare to elaborate? Or is it, "just no"?
- Macha 6y agoYou can't independently store different values in the sub-registers. Storing in EAX clobbers what's in RAX.
- colejohnson66 6y agoThey are the same architectural register, but due to register renaming, they may not reside in the same physical transistors. That’s probably why the author supersets them.
- fulafel 6y agoBut the author dismisses registers that are microarchitectural details.
- wtallis 6y agoThis analysis does have some limited value for characterizing the complexity required in the processor's front end to decode instructions. Register renaming means it has somewhat less relevance to the difficulty a compiler faces with register allocation, and basically no relevance to the actual size of a processor's physical register file(s).
- woodruffw 6y agoYep, register allocation is another reason that I omitted for brevity's sake.
- innocenat 6y agoDid I miss something, or why the opmask registers k0-k7 weren't count?
- woodruffw 6y agoYou didn't miss anything! I completely forgot them. I plan to do an update to the post this afternoon.
- innocenat 6y agoPhew. I must have re-read the post like 3 times to confirm they were actually missing. Thanks for clarification.
- corsix 6y agoThere's good evidence for mask registers and x87 registers sharing the same hardware on recent Intel chips: https://travisdowns.github.io/blog/2020/05/26/kreg2.html https://travisdowns.github.io/blog/2020/05/26/kreg2.html
- mikewarot 6y agoOnly registers that are orthogonal to each other should be counted. RAX,EAX,AX,AL,AH can not be independently varied, and thus should only count as 1.
- __s 6y agoAL/AH are distinct at least Maybe count how many bits of registers there are. Then count RAX as 64 bits of registers
- mikewarot 6y agoGood point, but they are both part of AX and up, so I don't think they should count.
- ithkuil 6y agoThey share the underlying storage (i.e. they are aliased) but they are independently addressed, and thus they consume instruction encoding space. Not saying that it's not interesting to know how much actual storage the register file offers; just highlighting that TFA focuses on the instruction encoding angle of the question, which is also important. CPU architectures are masterpieces of tradeoffs. Put too many registers and your instructions steam is not dense enough and you cannot keep your cpu busy due to stalls in the fetch phase. Also context switches become expensive (there are solutions to that though). Put to few registers and you have to spill registers to memory too often, and thus also consume precious instruction stream space.
- rwmj 6y ago> I won’t count microarchitectural implementation details, like shadow registers. I really think this article would have been more interesting if he had discussed the microarchitectural registers. Those are important to understand for optimization even if they're not directly visible. Also discussing MSRs but not special information tables like the page table and VMCS is a somewhat odd distinction. While they're probably stored differently, they are somewhat similar in how they are used. Also, isn't the TLB like a kind of set of registers? The TLB entries are very frequently accessed. How about store buffers and the like?
- bluetomcat 6y agoYep, what really happens under the hood is dynamic register allocation at runtime. I wonder how important is static register allocation by the compiler in that scenario. In theory, even if the compiler uses the same register over and over in sequential instructions, the renamer should be smart enough to detect the false data dependencies and allocate registers from individual instructions to different locations in the register file. Are there any x86 profiling tools which give any metrics about the real utilisation of the register file?
- recraft 6y agoI don't know of any profiling tools, but I've always relied on llvm-mca[0] -register-file-stats to show me what the expected register file usage is on an ISA [0] https://llvm.org/docs/CommandGuide/llvm-mca.html https://llvm.org/docs/CommandGuide/llvm-mca.html
- Tuna-Fish 6y agoNot just in theory. The way modern register renaming works is that every single write to a register name always allocates a new physical register. It's not even possible for there to be false dependencies because of reusing the same name over and over.
- gpderetta 6y agoThe number of architectural registers are still relevant for register allocation because of course overlapping and independent code sequences cannot share the same architectural register name. This is not very important for integer loads, but still relevant for FP where optimal scheduling requires having multiple computations in flight at the same time. In some cases 16 FP registers are not enough and Intel had to add 16 more FP registers with AVX512.
- andy_threos_io 6y agoFrom the programmers point of view only the working registers are really important, other registers are just OS related (MSR), some are really important, but the internal representation may be total different. Like a mode switch bit in a CR register. So MSR-r are just the interface. And the MSR register access can be "slow", so no synchronization or optimization required. But, the idea of more register makes better architecture, is a total bad assumption. See the dead body of Itanium (128 general-purpose 64 bit integer registers, 128 floating point registers etc. ) With multitasking, one have to switch between context, and larger context (register file size) takes more time. There are cases when you are better using just the GPRs, rather than the SIMD registers. (Linux kernel does not use FPU or SIMD registers) Also SIMD usage may slow down the clock, like AVX in x86_64. So you may trust your compiler for vectorization, but it may make more harm than good.
- bluetomcat 6y agoMore GPRs visible in the ISA also means more bits needed to encode instructions. If instruction length and encoding were not an issue, I bet we would have seen memory-to-memory ISAs where no GPRs exist, only instructions referencing memory locations. The dynamic register file would then be just a level below L1 cache, or even completely removed.
- mr_toad 6y ago> With multitasking, one have to switch between context, and larger context (register file size) takes more time. Sparc chips got around that by having sliding windows of registers: instead of having to push all the registers to the stack you just moved the window.
- deleted 6y ago[deleted]
- nine_k 6y agoIMHO what killed itanium wasn't too many registers, and not even compiler difficulties — it was an attempt to have a working x86 emulation. So, instead of a weird but very fast CPU, it ended up being not very fast both in x86 and native modes, while still being weird. (The makers of the Cell CPU did not compromise, went full weird, and had a winner of sorts.)
- Const-me 6y agoAMD64 has 32 registers: 16 scalar ones, and 16 vector ones. Maybe 34 if you count RIP and flags. From programmer’s perspective, the rest of them are either different ways to access these 32-34, or very exotic and rarely used. P.S. Modern compilers don’t normally emit x87 nor MMX instructions, because they are often slower compared to SSE (all AMD64 processors are required to support at least SSE1 and SSE2). For instance, FSQRT on Zen2 has 22 cycles both latency and throughput, VSQRTPD has 20 cycles latency and 8.5 cycles throughput (lower is better), despite taking 4 square roots in one shot. I think it’s safe to assume x87 and MMX instructions are only left for backward compatibility with old 32-bit binaries, when writing new code they can be ignored.
- jnwatson 6y agoTIL I learned about an entire Intel microprocessor subsystem, MPX, that was added and then deemed useless before I learned about it. It is both less secure and slower than software solutions. What a failure in processor design.
- jcranmer 6y agoThere's definitely several ways to ask the question, but IMHO the best answer to an unqualified question is to frame it in terms of what the necessary state to store in a thread context. To that end, the registers boil down to: * 16 general-purpose registers. * 16 or 32 vector registers. * 7 vector mask registers * 8 x87 floating-point registers, with 8 MMX registers aliased. (To separate or not separate x87/mmx is definitely a challenging question) * 3 normal status registers: RIP, RFLAGS, MXCSR * 6 x87 status registers: FSW, FCW, FTP, FDP, FIP, FOP * 6 segment registers * 6 debug registers * Relevant MPX registers (I don't know this ISA extension very well, so I can't count these registers accurately) These are the registers that I would expect to be able to poke at in a debugger or inspect/modify via something like ucontext_t, and they're going to be found in whatever kernel abstraction you use to save not-currently-running thread information.
- ithkuil 6y agoThat is a perfectly reasonable approach to that answer indeed. Registers do hold state and saving restoring them is burden of program code (user, compiler, lib, os). Contrast this with a hypothetical cpu that has only one register "base" and allows to address 32 words after the address at that base register. i.e. things like arithmetic instructions would have 5 bits to address operands which will be interpreters as base+8*n. To make things even more interesting this architecture's instruction pointer lives at base+0. Such an architecture would have one register under your metric (as only one register needs to be saved/restored to context switch an entire "register file"). However, implementations (microarchitecture) could actually shadow that memory range into hardware registers, and page in/out the whole register bank upon writes of the base register (effectively performing a hardware assisted context switch; hello TSS). However, since each instruction in this hypothetical ISA must have enough space in the encoding to address these operands, for all intents and purposes this architecture would have 32 registers. Deciding instructions, addressing operands, dealing with consequences of code density (icache misses), ... are all way more frequent events than context switches. Hence I do agree with TFA that operand encoding should be the default metric to count registers. And this also includes sub/overlapping registers, if they are independently addressed.
- 6y ago
- sm4rk0 6y agoTL;DR: >619