Skip to content

Commit 6f8d84d

Browse files
committed
feat: implement {get,set}payloadbf16 and setpayloadsigbf16 math functions
Signed-off-by: Krishna Pandey <[email protected]>
1 parent 12f1923 commit 6f8d84d

File tree

8 files changed

+171
-0
lines changed

8 files changed

+171
-0
lines changed

libc/src/math/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ add_math_entrypoint_object(getpayloadf)
330330
add_math_entrypoint_object(getpayloadl)
331331
add_math_entrypoint_object(getpayloadf16)
332332
add_math_entrypoint_object(getpayloadf128)
333+
add_math_entrypoint_object(getpayloadbf16)
333334

334335
add_math_entrypoint_object(hypot)
335336
add_math_entrypoint_object(hypotf)
@@ -507,12 +508,14 @@ add_math_entrypoint_object(setpayloadf)
507508
add_math_entrypoint_object(setpayloadl)
508509
add_math_entrypoint_object(setpayloadf16)
509510
add_math_entrypoint_object(setpayloadf128)
511+
add_math_entrypoint_object(setpayloadbf16)
510512

511513
add_math_entrypoint_object(setpayloadsig)
512514
add_math_entrypoint_object(setpayloadsigf)
513515
add_math_entrypoint_object(setpayloadsigl)
514516
add_math_entrypoint_object(setpayloadsigf16)
515517
add_math_entrypoint_object(setpayloadsigf128)
518+
add_math_entrypoint_object(setpayloadsigbf16)
516519

517520
add_math_entrypoint_object(sincos)
518521
add_math_entrypoint_object(sincosf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,6 +4609,20 @@ add_entrypoint_object(
46094609
libc.src.__support.FPUtil.basic_operations
46104610
)
46114611

4612+
add_entrypoint_object(
4613+
getpayloadbf16
4614+
SRCS
4615+
getpayloadbf16.cpp
4616+
HDRS
4617+
../getpayloadbf16.h
4618+
DEPENDS
4619+
libc.src.__support.common
4620+
libc.src.__support.FPUtil.basic_operations
4621+
libc.src.__support.FPUtil.bfloat16
4622+
libc.src.__support.macros.config
4623+
libc.src.__support.macros.properties.types
4624+
)
4625+
46124626
add_entrypoint_object(
46134627
setpayload
46144628
SRCS
@@ -4661,6 +4675,20 @@ add_entrypoint_object(
46614675
libc.src.__support.FPUtil.basic_operations
46624676
)
46634677

4678+
add_entrypoint_object(
4679+
setpayloadbf16
4680+
SRCS
4681+
setpayloadbf16.cpp
4682+
HDRS
4683+
../setpayloadbf16.h
4684+
DEPENDS
4685+
libc.src.__support.common
4686+
libc.src.__support.FPUtil.basic_operations
4687+
libc.src.__support.FPUtil.bfloat16
4688+
libc.src.__support.macros.config
4689+
libc.src.__support.macros.properties.types
4690+
)
4691+
46644692
add_entrypoint_object(
46654693
setpayloadsig
46664694
SRCS
@@ -4713,6 +4741,20 @@ add_entrypoint_object(
47134741
libc.src.__support.FPUtil.basic_operations
47144742
)
47154743

4744+
add_entrypoint_object(
4745+
setpayloadsigbf16
4746+
SRCS
4747+
setpayloadsigbf16.cpp
4748+
HDRS
4749+
../setpayloadsigbf16.h
4750+
DEPENDS
4751+
libc.src.__support.common
4752+
libc.src.__support.FPUtil.basic_operations
4753+
libc.src.__support.FPUtil.bfloat16
4754+
libc.src.__support.macros.config
4755+
libc.src.__support.macros.properties.types
4756+
)
4757+
47164758
add_entrypoint_object(
47174759
f16add
47184760
SRCS
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of getpayloadbf16 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/getpayloadbf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/FPUtil/bfloat16.h"
12+
#include "src/__support/common.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(bfloat16, getpayloadbf16, (const bfloat16 *x)) {
18+
return fputil::getpayload(*x);
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of setpayloadbf16 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/setpayloadbf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/FPUtil/bfloat16.h"
12+
#include "src/__support/common.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(int, setpayloadbf16, (bfloat16 * res, bfloat16 pl)) {
18+
return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of setpayloadsigbf16 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/setpayloadsigbf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/FPUtil/bfloat16.h"
12+
#include "src/__support/common.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(int, setpayloadsigbf16, (bfloat16 * res, bfloat16 pl)) {
18+
return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
19+
}
20+
21+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/getpayloadbf16.h

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

libc/src/math/setpayloadbf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for setpayloadbf16 ----------------*- 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_SETPAYLOADBF16_H
10+
#define LLVM_LIBC_SRC_MATH_SETPAYLOADBF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int setpayloadbf16(bfloat16 *res, bfloat16 pl);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADBF16_H

libc/src/math/setpayloadsigbf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for setpayloadsigbf16 -------------*- 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_SETPAYLOADSIGBF16_H
10+
#define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGBF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int setpayloadsigbf16(bfloat16 *res, bfloat16 pl);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADSIGBF16_H

0 commit comments

Comments
 (0)