This is an archive of the discontinued LLVM Phabricator instance.

APFloat: Add getExactLog2
ClosedPublic

Authored by arsenm on Aug 4 2023, 8:17 AM.

Diff Detail

Event Timeline

arsenm created this revision.Aug 4 2023, 8:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 8:17 AM
arsenm requested review of this revision.Aug 4 2023, 8:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 8:17 AM
Herald added a subscriber: wdng. · View Herald Transcript
foad added inline comments.Aug 4 2023, 8:20 AM
llvm/include/llvm/ADT/APFloat.h
495

"getExactLog2" or similar would make more sense to me.

arsenm updated this revision to Diff 547237.Aug 4 2023, 8:42 AM
arsenm retitled this revision from APFloat: Add getExactPowerOf2 to APFloat: Add getExactLog2.

Rename

jcranmer-intel added inline comments.Aug 4 2023, 11:25 AM
llvm/lib/Support/APFloat.cpp
4306

I would like to see a test that exercises the case of two different parts each having popcount = 1. Testing next(false) on the existing subnormal checks should do the trick, I think.

arsenm added inline comments.Aug 4 2023, 2:07 PM
llvm/lib/Support/APFloat.cpp
4306
if (PartCount == 2) {
  assert(!(llvm::popcount(Parts[0]) == 1 && llvm::popcount(Parts[0]) == 1));
}

already fires on the existing tests

foad added inline comments.Aug 7 2023, 1:47 AM
llvm/include/llvm/ADT/APFloat.h
493

Do you intentionally ignore the sign bit? Should at least document that, since most people would not call -8 a power of two.

arsenm updated this revision to Diff 547743.Aug 7 2023, 5:40 AM

Fail on negative

foad accepted this revision.Aug 7 2023, 5:45 AM
This revision is now accepted and ready to land.Aug 7 2023, 5:45 AM