1 /* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 * THE SOFTWARE. 21 */ 22 23 #ifndef __CLC_MATH_H_ 24 #define __CLC_MATH_H_ 25 26 #include "clc/clcfunc.h" 27 #include "clc/as_type.h" 28 #include "config.h" 29 30 #define SNAN 0x001 31 #define QNAN 0x002 32 #define NINF 0x004 33 #define NNOR 0x008 34 #define NSUB 0x010 35 #define NZER 0x020 36 #define PZER 0x040 37 #define PSUB 0x080 38 #define PNOR 0x100 39 #define PINF 0x200 40 41 #if (defined __AMDGCN__ || defined __R600__) && !defined __HAS_FMAF__ 42 #define HAVE_HW_FMA32() (0) 43 #else 44 #define HAVE_HW_FMA32() (1) 45 #endif 46 47 #define HAVE_BITALIGN() (0) 48 #define HAVE_FAST_FMA32() (0) 49 50 #define MATH_DIVIDE(X, Y) ((X) / (Y)) 51 #define MATH_RECIP(X) (1.0f / (X)) 52 #define MATH_SQRT(X) sqrt(X) 53 54 #define SIGNBIT_SP32 0x80000000 55 #define EXSIGNBIT_SP32 0x7fffffff 56 #define EXPBITS_SP32 0x7f800000 57 #define MANTBITS_SP32 0x007fffff 58 #define ONEEXPBITS_SP32 0x3f800000 59 #define TWOEXPBITS_SP32 0x40000000 60 #define HALFEXPBITS_SP32 0x3f000000 61 #define IMPBIT_SP32 0x00800000 62 #define QNANBITPATT_SP32 0x7fc00000 63 #define INDEFBITPATT_SP32 0xffc00000 64 #define PINFBITPATT_SP32 0x7f800000 65 #define NINFBITPATT_SP32 0xff800000 66 #define EXPBIAS_SP32 127 67 #define EXPSHIFTBITS_SP32 23 68 #define BIASEDEMIN_SP32 1 69 #define EMIN_SP32 -126 70 #define BIASEDEMAX_SP32 254 71 #define EMAX_SP32 127 72 #define LAMBDA_SP32 1.0e30 73 #define MANTLENGTH_SP32 24 74 #define BASEDIGITS_SP32 7 75 76 _CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) 77 { 78 int ix = as_int(x); 79 if (!__clc_fp32_subnormals_supported() && 80 ((ix & EXPBITS_SP32) == 0) && ((ix & MANTBITS_SP32) != 0)) { 81 ix &= SIGNBIT_SP32; 82 x = as_float(ix); 83 } 84 return x; 85 } 86 87 #ifdef cl_khr_fp64 88 89 #define SIGNBIT_DP64 0x8000000000000000L 90 #define EXSIGNBIT_DP64 0x7fffffffffffffffL 91 #define EXPBITS_DP64 0x7ff0000000000000L 92 #define MANTBITS_DP64 0x000fffffffffffffL 93 #define ONEEXPBITS_DP64 0x3ff0000000000000L 94 #define TWOEXPBITS_DP64 0x4000000000000000L 95 #define HALFEXPBITS_DP64 0x3fe0000000000000L 96 #define IMPBIT_DP64 0x0010000000000000L 97 #define QNANBITPATT_DP64 0x7ff8000000000000L 98 #define INDEFBITPATT_DP64 0xfff8000000000000L 99 #define PINFBITPATT_DP64 0x7ff0000000000000L 100 #define NINFBITPATT_DP64 0xfff0000000000000L 101 #define EXPBIAS_DP64 1023 102 #define EXPSHIFTBITS_DP64 52 103 #define BIASEDEMIN_DP64 1 104 #define EMIN_DP64 -1022 105 #define BIASEDEMAX_DP64 2046 /* 0x7fe */ 106 #define EMAX_DP64 1023 /* 0x3ff */ 107 #define LAMBDA_DP64 1.0e300 108 #define MANTLENGTH_DP64 53 109 #define BASEDIGITS_DP64 15 110 111 #endif // cl_khr_fp64 112 113 #define ALIGNED(x) __attribute__((aligned(x))) 114 #endif // __CLC_MATH_H_ 115