Skip to content

Commit e84a1e6

Browse files
committed
- Initial implementation of rsqrt for single precision float
Some small unrelated changes to this PR: - Added extra - to the top comments to make it look nicer in libc/shared/math/rsqrtf16.h - Put rsqrtf16 inside of libc/src/__support/math/CMakeLists.txt in sorted order - Rearanged libc_math_function rsqrtf16 in Bazel to match alphabetical order
1 parent b241cc9 commit e84a1e6

File tree

20 files changed

+249
-28
lines changed

20 files changed

+249
-28
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
735735
libc.src.math.rintf16
736736
libc.src.math.roundevenf16
737737
libc.src.math.roundf16
738+
libc.src.math.rsqrtf
738739
libc.src.math.rsqrtf16
739740
libc.src.math.scalblnf16
740741
libc.src.math.scalbnf16

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
749749
libc.src.math.rintf16
750750
libc.src.math.roundevenf16
751751
libc.src.math.roundf16
752+
libc.src.math.rsqrtf
752753
libc.src.math.rsqrtf16
753754
libc.src.math.scalblnf16
754755
libc.src.math.scalbnf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
784784
libc.src.math.rintf16
785785
libc.src.math.roundevenf16
786786
libc.src.math.roundf16
787+
libc.src.math.rsqrtf
787788
libc.src.math.rsqrtf16
788789
libc.src.math.scalblnf16
789790
libc.src.math.scalbnf16

libc/docs/headers/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Higher Math Functions
343343
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
344344
| rootn | | | | | | | 7.12.7.8 | F.10.4.8 |
345345
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
346-
| rsqrt | | | | |check| | | | 7.12.7.9 | F.10.4.9 |
346+
| rsqrt | |check| | | | |check| | | | 7.12.7.9 | F.10.4.9 |
347347
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
348348
| sin | |check| | |check| | | |check| | | | 7.12.4.6 | F.10.1.6 |
349349
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+

libc/include/math.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,12 @@ functions:
23492349
return_type: long double
23502350
arguments:
23512351
- type: long double
2352+
- name: rsqrtf
2353+
standards:
2354+
- stdc
2355+
return_type: float
2356+
arguments:
2357+
- type: float
23522358
- name: rsqrtf16
23532359
standards:
23542360
- stdc

libc/shared/math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include "math/ldexpf.h"
5353
#include "math/ldexpf128.h"
5454
#include "math/ldexpf16.h"
55-
55+
#include "math/rsqrtf.h"
5656
#include "math/rsqrtf16.h"
5757

5858
#endif // LLVM_LIBC_SHARED_MATH_H

libc/shared/math/rsqrtf.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Shared rsqrtf function ----------------------------------*- 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_SHARED_MATH_RSQRTF_H
10+
#define LLVM_LIBC_SHARED_MATH_RSQRTF_H
11+
12+
#include "shared/libc_common.h"
13+
#include "src/__support/math/rsqrtf.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
namespace shared {
17+
18+
using math::rsqrtf;
19+
20+
} // namespace shared
21+
} // namespace LIBC_NAMESPACE_DECL
22+
23+
#endif // LLVM_LIBC_SHARED_MATH_RSQRTF_H

libc/shared/math/rsqrtf16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Shared rsqrtf16 function -------------------------------*- C++ -*-===//
1+
//===-- Shared rsqrtf16 function --------------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/__support/math/CMakeLists.txt

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,6 @@ add_header_library(
109109
libc.src.__support.macros.properties.types
110110
)
111111

112-
113-
add_header_library(
114-
rsqrtf16
115-
HDRS
116-
rsqrtf16.h
117-
DEPENDS
118-
libc.src.__support.FPUtil.cast
119-
libc.src.__support.FPUtil.fenv_impl
120-
libc.src.__support.FPUtil.fp_bits
121-
libc.src.__support.FPUtil.multiply_add
122-
libc.src.__support.FPUtil.polyeval
123-
libc.src.__support.FPUtil.manipulation_functions
124-
libc.src.__support.macros.optimization
125-
libc.src.__support.macros.properties.types
126-
)
127-
128112
add_header_library(
129113
asin_utils
130114
HDRS
@@ -775,6 +759,36 @@ add_header_library(
775759
libc.src.__support.common
776760
)
777761

762+
add_header_library(
763+
rsqrtf16
764+
HDRS
765+
rsqrtf16.h
766+
DEPENDS
767+
libc.src.__support.FPUtil.cast
768+
libc.src.__support.FPUtil.fenv_impl
769+
libc.src.__support.FPUtil.fp_bits
770+
libc.src.__support.FPUtil.multiply_add
771+
libc.src.__support.FPUtil.polyeval
772+
libc.src.__support.FPUtil.manipulation_functions
773+
libc.src.__support.macros.optimization
774+
libc.src.__support.macros.properties.types
775+
)
776+
777+
add_header_library(
778+
rsqrtf
779+
HDRS
780+
rsqrtf.h
781+
DEPENDS
782+
libc.src.__support.FPUtil.cast
783+
libc.src.__support.FPUtil.fenv_impl
784+
libc.src.__support.FPUtil.fp_bits
785+
libc.src.__support.FPUtil.multiply_add
786+
libc.src.__support.FPUtil.polyeval
787+
libc.src.__support.FPUtil.manipulation_functions
788+
libc.src.__support.macros.optimization
789+
libc.src.__support.macros.properties.types
790+
)
791+
778792
add_header_library(
779793
sincos_eval
780794
HDRS

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ add_math_entrypoint_object(roundevenf16)
516516
add_math_entrypoint_object(roundevenf128)
517517
add_math_entrypoint_object(roundevenbf16)
518518

519+
add_math_entrypoint_object(rsqrtf)
519520
add_math_entrypoint_object(rsqrtf16)
520521

521522
add_math_entrypoint_object(scalbln)

0 commit comments

Comments
 (0)