1//===-- runtime/pgmath.h.inc -------------------------------===// 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// This file defines the interface of libpgmath to be used for folding 10// and code generation. 11// Usage: 12// define PGMATH_DECLARE if you simply want to declare pgmath interface. 13// Define the PGMATH_USE_S/D/C/Z(intrinsic name, function name) according 14// to what needs to be done with the runtime declaration. 15// This intrinsic will be called on all libpgmath function in the 16// intrinsic alphabetical order. 17// Define PGMATH_FAST/RELAXED/PRECISE to restrict the PGMATH_USE visit 18// to the targeted versions. 19// Define PGMATH_USE_OTHER to visit math functions that are not related to 20// floating points (e.g. int**int pow). 21 22// Control Macros 23#ifdef PGMATH_DECLARE 24#undef PGMATH_DECLARE 25#define PGMATH_DECLARE(x) extern "C" x; 26#define PGMATH_FAST 27#define PGMATH_PRECISE 28#define PGMATH_RELAXED 29#else 30#define PGMATH_DECLARE(x) 31#endif 32 33#ifdef PGMATH_USE_ALL_TYPES 34#define PGMATH_USE_S(name, func) PGMATH_USE_ALL_TYPES(name, func) 35#define PGMATH_USE_D(name, func) PGMATH_USE_ALL_TYPES(name, func) 36#define PGMATH_USE_OTHER(name, func) PGMATH_USE_ALL_TYPES(name, func) 37#endif 38 39#ifndef PGMATH_USE_S 40#define PGMATH_USE_S(name, x) 41#endif 42 43#ifndef PGMATH_USE_D 44#define PGMATH_USE_D(name, x) 45#endif 46 47#ifndef PGMATH_USE_C 48#define PGMATH_USE_C(name, x) 49#endif 50 51#ifndef PGMATH_USE_Z 52#define PGMATH_USE_Z(name, x) 53#endif 54 55#ifndef PGMATH_USE_OTHER 56#define PGMATH_USE_OTHER(name, x) 57#endif 58 59#define PGMATH_REAL_IMPL(impl, func) \ 60 PGMATH_DECLARE(float __##impl##s_##func##_1(float)) \ 61 PGMATH_DECLARE(double __##impl##d_##func##_1(double)) \ 62 PGMATH_USE_S(func, __##impl##s_##func##_1) \ 63 PGMATH_USE_D(func, __##impl##d_##func##_1) 64 65#define PGMATH_ALL_FP_IMPL(impl, func) \ 66 PGMATH_REAL_IMPL(impl, func) \ 67 68#define PGMATH_REAL2_IMPL(impl, func) \ 69 PGMATH_DECLARE(float __##impl##s_##func##_1(float, float)) \ 70 PGMATH_DECLARE(double __##impl##d_##func##_1(double, double)) \ 71 PGMATH_USE_S(func, __##impl##s_##func##_1) \ 72 PGMATH_USE_D(func, __##impl##d_##func##_1) 73 74#define PGMATH_ALL_FP2_IMPL(impl, func) \ 75 PGMATH_REAL2_IMPL(func) \ 76 77#undef PGMATH_FAST_REAL 78#undef PGMATH_FAST_COMPLEX 79#undef PGMATH_FAST_ALL_FP 80#undef PGMATH_FAST_REAL2 81#undef PGMATH_FAST_COMPLEX2 82#undef PGMATH_FAST_ALL_FP2 83#ifdef PGMATH_FAST 84#define PGMATH_FAST_REAL(func) PGMATH_REAL_IMPL(f, func) 85#define PGMATH_FAST_ALL_FP(func) PGMATH_ALL_IMPL(f, func) 86#define PGMATH_FAST_REAL2(func) PGMATH_REAL2_IMPL(f, func) 87#define PGMATH_FAST_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(f, func) 88#else 89#define PGMATH_FAST_REAL(func) 90#define PGMATH_FAST_COMPLEX(func) 91#define PGMATH_FAST_ALL_FP(func) 92#define PGMATH_FAST_REAL2(func) 93#define PGMATH_FAST_COMPLEX2(func) 94#define PGMATH_FAST_ALL_FP2(func) 95#endif 96 97#undef PGMATH_RELAXED_REAL 98#undef PGMATH_RELAXED_COMPLEX 99#undef PGMATH_RELAXED_ALL_FP 100#undef PGMATH_RELAXED_REAL2 101#undef PGMATH_RELAXED_COMPLEX2 102#undef PGMATH_RELAXED_ALL_FP2 103#ifdef PGMATH_RELAXED 104#define PGMATH_RELAXED_REAL(func) PGMATH_REAL_IMPL(r, func) 105#define PGMATH_RELAXED_ALL_FP(func) PGMATH_ALL_IMPL(r, func) 106#define PGMATH_RELAXED_REAL2(func) PGMATH_REAL2_IMPL(r, func) 107#define PGMATH_RELAXED_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(r, func) 108#else 109#define PGMATH_RELAXED_REAL(func) 110#define PGMATH_RELAXED_COMPLEX(func) 111#define PGMATH_RELAXED_ALL_FP(func) 112#define PGMATH_RELAXED_REAL2(func) 113#define PGMATH_RELAXED_COMPLEX2(func) 114#define PGMATH_RELAXED_ALL_FP2(func) 115#endif 116 117#undef PGMATH_PRECISE_REAL 118#undef PGMATH_PRECISE_COMPLEX 119#undef PGMATH_PRECISE_ALL_FP 120#undef PGMATH_PRECISE_REAL2 121#undef PGMATH_PRECISE_COMPLEX2 122#undef PGMATH_PRECISE_ALL_FP2 123#ifdef PGMATH_PRECISE 124#define PGMATH_PRECISE_REAL(func) PGMATH_REAL_IMPL(p, func) 125#define PGMATH_PRECISE_ALL_FP(func) PGMATH_ALL_IMPL(p, func) 126#define PGMATH_PRECISE_REAL2(func) PGMATH_REAL2_IMPL(p, func) 127#define PGMATH_PRECISE_ALL_FP2(func) PGMATH_ALL_FP2_IMPL(p, func) 128#else 129#define PGMATH_PRECISE_REAL(func) 130#define PGMATH_PRECISE_COMPLEX(func) 131#define PGMATH_PRECISE_ALL_FP(func) 132#define PGMATH_PRECISE_REAL2(func) 133#define PGMATH_PRECISE_COMPLEX2(func) 134#define PGMATH_PRECISE_ALL_FP2(func) 135#endif 136 137#define PGMATH_REAL(func) \ 138 PGMATH_FAST_REAL(func) \ 139 PGMATH_PRECISE_REAL(func) \ 140 PGMATH_RELAXED_REAL(func) 141 142#define PGMATH_ALL(func) \ 143 PGMATH_REAL(func) \ 144 145#define PGMATH_REAL2(func) \ 146 PGMATH_FAST_REAL2(func) \ 147 PGMATH_PRECISE_REAL2(func) \ 148 PGMATH_RELAXED_REAL2(func) 149 150#define PGMATH_ALL2(func) \ 151 PGMATH_REAL2(func) \ 152 153// Marcos to declare __mth_i libpgmath variants 154#define PGMATH_MTH_VERSION_REAL(func) \ 155 PGMATH_DECLARE(float __mth_i_##func(float)) \ 156 PGMATH_DECLARE(double __mth_i_d##func(double)) \ 157 PGMATH_USE_S(func, __mth_i_##func) \ 158 PGMATH_USE_D(func, __mth_i_d##func) 159 160// Actual libpgmath declarations 161PGMATH_ALL(acos) 162PGMATH_MTH_VERSION_REAL(acosh) 163PGMATH_ALL(asin) 164PGMATH_MTH_VERSION_REAL(asinh) 165PGMATH_ALL(atan) 166PGMATH_REAL2(atan2) 167PGMATH_MTH_VERSION_REAL(atanh) 168PGMATH_MTH_VERSION_REAL(bessel_j0) 169PGMATH_MTH_VERSION_REAL(bessel_j1) 170// bessel_jn and bessel_yn takes an int as first arg 171PGMATH_DECLARE(float __mth_i_bessel_jn(int, float)) 172PGMATH_DECLARE(double __mth_i_dbessel_jn(int, double)) 173PGMATH_USE_S(bessel_jn, __mth_i_bessel_jn) 174PGMATH_USE_D(bessel_jn, __mth_i_dbessel_jn) 175PGMATH_MTH_VERSION_REAL(bessel_y0) 176PGMATH_MTH_VERSION_REAL(bessel_y1) 177PGMATH_DECLARE(float __mth_i_bessel_yn(int, float)) 178PGMATH_DECLARE(double __mth_i_dbessel_yn(int, double)) 179PGMATH_USE_S(bessel_yn, __mth_i_bessel_yn) 180PGMATH_USE_D(bessel_yn, __mth_i_dbessel_yn) 181 182PGMATH_ALL(cos) 183PGMATH_ALL(cosh) 184PGMATH_MTH_VERSION_REAL(erf) 185PGMATH_MTH_VERSION_REAL(erfc) 186PGMATH_MTH_VERSION_REAL(erfc_scaled) 187PGMATH_ALL(exp) 188PGMATH_MTH_VERSION_REAL(gamma) 189 190PGMATH_DECLARE(float __mth_i_hypot(float, float)) 191PGMATH_DECLARE(double __mth_i_dhypot(double, double)) 192PGMATH_USE_S(hypot, __mth_i_hypot) 193PGMATH_USE_D(hypot, __mth_i_dhypot) 194 195PGMATH_ALL(log) 196PGMATH_REAL(log10) 197PGMATH_MTH_VERSION_REAL(log_gamma) 198// no function for modulo in libpgmath. 199// fast mod used in all versions. 200PGMATH_DECLARE(float __fs_mod_1(float, float)) 201PGMATH_DECLARE(double __fd_mod_1(double, double)) 202PGMATH_USE_S(mod, __fs_mod_1) 203PGMATH_USE_D(mod, __fd_mod_1) 204 205PGMATH_ALL2(pow) 206// Versions of pow with integer exponents 207#define PGMATH_DELCARE_POW(impl) \ 208 PGMATH_DECLARE(float __##impl##s_powi_1(float, int)) \ 209 PGMATH_DECLARE(double __##impl##d_powi_1(double, int)) \ 210 PGMATH_USE_S(pow, __##impl##s_powi_1) \ 211 PGMATH_USE_D(pow, __##impl##d_powi_1) \ 212 PGMATH_USE_C(pow, __##impl##c_powi_1) \ 213 PGMATH_USE_Z(pow, __##impl##z_powi_1) \ 214 PGMATH_DECLARE(float __##impl##s_powk_1(float, int64_t)) \ 215 PGMATH_DECLARE(double __##impl##d_powk_1(double, int64_t)) \ 216 PGMATH_USE_S(pow, __##impl##s_powk_1) \ 217 PGMATH_USE_D(pow, __##impl##d_powk_1) \ 218 PGMATH_USE_C(pow, __##impl##c_powk_1) \ 219 PGMATH_USE_Z(pow, __##impl##z_powk_1) 220 221#ifdef PGMATH_FAST 222PGMATH_DELCARE_POW(f) 223#endif 224#ifdef PGMATH_RELAXED 225PGMATH_DELCARE_POW(r) 226#endif 227#ifdef PGMATH_PRECISE 228PGMATH_DELCARE_POW(p) 229#endif 230 231// integer ** integer versions of pow 232PGMATH_DECLARE(int __mth_i_ipowi(int, int)) 233PGMATH_DECLARE(int64_t __mth_i_kpowk(int64_t, int64_t)) 234PGMATH_USE_OTHER(pow, __mth_i_ipowi) 235PGMATH_USE_OTHER(pow, __mth_i_kpowk) 236 237PGMATH_ALL(sin) 238PGMATH_ALL(sinh) 239PGMATH_MTH_VERSION_REAL(sqrt) 240PGMATH_ALL(tan) 241PGMATH_ALL(tanh) 242 243#undef PGMATH_DECLARE 244#undef PGMATH_FAST 245#undef PGMATH_PRECISE 246#undef PGMATH_RELAXED 247#undef PGMATH_USE_S 248#undef PGMATH_USE_D 249#undef PGMATH_USE_C 250#undef PGMATH_USE_Z 251#undef PGMATH_USE_OTHER 252#undef PGMATH_USE_ALL_TYPES 253