-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc][NFC] Move float macro into its own header / add target os detection #73311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===-- Float type support --------------------------------------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// Floating point properties are a combination of compiler support, target OS | ||
// and target architecture. | ||
|
||
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_FLOAT_H | ||
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_FLOAT_H | ||
|
||
#include "src/__support/macros/properties/architectures.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
#include "src/__support/macros/properties/os.h" | ||
|
||
// https://developer.arm.com/documentation/dui0491/i/C-and-C---Implementation-Details/Basic-data-types | ||
// https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms | ||
// https://docs.amd.com/bundle/HIP-Programming-Guide-v5.1/page/Programming_with_HIP.html | ||
#if defined(LIBC_TARGET_OS_IS_WINDOWS) || \ | ||
(defined(LIBC_TARGET_OS_IS_MACOS) && \ | ||
defined(LIBC_TARGET_ARCH_IS_AARCH64)) || \ | ||
defined(LIBC_TARGET_ARCH_IS_ARM) || defined(LIBC_TARGET_ARCH_IS_NVPTX) || \ | ||
defined(LIBC_TARGET_ARCH_IS_AMDGPU) | ||
#define LONG_DOUBLE_IS_DOUBLE | ||
#endif | ||
|
||
#if !defined(LONG_DOUBLE_IS_DOUBLE) && defined(LIBC_TARGET_ARCH_IS_X86) | ||
#define SPECIAL_X86_LONG_DOUBLE | ||
#endif | ||
|
||
// Check compiler features | ||
#if defined(FLT128_MANT_DIG) | ||
#define LIBC_COMPILER_HAS_FLOAT128 | ||
using float128 = _Float128; | ||
#elif defined(__SIZEOF_FLOAT128__) | ||
#define LIBC_COMPILER_HAS_FLOAT128 | ||
using float128 = __float128; | ||
#elif (defined(__linux__) && defined(__aarch64__)) | ||
#define LIBC_COMPILER_HAS_FLOAT128 | ||
#define LIBC_FLOAT128_IS_LONG_DOUBLE | ||
using float128 = long double; | ||
#endif | ||
|
||
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_FLOAT_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//===-- Target OS detection -------------------------------------*- 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_SRC___SUPPORT_MACROS_PROPERTIES_OS_H | ||
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_OS_H | ||
|
||
#if (defined(__freebsd__) || defined(__FreeBSD__)) | ||
#define LIBC_TARGET_OS_IS_FREEBSD | ||
#endif | ||
|
||
#if defined(__ANDROID__) | ||
#define LIBC_TARGET_OS_IS_ANDROID | ||
#endif | ||
|
||
#if defined(__linux__) && !defined(LIBC_TARGET_OS_IS_FREEBSD) && \ | ||
!defined(LIBC_TARGET_OS_IS_ANDROID) | ||
#define LIBC_TARGET_OS_IS_LINUX | ||
#endif | ||
|
||
#if (defined(_WIN64) || defined(_WIN32)) | ||
#define LIBC_TARGET_OS_IS_WINDOWS | ||
#endif | ||
|
||
#if (defined(__apple__) || defined(__APPLE__) || defined(__MACH__)) | ||
// From https://stackoverflow.com/a/49560690 | ||
#include "TargetConditionals.h" | ||
#if defined(TARGET_OS_OSX) | ||
#define LIBC_TARGET_OS_IS_MACOS | ||
#endif | ||
#if defined(TARGET_OS_IPHONE) | ||
// This is set for any non-Mac Apple products (IOS, TV, WATCH) | ||
#define LIBC_TARGET_OS_IS_IPHONE | ||
#endif | ||
#endif | ||
|
||
#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_OS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
#ifndef LLVM_LIBC_SRC_MATH_COPYSIGNF128_H | ||
#define LLVM_LIBC_SRC_MATH_COPYSIGNF128_H | ||
|
||
#include "src/__support/macros/properties/compiler.h" | ||
#include "src/__support/macros/properties/float.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably want to add a cmake dep for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll do this is a separate patch as well because |
||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a bunch of deps, you might want to add them too (in a separate patch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for noticing I'll fix this in a separate patch.