Unverified Commit 1561e51a authored by Anonmiraj's avatar Anonmiraj Committed by GitHub
Browse files

[libc][math] Refactor isnan family to header-only (#195598)

Refactors the isnan math family to be header-only.

part of: #147386

Target Functions:
  - isnan
  - isnanf
  - isnanl
  
Also adds `__LIBC_USE_BUILTIN_ISNAN` compiler feature detection
parent 52340a4f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ set(
    "builtin_ceil_floor_rint_trunc"
    "builtin_fmax_fmin"
    "builtin_fmaxf16_fminf16"
    "builtin_isnan"
    "builtin_round"
    "builtin_roundeven"
    "float16"
@@ -123,6 +124,8 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
      set(LIBC_COMPILER_HAS_BUILTIN_FMAX_FMIN TRUE)
    elseif(${feature} STREQUAL "builtin_fmaxf16_fminf16")
      set(LIBC_COMPILER_HAS_BUILTIN_FMAXF16_FMINF16 TRUE)
    elseif(${feature} STREQUAL "builtin_isnan")
      set(LIBC_COMPILER_HAS_BUILTIN_ISNAN TRUE)
    elseif(${feature} STREQUAL "builtin_round")
      set(LIBC_COMPILER_HAS_BUILTIN_ROUND TRUE)
    elseif(${feature} STREQUAL "builtin_roundeven")
+3 −0
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@ function(_get_compile_options_from_flags output_var)
        list(APPEND compile_options "-mfma")
      endif()
    endif()
    if(LIBC_COMPILER_HAS_BUILTIN_ISNAN)
      list(APPEND compile_options "-D__LIBC_USE_BUILTIN_ISNAN")
    endif()
    if(ADD_ROUND_OPT_FLAG)
      if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
        # ROUND_OPT_FLAG is only enabled if SSE4.2 is detected, not just SSE4.1,
+5 −0
Original line number Diff line number Diff line
int try_builtin_isnan(double x) { return __builtin_isnan(x); }
int try_builtin_isnanf(float x) { return __builtin_isnan(x); }
int try_builtin_isnanl(long double x) { return __builtin_isnan(x); }

extern "C" void _start() {}
+3 −0
Original line number Diff line number Diff line
@@ -287,6 +287,9 @@
#include "math/iscanonicalf128.h"
#include "math/iscanonicalf16.h"
#include "math/iscanonicall.h"
#include "math/isnan.h"
#include "math/isnanf.h"
#include "math/isnanl.h"
#include "math/issignaling.h"
#include "math/issignalingbf16.h"
#include "math/issignalingf.h"
+23 −0
Original line number Diff line number Diff line
//===-- Shared isnan function -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_MATH_ISNAN_H
#define LLVM_LIBC_SHARED_MATH_ISNAN_H

#include "shared/libc_common.h"
#include "src/__support/math/isnan.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using math::isnan;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_MATH_ISNAN_H
Loading