1 //===-- Template for diffing remquo results ---------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_FUZZING_MATH_REMQUO_H
10 #define LLVM_LIBC_FUZZING_MATH_REMQUO_H
12 #include "src/__support/FPUtil/FPBits.h"
18 template <typename T
> using RemQuoFunc
= T (*)(T
, T
, int *);
21 void RemQuoDiff(RemQuoFunc
<T
> func1
, RemQuoFunc
<T
> func2
, const uint8_t *data
,
23 constexpr size_t typeSize
= sizeof(T
);
24 if (size
< 2 * typeSize
)
27 T x
= *reinterpret_cast<const T
*>(data
);
28 T y
= *reinterpret_cast<const T
*>(data
+ typeSize
);
31 T remainder1
= func1(x
, y
, &q1
);
32 T remainder2
= func2(x
, y
, &q2
);
34 if (isnan(remainder1
)) {
35 if (!isnan(remainder2
))
40 if (isinf(remainder2
) != isinf(remainder1
))
43 // Compare only the 3 LS bits of the quotient.
44 if ((q1
& 0x7) != (q2
& 0x7))
47 LIBC_NAMESPACE::fputil::FPBits
<T
> bits1(remainder1
);
48 LIBC_NAMESPACE::fputil::FPBits
<T
> bits2(remainder2
);
49 if (bits1
.uintval() != bits2
.uintval())
53 #endif // LLVM_LIBC_FUZZING_MATH_REMQUO_H