[libc][math][c++23] Add fabsbf16 math function (#148398)
This PR implements fabsbf16 math function for BFloat16 type along with the tests. --------- Signed-off-by: krishna2803 <kpandey81930@gmail.com> Signed-off-by: Krishna Pandey <kpandey81930@gmail.com> Co-authored-by: OverMighty <its.overmighty@gmail.com>
This commit is contained in:
parent
32779cd698
commit
111edfcab8
@ -754,6 +754,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -757,6 +757,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -757,6 +757,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -588,6 +588,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -231,6 +231,11 @@ set(TARGET_LIBM_ENTRYPOINTS
|
|||||||
#libc.src.math.truncl
|
#libc.src.math.truncl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
||||||
${TARGET_LIBC_ENTRYPOINTS}
|
${TARGET_LIBC_ENTRYPOINTS}
|
||||||
${TARGET_LIBM_ENTRYPOINTS}
|
${TARGET_LIBM_ENTRYPOINTS}
|
||||||
|
@ -612,6 +612,11 @@ if(LIBC_TYPES_HAS_FLOAT16)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
||||||
${TARGET_LIBC_ENTRYPOINTS}
|
${TARGET_LIBC_ENTRYPOINTS}
|
||||||
${TARGET_LIBM_ENTRYPOINTS}
|
${TARGET_LIBM_ENTRYPOINTS}
|
||||||
|
@ -614,6 +614,11 @@ if(LIBC_TYPES_HAS_FLOAT16)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
||||||
${TARGET_LIBC_ENTRYPOINTS}
|
${TARGET_LIBC_ENTRYPOINTS}
|
||||||
${TARGET_LIBM_ENTRYPOINTS}
|
${TARGET_LIBM_ENTRYPOINTS}
|
||||||
|
@ -842,6 +842,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LLVM_LIBC_FULL_BUILD)
|
if(LLVM_LIBC_FULL_BUILD)
|
||||||
list(APPEND TARGET_LIBC_ENTRYPOINTS
|
list(APPEND TARGET_LIBC_ENTRYPOINTS
|
||||||
# assert.h entrypoints
|
# assert.h entrypoints
|
||||||
|
@ -458,6 +458,11 @@ set(TARGET_LIBM_ENTRYPOINTS
|
|||||||
libc.src.math.ufromfpxl
|
libc.src.math.ufromfpxl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
||||||
${TARGET_LIBC_ENTRYPOINTS}
|
${TARGET_LIBC_ENTRYPOINTS}
|
||||||
${TARGET_LIBM_ENTRYPOINTS}
|
${TARGET_LIBM_ENTRYPOINTS}
|
||||||
|
@ -861,6 +861,11 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -892,6 +892,12 @@ if(LIBC_TYPES_HAS_FLOAT128)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
if(LIBC_COMPILER_HAS_FIXED_POINT)
|
||||||
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
# stdfix.h _Fract and _Accum entrypoints
|
# stdfix.h _Fract and _Accum entrypoints
|
||||||
|
@ -304,6 +304,11 @@ set(TARGET_LIBM_ENTRYPOINTS
|
|||||||
libc.src.math.truncl
|
libc.src.math.truncl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND TARGET_LIBM_ENTRYPOINTS
|
||||||
|
# bfloat16 entrypoints
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
set(TARGET_LLVMLIBC_ENTRYPOINTS
|
||||||
${TARGET_LIBC_ENTRYPOINTS}
|
${TARGET_LIBC_ENTRYPOINTS}
|
||||||
${TARGET_LIBM_ENTRYPOINTS}
|
${TARGET_LIBM_ENTRYPOINTS}
|
||||||
|
@ -189,6 +189,7 @@ add_math_entrypoint_object(fabsf)
|
|||||||
add_math_entrypoint_object(fabsl)
|
add_math_entrypoint_object(fabsl)
|
||||||
add_math_entrypoint_object(fabsf16)
|
add_math_entrypoint_object(fabsf16)
|
||||||
add_math_entrypoint_object(fabsf128)
|
add_math_entrypoint_object(fabsf128)
|
||||||
|
add_math_entrypoint_object(fabsbf16)
|
||||||
|
|
||||||
add_math_entrypoint_object(fadd)
|
add_math_entrypoint_object(fadd)
|
||||||
add_math_entrypoint_object(faddl)
|
add_math_entrypoint_object(faddl)
|
||||||
|
21
libc/src/math/fabsbf16.h
Normal file
21
libc/src/math/fabsbf16.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//===-- Implementation header for fabsbf16 ----------------------*- 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_MATH_FABSBF16_H
|
||||||
|
#define LLVM_LIBC_SRC_MATH_FABSBF16_H
|
||||||
|
|
||||||
|
#include "src/__support/macros/config.h"
|
||||||
|
#include "src/__support/macros/properties/types.h"
|
||||||
|
|
||||||
|
namespace LIBC_NAMESPACE_DECL {
|
||||||
|
|
||||||
|
bfloat16 fabsbf16(bfloat16 x);
|
||||||
|
|
||||||
|
} // namespace LIBC_NAMESPACE_DECL
|
||||||
|
|
||||||
|
#endif // LLVM_LIBC_SRC_MATH_FABSBF16_H
|
@ -697,6 +697,19 @@ add_entrypoint_object(
|
|||||||
libc.src.__support.FPUtil.basic_operations
|
libc.src.__support.FPUtil.basic_operations
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_entrypoint_object(
|
||||||
|
fabsbf16
|
||||||
|
SRCS
|
||||||
|
fabsbf16.cpp
|
||||||
|
HDRS
|
||||||
|
../fabsbf16.h
|
||||||
|
DEPENDS
|
||||||
|
libc.src.__support.FPUtil.basic_operations
|
||||||
|
libc.src.__support.FPUtil.bfloat16
|
||||||
|
libc.src.__support.macros.config
|
||||||
|
libc.src.__support.macros.properties.types
|
||||||
|
)
|
||||||
|
|
||||||
add_entrypoint_object(
|
add_entrypoint_object(
|
||||||
fadd
|
fadd
|
||||||
SRCS
|
SRCS
|
||||||
|
19
libc/src/math/generic/fabsbf16.cpp
Normal file
19
libc/src/math/generic/fabsbf16.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//===-- Implementation of fabsbf16 function -------------------------------===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "src/math/fabsbf16.h"
|
||||||
|
|
||||||
|
#include "src/__support/FPUtil/BasicOperations.h"
|
||||||
|
#include "src/__support/FPUtil/bfloat16.h"
|
||||||
|
#include "src/__support/macros/config.h"
|
||||||
|
|
||||||
|
namespace LIBC_NAMESPACE_DECL {
|
||||||
|
|
||||||
|
LLVM_LIBC_FUNCTION(bfloat16, fabsbf16, (bfloat16 x)) { return fputil::abs(x); }
|
||||||
|
|
||||||
|
} // namespace LIBC_NAMESPACE_DECL
|
@ -30,4 +30,3 @@ add_fp_unittest(
|
|||||||
DEPENDS
|
DEPENDS
|
||||||
libc.src.math.generic.ceill
|
libc.src.math.generic.ceill
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -220,6 +220,19 @@ add_fp_unittest(
|
|||||||
libc.src.__support.FPUtil.fp_bits
|
libc.src.__support.FPUtil.fp_bits
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_fp_unittest(
|
||||||
|
fabsbf16_test
|
||||||
|
SUITE
|
||||||
|
libc-math-smoke-tests
|
||||||
|
SRCS
|
||||||
|
fabsbf16_test.cpp
|
||||||
|
HDRS
|
||||||
|
FAbsTest.h
|
||||||
|
DEPENDS
|
||||||
|
libc.src.__support.FPUtil.bfloat16
|
||||||
|
libc.src.math.fabsbf16
|
||||||
|
)
|
||||||
|
|
||||||
add_fp_unittest(
|
add_fp_unittest(
|
||||||
fadd_test
|
fadd_test
|
||||||
SUITE
|
SUITE
|
||||||
|
14
libc/test/src/math/smoke/fabsbf16_test.cpp
Normal file
14
libc/test/src/math/smoke/fabsbf16_test.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//===-- Unittests for fabsbf16 --------------------------------------------===//
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "FAbsTest.h"
|
||||||
|
|
||||||
|
#include "src/__support/FPUtil/bfloat16.h"
|
||||||
|
#include "src/math/fabsbf16.h"
|
||||||
|
|
||||||
|
LIST_FABS_TESTS(bfloat16, LIBC_NAMESPACE::fabsbf16)
|
Loading…
x
Reference in New Issue
Block a user