From 8eb5a992be00e122f5ca1039a5ee8bc692f0b2aa Mon Sep 17 00:00:00 2001 From: Alexey Brodkin Date: Fri, 24 Nov 2023 15:06:15 +0000 Subject: [PATCH] Remove stdatomic.h & tgmath.h Inspired by https://github.com/picolibc/picolibc/commit/7c9e9c3480a3e8c8ca1e8e20e4b90f0a38927ea1 As per Keth Packard: "These are provided by the compiler and shouldn't be replaced with our versions." And indeed, an attempt to use these Newlib's headers with Clang-based compilers lead to compilation error: ---------------------->8--------------------- clang -c test.c -I.../newlib/install/arc/include test.c:8:14: error: '__builtin_choose_expr' requires a constant expression f1 = acos(f); ^~~~~~~ .../newlib/install/arc/include/tgmath.h:111:20: note: expanded from macro 'acos' ^~~~~~~~~~~~~~~~~~~~ .../newlib/install/arc/include/tgmath.h:107:2: note: expanded from macro '__tg_full' __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../newlib/install/arc/include/tgmath.h:96:6: note: expanded from macro '__tg_impl_full' __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__), \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../newlib/install/arc/include/tgmath.h:86:3: note: expanded from macro '__tg_impl_simple' __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../newlib/install/arc/include/tgmath.h:71:2: note: expanded from macro '__tg_type_corr' (__tg_type3(__e1, __e2, __e3, __t) || \ ^ 1 error generated. ---------------------->8--------------------- See https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/584 Signed-off-by: Alexey Brodkin --- newlib/libc/include/stdatomic.h | 409 -------------------------------- newlib/libc/include/tgmath.h | 185 --------------- 2 files changed, 594 deletions(-) delete mode 100644 newlib/libc/include/stdatomic.h delete mode 100644 newlib/libc/include/tgmath.h diff --git a/newlib/libc/include/stdatomic.h b/newlib/libc/include/stdatomic.h deleted file mode 100644 index d58e795eb9..0000000000 --- a/newlib/libc/include/stdatomic.h +++ /dev/null @@ -1,409 +0,0 @@ -/*- - * Copyright (c) 2011 Ed Schouten - * David Chisnall - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _STDATOMIC_H_ -#define _STDATOMIC_H_ - -#include -#include - -#if __has_extension(c_atomic) || __has_extension(cxx_atomic) -#define __CLANG_ATOMICS -#elif __GNUC_PREREQ__(4, 7) -#define __GNUC_ATOMICS -#elif defined(__GNUC__) -#define __SYNC_ATOMICS -#else -#error "stdatomic.h does not support your compiler" -#endif - -/* - * 7.17.1 Atomic lock-free macros. - */ - -#ifdef __GCC_ATOMIC_BOOL_LOCK_FREE -#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_CHAR_LOCK_FREE -#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_CHAR16_T_LOCK_FREE -#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_CHAR32_T_LOCK_FREE -#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_WCHAR_T_LOCK_FREE -#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_SHORT_LOCK_FREE -#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_INT_LOCK_FREE -#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_LONG_LOCK_FREE -#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_LLONG_LOCK_FREE -#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE -#endif -#ifdef __GCC_ATOMIC_POINTER_LOCK_FREE -#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE -#endif - -/* - * 7.17.2 Initialization. - */ - -#if defined(__CLANG_ATOMICS) -#define ATOMIC_VAR_INIT(value) (value) -#define atomic_init(obj, value) __c11_atomic_init(obj, value) -#else -#define ATOMIC_VAR_INIT(value) { .__val = (value) } -#define atomic_init(obj, value) ((void)((obj)->__val = (value))) -#endif - -/* - * Clang and recent GCC both provide predefined macros for the memory - * orderings. If we are using a compiler that doesn't define them, use the - * clang values - these will be ignored in the fallback path. - */ - -#ifndef __ATOMIC_RELAXED -#define __ATOMIC_RELAXED 0 -#endif -#ifndef __ATOMIC_CONSUME -#define __ATOMIC_CONSUME 1 -#endif -#ifndef __ATOMIC_ACQUIRE -#define __ATOMIC_ACQUIRE 2 -#endif -#ifndef __ATOMIC_RELEASE -#define __ATOMIC_RELEASE 3 -#endif -#ifndef __ATOMIC_ACQ_REL -#define __ATOMIC_ACQ_REL 4 -#endif -#ifndef __ATOMIC_SEQ_CST -#define __ATOMIC_SEQ_CST 5 -#endif - -/* - * 7.17.3 Order and consistency. - * - * The memory_order_* constants that denote the barrier behaviour of the - * atomic operations. - */ - -typedef enum { - memory_order_relaxed = __ATOMIC_RELAXED, - memory_order_consume = __ATOMIC_CONSUME, - memory_order_acquire = __ATOMIC_ACQUIRE, - memory_order_release = __ATOMIC_RELEASE, - memory_order_acq_rel = __ATOMIC_ACQ_REL, - memory_order_seq_cst = __ATOMIC_SEQ_CST -} memory_order; - -/* - * 7.17.4 Fences. - */ - -static __inline void -atomic_thread_fence(memory_order __order __unused) -{ - -#ifdef __CLANG_ATOMICS - __c11_atomic_thread_fence(__order); -#elif defined(__GNUC_ATOMICS) - __atomic_thread_fence(__order); -#else - __sync_synchronize(); -#endif -} - -static __inline void -atomic_signal_fence(memory_order __order __unused) -{ - -#ifdef __CLANG_ATOMICS - __c11_atomic_signal_fence(__order); -#elif defined(__GNUC_ATOMICS) - __atomic_signal_fence(__order); -#else - __asm volatile ("" ::: "memory"); -#endif -} - -/* - * 7.17.5 Lock-free property. - */ - -#if defined(_KERNEL) -/* Atomics in kernelspace are always lock-free. */ -#define atomic_is_lock_free(obj) \ - ((void)(obj), (_Bool)1) -#elif defined(__CLANG_ATOMICS) || defined(__GNUC_ATOMICS) -#define atomic_is_lock_free(obj) \ - __atomic_is_lock_free(sizeof(*(obj)), obj) -#else -#define atomic_is_lock_free(obj) \ - ((void)(obj), sizeof((obj)->__val) <= sizeof(void *)) -#endif - -/* - * 7.17.6 Atomic integer types. - */ - -typedef _Atomic(_Bool) atomic_bool; -typedef _Atomic(char) atomic_char; -typedef _Atomic(signed char) atomic_schar; -typedef _Atomic(unsigned char) atomic_uchar; -typedef _Atomic(short) atomic_short; -typedef _Atomic(unsigned short) atomic_ushort; -typedef _Atomic(int) atomic_int; -typedef _Atomic(unsigned int) atomic_uint; -typedef _Atomic(long) atomic_long; -typedef _Atomic(unsigned long) atomic_ulong; -typedef _Atomic(long long) atomic_llong; -typedef _Atomic(unsigned long long) atomic_ullong; -#if 0 -typedef _Atomic(__char16_t) atomic_char16_t; -typedef _Atomic(__char32_t) atomic_char32_t; -#endif -typedef _Atomic(wchar_t) atomic_wchar_t; -typedef _Atomic(int_least8_t) atomic_int_least8_t; -typedef _Atomic(uint_least8_t) atomic_uint_least8_t; -typedef _Atomic(int_least16_t) atomic_int_least16_t; -typedef _Atomic(uint_least16_t) atomic_uint_least16_t; -typedef _Atomic(int_least32_t) atomic_int_least32_t; -typedef _Atomic(uint_least32_t) atomic_uint_least32_t; -typedef _Atomic(int_least64_t) atomic_int_least64_t; -typedef _Atomic(uint_least64_t) atomic_uint_least64_t; -typedef _Atomic(int_fast8_t) atomic_int_fast8_t; -typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; -typedef _Atomic(int_fast16_t) atomic_int_fast16_t; -typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; -typedef _Atomic(int_fast32_t) atomic_int_fast32_t; -typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; -typedef _Atomic(int_fast64_t) atomic_int_fast64_t; -typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; -typedef _Atomic(intptr_t) atomic_intptr_t; -typedef _Atomic(uintptr_t) atomic_uintptr_t; -typedef _Atomic(size_t) atomic_size_t; -typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; -typedef _Atomic(intmax_t) atomic_intmax_t; -typedef _Atomic(uintmax_t) atomic_uintmax_t; - -/* - * 7.17.7 Operations on atomic types. - */ - -/* - * Compiler-specific operations. - */ - -#if defined(__CLANG_ATOMICS) -#define atomic_compare_exchange_strong_explicit(object, expected, \ - desired, success, failure) \ - __c11_atomic_compare_exchange_strong(object, expected, desired, \ - success, failure) -#define atomic_compare_exchange_weak_explicit(object, expected, \ - desired, success, failure) \ - __c11_atomic_compare_exchange_weak(object, expected, desired, \ - success, failure) -#define atomic_exchange_explicit(object, desired, order) \ - __c11_atomic_exchange(object, desired, order) -#define atomic_fetch_add_explicit(object, operand, order) \ - __c11_atomic_fetch_add(object, operand, order) -#define atomic_fetch_and_explicit(object, operand, order) \ - __c11_atomic_fetch_and(object, operand, order) -#define atomic_fetch_or_explicit(object, operand, order) \ - __c11_atomic_fetch_or(object, operand, order) -#define atomic_fetch_sub_explicit(object, operand, order) \ - __c11_atomic_fetch_sub(object, operand, order) -#define atomic_fetch_xor_explicit(object, operand, order) \ - __c11_atomic_fetch_xor(object, operand, order) -#define atomic_load_explicit(object, order) \ - __c11_atomic_load(object, order) -#define atomic_store_explicit(object, desired, order) \ - __c11_atomic_store(object, desired, order) -#elif defined(__GNUC_ATOMICS) -#define atomic_compare_exchange_strong_explicit(object, expected, \ - desired, success, failure) \ - __atomic_compare_exchange_n(object, expected, \ - desired, 0, success, failure) -#define atomic_compare_exchange_weak_explicit(object, expected, \ - desired, success, failure) \ - __atomic_compare_exchange_n(object, expected, \ - desired, 1, success, failure) -#define atomic_exchange_explicit(object, desired, order) \ - __atomic_exchange_n(object, desired, order) -#define atomic_fetch_add_explicit(object, operand, order) \ - __atomic_fetch_add(object, operand, order) -#define atomic_fetch_and_explicit(object, operand, order) \ - __atomic_fetch_and(object, operand, order) -#define atomic_fetch_or_explicit(object, operand, order) \ - __atomic_fetch_or(object, operand, order) -#define atomic_fetch_sub_explicit(object, operand, order) \ - __atomic_fetch_sub(object, operand, order) -#define atomic_fetch_xor_explicit(object, operand, order) \ - __atomic_fetch_xor(object, operand, order) -#define atomic_load_explicit(object, order) \ - __atomic_load_n(object, order) -#define atomic_store_explicit(object, desired, order) \ - __atomic_store_n(object, desired, order) -#else -#define __atomic_apply_stride(object, operand) \ - (((__typeof__((object)->__val))0) + (operand)) -#define atomic_compare_exchange_strong_explicit(object, expected, \ - desired, success, failure) __extension__ ({ \ - __typeof__(expected) __ep = (expected); \ - __typeof__(*__ep) __e = *__ep; \ - (void)(success); (void)(failure); \ - (_Bool)((*__ep = __sync_val_compare_and_swap(&(object)->__val, \ - __e, desired)) == __e); \ -}) -#define atomic_compare_exchange_weak_explicit(object, expected, \ - desired, success, failure) \ - atomic_compare_exchange_strong_explicit(object, expected, \ - desired, success, failure) -#if __has_builtin(__sync_swap) -/* Clang provides a full-barrier atomic exchange - use it if available. */ -#define atomic_exchange_explicit(object, desired, order) \ - ((void)(order), __sync_swap(&(object)->__val, desired)) -#else -/* - * __sync_lock_test_and_set() is only an acquire barrier in theory (although in - * practice it is usually a full barrier) so we need an explicit barrier before - * it. - */ -#define atomic_exchange_explicit(object, desired, order) \ -__extension__ ({ \ - __typeof__(object) __o = (object); \ - __typeof__(desired) __d = (desired); \ - (void)(order); \ - __sync_synchronize(); \ - __sync_lock_test_and_set(&(__o)->__val, __d); \ -}) -#endif -#define atomic_fetch_add_explicit(object, operand, order) \ - ((void)(order), __sync_fetch_and_add(&(object)->__val, \ - __atomic_apply_stride(object, operand))) -#define atomic_fetch_and_explicit(object, operand, order) \ - ((void)(order), __sync_fetch_and_and(&(object)->__val, operand)) -#define atomic_fetch_or_explicit(object, operand, order) \ - ((void)(order), __sync_fetch_and_or(&(object)->__val, operand)) -#define atomic_fetch_sub_explicit(object, operand, order) \ - ((void)(order), __sync_fetch_and_sub(&(object)->__val, \ - __atomic_apply_stride(object, operand))) -#define atomic_fetch_xor_explicit(object, operand, order) \ - ((void)(order), __sync_fetch_and_xor(&(object)->__val, operand)) -#define atomic_load_explicit(object, order) \ - ((void)(order), __sync_fetch_and_add(&(object)->__val, 0)) -#define atomic_store_explicit(object, desired, order) \ - ((void)atomic_exchange_explicit(object, desired, order)) -#endif - -/* - * Convenience functions. - * - * Don't provide these in kernel space. In kernel space, we should be - * disciplined enough to always provide explicit barriers. - */ - -#ifndef _KERNEL -#define atomic_compare_exchange_strong(object, expected, desired) \ - atomic_compare_exchange_strong_explicit(object, expected, \ - desired, memory_order_seq_cst, memory_order_seq_cst) -#define atomic_compare_exchange_weak(object, expected, desired) \ - atomic_compare_exchange_weak_explicit(object, expected, \ - desired, memory_order_seq_cst, memory_order_seq_cst) -#define atomic_exchange(object, desired) \ - atomic_exchange_explicit(object, desired, memory_order_seq_cst) -#define atomic_fetch_add(object, operand) \ - atomic_fetch_add_explicit(object, operand, memory_order_seq_cst) -#define atomic_fetch_and(object, operand) \ - atomic_fetch_and_explicit(object, operand, memory_order_seq_cst) -#define atomic_fetch_or(object, operand) \ - atomic_fetch_or_explicit(object, operand, memory_order_seq_cst) -#define atomic_fetch_sub(object, operand) \ - atomic_fetch_sub_explicit(object, operand, memory_order_seq_cst) -#define atomic_fetch_xor(object, operand) \ - atomic_fetch_xor_explicit(object, operand, memory_order_seq_cst) -#define atomic_load(object) \ - atomic_load_explicit(object, memory_order_seq_cst) -#define atomic_store(object, desired) \ - atomic_store_explicit(object, desired, memory_order_seq_cst) -#endif /* !_KERNEL */ - -/* - * 7.17.8 Atomic flag type and operations. - * - * XXX: Assume atomic_bool can be used as an atomic_flag. Is there some - * kind of compiler built-in type we could use? - */ - -typedef struct { - atomic_bool __flag; -} atomic_flag; -#define ATOMIC_FLAG_INIT { ATOMIC_VAR_INIT(0) } - -static __inline _Bool -atomic_flag_test_and_set_explicit(volatile atomic_flag *__object, - memory_order __order) -{ - return (atomic_exchange_explicit(&__object->__flag, 1, __order)); -} - -static __inline void -atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order) -{ - - atomic_store_explicit(&__object->__flag, 0, __order); -} - -#ifndef _KERNEL -static __inline _Bool -atomic_flag_test_and_set(volatile atomic_flag *__object) -{ - - return (atomic_flag_test_and_set_explicit(__object, - memory_order_seq_cst)); -} - -static __inline void -atomic_flag_clear(volatile atomic_flag *__object) -{ - - atomic_flag_clear_explicit(__object, memory_order_seq_cst); -} -#endif /* !_KERNEL */ - -#endif /* !_STDATOMIC_H_ */ diff --git a/newlib/libc/include/tgmath.h b/newlib/libc/include/tgmath.h deleted file mode 100644 index 97dc50eaa1..0000000000 --- a/newlib/libc/include/tgmath.h +++ /dev/null @@ -1,185 +0,0 @@ -/* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/tgmath.h.html */ -/*- - * Copyright (c) 2004 Stefan Farfeleder. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _TGMATH_H_ -#define _TGMATH_H_ - -#include -#include - -#ifdef log2 -#undef log2 -#endif - -/* - * This implementation of requires two implementation-dependent - * macros to be defined: - * __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) - * Invokes fnl() if the corresponding real type of x, y or z is long - * double, fn() if it is double or any has an integer type, and fnf() - * otherwise. - * __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...) - * Invokes [c]fnl() if the corresponding real type of x, y or z is long - * double, [c]fn() if it is double or any has an integer type, and - * [c]fnf() otherwise. The function with the 'c' prefix is called if - * any of x, y or z is a complex number. - * Both macros call the chosen function with all additional arguments passed - * to them, as given by __VA_ARGS__. - * - * Note that these macros cannot be implemented with C's ?: operator, - * because the return type of the whole expression would incorrectly be long - * double complex regardless of the argument types. - */ - -/* requires GCC >= 3.1 */ -#if !__GNUC_PREREQ (3, 1) -#error " not implemented for this compiler" -#endif - -#define __tg_type(__e, __t) \ - __builtin_types_compatible_p(__typeof__(__e), __t) -#define __tg_type3(__e1, __e2, __e3, __t) \ - (__tg_type(__e1, __t) || __tg_type(__e2, __t) || \ - __tg_type(__e3, __t)) -#define __tg_type_corr(__e1, __e2, __e3, __t) \ - (__tg_type3(__e1, __e2, __e3, __t) || \ - __tg_type3(__e1, __e2, __e3, __t _Complex)) -#define __tg_integer(__e1, __e2, __e3) \ - (((__typeof__(__e1))1.5 == 1) || ((__typeof__(__e2))1.5 == 1) || \ - ((__typeof__(__e3))1.5 == 1)) -#define __tg_is_complex(__e1, __e2, __e3) \ - (__tg_type3(__e1, __e2, __e3, float _Complex) || \ - __tg_type3(__e1, __e2, __e3, double _Complex) || \ - __tg_type3(__e1, __e2, __e3, long double _Complex) || \ - __tg_type3(__e1, __e2, __e3, __typeof__(_Complex_I))) - -#if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__) -#define __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) \ - __builtin_choose_expr(__tg_type_corr(x, y, z, long double), \ - fnl(__VA_ARGS__), __builtin_choose_expr( \ - __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\ - fn(__VA_ARGS__), fnf(__VA_ARGS__))) -#else -#define __tg_impl_simple(__x, __y, __z, __fn, __fnf, __fnl, ...) \ - (__tg_type_corr(__x, __y, __z, double) || __tg_integer(__x, __y, __z)) \ - ? __fn(__VA_ARGS__) : __fnf(__VA_ARGS__) -#endif - -#define __tg_impl_full(__x, __y, __z, __fn, __fnf, __fnl, __cfn, __cfnf, __cfnl, ...) \ - __builtin_choose_expr(__tg_is_complex(__x, __y, __z), \ - __tg_impl_simple(__x, __y, __z, __cfn, __cfnf, __cfnl, __VA_ARGS__), \ - __tg_impl_simple(__x, __y, __z, __fn, __fnf, __fnl, __VA_ARGS__)) - -/* Macros to save lots of repetition below */ -#define __tg_simple(__x, __fn) \ - __tg_impl_simple(__x, __x, __x, __fn, __fn##f, __fn##l, __x) -#define __tg_simple2(__x, __y, __fn) \ - __tg_impl_simple(__x, __x, __y, __fn, __fn##f, __fn##l, __x, __y) -#define __tg_simplev(__x, __fn, ...) \ - __tg_impl_simple(__x, __x, __x, __fn, __fn##f, __fn##l, __VA_ARGS__) -#define __tg_full(__x, __fn) \ - __tg_impl_full(__x, __x, __x, __fn, __fn##f, __fn##l, c##__fn, c##__fn##f, c##__fn##l, __x) - -/* 7.22#4 -- These macros expand to real or complex functions, depending on - * the type of their arguments. */ -#define acos(__x) __tg_full(__x, acos) -#define asin(__x) __tg_full(__x, asin) -#define atan(__x) __tg_full(__x, atan) -#define acosh(__x) __tg_full(__x, acosh) -#define asinh(__x) __tg_full(__x, asinh) -#define atanh(__x) __tg_full(__x, atanh) -#define cos(__x) __tg_full(__x, cos) -#define sin(__x) __tg_full(__x, sin) -#define tan(__x) __tg_full(__x, tan) -#define cosh(__x) __tg_full(__x, cosh) -#define sinh(__x) __tg_full(__x, sinh) -#define tanh(__x) __tg_full(__x, tanh) -#define exp(__x) __tg_full(__x, exp) -#define log(__x) __tg_full(__x, log) -#define pow(__x, __y) __tg_impl_full(__x, __x, __y, pow, powf, powl, \ - cpow, cpowf, cpowl, __x, __y) -#define sqrt(__x) __tg_full(__x, sqrt) - -/* "The corresponding type-generic macro for fabs and cabs is fabs." */ -#define fabs(__x) __tg_impl_full(__x, __x, __x, fabs, fabsf, fabsl, \ - cabs, cabsf, cabsl, __x) - -/* 7.22#5 -- These macros are only defined for arguments with real type. */ -#define atan2(__x, __y) __tg_simple2(__x, __y, atan2) -#define cbrt(__x) __tg_simple(__x, cbrt) -#define ceil(__x) __tg_simple(__x, ceil) -#define copysign(__x, __y) __tg_simple2(__x, __y, copysign) -#define erf(__x) __tg_simple(__x, erf) -#define erfc(__x) __tg_simple(__x, erfc) -#define exp2(__x) __tg_simple(__x, exp2) -#define expm1(__x) __tg_simple(__x, expm1) -#define fdim(__x, __y) __tg_simple2(__x, __y, fdim) -#define floor(__x) __tg_simple(__x, floor) -#define fma(__x, __y, __z) __tg_impl_simple(__x, __y, __z, fma, fmaf, fmal, \ - __x, __y, __z) -#define fmax(__x, __y) __tg_simple2(__x, __y, fmax) -#define fmin(__x, __y) __tg_simple2(__x, __y, fmin) -#define fmod(__x, __y) __tg_simple2(__x, __y, fmod) -#define frexp(__x, __y) __tg_simplev(__x, frexp, __x, __y) -#define hypot(__x, __y) __tg_simple2(__x, __y, hypot) -#define ilogb(__x) __tg_simple(__x, ilogb) -#define ldexp(__x, __y) __tg_simplev(__x, ldexp, __x, __y) -#define lgamma(__x) __tg_simple(__x, lgamma) -#define llrint(__x) __tg_simple(__x, llrint) -#define llround(__x) __tg_simple(__x, llround) -#define log10(__x) __tg_simple(__x, log10) -#define log1p(__x) __tg_simple(__x, log1p) -#define log2(__x) __tg_simple(__x, log2) -#define logb(__x) __tg_simple(__x, logb) -#define lrint(__x) __tg_simple(__x, lrint) -#define lround(__x) __tg_simple(__x, lround) -#define nearbyint(__x) __tg_simple(__x, nearbyint) -#define nextafter(__x, __y) __tg_simple2(__x, __y, nextafter) -/* not yet implemented even for _LDBL_EQ_DBL platforms */ -#ifdef __CYGWIN__ -#define nexttoward(__x, __y) __tg_simplev(__x, nexttoward, __x, __y) -#endif -#define remainder(__x, __y) __tg_simple2(__x, __y, remainder) -#define remquo(__x, __y, __z) __tg_impl_simple(__x, __x, __y, remquo, remquof, \ - remquol, __x, __y, __z) -#define rint(__x) __tg_simple(__x, rint) -#define round(__x) __tg_simple(__x, round) -#define scalbn(__x, __y) __tg_simplev(__x, scalbn, __x, __y) -#define scalbln(__x, __y) __tg_simplev(__x, scalbln, __x, __y) -#define tgamma(__x) __tg_simple(__x, tgamma) -#define trunc(__x) __tg_simple(__x, trunc) - -/* 7.22#6 -- These macros always expand to complex functions. */ -#define carg(__x) __tg_simple(__x, carg) -#define cimag(__x) __tg_simple(__x, cimag) -#define conj(__x) __tg_simple(__x, conj) -#define cproj(__x) __tg_simple(__x, cproj) -#define creal(__x) __tg_simple(__x, creal) - -#endif /* !_TGMATH_H_ */