This is an archive of the discontinued LLVM Phabricator instance.

APFloat: Add isSmallestNormalized predicate function
ClosedPublic

Authored by arsenm on Dec 1 2022, 8:25 AM.

Details

Summary

It was annoying to write the check for this in the one case I added,
and I'm planning on adding another, so add a convenient PatternMatch
like for other special case values.

I have no idea what is going on in the DoubleAPFloat case, I reversed
this from the makeSmallestNormalized test. Also could implement this
as *this == getSmallestNormalized() for less code, but this avoids the
construction of a temporary APFloat copy and follows the style of the
other functions.

Diff Detail

Event Timeline

arsenm created this revision.Dec 1 2022, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 8:25 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Dec 1 2022, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2022, 8:25 AM
Herald added a subscriber: wdng. · View Herald Transcript
sepavloff added inline comments.Dec 5 2022, 9:14 PM
llvm/include/llvm/ADT/APFloat.h
396

Returns *true* if...

llvm/lib/Support/APFloat.cpp
5022–5026

What prevents from using the same technique as in isSmallest? It looks more readable.

arsenm updated this revision to Diff 481811.Dec 9 2022, 6:29 PM
arsenm marked an inline comment as done.

Simplify DoubleFloat case

arsenm marked an inline comment as done.Dec 9 2022, 6:29 PM
arsenm updated this revision to Diff 482448.Dec 13 2022, 6:26 AM

Split out PatternMatch part

arsenm updated this revision to Diff 482461.Dec 13 2022, 7:02 AM

Really move the patternmatch part

sepavloff added inline comments.Dec 13 2022, 10:02 AM
llvm/unittests/ADT/APFloatTest.cpp
695

Could you please also specify the numbers explicitly as float/double? I mean tests like:

EXPECT_TRUE(APFloat(0x1.0p-126F).isSmallestNormalized());

and similar check for double?

arsenm updated this revision to Diff 482835.Dec 14 2022, 6:22 AM
arsenm marked an inline comment as done.

Also check parsed strings in getSmallestNormalized

This revision is now accepted and ready to land.Dec 15 2022, 3:50 AM