From 81aa19a8f0b11f14c9c95ce8795ff8a5d6dd868f Mon Sep 17 00:00:00 2001 From: Evghenii Date: Fri, 7 Feb 2014 11:49:24 +0100 Subject: [PATCH] added use of native_transendentals, need to add IR --- stdlib.ispc | 227 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 163 insertions(+), 64 deletions(-) diff --git a/stdlib.ispc b/stdlib.ispc index 24217cd0..eb5ee9c4 100644 --- a/stdlib.ispc +++ b/stdlib.ispc @@ -2298,8 +2298,12 @@ static inline uniform float frexp(uniform float x, uniform int * uniform pw2) { __declspec(safe) static inline float sin(float x_full) { - if (__math_lib == __math_lib_svml) { - return __svml_sinf(x_full); + if (__have_native_trigonometry) + { + return __sin_varying_float(x_full); + } + else if (__math_lib == __math_lib_svml) { + return __svml_sinf(x_full); } else if (__math_lib == __math_lib_system) { float ret; @@ -2360,7 +2364,11 @@ static inline float sin(float x_full) { __declspec(safe) static inline uniform float sin(uniform float x_full) { - if (__math_lib == __math_lib_system || + if (__have_native_trigonometry) + { + return __sin_uniform_float(x_full); + } + else if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { return __stdlib_sinf(x_full); } @@ -2432,7 +2440,11 @@ static inline float asin(float x) { bool isnan = (x > 1); float v; - if (__math_lib == __math_lib_svml) { + if (__have_native_trigonometry) + { + return __asin_varying_float(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_asinf(x); } else if (__math_lib == __math_lib_system) { @@ -2491,7 +2503,11 @@ static inline uniform float asin(uniform float x) { uniform bool isnan = (x > 1); uniform float v; - if (__math_lib == __math_lib_svml || + if (__have_native_trigonometry) + { + return __asin_uniform_float(x_full); + } + else if (__math_lib == __math_lib_svml || __math_lib == __math_lib_system) { return __stdlib_asinf(x); } @@ -2537,6 +2553,10 @@ static inline uniform float asin(uniform float x) { __declspec(safe) static inline float cos(float x_full) { + if (__have_native_trigonometry) + { + return __cos_varying_float(x_full); + } if (__math_lib == __math_lib_svml) { return __svml_cosf(x_full); } @@ -2598,7 +2618,11 @@ static inline float cos(float x_full) { __declspec(safe) static inline uniform float cos(uniform float x_full) { - if (__math_lib == __math_lib_system || + if (__have_native_trigonometry) + { + return __cos_uniform_float(x_full); + } + else if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { return __stdlib_cosf(x_full); } @@ -2686,6 +2710,10 @@ static inline uniform double acos(const uniform double v) { __declspec(safe) static inline void sincos(float x_full, varying float * uniform sin_result, varying float * uniform cos_result) { + if (__have_native_trigonometry) + { + __sincos_varying_float(x_full,sin_result,cos_result); + } if (__math_lib == __math_lib_svml) { __svml_sincosf(x_full, sin_result, cos_result); } @@ -2756,6 +2784,10 @@ static inline void sincos(float x_full, varying float * uniform sin_result, __declspec(safe) static inline void sincos(uniform float x_full, uniform float * uniform sin_result, uniform float * uniform cos_result) { + if (__have_native_trigonometry) + { + __sincos_uniform_float(x_full, sin_result, cos_result); + } if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { __stdlib_sincosf(x_full, sin_result, cos_result); @@ -2818,7 +2850,11 @@ static inline void sincos(uniform float x_full, uniform float * uniform sin_resu __declspec(safe) static inline float tan(float x_full) { - if (__math_lib == __math_lib_svml) { + if (__have_native_trigonometry) + { + return __tan_varying_float(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_tanf(x_full); } else if (__math_lib == __math_lib_system) { @@ -2897,7 +2933,11 @@ static inline float tan(float x_full) { __declspec(safe) static inline uniform float tan(uniform float x_full) { - if (__math_lib == __math_lib_system || + if (__have_native_trigonometry) + { + return __tan_uniform_float(x_full); + } + else if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { return __stdlib_tanf(x_full); } @@ -2969,7 +3009,11 @@ static inline uniform float tan(uniform float x_full) { __declspec(safe) static inline float atan(float x_full) { - if (__math_lib == __math_lib_svml) { + if (__have_native_trigonometry) + { + return __atan_varying_float(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_atanf(x_full); } else if (__math_lib == __math_lib_system) { @@ -3020,7 +3064,11 @@ static inline float atan(float x_full) { __declspec(safe) static inline uniform float atan(uniform float x_full) { - if (__math_lib == __math_lib_system || + if (__have_native_trigonometry) + { + return __atan_uniform_float(x_full); + } + else if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { return __stdlib_atanf(x_full); } @@ -3064,7 +3112,11 @@ static inline uniform float atan(uniform float x_full) { __declspec(safe) static inline float atan2(float y, float x) { - if (__math_lib == __math_lib_svml) { + if (__have_native_trigonometry) + { + return __atan2_varying_float(y,x); + } + else if (__math_lib == __math_lib_svml) { return __svml_atan2f(y, x); } else if (__math_lib == __math_lib_system) { @@ -3103,7 +3155,11 @@ static inline float atan2(float y, float x) { __declspec(safe) static inline uniform float atan2(uniform float y, uniform float x) { - if (__math_lib == __math_lib_system || + if (__have_native_trigonometry) + { + return __atan2_uniform_float(y,x); + } + else if (__math_lib == __math_lib_system || __math_lib == __math_lib_svml) { return __stdlib_atan2f(y, x); } @@ -3638,12 +3694,14 @@ static inline uniform double frexp(uniform double x, uniform int * uniform pw2) __declspec(safe) static inline double sin(double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_trigonometry) + { + return __sin_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_sind(x); } - else if (__math_lib == __math_lib_ispc_fast) - return sin((float)x); else { double ret; foreach_active (i) { @@ -3653,23 +3711,46 @@ static inline double sin(double x) { return ret; } } +__declspec(safe) +static inline double asin(double x) { + if (__have_native_trigonometry) + { + return __asin_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) + { + return __svml_asind(x); + } + else { + double ret; + foreach_active (i) { + uniform double r = __stdlib_asin(extract(x, i)); + ret = insert(ret, i, r); + } + return ret; + } +} __declspec(safe) static inline uniform double sin(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return sin((float)x); + if (__have_native_trigonometry) + { + return __sin_uniform_double(x_full); + } else return __stdlib_sin(x); } __declspec(safe) static inline double asin(const double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_trigonometry) + { + return __asin_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_asind(x); } - else if (__math_lib == __math_lib_ispc_fast) - return asin((float)x); else { double ret; foreach_active (i) { @@ -3682,12 +3763,14 @@ static inline double asin(const double x) { __declspec(safe) static inline double cos(const double x) { + if (__have_native_trigonometry) + { + return __cos_varying_double(x_full); + } if (__math_lib == __math_lib_svml) { return __svml_cosd(x); } - else if (__math_lib == __math_lib_ispc_fast) - return cos((float)x); else { double ret; foreach_active (i) { @@ -3700,8 +3783,10 @@ static inline double cos(const double x) { __declspec(safe) static inline uniform double cos(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return cos((float)x); + if (__have_native_trigonometry) + { + return __cos_uniform_double(x_full); + } else return __stdlib_cos(x); } @@ -3709,16 +3794,14 @@ static inline uniform double cos(uniform double x) { __declspec(safe) static inline void sincos(double x, varying double * uniform sin_result, varying double * uniform cos_result) { + if (__have_native_trigonometry) + { + __sincos_varying_double(x_full),sin_result,cos_result); + } if (__math_lib == __math_lib_svml) { __svml_sincosd(x, sin_result, cos_result); } - else if (__math_lib == __math_lib_ispc_fast) { - float sr, cr; - sincos((float)x, &sr, &cr); - *sin_result = sr; - *cos_result = cr; - } else { foreach_active (i) { uniform double sr, cr; @@ -3732,11 +3815,9 @@ static inline void sincos(double x, varying double * uniform sin_result, __declspec(safe) static inline void sincos(uniform double x, uniform double * uniform sin_result, uniform double * uniform cos_result) { - if (__math_lib == __math_lib_ispc_fast) { - uniform float sr, cr; - sincos((uniform float)x, &sr, &cr); - *sin_result = sr; - *cos_result = cr; + if (__have_native_trigonometry) + { + __sincos_uniform_double(x_full,sin_result, cos_result); } else __stdlib_sincos(x, sin_result, cos_result); @@ -3744,12 +3825,14 @@ static inline void sincos(uniform double x, uniform double * uniform sin_result, __declspec(safe) static inline double tan(double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_trigonometry) + { + return __tan_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_tand(x); } - else if (__math_lib == __math_lib_ispc_fast) - return tan((float)x); else { double ret; foreach_active (i) { @@ -3762,16 +3845,20 @@ static inline double tan(double x) { __declspec(safe) static inline uniform double tan(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return tan((float)x); + if (__have_native_trigonometry) + { + return __tan_uniform_double(x_full); + } else return __stdlib_tan(x); } __declspec(safe) static inline double atan(double x) { - if (__math_lib == __math_lib_ispc_fast) - return atan((float)x); + if (__have_native_trigonometry) + { + return __atan_varying_double(x_full); + } else { double ret; foreach_active (i) { @@ -3784,20 +3871,24 @@ static inline double atan(double x) { __declspec(safe) static inline uniform double atan(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return atan((float)x); + if (__have_native_trigonometry) + { + return __atan_uniform_double(x_full); + } else return __stdlib_atan(x); } __declspec(safe) static inline double atan2(double y, double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_trigonometry) + { + return __atan2_varying_double(y,x); + } + else if (__math_lib == __math_lib_svml) { return __svml_atan2d(y,x); } - else if (__math_lib == __math_lib_ispc_fast) - return atan2((float)y, (float)x); else { double ret; foreach_active (i) { @@ -3810,20 +3901,23 @@ static inline double atan2(double y, double x) { __declspec(safe) static inline uniform double atan2(uniform double y, uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return atan2((float)y, (float)x); + if (__have_native_trigonometry) + { + return __atan2_uniform_double(y,x); + } else return __stdlib_atan2(y, x); } __declspec(safe) static inline double exp(double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_transcendentals) { + return __exp_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_expd(x); } - else if (__math_lib == __math_lib_ispc_fast) - return exp((float)x); else { double ret; foreach_active (i) { @@ -3836,20 +3930,22 @@ static inline double exp(double x) { __declspec(safe) static inline uniform double exp(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return exp((float)x); + if (__have_native_transcendentals) { + return __exp_uniform_double(x_full); + } else return __stdlib_exp(x); } __declspec(safe) static inline double log(double x) { - if (__math_lib == __math_lib_svml) + if (__have_native_transcendentals) { + return __log_varying_double(x_full); + } + else if (__math_lib == __math_lib_svml) { return __svml_logd(x); } - else if (__math_lib == __math_lib_ispc_fast) - return log((float)x); else { double ret; foreach_active (i) { @@ -3862,20 +3958,22 @@ static inline double log(double x) { __declspec(safe) static inline uniform double log(uniform double x) { - if (__math_lib == __math_lib_ispc_fast) - return log((float)x); + if (__have_native_transcendentals) { + return __log_uniform_double(x_full); + } else return __stdlib_log(x); } __declspec(safe) static inline double pow(double a, double b) { - if (__math_lib == __math_lib_svml) + if (__have_native_transcendentals) { + return __pow_varying_double(a,b); + } + else if (__math_lib == __math_lib_svml) { return __svml_powd(a,b); } - else if (__math_lib == __math_lib_ispc_fast) - return pow((float)a, (float)b); else { double ret; foreach_active (i) { @@ -3888,8 +3986,9 @@ static inline double pow(double a, double b) { __declspec(safe) static inline uniform double pow(uniform double a, uniform double b) { - if (__math_lib == __math_lib_ispc_fast) - return pow((float)a, (float)b); + if (__have_native_transcendentals) { + return __pow_uniform_double(a,b); + } else return __stdlib_pow(a, b); }