Skip to content

Commit 54e2843

Browse files
authored
Merge pull request #212 from Xilinx/ferdinand.update_log2_pdll_return_value
PDLL builtins: Allow float log2 to return even if the log2 is not exact
2 parents ecad3c5 + 31a681d commit 54e2843

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mlir/lib/Dialect/PDL/IR/Builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ LogicalResult static unaryOp(PatternRewriter &rewriter, PDLResultList &results,
169169
} else if constexpr (T == UnaryOpKind::log2) {
170170
results.push_back(rewriter.getFloatAttr(
171171
operandFloatAttr.getType(),
172-
(double)operandFloatAttr.getValue().getExactLog2()));
172+
std::log2(operandFloatAttr.getValueAsDouble())));
173173
} else if constexpr (T == UnaryOpKind::abs) {
174174
auto resultVal = operandFloatAttr.getValue();
175175
resultVal.clearSign();

mlir/unittests/Dialect/PDL/BuiltinTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ TEST_F(BuiltinTest, log2) {
634634
cast<FloatAttr>(result.cast<Attribute>()).getValue().convertToFloat(),
635635
2.0);
636636
}
637+
638+
auto threeF16 = rewriter.getF16FloatAttr(3.0);
639+
640+
// check correctness
641+
{
642+
TestPDLResultList results(1);
643+
EXPECT_TRUE(builtin::log2(rewriter, results, {threeF16}).succeeded());
644+
645+
PDLValue result = results.getResults()[0];
646+
float resultVal = cast<FloatAttr>(result.cast<Attribute>()).getValue().convertToFloat();
647+
EXPECT_TRUE(resultVal > 1.58 && resultVal < 1.59);
648+
}
637649
}
638650

639651
TEST_F(BuiltinTest, exp2) {

0 commit comments

Comments
 (0)