Hacker News new | ask | show | jobs
by sylware 21 days ago
This disconnect is really light compared to x86_64 mess (status register on out-of-order CPU).

The transition is going, if any, will be tough: basically you would need a "x86_64" hardware 'slow' mode, on the side of the 'clean' and light RISC one.

1 comments

Condition codes are not hard to do on an OOO machine. I know that there are RISC books that say there, but they are not.

z/Arch, x86, ARM, PowerPC, and SPARC all have condition codes. They all have OOO implementations and all but SPARC have really, really fast implementations.

---

µops are not at all like RISC instructions. They tend to be quite big, for example, or have really strange encodings (that vary from place to place inside the CPU). A group of 2-4 µops may share a single wide literal field (or bigger literals will be encoded with a number of µops or something else crazy).

Pentium Pro (P6) had a µops length (at some point inside the CPU) of around 115 bits, for example.

µops also typically expose the pipeline(s) to some extent which is just ugly and very, very for from being clean.

> know that there are RISC books that say there, but they are not.

You don't have to look far, the RISC-V spec makes this incorrect claim.

> µops are not at all like RISC instructions

Yeah. Zen μops are actually documented to be variable length (at least when stored in the μop cache, but presumably elsewhere). And μops hold both a memory load and an ALU operation... very CISC.

It's only the full read-modify-write instructions that still get split into two μops. And I doubt it's actually two fully independent μops, because seems a waste to send the instruction through the AGU twice.

Much content on HN says the opposite: "a status register on OOO is disgusting". Should not have been there in the first place, but x86_64 has too much toxic legacy. Namely, you have to pay with serious implementation complexity that legacy for high performance.

And RISC-V as its sweet spot roughly set for implementation simplicity, namely some core design choices show a strong difference here.

Obviously µops are encoded specific to some µarchitecture, but their "operations" may tell us what would be a "good" ISA for performance, and many seem to agree that this ISA would be "RISC" based. This what I intended to say.

> Much content on HN says the opposite

Doesn't mean they are right. It's mostly just RISC-V fans blindly repeating the RISC-V justification for not having flags without understanding the situation.

And it's only RISC-V (and MIPS before it) which sticks to this position. Most other high-performance RISC arches have flags. Including ARMv8, a complete departure from 32-bit ARM, and one which was explicitly designed with high-performance OoO cores in mind. ARMv8 dropped many fun RISC features from Arm32, but they kept flags.

Really, the cost for flags on OoO cores isn't that high. You have already implemented everything you need to rename regular registers, which you can reuse to implement flag renaming too. It costs a tiny bit of area and maybe a little routing complexity, but doesn't have any impact on fmax.

> but their "operations" may tell us what would be a "good" ISA for performance, and many seem to agree that this ISA would be "RISC" based.

Well... given that the current μops of x86 cores aren't RISC-like, (because they are variable length, and aren't load-store), your suggested philosophy would not result in a RISC-like replacement ISA for x86.

Like, the weaker form of your argument is probably correct. If we were designing a replacement x86 ISA, then the current μops of various x86 implementations would be a good inspiration for informing what that ISA could look like.

It's only the strong form that I disagree with: There is no good reason for any ISA to be a 1:1 mapping of the μops it decodes into. And there are many good arguments for not doing that. μops can be arbitrarily wide, as they are only used for internal purposes. Instructions need to be dense and compressed, as code density can have a large impact on performance. There is no good reason why a single instruction shouldn't decode to two or even hundreds of μops... that's just good compression.

> Really, the cost for flags on OoO cores isn't that high. You have already implemented everything you need to rename regular registers, which you can reuse to implement flag renaming too. It costs a tiny bit of area and maybe a little routing complexity, but doesn't have any impact on fmax.

I generally agree, but want to point out that they aren't "free" either. Look at contemporary wide OoO Arm cores, most (Apple Silicon, C1-Ultra, ...) have half the throughput on flag reading/writing instructions than the equivalent instruction without the flag write (ADD vs ADC vs ADDS). So clearly the cost is high enough to drive towards such tradeoffs being made.

Yeah, not free.

I'm only really arguing that handling flags in OoO designs doesn't require massive amounts of extra "complexity", which is the common argument.

They don't argue that flags add area, or power consumption. Just an unreasonable amount of extra design complexity (and maybe a FMAX limitation) to the extent that OoO μarches would be far better with flags not existing.

Of course flags uses more area (though IMO, probably not much that area). And if it uses area (even a tiny bit), then engineers are probably going to spend time optimising it. Even tiny savings can be put to use elsewhere.

> Doesn't mean they are right. It's mostly just RISC-V fans blindly repeating the RISC-V justification for not having flags without understanding the situation.

It seems it comes from some CPU designers which have that understanding: for performant implementations, not having a status flag would remove some significant complexity from the way. Having a status flag is said to make classic performant implementation more complicated, and newer ISAs removes that (RISC-V is one of them). And this is only one design choices, I guess they made many others which were done in a similar fashion.

Yeah, I actually meant the distance between µops and the "operation" should be reduced in order to avoid implementation complexity. This statement was not to be taken as verbatim, my bad. The thing is how much of the bad from some ISA legacy did infuse in those µops.

> It seems it comes from some CPU designers

It comes from CPU designers who don't have a history of making OoO designs. Designers who love making high-performance area-optimised in-order RISC cores. CPU designers who created RISC-V.

I mean, I design CPUs too, (as a hobby) so why not take my word?

RISC-V is not a modern ISA. It might be a new ISA, but it's very much a design stuck in the late-80s. It's basically just "MIPS, but with the benefit of hindsight". They didn't get rid of flags because that was the modern approach, they just blindly copied what MIPS already did in 1984 and tried to come up with a post-hoc rationalisation for it.

Don't get me wrong, RISC-V is not the worst ISA. It does a good job in its intended use-case (of being a great university ISA, easy for students and hobbyists to implement themselves. Or a starting point for weird cores with lots of custom vector instructions). It's just not a modern ISA.

If you want to see an actual modern ISA, take a look at ARMv8.

ARMv8 was designed around the same time as RISC-V, but by professional CPU designers. It was a joint project between ARM Inc and Apple. Those Apple engineers were working on what later became the M1, and the ARMv8 ISA shows very clear signs of being optimised for modern very-wide OoO cores.

> You have already implemented everything you need to rename regular registers, which you can reuse to implement flag renaming too. It costs a tiny bit of area and maybe a little routing complexity, but doesn't have any impact on fmax.

Renaming the condition codes separately from the registers seems to be the current fashion but it is not the only way.

The Intel P6 kept the condition code outputs together with the register outputs from the ALU -- so it would rename the condition codes and registers together.

However the renaming is done, it is abundantly clear that it can be done. We have 30 years of CPUs in the hands of customers that do it, and they do it fast and using very little area.

RMW memory instructions are actually pretty nice (and totally counter to the RISC philosophy).

Not only are they compact, they also make it crystal clear that the cache line in question should be marked exclusive as soon as it gets read.

The x86 does not have that much implementation complexity. There's the complexity you always get from high-performance implementations, but Apple, ARM, and IBM pay for that, too. The main issue is that there's just a lot to implement and verify.

And if I am not too mistaken, many RISC-V design choices were made to remove that complexity (to bring saner high-performance silicon... and that without IP lock).