Skip to content

Commit

Permalink
Merge pull request #212 from Xilinx/ferdinand.update_log2_pdll_return…
Browse files Browse the repository at this point in the history
…_value

PDLL builtins: Allow float log2 to return even if the log2 is not exact
  • Loading branch information
flemairen6 authored Jul 10, 2024
2 parents ecad3c5 + 31a681d commit 54e2843
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 54e2843

Please sign in to comment.