3 ms·
> a = (x & c) | (y & ~c) > is a branch-free conditional assignment, and only works with c = 0 or ~0. Using this hack only makes sense if there is no "condit
by avianes 6y ago
> a = (x & c) | (y & ~c)
> is a branch-free conditional assignment, and only works with c = 0 or ~0.
Using this hack only makes sense if there is no "conditional move".
But the bitmanip risc-v extension offers a "conditional move" (cmov) [1].
With the addition of this operation there's no longer a need to use "0/-1" instead of "0/1".
[1]: https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip-0.92.pdf https://github.com/riscv/riscv-bitmanip/blob/master/bitmanip...
page 36
PS: You may notice that there's also an operation (cmix: conditional max) to do what you're suggesting: rd = (rs1 & rs2) | (rs3 & ~rs2)
Which allows to mix the bits of two registers.
- klyrs 6y agoAgreed, all that's better than my hacks.
- ncmncm 6y agoThere are no bitmanip extensions in the core instruction set where it is needed. And there are no bitmanip extensions in any existing chips, may never be in any future chips, and will likely not be in future microcontrollers if it ever does get adopted, so anything you find there is moot. The notion that basic bit manipulation primitives are an obscure optional feature is a serious problem in the RISC-V process.
- avianes 6y ago> There are no bitmanip extensions in the core instruction set where it is needed. That's the whole idea of an extension. You may or may not include it depending on your needs. > And there are no bitmanip extensions in any existing chips RISC-V is a big project, and it is not yet complete. Some extensions are completed and some are not. The bitmanip extension is not finished yet, so it's understandable that it hasn't yet been integrated into chips. > may never be in any future chips Where did that statement come from? > The notion that basic bit manipulation primitives are an obscure optional feature is a serious problem in the RISC-V process. Bit manipulation is not an "obscure optional feature", but an "optional feature" just like the other extensions. Please explain why this is a problem? You're just blaming RISC-V without any argument there.
- klyrs 6y agoIt's an open source ecosystem. This piece sounds important to you. Have you considered contributing? It sounds like you've identified a niche that isn't filled -- perhaps you could "corner the market" taking advantage of the SkyWater / Google offering. A risc-v microcontroller with the bitmanip extensions would be very cool, and its existence could prompt compilers to start targeting it. Go for it!