News for hackers. Stuff that matters.
Re:An ex-ARM engineer critiques RISC-V by rwmj on Sunday November 01, 2020 @09:54AM (#24959834)
The idea is that high end processors will recognise these sequences of instructions and optimize them (something called macro-op fusion). Whether this is a good idea is an open question because we don't yet have such high performance RISC-V chips, but that's what the RISC-V designers are thinking. At the same time it permits very simple implementations which wouldn't be possible if the base instruction set contained every pet instruction that someone thought was a good idea.

Note macro op fusion is widely used for other architectures already, particularly ones like x86 where what the processor actually runs looks nothing like the machine code.

Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @10:31AM (#24960088)
Two words: instruction density.

It doesn’t matter if they’re fused or not if the reduced instruction density increases memory usage and puts more pressure on I$.

Also, I don’t buy the whole fusion argument on the grounds that having to fuse super complex (5 instruction or more) sequences adds enough complexity that you’ve got opportunity cost. Much better for everyone if the CPU doesn’t have to do that fusion. That’s the whole point of good ISA design - to prevent the need for fusing in cases you’re doing something super common.

Re:An ex-ARM engineer critiques RISC-V by rwmj on Sunday November 01, 2020 @10:45AM (#24960198)
That's what the RISC-V compressed instruction encoding is all about. There is a paper which I can't find right now about how the compressed encoding achieves something similar to x86 code size on typical application code. As I said above, the jury is still out until we get very high performance RISC-V implementations which are equivalent to existing high end x86 and aarch64 designs.

Edit: Here's the thesis about the design decisions in the C encoding: https://people.eecs.berkeley.edu/~krste/papers/waterman-ms.p... See also the diagram on page 62 of this document: https://people.eecs.berkeley.edu/~krste/papers/EECS-2016-1.p...

Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @12:49PM (#24961132)
First of all: I agree with you that the jury is out. We are all speculating. I might be wrong.

The thing I see is this: you can also add compressed encodings for any ISA. And that has its own costs (it’s harder to decode and it’s harder on software that wants to do bidirectional analysis of machine code). So “my isa has shortcomings but it’s cool because compression” isn’t a perfect argument since if your isa lacks those shortcomings then you still benefit from compression and you don’t need it as much, which is better.

Re:An ex-ARM engineer critiques RISC-V by andrekandre on Sunday November 01, 2020 @04:53PM (#24962856)
> it’s harder to decode and it’s harder on software that wants to do bidirectional analysis of machine code

not necessarily, since

1. the compressed versions are basically 1-1 to the non-compressed versions

2. the uncompressed versions are more for study/academia and clarity; its expected that irl only compressed instructions are used (for instructions that can be compressed)

more info: https://riscv.org/wp-content/uploads/2015/11/riscv-compresse...

Re:An ex-ARM engineer critiques RISC-V by anp on Sunday November 01, 2020 @03:12PM (#24962103)
Do any other ISAs have compressed encodings in wide use? It seems a bit like a chicken and egg problem - why build all the silicon to handle decoding it if your base ISA is dense enough?
Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @03:47PM (#24962372)
Arguably x86 only has a compressed encoding in the sense that super common instructions often fit in fewer than 4 bytes and some of the most used ones are 1 byte. I don’t think the compression is deliberate or optimal though.
Re:An ex-ARM engineer critiques RISC-V by saagarjha on Sunday November 01, 2020 @05:26PM (#24963086)
Arguably most of the 1 byte instructions are garbage, though ;)
Re:An ex-ARM engineer critiques RISC-V by rwmj on Monday November 02, 2020 @02:44PM (#24972244)
What, no love for AAA :-?

(IIRC they removed that one on x86-64)

Re:An ex-ARM engineer critiques RISC-V by darknoon on Sunday November 01, 2020 @03:27PM (#24962211)
Sounds pretty similar to thumb mode on ARM, no?
Re:An ex-ARM engineer critiques RISC-V by mark_mcs on Sunday November 01, 2020 @03:43PM (#24962337)
And ARM licensed the Hitachi SuperH patents when implementing Thumb. It's not exactly a new concept.
Re:An ex-ARM engineer critiques RISC-V by fulafel on Friday November 06, 2020 @12:50AM (#25005276)
In addition to Thumb there are apparently at least MIPS16e ASE and PowerPC VLE.
Re:An ex-ARM engineer critiques RISC-V by loeg on Sunday November 01, 2020 @03:40PM (#24962314)
ARM had Thumb, right? Is that a deadend at this point?
Re:An ex-ARM engineer critiques RISC-V by deaddodo on Sunday November 01, 2020 @09:47PM (#24964426)
Thumb was removed from ARMv8 (AArch64). If you use 32-but legacy, it may exist on some chips; but it’s no longer the benefit it once was.
Re:An ex-ARM engineer critiques RISC-V by hajile on Monday November 02, 2020 @09:33AM (#24968475)
It's always been of the same value. You exchange performance for code density. They want aarch64 to be high-performance, so they removed thumb.

RISC-V compact instructions don't require special modes and run in fully-mixed mode with 32-bit instructions without all the penalties thumb has (they are literally just extended into their 32-bit counterparts internally).

Re:An ex-ARM engineer critiques RISC-V by deaddodo on Monday November 02, 2020 @03:51PM (#24973162)
> It's always been of the same value. You exchange performance for code density.

High code density became less valuable, was the point.

Re:An ex-ARM engineer critiques RISC-V by Veedrac on Sunday November 01, 2020 @11:06AM (#24960353)
> having to fuse super complex (5 instruction or more) sequences

Can you give an example of someone advocating for 5 instruction fusion? Normally it's limited to three.

Re:An ex-ARM engineer critiques RISC-V by jhallenworld on Sunday November 01, 2020 @11:26AM (#24960484)
They have this example for general signed overflow checking in the 2.2 spec (but I'm not sure if this counts as a recommended sequence for fusion):

    add t0, t1, t2
    slti t3, t2, 0
    slt t4, t0, t1
    bne t3, t4, overflow
So two extra registers needed also..

edit: so I now think a good extension to add overflow checking to RISC-V is with an instruction that works like "slt"- call it "sov", set if add would overflow:

    add t0, t1, t2
    sov t3, t1, t2
    bnez t3, overflow
add/sov could be fused..
Re:An ex-ARM engineer critiques RISC-V by Veedrac on Sunday November 01, 2020 @11:43AM (#24960622)
Fusing that would be very difficult, since it's hard to write that many registers with a single op, and I don't think they recommend it. This does mean signed overflow checking will be comparatively expensive. But thanks for the reference, I agree this is a weak point :).
Re:An ex-ARM engineer critiques RISC-V by ithkuil on Sunday November 01, 2020 @12:10PM (#24960852)
You don't have to use real registers in a single op. Fusing means interpreting a pattern in the input stream and issuing a different instruction from a richer microarchitectural instruction set
Re:An ex-ARM engineer critiques RISC-V by jcranmer on Sunday November 01, 2020 @12:30PM (#24960995)
You have to preserve the architectural registers at the end of the sequence. So if there are 5 registers, you either have to have a 5-register microinstruction, or issue multiple 3-register microinstructions instead.
Re:An ex-ARM engineer critiques RISC-V by ithkuil on Sunday November 01, 2020 @04:20PM (#24962597)
You have to preserve architectural registers only when some other instruction actually depends on them. When you detect a dependency you lazily compute their content (causing a stall)
Re:An ex-ARM engineer critiques RISC-V by brucehoult on Sunday November 01, 2020 @05:26PM (#24963090)
The dependency could be arbitrarily many millions of instructions away.

The only way to know there isn't a dependency is if that register gets clobbered by something else very soon afterwards.

But this whole topic of "checking for signed overflow is expensive" is overblown. It's simply not that important an operation, especially in the context of those languages that do it a lot also doing a lot of memory references, which are far more expensive.

Adding arbitrary completely unknown integers is pretty rare. If you know both numbers are greater than zero then a single compare-and-branch is all you need. If one of the numbers is a constant then a single compare-and-branch is all you need.

Re:An ex-ARM engineer critiques RISC-V by jcranmer on Sunday November 01, 2020 @05:32PM (#24963127)
That sounds like an amazingly bad idea, because you would instead have to retain the two source registers until you can prove that you don't need the two output registers anymore, which can be arbitrarily far in the future.
Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @04:42PM (#24962766)
At least in their papers and mailing list discussion, the limit for simple fusion is not on the number of source operands, but on the number of destination operands. A classic example is a PC-relative long jump:

  auipc lr, zero, .LONG_TARGET20
  jalr  lr, lr, .LONG_TARGET12
Only one register (the link register) is clobbered, so the pair can be fused into a single wide jump-and-link.

So in parent's example, sov might fuse with the following bnez, but it likely wouldn't fuse with the preceding addition.

Re:An ex-ARM engineer critiques RISC-V by Veedrac on Monday November 02, 2020 @05:09AM (#24966391)
Yes, I missed the edit, I was only commenting on the first part.

Quite a few things determine whether a fusion is doable or not. In addition to the number of destination registers, you do, to a more relaxed extent, care about source operands, but also things like ‘does this fit nicely in a single pass through the pipeline?’ and even just ‘is this materially beneficial?’

Lots of cores (but not all) can write two registers from a fused instruction, given the right conditions, and sov does rerun the addition, so add-sov fusion sounds very doable to me.

Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @11:23AM (#24960461)
rotate-and-xor (and xor-and-rotate) are both common operations in ARX ciphers. They demand 4 macro-ops in RISC-V, but only one in ARMv8.

Bitfield insertion is only one instruction in most RISC ISAs, but 5 or more in RISC-V.

Re:An ex-ARM engineer critiques RISC-V by Veedrac on Sunday November 01, 2020 @11:44AM (#24960636)
The (unfinalized) bitmanip extension has single-op rotates.
Re:An ex-ARM engineer critiques RISC-V by CalChris on Sunday November 01, 2020 @12:23PM (#24960939)
I really don't like it. It seems like they copied x86 (bext, bdep) where they should have been plagiarizing armv8 (BFM, ...).
Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @12:38PM (#24961061)
I've watched that extension's development since it was little more than one smart guy's wish list. I don't think its fair to say that they copied any one architecture. The authors have put in a ton of time researching the tradeoffs and investigating the trade space over the years.

That said, until it gets ratified by the consortium and implemented in silicon its still just a (well-researched) wishlist.

Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @11:17AM (#24960424)
I’d have to reinvestigate more than I feel like doing right now so I’ll tell you where to look.

You need fast sequences for all of these variants:

- add or sub or mul

- signed or unsigned

- 32 bit or 64 bit

Some of those need 5 instructions. I don’t remember which adventure you need to pick to get 5.

Re:An ex-ARM engineer critiques RISC-V by Veedrac on Sunday November 01, 2020 @11:46AM (#24960656)
Thanks for the reply but I'm not sure what you mean. Are you saying you want to add an i32 to a u64? Or am I completely misunderstanding? I'm not sure why unsigned-unsigned or signed-signed instructions would be hard. Idk about mixed sign operations, but when do they ever occur without first casting one to the other?
Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @12:30PM (#24960996)
I mean you will do overflow checks on the following. I’ll use the “s” and “u” prefixes to mean signed and unsigned. Unsigned matters less than signed.

sadd32, sadd64, uadd32, uadd64, ssub32, ssub64, usub32, usub64, smul32, smul64, umul32, umul64

Re:An ex-ARM engineer critiques RISC-V by Veedrac on Sunday November 01, 2020 @01:40PM (#24961466)
Ah, I get you now. Yes, this looks like a weak point, and I totally get why it'd screw with Javascript optimizations.

I don't think it's a fusion problem; even if you did fuse these sequences, they'd still be bad, since they'd be writing lots of extra registers.

Re:An ex-ARM engineer critiques RISC-V by pizlonator on Sunday November 01, 2020 @03:48PM (#24962384)
Yeah exactly!

And worth noting that these are just the ones where you usually have good sequences on other cpus, but even then (like signed mul) they’re not perfect. Lots of room for improvement. It’s just that risc-v didn’t seize the opportunity.

Re:An ex-ARM engineer critiques RISC-V by dmix on Sunday November 01, 2020 @11:49AM (#24960677)
> particularly ones like x86 where what the processor actually runs looks nothing like the machine code.

(Quoted from OPs comment)

This isn’t a subject I’m an expert at but wouldn’t this mean there’s already some sort of translation going on already on the other systems? So it’s mostly just added end user work not a giant performance loss on RISC?

It would just then simply be a layer of abstraction that is lost.

Re:An ex-ARM engineer critiques RISC-V by lopsidedBrain on Sunday November 01, 2020 @12:29PM (#24960990)
Yes. x86 processors translate instructions to internal micro opcodes before scheduling or running them. Those look nothing like the x86 instructions.
Re:An ex-ARM engineer critiques RISC-V by monocasa on Sunday November 01, 2020 @04:42PM (#24962765)
What little we've seen of x86 micro ops (the great work reverse engineering the k10 microcode), shows that the micro ops look very much like x86 instructions. Still predominantly two address, RMW instructions for instance. Very similar to the original 8086's microcode structure rather than some reaction to the RISC movement, despite the common trope to state the contrary.

Can't wait to see more information about the goldmont microcode work to see if that holds for intel as well as it does for AMD.

Re:An ex-ARM engineer critiques RISC-V by arcticbull on Sunday November 01, 2020 @12:04PM (#24960804)
Some huge portion of the x86 power budget is just the instruction decoder. The instruction set is so nutty that trying to implement them all directly in hardware is a non-starter.

The x86 front end breaks down big instructions into smaller RISC-like micro-ops and then fuses/re-orders/optimizes/etc and runs those instead. There’s pros and cons, the con being sheer complexity and power budget, the pros are that it’s an abstraction so the microarchitecture can change completely without recompiling your code —- and you get CPU specific optimizations too. The CPU is basically emulating x86.

You could in theory build an x86 CPU with a RISC-V core behind that decoder.

Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @12:17PM (#24960897)
> Some huge portion of the x86 power budget is just the instruction decoder.

This is a widely held meme, but the internet at large doesn't have any evidence to back it up. A couple of publicly visible engineers that do have experience are on record as saying that cell-phone-class competitive x86 was absolutely possible. Intel and AMD chose not to pursue those markets.

The expensive parts of a high-end CPU aren't normally in the instruction decode part. They are in the branch prediction, branch mispredict recovery, forwarding networks, memory re-ordering, and so on. Anything short of a dataflow ISA has little impact on those structures.

Re:An ex-ARM engineer critiques RISC-V by klelatti on Sunday November 01, 2020 @05:16PM (#24963021)
I'm sure that you're right that the instruction decoder power budget isn't a huge issue.

Don't think its strictly accurate to say that Intel 'chose not to pursue' the mobile SoC market - IIRC they tried, made little progress and gave up having spent a lot of money in the process.

Re:An ex-ARM engineer critiques RISC-V by arcticbull on Sunday November 01, 2020 @03:23PM (#24962184)
By large I mean up to 10%, and I have a study for you. [1]

[1] https://www.usenix.org/system/files/conference/cooldc16/cool...

Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @03:40PM (#24962319)
I skimmed the paper. They reported that the difference in total power spent in two(!) microbenchmarks when switching between L1I and the decode cache is 10% for one, and 3% for the other. The attribution of power was done entirely using a linear regression model on some core perf counters, and the core's own internal estimate for power consumption over the whole package.

I don't think you can generalize from that result to much of anything.

Re:An ex-ARM engineer critiques RISC-V by reitzensteinm on Sunday November 01, 2020 @07:47PM (#24963927)
I don't have a source, but back when ARM Zen was going to be a thing (hopefully it still will), AMD was claiming a 10% uplift in performance over x64.

That struck me as one of the few apples to apples comparisons ever of the instruction sets at the high end, from a party not really incentivized to bend the truth one way or another.

But it could have easily come from something like the relaxed memory model, or they could have just been overly optimistic. The chip was cut after all.

Re:An ex-ARM engineer critiques RISC-V by hajile on Monday November 02, 2020 @11:34AM (#24969916)
You're running into the same problem, just from a different angle.

With the exception of Atom, all recent Intel designs have been a RISC core with a CISC decoder slapped on top. Everything else being equal, the simpler decoder will create a smaller chip. Because the decoder is always running all-out, the simpler decoder will also use less power.

x86 instructions are multi-length from 1 to 15 bytes. The cost to slice that up is always going to be bigger than fixed-length instructions. RISC-V has variable length in theory, but in practice, compact instructions extend into 32-bit instructions with some bits added which is important for decode cache while longer instructions are ignored.

Because there's a maximum tolerable decode latency of a very few cycles and latency increases with cache size, decode cache size has a definite cap. x86 has a couple orders of magnitude more potential instructions than RISC-V. More instructions translates into a lower hit rate for the same size cache barring any heuristics (more on that below).

Matching variable-length arrays to an unknown set of arrays in cache is inherently a hard problem. Every solution has tradeoffs and the resulting heuristics are bad for computing (see below). In contrast, searching for a match on a fixed 32-bit array has much more simple general solutions that don't require tradeoffs.

C and CPU designs feed off each other. Let's say there are instructions X and Y which can do equivalent things. x86 engineers played around with both and got a lucky insight into how to make X a bit faster. Compiler writers jump on it and start using the faster solution. x86 engineers now all but stop looking to improve Y and spend their time tinkering with X instead. Compilers now focus even more heavily around not just X, but any instructions more closely associated with X.

In that entire (true) story, nobody gave a second thought to whether the final result of Y would have been faster overall if not for the lucky break with X. If x86 developers were actually free to choose whichever instructions they wanted, x86 decode would be much, much slower than it appears to be. This self limitation argues that perhaps a more RISC-like ISA is inevitable.

A new ISA where everything is used would definitely have complexity, transistor, and power disadvantages vs a new ISA that didn't make that mistake.

Re:An ex-ARM engineer critiques RISC-V by MrBuddyCasino on Sunday November 01, 2020 @12:29PM (#24960983)
> A couple of publicly visible engineers that do have experience are on record as saying that cell-phone-class competitive x86 was absolutely possible.

Weren't there Windows Phone devices with x86 SoC, but they weren't competitive?

Re:An ex-ARM engineer critiques RISC-V by toast0 on Sunday November 01, 2020 @12:50PM (#24961138)
Public Windows Phone 7, 8, and Windows Mobile 10 devices were all arm. Intel cancelled further development on Atom for phones at roughly the same time Microsoft announced Windows Mobile 10's desktop convergence feature (plug phone into monitor and get a desktop-like experience, I think there was a wireless option as well). It's pretty simple to speculate this would have been way more nifty on an x86 chip, because Windows Mobile 10 was more or less Windows 10, so you would have a bigger software library, instead of only UWP applications.

Commercially made x86 Android phones exist, the most popular to my knowledge were some of the Asus ZenPhone models.

Re:An ex-ARM engineer critiques RISC-V by hajile on Monday November 02, 2020 @03:57PM (#24973240)
It existed, but why bother?

When Atom was released in 2008, the A9 had already been announced (a year before). A9 was around 10-15% faster per clock and were often multicore meaning a 1.5GHz chip was faster in all metrics over the 1.6GHz Atom.

A few articles came out June/July of this year with Analysts saying that Intel had spent over 10 Billion dollars trying to break into the mobile market with no success. ARM's current R&D budget (according to Nvidia a month or so ago) is 0.5B. If they spent that much every year since 2000, they would barely match Intel, but their entire market cap in stayed under 4B all the way until 2009. Remember, that R&D includes their high-end ARM cores, but also GPU, midrange designs, various microcontroller designs, a realtime OS, ARM tooling, NPUs, various kernel support, etc

If that much money can't fix up x86 to keep up with a budget a fraction of the size, I take that as proof that the ISA really does matter.

Re:An ex-ARM engineer critiques RISC-V by ThrowawayR2 on Sunday November 01, 2020 @01:25PM (#24961370)
There never were any. Intel cancelled their Broxton phone SoC in 2016: https://www.anandtech.com/show/10288/intel-broxton-sofia-sma... (A major mistake on their part IMO.) There was some speculation back then that Microsoft might have been interested in x86 phones but no proof ever emerged.
Re:An ex-ARM engineer critiques RISC-V by jhallenworld on Sunday November 01, 2020 @10:35AM (#24960132)
You need the icache to be post-fusion..
Re:An ex-ARM engineer critiques RISC-V by bertr4nd on Sunday November 01, 2020 @10:43AM (#24960184)
It’s not just the I$ though, it’s the MLC, LLC, and I-TLB. And instruction density at those levels actually matters quite a lot for big binaries (my experience in this regard is with HHVM at FB, but it’s certainly not unique).
Re:An ex-ARM engineer critiques RISC-V by jhallenworld on Sunday November 01, 2020 @11:02AM (#24960323)
Yeah, pretty much agreeing with you. I think if they are going to rely on fusion in the ISA, they should limit it to the most minimal fusion implementation to have the widest possible chance of adoption. So assume the hardware can only fuse two instructions and design the ISA with this restriction in mind.
Re:An ex-ARM engineer critiques RISC-V by brandmeyer on Sunday November 01, 2020 @11:26AM (#24960491)
Intel and AMD's experience with complex transformations on the instruction stream suggests that its overall better to do it in a L0 decode cache.
Re:An ex-ARM engineer critiques RISC-V by CalChris on Sunday November 01, 2020 @11:58AM (#24960761)
I don't think the instruction sequence from the article would qualify for macro-op fusion. Berkeley looked at this for the simplest case of LEA [1]:

  // &(array[offset])
  slli rd, rs1, {1,2,3}
  add  rd, rd,  rs2
The sequence in the article uses what Intel calls the fast case but it still wouldn't qualify for Berkeley's two instruction fusion. Dunno if anyone does three instruction fusion.

As an aside, LEA is never getting added to the base RISC-V nor should it be. But I'm surprised it isn't considered for an extension.

[1] https://www2.eecs.berkeley.edu/Pubs/TechRpts/2016/EECS-2016-...

Re:An ex-ARM engineer critiques RISC-V by IshKebab on Sunday November 01, 2020 @05:21PM (#24963049)
> The idea is that high end processors will recognise these sequences

I'm not sure that is the idea, given that RISC-V is targeted at processors so low-end that they don't even implement multiply.

Re:An ex-ARM engineer critiques RISC-V by audunw on Monday November 02, 2020 @03:53PM (#24973188)
That’s not true. RISC-V targets the full spectrum of processors (well, not 8/16-bit, so not the very low end). Some of the decisions they made, compared to say OpenRISC is made just to make the ISA easier to implement with superscalar CPUs (not having branch delay slots)
Re:An ex-ARM engineer critiques RISC-V by spacenick88 on Sunday November 01, 2020 @03:42PM (#24962334)
Instead of fusing them, shouldn't it be possible to speculate that it will not overflow, process the check on a separate slow path and do a roll back in case it did overflow?
Re:An ex-ARM engineer critiques RISC-V by 8note on Sunday November 01, 2020 @08:12PM (#24964025)
I'm not super familiar with compiler and processor design, but why do I want the processor to do this optimization instead of the compiler?