1 //===-- Exhaustive test template for math functions -------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <fenv.h>
10 #include <functional>
11 #include <iostream>
12 #include <sstream>
13 #include <string>
14 #include <thread>
15 #include <vector>
16 
17 #include "exhaustive_test.h"
18 #include "utils/UnitTest/Test.h"
19 
20 template <typename T>
21 void LlvmLibcExhaustiveTest<T>::test_full_range(T start, T stop, int nthreads,
22                                                 mpfr::RoundingMode rounding) {
23   std::vector<std::thread> thread_list(nthreads);
24   T increment = (stop - start - 1) / nthreads + 1;
25   T begin = start;
26   T end = start + increment - 1;
27   for (int i = 0; i < nthreads; ++i) {
28     thread_list.emplace_back([this, begin, end, rounding]() {
29       std::stringstream msg;
30       msg << "-- Testing from " << begin << " to " << end << " [0x" << std::hex
31           << begin << ", 0x" << end << ") ..." << std::endl;
32       std::cout << msg.str();
33       msg.str("");
34 
35       check(begin, end, rounding);
36 
37       msg << "** Finished testing from " << std::dec << begin << " to " << end
38           << " [0x" << std::hex << begin << ", 0x" << end << ")" << std::endl;
39       std::cout << msg.str();
40     });
41     begin += increment;
42     end += increment;
43     if (end > stop)
44       end = stop;
45   }
46   for (auto &thread : thread_list) {
47     if (thread.joinable()) {
48       thread.join();
49     }
50   }
51 }
52 
53 template void
54 LlvmLibcExhaustiveTest<uint32_t>::test_full_range(uint32_t, uint32_t, int,
55                                                   mpfr::RoundingMode);
56 template void
57 LlvmLibcExhaustiveTest<uint64_t>::test_full_range(uint64_t, uint64_t, int,
58                                                   mpfr::RoundingMode);
59