Skip to content

Commit 825f3b6

Browse files
committed
merge main into amd-staging
Revert : breaks lots of OCL tests. 7cfffe7 Unittests and usability for BitstreamWriter incremental flushing (llvm#92983) Change-Id: Ic52106ccfb631168b99bae34ab6d14ad3a548408
2 parents 609fb0e + 0eb9e02 commit 825f3b6

File tree

22 files changed

+148
-32
lines changed

22 files changed

+148
-32
lines changed

libc/cmake/modules/CheckCompilerFeatures.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Compiler features definition and flags
33
# ------------------------------------------------------------------------------
44

5-
set(ALL_COMPILER_FEATURES "float128" "fixed_point")
5+
set(ALL_COMPILER_FEATURES "float16" "float128" "fixed_point")
66

77
# Making sure ALL_COMPILER_FEATURES is sorted.
88
list(SORT ALL_COMPILER_FEATURES)
@@ -54,7 +54,9 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
5454
)
5555
if(has_feature)
5656
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})
57-
if(${feature} STREQUAL "float128")
57+
if(${feature} STREQUAL "float16")
58+
set(LIBC_TYPES_HAS_FLOAT16 TRUE)
59+
elseif(${feature} STREQUAL "float128")
5860
set(LIBC_TYPES_HAS_FLOAT128 TRUE)
5961
elseif(${feature} STREQUAL "fixed_point")
6062
set(LIBC_COMPILER_HAS_FIXED_POINT TRUE)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "include/llvm-libc-macros/float16-macros.h"
2+
3+
#ifndef LIBC_TYPES_HAS_FLOAT16
4+
#error unsupported
5+
#endif

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ set(TARGET_LIBM_ENTRYPOINTS
496496
libc.src.math.ufromfpxl
497497
)
498498

499+
if(LIBC_TYPES_HAS_FLOAT16)
500+
list(APPEND TARGET_LIBM_ENTRYPOINTS
501+
# math.h C23 _Float16 entrypoints
502+
libc.src.math.fabsf16
503+
)
504+
endif()
505+
499506
if(LIBC_TYPES_HAS_FLOAT128)
500507
list(APPEND TARGET_LIBM_ENTRYPOINTS
501508
# math.h C23 _Float128 entrypoints

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,13 @@ set(TARGET_LIBM_ENTRYPOINTS
528528
libc.src.math.ufromfpxl
529529
)
530530

531+
if(LIBC_TYPES_HAS_FLOAT16)
532+
list(APPEND TARGET_LIBM_ENTRYPOINTS
533+
# math.h C23 _Float16 entrypoints
534+
libc.src.math.fabsf16
535+
)
536+
endif()
537+
531538
if(LIBC_TYPES_HAS_FLOAT128)
532539
list(APPEND TARGET_LIBM_ENTRYPOINTS
533540
# math.h C23 _Float128 entrypoints

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Basic Operations
124124
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
125125
| dsub | N/A | N/A | | N/A | | 7.12.14.2 | F.10.11 |
126126
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
127-
| fabs | |check| | |check| | |check| | | |check| | 7.12.7.3 | F.10.4.3 |
127+
| fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 |
128128
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
129129
| fadd | N/A | | | N/A | | 7.12.14.1 | F.10.11 |
130130
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ add_gen_header(
111111
GEN_HDR math.h
112112
DEPENDS
113113
.llvm_libc_common_h
114+
.llvm-libc-macros.float16_macros
114115
.llvm-libc-macros.math_macros
115116
.llvm-libc-types.double_t
116117
.llvm-libc-types.float_t

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ add_macro_header(
9191
float-macros.h
9292
)
9393

94+
add_macro_header(
95+
float16_macros
96+
HDR
97+
float16-macros.h
98+
)
99+
94100
add_macro_header(
95101
limits_macros
96102
HDR
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Detection of _Float16 compiler builtin type -----------------------===//
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+
#ifndef LLVM_LIBC_MACROS_FLOAT16_MACROS_H
10+
#define LLVM_LIBC_MACROS_FLOAT16_MACROS_H
11+
12+
#if defined(__FLT16_MANT_DIG__) && \
13+
(!defined(__GNUC__) || __GNUC__ >= 13 || defined(__clang__))
14+
#define LIBC_TYPES_HAS_FLOAT16
15+
#endif
16+
17+
#endif // LLVM_LIBC_MACROS_FLOAT16_MACROS_H

libc/include/math.h.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_LIBC_MATH_H
1111

1212
#include "__llvm-libc-common.h"
13+
#include "llvm-libc-macros/float16-macros.h"
1314
#include "llvm-libc-macros/math-macros.h"
1415
#include "llvm-libc-types/float128.h"
1516

libc/spec/spec.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def UnsignedCharType : NamedType<"unsigned char">;
5353
def UnsignedShortType : NamedType<"unsigned short">;
5454
def BoolType : NamedType<"bool">;
5555

56+
def Float16Type : NamedType<"_Float16">;
5657
def Float128Type : NamedType<"float128">;
5758

5859
// Common types

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ def StdC : StandardSpec<"stdc"> {
395395
FunctionSpec<"fabs", RetValSpec<DoubleType>, [ArgSpec<DoubleType>], [ConstAttr]>,
396396
FunctionSpec<"fabsf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
397397
FunctionSpec<"fabsl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>]>,
398+
GuardedFunctionSpec<"fabsf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
398399
GuardedFunctionSpec<"fabsf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
399400

400401
FunctionSpec<"fdim", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,

libc/src/__support/CPP/type_traits/is_floating_point.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ template <typename T> struct is_floating_point {
2424
}
2525

2626
public:
27-
#if defined(LIBC_TYPES_HAS_FLOAT128)
2827
LIBC_INLINE_VAR static constexpr bool value =
29-
__is_unqualified_any_of<T, float, double, long double, float128>();
30-
#else
31-
LIBC_INLINE_VAR static constexpr bool value =
32-
__is_unqualified_any_of<T, float, double, long double>();
33-
#endif // LIBC_TYPES_HAS_FLOAT128
28+
__is_unqualified_any_of<T, float, double, long double
29+
#ifdef LIBC_TYPES_HAS_FLOAT16
30+
,
31+
float16
32+
#endif
33+
#ifdef LIBC_TYPES_HAS_FLOAT128
34+
,
35+
float128
36+
#endif
37+
>();
3438
};
3539
template <typename T>
3640
LIBC_INLINE_VAR constexpr bool is_floating_point_v =

libc/src/__support/FPUtil/FPBits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ struct FPRepImpl : public FPRepSem<fp_type, RetT> {
651651

652652
// Modifiers
653653
LIBC_INLINE constexpr RetT abs() const {
654-
return RetT(bits & UP::EXP_SIG_MASK);
654+
return RetT(static_cast<StorageType>(bits & UP::EXP_SIG_MASK));
655655
}
656656

657657
// Observers

libc/src/__support/macros/properties/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ add_header_library(
3434
.cpu_features
3535
.os
3636
libc.hdr.float_macros
37+
libc.include.llvm-libc-macros.float16_macros
3738
libc.include.llvm-libc-types.float128
3839
)

libc/src/__support/macros/properties/types.h

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
1212

1313
#include "hdr/float_macros.h" // LDBL_MANT_DIG
14-
#include "include/llvm-libc-types/float128.h" // float128
14+
#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
15+
#include "include/llvm-libc-types/float128.h" // float128
1516
#include "src/__support/macros/properties/architectures.h"
1617
#include "src/__support/macros/properties/compiler.h"
1718
#include "src/__support/macros/properties/cpu_features.h"
@@ -39,28 +40,12 @@
3940
#endif // defined(__SIZEOF_INT128__)
4041

4142
// -- float16 support ---------------------------------------------------------
42-
// TODO: move this logic to "llvm-libc-types/float16.h"
43-
#if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2)
44-
#if (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 1500)) || \
45-
(defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1201))
46-
#define LIBC_TYPES_HAS_FLOAT16
43+
// LIBC_TYPES_HAS_FLOAT16 is provided by
44+
// "include/llvm-libc-macros/float16-macros.h"
45+
#ifdef LIBC_TYPES_HAS_FLOAT16
46+
// Type alias for internal use.
4747
using float16 = _Float16;
48-
#endif
49-
#endif
50-
#if defined(LIBC_TARGET_ARCH_IS_AARCH64)
51-
#if (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 900)) || \
52-
(defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301))
53-
#define LIBC_TYPES_HAS_FLOAT16
54-
using float16 = _Float16;
55-
#endif
56-
#endif
57-
#if defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
58-
#if (defined(LIBC_COMPILER_CLANG_VER) && (LIBC_COMPILER_CLANG_VER >= 1300)) || \
59-
(defined(LIBC_COMPILER_GCC_VER) && (LIBC_COMPILER_GCC_VER >= 1301))
60-
#define LIBC_TYPES_HAS_FLOAT16
61-
using float16 = _Float16;
62-
#endif
63-
#endif
48+
#endif // LIBC_TYPES_HAS_FLOAT16
6449

6550
// -- float128 support --------------------------------------------------------
6651
// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ add_math_entrypoint_object(expm1f)
9999
add_math_entrypoint_object(fabs)
100100
add_math_entrypoint_object(fabsf)
101101
add_math_entrypoint_object(fabsl)
102+
add_math_entrypoint_object(fabsf16)
102103
add_math_entrypoint_object(fabsf128)
103104

104105
add_math_entrypoint_object(fdim)

libc/src/math/fabsf16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for fabsf16 -----------------------*- 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+
#ifndef LLVM_LIBC_SRC_MATH_FABSF16_H
10+
#define LLVM_LIBC_SRC_MATH_FABSF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 fabsf16(float16 x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FABSF16_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ add_entrypoint_object(
241241
-O2
242242
)
243243

244+
add_entrypoint_object(
245+
fabsf16
246+
SRCS
247+
fabsf16.cpp
248+
HDRS
249+
../fabsf16.h
250+
DEPENDS
251+
libc.src.__support.macros.properties.types
252+
libc.src.__support.FPUtil.basic_operations
253+
COMPILE_OPTIONS
254+
-O3
255+
)
256+
244257
add_entrypoint_object(
245258
fabsf128
246259
SRCS

libc/src/math/generic/fabsf16.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-- Implementation of fabsf16 function --------------------------------===//
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 "src/math/fabsf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, fabsf16, (float16 x)) { return fputil::abs(x); }
16+
17+
} // namespace LIBC_NAMESPACE

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ add_fp_unittest(
9292
libc.src.__support.FPUtil.fp_bits
9393
)
9494

95+
add_fp_unittest(
96+
fabsf16_test
97+
SUITE
98+
libc-math-smoke-tests
99+
SRCS
100+
fabsf16_test.cpp
101+
HDRS
102+
FAbsTest.h
103+
DEPENDS
104+
libc.src.math.fabsf16
105+
)
106+
95107
add_fp_unittest(
96108
fabsf128_test
97109
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fabsf16 ---------------------------------------------===//
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 "FAbsTest.h"
10+
11+
#include "src/math/fabsf16.h"
12+
13+
LIST_FABS_TESTS(float16, LIBC_NAMESPACE::fabsf16)

revert_patches.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ contact : RonL
7070
---
7171
Revert: ocl*tests failing
7272
f8cc183e Fix the dsymutil heuristic for excluding system interfaces. (#93745)
73+
7cfffe74 Unittests and usability for BitstreamWriter incremental flushing (#92983)
74+
7375
Contact : RonL
7476
---

0 commit comments

Comments
 (0)