Live data from Hacker News

RISC-V formal spec public review

github.com

31–38 of 38 posts

Re: RISC-V formal spec public review

#31

Earlier quoted context omitted.

They can't guess, which is why they all offer `__builtin_expect` to control them (which people often wrap in LIKELY/UNLIKELY macros).

Yes, but we need the opposite. There's no way to say a branch has no expected value.

Clang does have __builtin_unpredictable, but last I checked it doesn't actually seem to have an effect.

Re: RISC-V formal spec public review

#32
post #25

Earlier quoted context omitted.

FYI, here is the rationale section on that subject: We did not include special instruction set support for overflow checks on integer arithmetic operations in the base instruction set, as many overflow checks can be cheaply implemented using RISC-V branches. Overflow checking for unsigned addition requires only a single additional branch instruction after the addition: add t0, t1, t2; bltu t0, t1, overflow. For signe…

For an ISA whose main use will be IoT (at least in the beginning), this isn't good.. Rust didn't put integer overflow checks in release mode because current CPU don't provide "free" integer overflow detection, RISC V is even a regression over MIPS here..

> Rust didn't put integer overflow checks in release mode because current CPU don't provide "free" integer overflow detection

Not really; the main performance drawback of obligate overflow checks is excessively-constrained semantics of the resulting code making optimization harder, not the direct CPU cost of checking. There are other ways of detecting possible overflows, and Rust does check for overflow in debug mode (this is specifically in order to ensure that most Rust code will work properly even when checks are enabled, and will not simply end up relying on underspecified semantics.)

Re: RISC-V formal spec public review

#33
post #3

Well, this is progress. I wonder how many counterparts to delay slots, stack windows, conditional moves, and other embarrassments we are inadvertently enshrining. There's nothing like hindsight to make you facepalm. (The crypto extension is my bet ATM for most-likely-to-embarrass. But that's without reading it.) The only way to approach this project sensibly is to assume every single FPGA produced after some near fut…

Compressed versions of the load/store instructions don't support 8bit or 16bit values, so in situations where you most care about memory usage you're forced to use the full size versions.

Re: RISC-V formal spec public review

#34
post #5
post #4

Earlier quoted context omitted.

What's wrong with conditional moves? They're good for mispredictable branches, although I liked them better on PPC which had 8 condition/flags registers instead of just 1.

Conditional moves depend on state left over from the last instruction. But when you want to re-order your instructions to keep all your functional units busy, keeping the conditional moves right makes a big mess. They're fine as micro-ops after you've scheduled them all, but are lousy at the ISA level. Intel and AMD make it work by throwing another 10,000 or 100,000 transistors at it. It is better to let macro-op fus…

Unless I've understood you poorly, this is confused.

The issue with CMOV is primarily that it's a three operand instruction. If it was a two-instruction operation, it would just be arithmetic, and nobody would care.

A minor, secondary issue is that conditional moves have a data dependency on both of the source operands, unlike conditional branch and move, which means that they are often slower than a predictable branch and move on a fast processor. However, this doesn't matter all that much, because they're optional, so just don't use them when they aren't a good fit.

Re: RISC-V formal spec public review

#35
post #34
post #5

Earlier quoted context omitted.

Conditional moves depend on state left over from the last instruction. But when you want to re-order your instructions to keep all your functional units busy, keeping the conditional moves right makes a big mess. They're fine as micro-ops after you've scheduled them all, but are lousy at the ISA level. Intel and AMD make it work by throwing another 10,000 or 100,000 transistors at it. It is better to let macro-op fus…

Unless I've understood you poorly, this is confused. The issue with CMOV is primarily that it's a three operand instruction. If it was a two-instruction operation, it would just be arithmetic, and nobody would care. A minor, secondary issue is that conditional moves have a data dependency on both of the source operands, unlike conditional branch and move, which means that they are often slower than a predictable bran…

It probably is confused.

Re: RISC-V formal spec public review

#36
post #27

Earlier quoted context omitted.

> Conditional moves depend on state left over from the last instruction. So, literally exactly the same state that conditional branch instructions depend on? Aside from implementation details (like >Intel refuses to speculate loads in them<, which, to be fair, might be its own problem), "cmovz D S" is just "jnz skip ; mov D S ; skip:" without the useless branch overhead.

Branches are in a different category than moves and ALU ops, for instruction reordering.

> Aside from implementation details

Re: RISC-V formal spec public review

#37
post #27

Earlier quoted context omitted.

Branches are in a different category than moves and ALU ops, for instruction reordering.

> Aside from implementation details

Performance is 100% implementation details, from top to bottom. And the only reason anybody uses a cmov instruction is for hoped-for better performance.

There is hope that it doesn't squat a precious branch-prediction slot, hope that it doesn't incur a branch misprediction pipeline stall if it's taken, or not taken, hope that fewer instructions translates to fewer clock cycles, hope that what looks like a copy really just does a register-renaming accounting trick, ...

Re: RISC-V formal spec public review

#38
post #25

Earlier quoted context omitted.

For an ISA whose main use will be IoT (at least in the beginning), this isn't good.. Rust didn't put integer overflow checks in release mode because current CPU don't provide "free" integer overflow detection, RISC V is even a regression over MIPS here..

> Rust didn't put integer overflow checks in release mode because current CPU don't provide "free" integer overflow detection Not really; the main performance drawback of obligate overflow checks is excessively-constrained semantics of the resulting code making optimization harder, not the direct CPU cost of checking. There are other ways of detecting possible overflows, and Rust does check for overflow in debug mode…

Interesting, do you have studies on this topic?

That said the 'CPU costs' of adding these branch are mostly ICache usage cost so benchmarks aren't very useful..

Post reply on HN