This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][Power10] Implement Count Leading/Trailing Zeroes Builtins under bit Mask in LLVM/Clang
ClosedPublic

Authored by amyk on Jun 1 2020, 11:21 AM.

Details

Summary

This patch implements builtins for the following prototypes:

unsigned long long __builtin_cntlzdm (unsigned long long, unsigned long long)
unsigned long long __builtin_cnttzdm (unsigned long long, unsigned long long)
vector unsigned long long vec_cntlzm (vector unsigned long long, vector unsigned long long)
vector unsigned long long vec_cnttzm (vector unsigned long long, vector unsigned long long)

Depends on D80935

Diff Detail

Event Timeline

amyk created this revision.Jun 1 2020, 11:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2020, 11:21 AM
jsji added a reviewer: Restricted Project.Jun 1 2020, 11:22 AM
jsji added a project: Restricted Project.

Why not lower it to @llvm.cttz(and(a, b))?

nemanjai requested changes to this revision.Jun 2 2020, 5:33 AM

Why not lower it to @llvm.cttz(and(a, b))?

That's a great idea. Particularly in the back end where this pattern can appear irrespective of the use of the builtins.

This revision now requires changes to proceed.Jun 2 2020, 5:33 AM
amyk updated this revision to Diff 268331.Jun 3 2020, 4:12 PM
amyk retitled this revision from [PowerPC][Power10] Implement Count Leading/Trailing Zeroes Builtins in LLVM/Clang to [PowerPC][Power10] Implement Count Leading/Trailing Zeroes Builtins under bit Mask in LLVM/Clang.

Addressed review comment of lowering the function prototypes to use @llvm.ct[t|l]z and and.

Amy, I am really sorry. I initially did not read the description of the instructions in the ISA carefully. The semantics of these instructions are not actually (op (and a, b)). The mask is used to determine if a leading/trailing zero is counted or skipped.
Take for example the following two binary values:

Mask:  1001111
Value: 0010011

the result of cntlzdm Value, Mask should be 3 whereas the result of (ctlz (and Value, Mask)) would be 5. Namely, the instruction will count the first leading zero, ignore the next two bits and then count the next two zeros.

So you will need to revert back to the initial implementation. I am so sorry about going back and forth like this.

amyk updated this revision to Diff 268470.Jun 4 2020, 7:47 AM

Revert back to the initial implementation of the patch. Thanks Nemanja for clarifying.

nemanjai accepted this revision.Jun 9 2020, 2:33 AM

LGTM. Thanks Amy.

This revision is now accepted and ready to land.Jun 9 2020, 2:33 AM
This revision was automatically updated to reflect the committed changes.