This is an archive of the discontinued LLVM Phabricator instance.

[RISCV]Add CTZ Intrinsic for ZBB in Clang
ClosedPublic

Authored by joker881 on Apr 24 2022, 9:56 AM.

Details

Summary

Add Intrinsics and test for B extension (updating coming soon (:

Diff Detail

Event Timeline

joker881 created this revision.Apr 24 2022, 9:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2022, 9:56 AM
joker881 requested review of this revision.Apr 24 2022, 9:56 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 24 2022, 9:56 AM
joker881 edited the summary of this revision. (Show Details)Apr 24 2022, 9:59 AM
joker881 added reviewers: craig.topper, MaskRay.
joker881 edited the summary of this revision. (Show Details)Apr 24 2022, 10:35 AM

The "B extension" terminology no longer exists.

clang/include/clang/Basic/BuiltinsRISCV.def
29

The only ones of these we need is ctz_32 and ctz_64 and they should be implemented the same as clz_32/clz_64.

I guess we might also need max_32/max_64/maxu_32/maxu_64/min_32/min_64/minu_32/minu_64 for -O0. For -O1 and above (x > y) ? x : y already works. They can use the existing llvm.smax/smin/umax/umin intrinsics.

andn can be represented directly in C with X & ~Y
orn is X | ~Y
cpop_32 is builtin_popcount
cpop_64 is
builtin_popcountll
clzw_32 is __builtin_riscv_clz_32 sign extended to 64 bits. Similar for ctzw_64.

llvm/include/llvm/IR/IntrinsicsRISCV.td
90 ↗(On Diff #424790)

We don't need any of these intrinsics.

Max already has llvm.smax and llvm.umax.
clzw is (signext (llvm.cltz))
cpop is llvm.ctpop
cpopw is (signext (llvm.ctpop))
andn is (and X, (not Y))
orn is (or X, (not Y))
ctz is llvm.ctlz

The "B extension" terminology no longer exists.

Thank you for your comments. I will consider them carefully. And I want to know that do you have any documents about intrinsic of bitmanip extension, like RISC-V Vector Extension Intrinsic Document.

kito-cheng added a comment.EditedApr 26 2022, 1:46 AM

And I want to know that do you have any documents about intrinsic of bitmanip extension, like RISC-V Vector Extension Intrinsic Document.

No, we didn't have a formal document for that, I expect we will have one once this finalized https://github.com/riscv-non-isa/riscv-c-api-doc/pull/25 ...

joker881 added a comment.EditedApr 28 2022, 3:36 AM

The "B extension" terminology no longer exists.

And I decide to implement ctz_32 and ctz_64 like clz.

joker881 updated this revision to Diff 425793.Apr 28 2022, 8:27 AM

Implement intrinsic ctz for bitmanip extension

craig.topper accepted this revision.Apr 28 2022, 9:19 PM

LGTM, but please fix the title to not use "B extension" since the "B extension" was never ratified. Only Zba, Zbb, Zbc, Zbs were ratified and there will never be a B.

This revision is now accepted and ready to land.Apr 28 2022, 9:19 PM
joker881 retitled this revision from [1/2][RISCV]Add Intrinsics for B extension in Clang to [RISCV]Add Intrinsics for ZBB in Clang.Apr 29 2022, 1:23 AM
joker881 retitled this revision from [RISCV]Add Intrinsics for ZBB in Clang to [RISCV]Add CTZ Intrinsic for ZBB in Clang.
joker881 updated this revision to Diff 426187.Apr 29 2022, 4:16 PM

update test

This revision was automatically updated to reflect the committed changes.