1616
1717namespace LIBC_NAMESPACE_DECL {
1818namespace testing {
19-
20- template < typename T> class BinaryOpSingleOutputPerf {
21- using FPBits = fputil::FPBits<T >;
19+ template < typename OutputType, typename InputType>
20+ class BinaryOpSingleOutputPerf {
21+ using FPBits = fputil::FPBits<OutputType >;
2222 using StorageType = typename FPBits::StorageType;
2323 static constexpr StorageType UIntMax =
2424 cpp::numeric_limits<StorageType>::max();
2525
2626public:
27- typedef T Func (T, T );
27+ typedef OutputType Func (InputType, InputType );
2828
2929 static void run_perf_in_range (Func myFunc, Func otherFunc,
3030 StorageType startingBit, StorageType endingBit,
@@ -33,7 +33,7 @@ template <typename T> class BinaryOpSingleOutputPerf {
3333 N = cpp::min (N, static_cast <size_t >(endingBit - startingBit));
3434
3535 auto runner = [=](Func func) {
36- [[maybe_unused]] volatile T result;
36+ [[maybe_unused]] volatile OutputType result;
3737 if (endingBit < startingBit) {
3838 return ;
3939 }
@@ -42,8 +42,8 @@ template <typename T> class BinaryOpSingleOutputPerf {
4242 for (size_t i = 0 ; i < rounds; i++) {
4343 for (StorageType bitsX = startingBit, bitsY = endingBit;;
4444 bitsX += step, bitsY -= step) {
45- T x = FPBits (bitsX).get_val ();
46- T y = FPBits (bitsY).get_val ();
45+ InputType x = FPBits (bitsX).get_val ();
46+ InputType y = FPBits (bitsY).get_val ();
4747 result = func (x, y);
4848 if (endingBit - bitsX < step) {
4949 break ;
@@ -94,10 +94,11 @@ template <typename T> class BinaryOpSingleOutputPerf {
9494 1'000'001 , rounds, log);
9595 log << " \n Performance tests with inputs in normal range with exponents "
9696 " close to each other:\n " ;
97- run_perf_in_range (myFunc, otherFunc,
98- /* startingBit= */ FPBits (T (0x1 .0p-10 )).uintval (),
99- /* endingBit= */ FPBits (T (0x1 .0p+10 )).uintval (),
100- 1'000'001 , rounds, log);
97+ run_perf_in_range (
98+ myFunc, otherFunc,
99+ /* startingBit= */ FPBits (OutputType (0x1 .0p-10 )).uintval (),
100+ /* endingBit= */ FPBits (OutputType (0x1 .0p+10 )).uintval (), 1'000'001 ,
101+ rounds, log);
101102 }
102103
103104 static void run_diff (Func myFunc, Func otherFunc, const char *logFile) {
@@ -115,8 +116,10 @@ template <typename T> class BinaryOpSingleOutputPerf {
115116 log << " \n Diff tests with inputs in normal range with exponents "
116117 " close to each other:\n " ;
117118 diffCount += run_diff_in_range (
118- myFunc, otherFunc, /* startingBit= */ FPBits (T (0x1 .0p-10 )).uintval (),
119- /* endingBit= */ FPBits (T (0x1 .0p+10 )).uintval (), 10'000'001 , log);
119+ myFunc, otherFunc,
120+ /* startingBit= */ FPBits (OutputType (0x1 .0p-10 )).uintval (),
121+ /* endingBit= */ FPBits (OutputType (0x1 .0p+10 )).uintval (), 10'000'001 ,
122+ log);
120123
121124 log << " Total number of differing results: " << diffCount << ' \n ' ;
122125 }
@@ -125,18 +128,21 @@ template <typename T> class BinaryOpSingleOutputPerf {
125128} // namespace testing
126129} // namespace LIBC_NAMESPACE_DECL
127130
128- #define BINARY_OP_SINGLE_OUTPUT_PERF (T, myFunc, otherFunc, filename ) \
131+ #define BINARY_OP_SINGLE_OUTPUT_PERF (OutputType, InputType, myFunc, otherFunc, \
132+ filename) \
129133 int main () { \
130- LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf<T>:: run_perf ( \
131- &myFunc, &otherFunc, 1 , filename); \
134+ LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf< \
135+ OutputType, InputType>:: run_perf ( &myFunc, &otherFunc, 1 , filename); \
132136 return 0 ; \
133137 }
134138
135- #define BINARY_OP_SINGLE_OUTPUT_PERF_EX (T, myFunc, otherFunc, rounds, \
136- filename) \
139+ #define BINARY_OP_SINGLE_OUTPUT_PERF_EX (OutputType, InputType, myFunc, \
140+ otherFunc, rounds, filename) \
137141 { \
138- LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf<T>::run_perf ( \
139- &myFunc, &otherFunc, rounds, filename); \
140- LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf<T>::run_perf ( \
141- &myFunc, &otherFunc, rounds, filename); \
142+ LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf< \
143+ OutputType, InputType>::run_perf (&myFunc, &otherFunc, rounds, \
144+ filename); \
145+ LIBC_NAMESPACE::testing::BinaryOpSingleOutputPerf< \
146+ OutputType, InputType>::run_perf (&myFunc, &otherFunc, rounds, \
147+ filename); \
142148 }
0 commit comments