Hacker News new | ask | show | jobs
by phire 20 days ago
> 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.

3 comments

> 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.

Indeed, zero area is better than "small area" to work around a performance bottleneck.

Even one is too many.

But it's not a performance bottleneck.

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.

As said by others on HN, on performant µarchitectures it seems to require significant complexity to fit into the 'standard' optimizations those µarchitecture does, and the one which is often put forward is out of order exectution.
> 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.

Weird, you are the only and first one to say that from my point of view. Maybe "modern" is not the right work, maybe "not legacy" should be used instead.

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).

You clearly missed the recent "RISC-V: They Should Have Known Better" blog post [0] and associated HN comments [1]. Though, criticism goes back much further (like this post [2] from an ex-ARM engineer).

> 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...

As far as I understood, it is the RISC-V compressed instructions which adds significant complexity for performant µarchitectures. There were many threads about RISC-V (ofc, there is a lot of ARM dependent zealots working hard at FUDing RISC-V) where it was put forward.

The point is to reduce the implementation complexity required to achieve 'classic' high performance. This is very important for new µarchitecture designers.

In other word, you get 'classic' high performance more easily, faster with less work to do, and I guess this has been one of the main drivers for RISC-V design (and the fact the ISA is not IP locked).

I read it here that some RISC-V performant/large µarchitectures did add the complexity required to work around the compressed instructions, but it took them a while, and that would not have been required without the compressed instructions (this is not really RISC-V but "RVA"). Some CPU designers say it would have been the same mess with a status flag while implementing OoO performance.

And I am talking about 'implementation complexity' to achieve classic high performance: we all know that with enough complexity and additional work you can work around many performance bottlenecks, but it will "cost" each time.

RISC-V designers did try hard to design their ISA to reduce the road torwards high performance, with more or less success.

In other words, what the RISC-V designers seemed to have achieved: you need "less " to reach high performance, but this is not perfect.

> ISA doesn't matter anymore

ISA matters in the sense that if you expose better mechanisms for trust boundary transitions and (hardware/non-privileged/etc) notifications, you'll gain significant performance in just about anything that isn't 100% compute. And if you expose better control flow mechanisms you get more secure code.

If you can "think RISC well" and manage to express those mechanisms with a neat small ISA, good for you. If not, just slap on more CISC and the end result will still be better than a RISC missing the relevant thing.

Here's an apparent ~40% improvement on I/O with a small ISA change to get out of legacy x86 syscall hell: https://www.phoronix.com/review/intel-fred-panther-lake/2

« 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 »

But apparently it doesn't allow it to run really cool, thermally speaking: ARM has an edge over x86 for mobile. Is that a difference that is independent of µarch? If so, what is it down to, provided it can be expressed in reasonable simplicity?

It's mostly independent. Intel did have its Atom line of in-order low-power processors.
RE [0]: That blog post is quite disingenuous/wrong, e.g. the entire thing on the encoding misinterprets what RISC-V was optimized for (the table needs to be inverted) It's probably to late to write a response now though? If you are interested, maybe I can find the motivation to go through everything.
> 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.