by phire · 3w ago · 0 comments
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.
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.
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.
Even one is too many.
Flags are a performance advantage. RISC-V needs extra instructions to do the same thing as ARMv8. Or sometimes the same number of instructions, but the compare-and-branch is more heavy (instead of reading an independent 4-bit flags register, it needs to tie up the register ports to do full sized register reads and run compare).
And ARMv8 can use the flags registers to reduce contention on GPRs, while RISC-V is sometimes forced to waste GPRs on emulating flags registers. And it does take a tiny bit more energy to write to a 64-bit register than a 4-bit one.
There are a few cases where compare-and-branch is more optimal than seperate compare and branch instructions... But ARMv8 gets the best of both worlds because it has a set of compare-and-branch instructions too (though some implementations will split that into two μops)
The major advantage of flags is that they give you certain three-input instructions (cmov, addc and ccmp) without requiring a proper three-wide register file.
TBH... I'm not entirely sure the amount of area spent on implementing flags actually provides more benefit than the cost, that would be next to impossible to prove. But they certainly provide more than zero benefit, and IMO it's a quite large advantage.
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 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.
I code RISC-V assembly and I coded ARM assembly, RISC-V is just a leaner and cleaner version of ARM, aka RISC (without IP lock... which is why new and small manufacturers do prefer RISC-V over ARM).
It seems RISC-V does a good enough job at reducing the amount of work to design high performance implementations (it seems the companies doing that are bought by ARM dominant corpos... to kill them or absorb them... the future will tell). Of course it is all about sweet spots and tradeoffs, for instance RVA is getting some heat about the RISC-V compressed instructions which seems to require significantly more work for high performance µarchitectures.
Many are waiting for those RISC-V high performance µarchitectures on latest silicon node (if they are not mostly bought to be killed).
> RISC-V is just a leaner and cleaner version of ARM, aka RISC
But does leaner and cleaner actually result in better performance? And really RISC-V is only lean and clean if you ignore all the extensions. With extensions, it's doing many of the same things as ARM.
And IMO RISC is legacy (or at least that lean-and-clean version of RISC is), we are actually in a post-RISC era where massive out-of-order μarches absolutely dominate the high-performance computing space.
> without IP lock...
Yes, that is the major advantage of RISC-V, along with extensibility.
And TBH, it's good enough for many usecases.
One thing that the massive dominance of x86 over the last 30 years should have taught us, is that ISA doesn't matter anymore. The modern post-RISC Out-of-Order paradigm allows us to complexly detach a legacy ISA from the internal μarch and make it run really fast despite all the legacy issues.
[0] https://dmitry.gr/?r=06.%20Thoughts&proj=12.%20RV
[1] https://news.ycombinator.com/item?id=49298035
[2] https://gist.github.com/erincandescent/8a10eeeea1918ee4f9d99...
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.