source/projects/vb.mi.rppls_tilde/vcvrack/include/simd/sse_mathfun.h
inline void sse_mathfun_sincos_ps(__m128 x, __m128* s, __m128* c) {
	__m128 xmm1, xmm2, xmm3 = _mm_setzero_ps(), sign_bit_sin, y;
	__m128i emm0, emm2, emm4;
	sign_bit_sin = x;
	/* take the absolute value */
	const __m128 inv_sign_mask = _mm_castsi128_ps(_mm_set1_epi32(~0x80000000));
	x = _mm_and_ps(x, inv_sign_mask);
	/* extract the sign bit (upper one) */
	const __m128 sign_mask = _mm_castsi128_ps(_mm_set1_epi32(0x80000000));
	sign_bit_sin = _mm_and_ps(sign_bit_sin, sign_mask);

	/* scale by 4/Pi */
	const __m128 cephes_FOPI = _mm_set_ps1(1.27323954473516); // 4 / M_PI
	y = _mm_mul_ps(x, cephes_FOPI);

	/* store the integer part of y in emm2 */
	emm2 = _mm_cvttps_epi32(y);

	/* j=(j+1) & (~1) (see the cephes sources) */
	emm2 = _mm_add_epi32(emm2, _mm_set1_epi32(1));
	emm2 = _mm_and_si128(emm2, _mm_set1_epi32(~1));
	y = _mm_cvtepi32_ps(emm2);

	emm4 = emm2;

	/* get the swap sign flag for the sine */
	emm0 = _mm_and_si128(emm2, _mm_set1_epi32(4));
	emm0 = _mm_slli_epi32(emm0, 29);
	__m128 swap_sign_bit_sin = _mm_castsi128_ps(emm0);

	/* get the polynom selection mask for the sine*/
	emm2 = _mm_and_si128(emm2, _mm_set1_epi32(2));
	emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
	__m128 poly_mask = _mm_castsi128_ps(emm2);

	/* The magic pass: "Extended precision modular arithmetic"
	   x = ((x - y * DP1) - y * DP2) - y * DP3; */
	xmm1 = _mm_set_ps1(-0.78515625);
	xmm2 = _mm_set_ps1(-2.4187564849853515625e-4);
	xmm3 = _mm_set_ps1(-3.77489497744594108e-8);
	xmm1 = _mm_mul_ps(y, xmm1);
	xmm2 = _mm_mul_ps(y, xmm2);
	xmm3 = _mm_mul_ps(y, xmm3);
	x = _mm_add_ps(x, xmm1);
	x = _mm_add_ps(x, xmm2);
	x = _mm_add_ps(x, xmm3);

	emm4 = _mm_sub_epi32(emm4, _mm_set1_epi32(2));
	emm4 = _mm_andnot_si128(emm4, _mm_set1_epi32(4));
	emm4 = _mm_slli_epi32(emm4, 29);
	__m128 sign_bit_cos = _mm_castsi128_ps(emm4);

	sign_bit_sin = _mm_xor_ps(sign_bit_sin, swap_sign_bit_sin);


	/* Evaluate the first polynom  (0 <= x <= Pi/4) */
	__m128 z = _mm_mul_ps(x, x);
	y = _mm_set_ps1(2.443315711809948E-005);

	y = _mm_mul_ps(y, z);
	y = _mm_add_ps(y, _mm_set_ps1(-1.388731625493765E-003));
	y = _mm_mul_ps(y, z);
	y = _mm_add_ps(y, _mm_set_ps1(4.166664568298827E-002));
	y = _mm_mul_ps(y, z);
	y = _mm_mul_ps(y, z);
	__m128 tmp = _mm_mul_ps(z, _mm_set_ps1(0.5));
	y = _mm_sub_ps(y, tmp);
	y = _mm_add_ps(y, _mm_set_ps1(1.0));

	/* Evaluate the second polynom  (Pi/4 <= x <= 0) */

	__m128 y2 = _mm_set_ps1(-1.9515295891E-4);
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_add_ps(y2, _mm_set_ps1(8.3321608736E-3));
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_add_ps(y2, _mm_set_ps1(-1.6666654611E-1));
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_mul_ps(y2, x);
	y2 = _mm_add_ps(y2, x);

	/* select the correct result from the two polynoms */
	xmm3 = poly_mask;
	__m128 ysin2 = _mm_and_ps(xmm3, y2);
	__m128 ysin1 = _mm_andnot_ps(xmm3, y);
	y2 = _mm_sub_ps(y2, ysin2);
	y = _mm_sub_ps(y, ysin1);

	xmm1 = _mm_add_ps(ysin1, ysin2);
	xmm2 = _mm_add_ps(y, y2);

	/* update the sign */
	*s = _mm_xor_ps(xmm1, sign_bit_sin);
	*c = _mm_xor_ps(xmm2, sign_bit_cos);
}
/* since sin_ps and cos_ps are almost identical, sincos_ps could replace both of them..
   it is almost as fast, and gives you a free cosine with your sine */
since sin_ps and cos_ps are almost identical, sincos_ps could replace both of them
it is almost as fast, and gives you a free cosine with your sine
since sin_ps and cos_ps are almost identical sincos_ps could replace both of them it is almost as fast and gives you a free cosine with your sine
inline void sse_mathfun_sincos_ps(__m128 x, __m128* s, __m128* c) {
	__m128 xmm1, xmm2, xmm3 = _mm_setzero_ps(), sign_bit_sin, y;
	__m128i emm0, emm2, emm4;
	sign_bit_sin = x;
	const __m128 inv_sign_mask = _mm_castsi128_ps(_mm_set1_epi32(~0x80000000));
	x = _mm_and_ps(x, inv_sign_mask);
	const __m128 sign_mask = _mm_castsi128_ps(_mm_set1_epi32(0x80000000));
	sign_bit_sin = _mm_and_ps(sign_bit_sin, sign_mask);
	const __m128 cephes_FOPI = _mm_set_ps1(1.27323954473516); 
	y = _mm_mul_ps(x, cephes_FOPI);
	emm2 = _mm_cvttps_epi32(y);
	emm2 = _mm_add_epi32(emm2, _mm_set1_epi32(1));
	emm2 = _mm_and_si128(emm2, _mm_set1_epi32(~1));
	y = _mm_cvtepi32_ps(emm2);
	emm4 = emm2;
	emm0 = _mm_and_si128(emm2, _mm_set1_epi32(4));
	emm0 = _mm_slli_epi32(emm0, 29);
	__m128 swap_sign_bit_sin = _mm_castsi128_ps(emm0);
	emm2 = _mm_and_si128(emm2, _mm_set1_epi32(2));
	emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
	__m128 poly_mask = _mm_castsi128_ps(emm2);
	xmm1 = _mm_set_ps1(-0.78515625);
	xmm2 = _mm_set_ps1(-2.4187564849853515625e-4);
	xmm3 = _mm_set_ps1(-3.77489497744594108e-8);
	xmm1 = _mm_mul_ps(y, xmm1);
	xmm2 = _mm_mul_ps(y, xmm2);
	xmm3 = _mm_mul_ps(y, xmm3);
	x = _mm_add_ps(x, xmm1);
	x = _mm_add_ps(x, xmm2);
	x = _mm_add_ps(x, xmm3);
	emm4 = _mm_sub_epi32(emm4, _mm_set1_epi32(2));
	emm4 = _mm_andnot_si128(emm4, _mm_set1_epi32(4));
	emm4 = _mm_slli_epi32(emm4, 29);
	__m128 sign_bit_cos = _mm_castsi128_ps(emm4);
	sign_bit_sin = _mm_xor_ps(sign_bit_sin, swap_sign_bit_sin);
	__m128 z = _mm_mul_ps(x, x);
	y = _mm_set_ps1(2.443315711809948E-005);
	y = _mm_mul_ps(y, z);
	y = _mm_add_ps(y, _mm_set_ps1(-1.388731625493765E-003));
	y = _mm_mul_ps(y, z);
	y = _mm_add_ps(y, _mm_set_ps1(4.166664568298827E-002));
	y = _mm_mul_ps(y, z);
	y = _mm_mul_ps(y, z);
	__m128 tmp = _mm_mul_ps(z, _mm_set_ps1(0.5));
	y = _mm_sub_ps(y, tmp);
	y = _mm_add_ps(y, _mm_set_ps1(1.0));
	__m128 y2 = _mm_set_ps1(-1.9515295891E-4);
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_add_ps(y2, _mm_set_ps1(8.3321608736E-3));
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_add_ps(y2, _mm_set_ps1(-1.6666654611E-1));
	y2 = _mm_mul_ps(y2, z);
	y2 = _mm_mul_ps(y2, x);
	y2 = _mm_add_ps(y2, x);
	xmm3 = poly_mask;
	__m128 ysin2 = _mm_and_ps(xmm3, y2);
	__m128 ysin1 = _mm_andnot_ps(xmm3, y);
	y2 = _mm_sub_ps(y2, ysin2);
	y = _mm_sub_ps(y, ysin1);
	xmm1 = _mm_add_ps(ysin1, ysin2);
	xmm2 = _mm_add_ps(y, y2);
	*s = _mm_xor_ps(xmm1, sign_bit_sin);
	*c = _mm_xor_ps(xmm2, sign_bit_cos);
}
inline void sse_mathfun_sincos_ps ( __m128 x , __m128 * s , __m128 * c ) { __m128 xmm1 , xmm2 , xmm3 = _mm_setzero_ps ( ) , sign_bit_sin , y ; __m128i emm0 , emm2 , emm4 ; sign_bit_sin = x ; const __m128 inv_sign_mask = _mm_castsi128_ps ( _mm_set1_epi32 ( ~ 0x80000000 ) ) ; x = _mm_and_ps ( x , inv_sign_mask ) ; const __m128 sign_mask = _mm_castsi128_ps ( _mm_set1_epi32 ( 0x80000000 ) ) ; sign_bit_sin = _mm_and_ps ( sign_bit_sin , sign_mask ) ; const __m128 cephes_FOPI = _mm_set_ps1 ( 1.27323954473516 ) ; y = _mm_mul_ps ( x , cephes_FOPI ) ; emm2 = _mm_cvttps_epi32 ( y ) ; emm2 = _mm_add_epi32 ( emm2 , _mm_set1_epi32 ( 1 ) ) ; emm2 = _mm_and_si128 ( emm2 , _mm_set1_epi32 ( ~ 1 ) ) ; y = _mm_cvtepi32_ps ( emm2 ) ; emm4 = emm2 ; emm0 = _mm_and_si128 ( emm2 , _mm_set1_epi32 ( 4 ) ) ; emm0 = _mm_slli_epi32 ( emm0 , 29 ) ; __m128 swap_sign_bit_sin = _mm_castsi128_ps ( emm0 ) ; emm2 = _mm_and_si128 ( emm2 , _mm_set1_epi32 ( 2 ) ) ; emm2 = _mm_cmpeq_epi32 ( emm2 , _mm_setzero_si128 ( ) ) ; __m128 poly_mask = _mm_castsi128_ps ( emm2 ) ; xmm1 = _mm_set_ps1 ( -0.78515625 ) ; xmm2 = _mm_set_ps1 ( -2.4187564849853515625e-4 ) ; xmm3 = _mm_set_ps1 ( -3.77489497744594108e-8 ) ; xmm1 = _mm_mul_ps ( y , xmm1 ) ; xmm2 = _mm_mul_ps ( y , xmm2 ) ; xmm3 = _mm_mul_ps ( y , xmm3 ) ; x = _mm_add_ps ( x , xmm1 ) ; x = _mm_add_ps ( x , xmm2 ) ; x = _mm_add_ps ( x , xmm3 ) ; emm4 = _mm_sub_epi32 ( emm4 , _mm_set1_epi32 ( 2 ) ) ; emm4 = _mm_andnot_si128 ( emm4 , _mm_set1_epi32 ( 4 ) ) ; emm4 = _mm_slli_epi32 ( emm4 , 29 ) ; __m128 sign_bit_cos = _mm_castsi128_ps ( emm4 ) ; sign_bit_sin = _mm_xor_ps ( sign_bit_sin , swap_sign_bit_sin ) ; __m128 z = _mm_mul_ps ( x , x ) ; y = _mm_set_ps1 ( 2.443315711809948E-005 ) ; y = _mm_mul_ps ( y , z ) ; y = _mm_add_ps ( y , _mm_set_ps1 ( -1.388731625493765E-003 ) ) ; y = _mm_mul_ps ( y , z ) ; y = _mm_add_ps ( y , _mm_set_ps1 ( 4.166664568298827E-002 ) ) ; y = _mm_mul_ps ( y , z ) ; y = _mm_mul_ps ( y , z ) ; __m128 tmp = _mm_mul_ps ( z , _mm_set_ps1 ( 0.5 ) ) ; y = _mm_sub_ps ( y , tmp ) ; y = _mm_add_ps ( y , _mm_set_ps1 ( 1.0 ) ) ; __m128 y2 = _mm_set_ps1 ( -1.9515295891E-4 ) ; y2 = _mm_mul_ps ( y2 , z ) ; y2 = _mm_add_ps ( y2 , _mm_set_ps1 ( 8.3321608736E-3 ) ) ; y2 = _mm_mul_ps ( y2 , z ) ; y2 = _mm_add_ps ( y2 , _mm_set_ps1 ( -1.6666654611E-1 ) ) ; y2 = _mm_mul_ps ( y2 , z ) ; y2 = _mm_mul_ps ( y2 , x ) ; y2 = _mm_add_ps ( y2 , x ) ; xmm3 = poly_mask ; __m128 ysin2 = _mm_and_ps ( xmm3 , y2 ) ; __m128 ysin1 = _mm_andnot_ps ( xmm3 , y ) ; y2 = _mm_sub_ps ( y2 , ysin2 ) ; y = _mm_sub_ps ( y , ysin1 ) ; xmm1 = _mm_add_ps ( ysin1 , ysin2 ) ; xmm2 = _mm_add_ps ( y , y2 ) ; * s = _mm_xor_ps ( xmm1 , sign_bit_sin ) ; * c = _mm_xor_ps ( xmm2 , sign_bit_cos ) ; }
since sin_ps and cos_ps are almost identical, sincos_ps could replace both of them..
it is almost as fast, and gives you a free cosine with your sine
since sin_ps and cos_ps are almost identical sincos_ps could replace both of them .. it is almost as fast and gives you a free cosine with your sine
/* take the absolute value */ /* extract the sign bit (upper one) */ /* scale by 4/Pi */ // 4 / M_PI /* store the integer part of y in emm2 */ /* j=(j+1) & (~1) (see the cephes sources) */ /* get the swap sign flag for the sine */ /* get the polynom selection mask for the sine*/ /* The magic pass: "Extended precision modular arithmetic"
	   x = ((x - y * DP1) - y * DP2) - y * DP3; */ /* Evaluate the first polynom  (0 <= x <= Pi/4) */ /* Evaluate the second polynom  (Pi/4 <= x <= 0) */ /* select the correct result from the two polynoms */ /* update the sign */