Skip to content

Commit

Permalink
Allow log2 pdll builtin to return a floating point value even if the …
Browse files Browse the repository at this point in the history
…log2 is not exact
  • Loading branch information
Ferdinand Lemaire committed Jul 9, 2024
1 parent ecad3c5 commit 31a681d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/PDL/IR/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ LogicalResult static unaryOp(PatternRewriter &rewriter, PDLResultList &results,
} else if constexpr (T == UnaryOpKind::log2) {
results.push_back(rewriter.getFloatAttr(
operandFloatAttr.getType(),
(double)operandFloatAttr.getValue().getExactLog2()));
std::log2(operandFloatAttr.getValueAsDouble())));
} else if constexpr (T == UnaryOpKind::abs) {
auto resultVal = operandFloatAttr.getValue();
resultVal.clearSign();
Expand Down
12 changes: 12 additions & 0 deletions mlir/unittests/Dialect/PDL/BuiltinTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,18 @@ TEST_F(BuiltinTest, log2) {
cast<FloatAttr>(result.cast<Attribute>()).getValue().convertToFloat(),
2.0);
}

auto threeF16 = rewriter.getF16FloatAttr(3.0);

// check correctness
{
TestPDLResultList results(1);
EXPECT_TRUE(builtin::log2(rewriter, results, {threeF16}).succeeded());

PDLValue result = results.getResults()[0];
float resultVal = cast<FloatAttr>(result.cast<Attribute>()).getValue().convertToFloat();
EXPECT_TRUE(resultVal > 1.58 && resultVal < 1.59);
}
}

TEST_F(BuiltinTest, exp2) {
Expand Down

0 comments on commit 31a681d

Please sign in to comment.