News for hackers. Stuff that matters.
Re:RISC-V Stumbling Blocks by jleahy on Thursday January 02, 2020 @06:28AM (#21934525)
It's a single instruction to then subtract 1 from the result of SLT/SLTI, which then gives you 0xffffffff or 0x00000000 rather than 0 or 1, which you can use as a mask.

RISC-V was designed to be a good target for a C compiler, given that's what people almost always need. Compilers frequently see code line `int x = (a > b)` and SLT is perfect for that. Compilers don't do clever masking tricks to avoid branches, in general (there are a few hard-coded tricks like divide by signed constant).

Re:RISC-V Stumbling Blocks by bonzini on Thursday January 02, 2020 @08:14AM (#21935071)
> Compilers don't do clever masking tricks to avoid branches, in general

They actually do a lot of such tricks. Check out the GCC sources, for example tree-ssa-phiopt.c[1] and ifcvt.c[2]

[1] https://github.com/gcc-mirror/gcc/blob/master/gcc/tree-ssa-p...

[2] https://github.com/gcc-mirror/gcc/blob/master/gcc/ifcvt.c

Re:RISC-V Stumbling Blocks by ncmncm on Thursday January 02, 2020 @01:51PM (#21938393)
They do it a bit, but they leave a very great deal on the table. Clang will convert

  a = (b&m)|(c&~m)
into cmov, but gcc won't.
Re:RISC-V Stumbling Blocks by jleahy on Thursday January 02, 2020 @09:14AM (#21935466)
Well I was thinking of ifcvt when I mentioned a few special cases. Particularly things like minmax and abs are very specific.
Re:RISC-V Stumbling Blocks by ncmncm on Thursday January 02, 2020 @06:37AM (#21934563)
In other words, two more instructions, instead of zero.

That compilers fail to do clever masking tricks to avoid branches frequently results in 2x slower programs.

Re:RISC-V Stumbling Blocks by avianes on Thursday January 02, 2020 @07:53AM (#21934947)
No, as jleahy said, it cost a single instruction to transform 0 to 0b00..00 and 1 to 0b11..11 - SUB X, $0, X.

And your proposal - using the zero register as a flag register - breaks way more micro-optimizations (like the simple ones described in "The RISC-V Reader" book) than it allows