Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: NaN propagation test for unary instructions
Browse files Browse the repository at this point in the history
gumb0 committed Aug 13, 2020

Partially verified

This commit is signed with the committer’s verified signature.
gsmet’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
1 parent 27ad94e commit 639400a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/unittests/execute_floating_point_test.cpp
Original file line number Diff line number Diff line change
@@ -223,6 +223,36 @@ TYPED_TEST(execute_floating_point_types, nan_matchers)
EXPECT_THAT(ExecutionResult{Value{-FP::nan(1)}}, Not(ArithmeticNaN(TypeParam{})));
}

TYPED_TEST(execute_floating_point_types, unop_nan_propagation)
{
// Tests NaN propagation in unary instructions (unnop).
// If NaN input is canonical NN, the result must be the canonical NaN.
// Otherwise, the result must be an arithmetic NaN.

// The list of instructions to be tested.
// Only f32 variants, but f64 variants are going to be covered as well.
constexpr Instr opcodes[] = {
Instr::f32_sqrt,
};

for (const auto op : opcodes)
{
auto instance = instantiate(parse(this->get_unop_code(op)));

const auto cnan = FP<TypeParam>::nan(FP<TypeParam>::canon);
EXPECT_THAT(execute(*instance, 0, {cnan}), CanonicalNaN(TypeParam{}));
EXPECT_THAT(execute(*instance, 0, {-cnan}), CanonicalNaN(TypeParam{}));

const auto anan = FP<TypeParam>::nan(FP<TypeParam>::canon + 1);
EXPECT_THAT(execute(*instance, 0, {anan}), ArithmeticNaN(TypeParam{}));
EXPECT_THAT(execute(*instance, 0, {-anan}), ArithmeticNaN(TypeParam{}));

const auto snan = FP<TypeParam>::nan(1);
EXPECT_THAT(execute(*instance, 0, {snan}), ArithmeticNaN(TypeParam{}));
EXPECT_THAT(execute(*instance, 0, {-snan}), ArithmeticNaN(TypeParam{}));
}
}

TYPED_TEST(execute_floating_point_types, binop_nan_propagation)
{
// Tests NaN propagation in binary instructions (binop).

0 comments on commit 639400a

Please sign in to comment.