| 1 |
//===----------------------------------------------------------------------===// |
| 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 |
/// \file |
| 10 |
/// This file contains the conformance test of the log2 function. |
| 11 |
/// |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#include "mathtest/CommandLineExtras.hpp" |
| 15 |
#include "mathtest/IndexedRange.hpp" |
| 16 |
#include "mathtest/RandomGenerator.hpp" |
| 17 |
#include "mathtest/RandomState.hpp" |
| 18 |
#include "mathtest/TestConfig.hpp" |
| 19 |
#include "mathtest/TestRunner.hpp" |
| 20 |
|
| 21 |
#include "llvm/ADT/StringRef.h" |
| 22 |
|
| 23 |
#include <cstdlib> |
| 24 |
#include <limits> |
| 25 |
#include <math.h> |
| 26 |
|
| 27 |
namespace { |
| 28 |
|
| 29 |
// Disambiguate the overloaded 'log2' function to select the double version |
| 30 |
constexpr auto log2d // NOLINT(readability-identifier-naming) |
| 31 |
= static_cast<double (*)(double)>(log2); |
| 32 |
} // namespace |
| 33 |
|
| 34 |
namespace mathtest { |
| 35 |
|
| 36 |
template <> struct FunctionConfig<log2d> { |
| 37 |
static constexpr llvm::StringRef Name = "log2"; |
| 38 |
static constexpr llvm::StringRef KernelName = "log2Kernel"; |
| 39 |
|
| 40 |
// Source: The Khronos Group, The OpenCL C Specification v3.0.19, Sec. 7.4, |
| 41 |
// Table 68, Khronos Registry [July 10, 2025]. |
| 42 |
static constexpr uint64_t UlpTolerance = 3; |
| 43 |
}; |
| 44 |
} // namespace mathtest |
| 45 |
|
| 46 |
int main(int argc, const char **argv) { |
| 47 |
llvm::cl::ParseCommandLineOptions(argc, argv, |
| 48 |
"Conformance test of the log2 function"); |
| 49 |
|
| 50 |
using namespace mathtest; |
| 51 |
|
| 52 |
uint64_t Seed = 42; |
| 53 |
uint64_t Size = 1ULL << 32; |
| 54 |
IndexedRange<double> Range(/*Begin=*/0.0, |
| 55 |
/*End=*/std::numeric_limits<double>::infinity(), |
| 56 |
/*Inclusive=*/true); |
| 57 |
RandomGenerator<double> Generator(SeedTy{Seed}, Size, Range); |
| 58 |
|
| 59 |
const auto Configs = cl::getTestConfigs(); |
| 60 |
const llvm::StringRef DeviceBinaryDir = DEVICE_BINARY_DIR; |
| 61 |
const bool IsVerbose = cl::IsVerbose; |
| 62 |
|
| 63 |
bool Passed = runTests<log2d>(Generator, Configs, DeviceBinaryDir, IsVerbose); |
| 64 |
|
| 65 |
return Passed ? EXIT_SUCCESS : EXIT_FAILURE; |
| 66 |
} |