Bit Manipulation C code style testing

162 views
Skip to first unread message

Rohan Ahmed

unread,
Apr 17, 2024, 5:08:18 AMApr 17
to RISC-V ISA Dev

Hi, I am trying to emit the orc.b instruction with a c program. I wrote different scalar optmized c code but it didn't generate the orc.b instruction and I have to provide the pure scalar code which emits this instruction. can you suggest something

Also I am able to generate all others zbb type instruction using scalar code, you can found in this sheet.
https://docs.google.com/spreadsheets/d/1A5dQQVhP_8RrnpvLiUgXO3rc5Q2yjKwAMJNZpheK2RM/edit#gid=556068285

Christoph Müllner

unread,
Apr 17, 2024, 5:26:01 AMApr 17
to Rohan Ahmed, RISC-V ISA Dev
What are real-world code examples where orc.b could be used?
GCC has inline expansion for str(n)cmp/strlen, which utilizes orc.b
(if the requirements are met):
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/riscv/riscv-string.cc;h=b09b51d7526b9085cdd20706d10f95ecff91db69;hb=HEAD#l147

BR
Christoph
> --
> You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
> To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/aa607f7f-8e89-4e3a-a2c8-709dac6247d0n%40groups.riscv.org.

Rohan Ahmed

unread,
Apr 17, 2024, 6:10:17 AMApr 17
to RISC-V ISA Dev, Christoph Müllner, RISC-V ISA Dev, Rohan Ahmed
orc.b appear to be well-suited for the byte mask generation

Regards,
Rohan Ahmed

Rohan Ahmed

unread,
Apr 17, 2024, 6:59:44 AMApr 17
to RISC-V ISA Dev, Rohan Ahmed, Christoph Müllner, RISC-V ISA Dev
is there any way, we can emit orc.b instruction using scalar c code like others in sheet?

Thanks,
Rohan Ahmed

Christoph Müllner

unread,
Apr 17, 2024, 7:08:07 AMApr 17
to Rohan Ahmed, RISC-V ISA Dev
Regarding the byte mask generation:
Where would orc.b be superior over existing approaches?
You still have to set a bit in each byte.

The two examples in your spreadsheet are attempts to synthesize an
orc.b in C code.
However, where would this code then be used?

As mentioned, GCC only emits orc.b via str*/mem* inline expansion (if
the requirements for that are fulfilled).
Other than that you can just use the __riscv_orc_b_* intrinsics.

BR
Christoph

Tommy Murphy

unread,
Apr 17, 2024, 8:05:19 AMApr 17
to Christoph Müllner, Rohan Ahmed, RISC-V ISA Dev
Other than that you can just use the __riscv_orc_b_* intrinsics.

Bruce Hoult

unread,
Apr 17, 2024, 10:20:23 PMApr 17
to Rohan Ahmed, RISC-V ISA Dev
I have already explained to you, at length, that there is no guarantee
that any particular instruction can be generated from pattern matching
plain C code in any given compiler. I have also given you the kind of
code that might be matched in some compiler, if any is.

https://new.reddit.com/r/RISCV/comments/syu3s3/comment/kzybuy0/?context=3

Rohan Ahmed

unread,
Apr 18, 2024, 12:33:09 AMApr 18
to RISC-V ISA Dev, Bruce Hoult, RISC-V ISA Dev, Rohan Ahmed
Thanks to all of you for giving your insights.

BR,
Rohan
Reply all
Reply to author
Forward
Message has been deleted
0 new messages