static inline Math::Vector3<float> Vector3Orthonormalize(const float &eps, const Math::Vector3<float> &u, const Math::Vector3<float> &v) { Math::Vector3<float> p; float D = __builtin_sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); if( __builtin_fabsf( D - 1.0 ) > eps ) { double N = u.x * v.x + u.y * v.y + u.z * v.z; double Q = N / D; p.x = u.x - Q * v.x; p.y = u.y - Q * v.y; p.z = u.z - Q * v.z; double L = 1.0 / __builtin_sqrtf(p.x * p.x + p.y * p.y + p.z * p.z); p.x *= L; p.y *= L; p.z *= L; } // if return p; } // Vector3Orthonormalize
void test_float_sqrt (void) { int i; for (i = 0; i < SIZE; i++) f1[i] = __builtin_sqrtf (f2[i]); }
buffer_f32_t AM::execute( const buffer_c16_t& src, const buffer_f32_t& dst ) { const auto src_p = src.p; const auto src_end = &src.p[src.count]; auto dst_p = dst.p; while(src_p < src_end) { const uint32_t sample0 = *__SIMD32(src_p)++; const uint32_t sample1 = *__SIMD32(src_p)++; const uint32_t mag_sq0 = __SMUAD(sample0, sample0); const uint32_t mag_sq1 = __SMUAD(sample1, sample1); *(dst_p++) = __builtin_sqrtf(mag_sq0) * k; *(dst_p++) = __builtin_sqrtf(mag_sq1) * k; } return { dst.p, src.count, src.sampling_rate }; }
static inline Math::Vector2<float> Vector2Normalize(const float eps, const Math::Vector2<float> &v) { Math::Vector2<float> p(v); float L = __builtin_sqrtf(v.x * v.x + v.y * v.y); if( __builtin_fabsf( L - 1.0 ) > eps ) { L = 1.0/L; p.x *= L; p.y *= L; } // if return p; } // Vector2Normalize
static void prepareCircle(ClipBuffer *buf, int centerX, int centerY, int radius) { int r, i; i = 0; for (r = -radius; r <= radius; r++) { int chordRadius = __builtin_sqrtf(radius * radius - r * r) + 0.5f; SVGASignedRect *rect = &buf->rects[i++]; rect->left = centerX - chordRadius; rect->top = centerY - r; rect->right = centerX + chordRadius; rect->bottom = centerY - r + 1; ScreenDraw_Rectangle(rect->left - 1, rect->top - 1, rect->right + 1, rect->bottom + 1, 0xffffff); } buf->numRects = i; }
float rsqrt_f (float a) { return 1.0f / __builtin_sqrtf (a); }
void test2f(float x, float y) { if (-tanf(x-y) != tanf(y-x)) link_error (); if (-sinf(x-y) != sinf(y-x)) link_error (); if (cosf(-x*y) != cosf(x*y)) link_error (); if (cosf(x*-y) != cosf(x*y)) link_error (); if (cosf(-x/y) != cosf(x/y)) link_error (); if (cosf(x/-y) != cosf(x/y)) link_error (); if (cosf(-fabsf(tanf(x/-y))) != cosf(tanf(x/y))) link_error (); if (cosf(y<10 ? -x : y) != cosf(y<10 ? x : y)) link_error (); if (cosf(y<10 ? x : -y) != cosf(y<10 ? x : y)) link_error (); if (cosf(y<10 ? -fabsf(x) : tanf(x<20 ? -x : -fabsf(y))) != cosf(y<10 ? x : tanf(x<20 ? x : y))) link_error (); if (cosf((y*=3, -x)) != cosf((y*=3,x))) link_error (); if (cosf((y*=2, -fabsf(tanf(x/-y)))) != cosf((y*=2,tanf(x/y)))) link_error (); if (cosf(copysignf(x,y)) != cosf(x)) link_error (); if (cosf(copysignf(-fabsf(x),y*=2)) != cosf((y*=2,x))) link_error (); if (hypotf (x, 0) != fabsf(x)) link_error (); if (hypotf (0, x) != fabsf(x)) link_error (); if (hypotf (x, x) != fabsf(x) * __builtin_sqrtf(2)) link_error (); if (hypotf (-x, y) != hypotf (x, y)) link_error (); if (hypotf (x, -y) != hypotf (x, y)) link_error (); if (hypotf (-x, -y) != hypotf (x, y)) link_error (); if (hypotf (fabsf(x), y) != hypotf (x, y)) link_error (); if (hypotf (x, fabsf(y)) != hypotf (x, y)) link_error (); if (hypotf (fabsf(x), fabsf(y)) != hypotf (x, y)) link_error (); if (hypotf (-fabsf(-x), -fabsf(fabsf(fabsf(-y)))) != hypotf (x, y)) link_error (); if (hypotf (-x, 0) != fabsf(x)) link_error (); if (hypotf (-x, x) != fabsf(x) * __builtin_sqrtf(2)) link_error (); if (hypotf (puref(x), -puref(x)) != fabsf(puref(x)) * __builtin_sqrtf(2)) link_error (); if (hypotf (tanf(-x), tanf(-fabsf(y))) != hypotf (tanf(x), tanf(y))) link_error (); if (fminf (fmaxf(x,y),y) != y) link_error (); if (fminf (fmaxf(y,x),y) != y) link_error (); if (fminf (x,fmaxf(x,y)) != x) link_error (); if (fminf (x,fmaxf(y,x)) != x) link_error (); if (fmaxf (fminf(x,y),y) != y) link_error (); if (fmaxf (fminf(y,x),y) != y) link_error (); if (fmaxf (x,fminf(x,y)) != x) link_error (); if (fmaxf (x,fminf(y,x)) != x) link_error (); if ((__complex__ float) x != -(__complex__ float) (-x)) link_error (); if (x+(x-y)*1i != -(-x+(y-x)*1i)) link_error (); if (x+(x-y)*1i != -(-x-(x-y)*1i)) link_error (); if (ccosf(tanf(x)+sinf(y)*1i) != ccosf(-tanf(-x)+-sinf(-y)*1i)) link_error (); if (ccosf(tanf(x)+sinf(x-y)*1i) != ccosf(-tanf(-x)-sinf(y-x)*1i)) link_error (); if (-5+x*1i != -~(5+x*1i)) link_error (); if (tanf(x)+tanf(y)*1i != -~(tanf(-x)+tanf(y)*1i)) link_error (); }
Math::Vector2<float> Math::proj(const Math::Vector2<float> &u, const Math::Vector2<float> &v) { return v * ((u * v) / __builtin_sqrtf(v * v)); } // proj
float Math::inorm(const Math::Vector2<float> &v) { return 1.0f / __builtin_sqrtf(v.x * v.x + v.y * v.y); } // inorm
float Math::norm(const Math::Vector2<float> &v) { return __builtin_sqrtf(v.x * v.x + v.y * v.y); } // norm
//static Sfloat sqrt1 (Sfloat AC, Sfloat Y) { return __builtin_sqrtf (Y); } static Sfloat sqrt2 (Sfloat AC, Sfloat *X) { return __builtin_sqrtf (*X); }
float test1f(float x) { return __builtin_sqrtf(x); }
float __ieee754_sqrtf (float s) { return __builtin_sqrtf (s); }
float Math::abs(const Math::Vector3<float> &v) { return __builtin_sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); } // abs
// CHECK-LABEL: define void @test_float_builtin_ops void test_float_builtin_ops(float F, double D, long double LD) { volatile float resf; volatile double resd; volatile long double resld; resf = __builtin_fmodf(F,F); // CHECK: frem float resd = __builtin_fmod(D,D); // CHECK: frem double resld = __builtin_fmodl(LD,LD); // CHECK: frem x86_fp80 resf = __builtin_fabsf(F); resd = __builtin_fabs(D); resld = __builtin_fabsl(LD); // CHECK: call float @llvm.fabs.f32(float // CHECK: call double @llvm.fabs.f64(double // CHECK: call x86_fp80 @llvm.fabs.f80(x86_fp80 resf = __builtin_canonicalizef(F); resd = __builtin_canonicalize(D); resld = __builtin_canonicalizel(LD); // CHECK: call float @llvm.canonicalize.f32(float // CHECK: call double @llvm.canonicalize.f64(double // CHECK: call x86_fp80 @llvm.canonicalize.f80(x86_fp80 resf = __builtin_fminf(F, F); // CHECK: call float @llvm.minnum.f32 resd = __builtin_fmin(D, D); // CHECK: call double @llvm.minnum.f64 resld = __builtin_fminl(LD, LD); // CHECK: call x86_fp80 @llvm.minnum.f80 resf = __builtin_fmaxf(F, F); // CHECK: call float @llvm.maxnum.f32 resd = __builtin_fmax(D, D); // CHECK: call double @llvm.maxnum.f64 resld = __builtin_fmaxl(LD, LD); // CHECK: call x86_fp80 @llvm.maxnum.f80 resf = __builtin_fabsf(F); // CHECK: call float @llvm.fabs.f32 resd = __builtin_fabs(D); // CHECK: call double @llvm.fabs.f64 resld = __builtin_fabsl(LD); // CHECK: call x86_fp80 @llvm.fabs.f80 resf = __builtin_copysignf(F, F); // CHECK: call float @llvm.copysign.f32 resd = __builtin_copysign(D, D); // CHECK: call double @llvm.copysign.f64 resld = __builtin_copysignl(LD, LD); // CHECK: call x86_fp80 @llvm.copysign.f80 resf = __builtin_ceilf(F); // CHECK: call float @llvm.ceil.f32 resd = __builtin_ceil(D); // CHECK: call double @llvm.ceil.f64 resld = __builtin_ceill(LD); // CHECK: call x86_fp80 @llvm.ceil.f80 resf = __builtin_floorf(F); // CHECK: call float @llvm.floor.f32 resd = __builtin_floor(D); // CHECK: call double @llvm.floor.f64 resld = __builtin_floorl(LD); // CHECK: call x86_fp80 @llvm.floor.f80 resf = __builtin_sqrtf(F); // CHECK: call float @llvm.sqrt.f32( resd = __builtin_sqrt(D); // CHECK: call double @llvm.sqrt.f64( resld = __builtin_sqrtl(LD); // CHECK: call x86_fp80 @llvm.sqrt.f80 resf = __builtin_truncf(F); // CHECK: call float @llvm.trunc.f32 resd = __builtin_trunc(D); // CHECK: call double @llvm.trunc.f64 resld = __builtin_truncl(LD); // CHECK: call x86_fp80 @llvm.trunc.f80 resf = __builtin_rintf(F); // CHECK: call float @llvm.rint.f32 resd = __builtin_rint(D); // CHECK: call double @llvm.rint.f64 resld = __builtin_rintl(LD); // CHECK: call x86_fp80 @llvm.rint.f80 resf = __builtin_nearbyintf(F); // CHECK: call float @llvm.nearbyint.f32 resd = __builtin_nearbyint(D); // CHECK: call double @llvm.nearbyint.f64 resld = __builtin_nearbyintl(LD); // CHECK: call x86_fp80 @llvm.nearbyint.f80 resf = __builtin_roundf(F); // CHECK: call float @llvm.round.f32 resd = __builtin_round(D); // CHECK: call double @llvm.round.f64 resld = __builtin_roundl(LD); // CHECK: call x86_fp80 @llvm.round.f80 }