brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 2ae7e5c Raw
67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// 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 27namespace {28 29// Disambiguate the overloaded 'log2' function to select the double version30constexpr auto log2d // NOLINT(readability-identifier-naming)31    = static_cast<double (*)(double)>(log2);32} // namespace33 34namespace mathtest {35 36template <> 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 mathtest45 46int 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}67