Skip to content

[libc][complex] implement different flavors of creal and cimag functions #113300

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

Merged
merged 7 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -603,6 +611,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float16 entrypoints
libc.src.complex.crealf16
libc.src.complex.cimagf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
Expand Down Expand Up @@ -703,6 +715,10 @@ endif()

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
libc.src.complex.crealf128
libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
8 changes: 8 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down
12 changes: 12 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -606,6 +614,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
libc.src.complex.crealf128
libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
16 changes: 16 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,14 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

set(TARGET_LIBM_ENTRYPOINTS
# complex.h entrypoints
libc.src.complex.creal
libc.src.complex.crealf
libc.src.complex.creall
libc.src.complex.cimag
libc.src.complex.cimagf
libc.src.complex.cimagl

# fenv.h entrypoints
libc.src.fenv.feclearexcept
libc.src.fenv.fedisableexcept
Expand Down Expand Up @@ -606,6 +614,10 @@ set(TARGET_LIBM_ENTRYPOINTS

if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float16 entrypoints
libc.src.complex.crealf16
libc.src.complex.cimagf16

# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
Expand Down Expand Up @@ -708,6 +720,10 @@ endif()

if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# complex.h C23 _Complex _Float128 entrypoints
libc.src.complex.crealf128
libc.src.complex.cimagf128

# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
libc.src.math.ceilf128
Expand Down
4 changes: 2 additions & 2 deletions libc/docs/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| carg | | | | | | 7.3.9.1 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cimag | | | | | | 7.3.9.2 | N/A |
| cimag | |check| | |check| | |check| | |check| | |check| | 7.3.9.2 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| conj | | | | | | 7.3.9.4 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| cproj | | | | | | 7.3.9.5 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| creal | | | | | | 7.3.9.6 | N/A |
| creal | |check| | |check| | |check| | |check| | |check| | 7.3.9.6 | N/A |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
1 change: 1 addition & 0 deletions libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(__support)

add_subdirectory(complex)
add_subdirectory(ctype)
add_subdirectory(dlfcn)
add_subdirectory(errno)
Expand Down
6 changes: 6 additions & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ add_header_library(
libc.src.__support.CPP.limits
)

add_header_library(
complex_type
HDRS
complex_type.h
)

add_header_library(
integer_operations
HDRS
Expand Down
20 changes: 20 additions & 0 deletions libc/src/__support/complex_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- complex type --------------------------------------------*- 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_COMPLEX_TYPE_H
#define LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
template <typename T> struct Complex {
T real;
T imag;
};
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_COMPLEX_TYPE_H
26 changes: 26 additions & 0 deletions libc/src/complex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
add_subdirectory(generic)

function(add_complex_entrypoint_object name)
get_fq_target_name("generic.${name}" fq_generic_target_name)
if(TARGET ${fq_generic_target_name})
add_entrypoint_object(
${name}
ALIAS
DEPENDS
.generic.${name}
)
return()
endif()
endfunction()

add_complex_entrypoint_object(creal)
add_complex_entrypoint_object(crealf)
add_complex_entrypoint_object(creall)
add_complex_entrypoint_object(crealf16)
add_complex_entrypoint_object(crealf128)

add_complex_entrypoint_object(cimag)
add_complex_entrypoint_object(cimagf)
add_complex_entrypoint_object(cimagl)
add_complex_entrypoint_object(cimagf16)
add_complex_entrypoint_object(cimagf128)
20 changes: 20 additions & 0 deletions libc/src/complex/cimag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimag -------------------------*- 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_COMPLEX_CIMAG_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAG_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double cimag(_Complex double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAG_H
20 changes: 20 additions & 0 deletions libc/src/complex/cimagf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimagf ------------------------*- 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_COMPLEX_CIMAGF_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float cimagf(_Complex float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF_H
27 changes: 27 additions & 0 deletions libc/src/complex/cimagf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for cimagf128 ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float128 cimagf128(cfloat128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF128_H

#endif // LIBC_TYPES_HAS_CFLOAT128
27 changes: 27 additions & 0 deletions libc/src/complex/cimagf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for cimagf16 ----------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT16)

#ifndef LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float16 cimagf16(cfloat16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGF16_H

#endif // LIBC_TYPES_HAS_CFLOAT16
20 changes: 20 additions & 0 deletions libc/src/complex/cimagl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for cimagl ------------------------*- 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_COMPLEX_CIMAGL_H
#define LLVM_LIBC_SRC_COMPLEX_CIMAGL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

long double cimagl(_Complex long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CIMAGL_H
20 changes: 20 additions & 0 deletions libc/src/complex/creal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for creal -------------------------*- 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_COMPLEX_CREAL_H
#define LLVM_LIBC_SRC_COMPLEX_CREAL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

double creal(_Complex double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREAL_H
20 changes: 20 additions & 0 deletions libc/src/complex/crealf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for crealf ------------------------*- 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_COMPLEX_CREALF_H
#define LLVM_LIBC_SRC_COMPLEX_CREALF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float crealf(_Complex float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALF_H
27 changes: 27 additions & 0 deletions libc/src/complex/crealf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===-- Implementation header for crealf128 ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/macros/properties/complex_types.h"
#include "src/__support/macros/properties/types.h"

#if defined(LIBC_TYPES_HAS_CFLOAT128)

#ifndef LLVM_LIBC_SRC_COMPLEX_CREALF128_H
#define LLVM_LIBC_SRC_COMPLEX_CREALF128_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

float128 crealf128(cfloat128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_COMPLEX_CREALF128_H

#endif // LIBC_TYPES_HAS_CFLOAT128
Loading
Loading