mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	audioconvert: somewhat avoid precision loss in F32 to S32 conversion
At the very least, we should go through s25_32 intermediate instead of s24_32, to avoid needlessly loosing 1 LSB precision bit. FIXME: the noise codepath is not covered with tests.
This commit is contained in:
		
							parent
							
								
									2a035ac49e
								
							
						
					
					
						commit
						175d533b56
					
				
					 4 changed files with 66 additions and 71 deletions
				
			
		| 
						 | 
				
			
			@ -490,9 +490,9 @@ conv_f32d_to_s32_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m128 in[1];
 | 
			
		||||
	__m128i out[4];
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 16))
 | 
			
		||||
		unrolled = n_samples & ~3;
 | 
			
		||||
| 
						 | 
				
			
			@ -503,7 +503,7 @@ conv_f32d_to_s32_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(_mm_load_ps(&s0[n]), scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(0, 3, 2, 1));
 | 
			
		||||
		out[2] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(1, 0, 3, 2));
 | 
			
		||||
		out[3] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(2, 1, 0, 3));
 | 
			
		||||
| 
						 | 
				
			
			@ -518,7 +518,7 @@ conv_f32d_to_s32_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_load_ss(&s0[n]);
 | 
			
		||||
		in[0] = _mm_mul_ss(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_SS(in[0], int_min, int_max);
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 8;
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 7;
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -538,12 +538,12 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m256 in[2];
 | 
			
		||||
	__m256i out[2], t[2];
 | 
			
		||||
	__m256 scale = _mm256_set1_ps(S24_SCALE);
 | 
			
		||||
	__m256 int_min = _mm256_set1_ps(S24_MIN);
 | 
			
		||||
	__m256 int_max = _mm256_set1_ps(S24_MAX);
 | 
			
		||||
	__m256 scale = _mm256_set1_ps(S25_SCALE);
 | 
			
		||||
	__m256 int_min = _mm256_set1_ps(S25_MIN);
 | 
			
		||||
	__m256 int_max = _mm256_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 32) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s1, 32))
 | 
			
		||||
		SPA_IS_ALIGNED(s1, 32))
 | 
			
		||||
		unrolled = n_samples & ~7;
 | 
			
		||||
	else
 | 
			
		||||
		unrolled = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -557,8 +557,8 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
 | 
			
		||||
		out[0] = _mm256_cvtps_epi32(in[0]);	/* a0 a1 a2 a3 a4 a5 a6 a7 */
 | 
			
		||||
		out[1] = _mm256_cvtps_epi32(in[1]);	/* b0 b1 b2 b3 b4 b5 b6 b7 */
 | 
			
		||||
		out[0] = _mm256_slli_epi32(out[0], 8);
 | 
			
		||||
		out[1] = _mm256_slli_epi32(out[1], 8);
 | 
			
		||||
		out[0] = _mm256_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm256_slli_epi32(out[1], 7);
 | 
			
		||||
 | 
			
		||||
		t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
 | 
			
		||||
		t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
 | 
			
		||||
| 
						 | 
				
			
			@ -587,9 +587,9 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	for(; n < n_samples; n++) {
 | 
			
		||||
		__m128 in[2];
 | 
			
		||||
		__m128i out[2];
 | 
			
		||||
		__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
		__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
		__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
		__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
		__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
		__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
		in[0] = _mm_load_ss(&s0[n]);
 | 
			
		||||
		in[1] = _mm_load_ss(&s1[n]);
 | 
			
		||||
| 
						 | 
				
			
			@ -599,7 +599,7 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		_mm_storel_epi64((__m128i*)d, out[0]);
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -614,14 +614,14 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m256 in[4];
 | 
			
		||||
	__m256i out[4], t[4];
 | 
			
		||||
	__m256 scale = _mm256_set1_ps(S24_SCALE);
 | 
			
		||||
	__m256 int_min = _mm256_set1_ps(S24_MIN);
 | 
			
		||||
	__m256 int_max = _mm256_set1_ps(S24_MAX);
 | 
			
		||||
	__m256 scale = _mm256_set1_ps(S25_SCALE);
 | 
			
		||||
	__m256 int_min = _mm256_set1_ps(S25_MIN);
 | 
			
		||||
	__m256 int_max = _mm256_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 32) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s1, 32) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s2, 32) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s3, 32))
 | 
			
		||||
		SPA_IS_ALIGNED(s1, 32) &&
 | 
			
		||||
		SPA_IS_ALIGNED(s2, 32) &&
 | 
			
		||||
		SPA_IS_ALIGNED(s3, 32))
 | 
			
		||||
		unrolled = n_samples & ~7;
 | 
			
		||||
	else
 | 
			
		||||
		unrolled = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -641,10 +641,10 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		out[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
 | 
			
		||||
		out[2] = _mm256_cvtps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
 | 
			
		||||
		out[3] = _mm256_cvtps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
 | 
			
		||||
		out[0] = _mm256_slli_epi32(out[0], 8);
 | 
			
		||||
		out[1] = _mm256_slli_epi32(out[1], 8);
 | 
			
		||||
		out[2] = _mm256_slli_epi32(out[2], 8);
 | 
			
		||||
		out[3] = _mm256_slli_epi32(out[3], 8);
 | 
			
		||||
		out[0] = _mm256_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm256_slli_epi32(out[1], 7);
 | 
			
		||||
		out[2] = _mm256_slli_epi32(out[2], 7);
 | 
			
		||||
		out[3] = _mm256_slli_epi32(out[3], 7);
 | 
			
		||||
 | 
			
		||||
		t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
 | 
			
		||||
		t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
 | 
			
		||||
| 
						 | 
				
			
			@ -669,9 +669,9 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	for(; n < n_samples; n++) {
 | 
			
		||||
		__m128 in[4];
 | 
			
		||||
		__m128i out[4];
 | 
			
		||||
		__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
		__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
		__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
		__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
		__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
		__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
		in[0] = _mm_load_ss(&s0[n]);
 | 
			
		||||
		in[1] = _mm_load_ss(&s1[n]);
 | 
			
		||||
| 
						 | 
				
			
			@ -685,7 +685,7 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		_mm_storeu_si128((__m128i*)d, out[0]);
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -381,9 +381,9 @@ conv_f32d_to_s32_1s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m128 in[1];
 | 
			
		||||
	__m128i out[4];
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 16))
 | 
			
		||||
		unrolled = n_samples & ~3;
 | 
			
		||||
| 
						 | 
				
			
			@ -394,7 +394,7 @@ conv_f32d_to_s32_1s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(_mm_load_ps(&s0[n]), scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(0, 3, 2, 1));
 | 
			
		||||
		out[2] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(1, 0, 3, 2));
 | 
			
		||||
		out[3] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(2, 1, 0, 3));
 | 
			
		||||
| 
						 | 
				
			
			@ -409,7 +409,7 @@ conv_f32d_to_s32_1s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_load_ss(&s0[n]);
 | 
			
		||||
		in[0] = _mm_mul_ss(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_SS(in[0], int_min, int_max);
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 8;
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 7;
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -423,12 +423,12 @@ conv_f32d_to_s32_2s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m128 in[2];
 | 
			
		||||
	__m128i out[2], t[2];
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 16) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s1, 16))
 | 
			
		||||
		SPA_IS_ALIGNED(s1, 16))
 | 
			
		||||
		unrolled = n_samples & ~3;
 | 
			
		||||
	else
 | 
			
		||||
		unrolled = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -442,8 +442,8 @@ conv_f32d_to_s32_2s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[1] = _mm_cvtps_epi32(in[1]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[1] = _mm_slli_epi32(out[1], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm_slli_epi32(out[1], 7);
 | 
			
		||||
 | 
			
		||||
		t[0] = _mm_unpacklo_epi32(out[0], out[1]);
 | 
			
		||||
		t[1] = _mm_unpackhi_epi32(out[0], out[1]);
 | 
			
		||||
| 
						 | 
				
			
			@ -463,7 +463,7 @@ conv_f32d_to_s32_2s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		_mm_storel_epi64((__m128i*)d, out[0]);
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -478,14 +478,14 @@ conv_f32d_to_s32_4s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m128 in[4];
 | 
			
		||||
	__m128i out[4];
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s0, 16) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s1, 16) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s2, 16) &&
 | 
			
		||||
	    SPA_IS_ALIGNED(s3, 16))
 | 
			
		||||
		SPA_IS_ALIGNED(s1, 16) &&
 | 
			
		||||
		SPA_IS_ALIGNED(s2, 16) &&
 | 
			
		||||
		SPA_IS_ALIGNED(s3, 16))
 | 
			
		||||
		unrolled = n_samples & ~3;
 | 
			
		||||
	else
 | 
			
		||||
		unrolled = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -507,10 +507,10 @@ conv_f32d_to_s32_4s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		out[1] = _mm_cvtps_epi32(in[1]);
 | 
			
		||||
		out[2] = _mm_cvtps_epi32(in[2]);
 | 
			
		||||
		out[3] = _mm_cvtps_epi32(in[3]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[1] = _mm_slli_epi32(out[1], 8);
 | 
			
		||||
		out[2] = _mm_slli_epi32(out[2], 8);
 | 
			
		||||
		out[3] = _mm_slli_epi32(out[3], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm_slli_epi32(out[1], 7);
 | 
			
		||||
		out[2] = _mm_slli_epi32(out[2], 7);
 | 
			
		||||
		out[3] = _mm_slli_epi32(out[3], 7);
 | 
			
		||||
 | 
			
		||||
		_mm_storeu_si128((__m128i*)(d + 0*n_channels), out[0]);
 | 
			
		||||
		_mm_storeu_si128((__m128i*)(d + 1*n_channels), out[1]);
 | 
			
		||||
| 
						 | 
				
			
			@ -531,7 +531,7 @@ conv_f32d_to_s32_4s_sse2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
 | 
			
		|||
		in[0] = _mm_mul_ps(in[0], scale);
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		_mm_storeu_si128((__m128i*)d, out[0]);
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -620,6 +620,7 @@ void conv_noise_tri_hf_sse2(struct convert *conv, float *noise, uint32_t n_sampl
 | 
			
		|||
	_mm_store_si128((__m128i*)p, old[0]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FIXME: this function is not covered with tests.
 | 
			
		||||
static void
 | 
			
		||||
conv_f32d_to_s32_1s_noise_sse2(struct convert *conv, void * SPA_RESTRICT dst, const void * SPA_RESTRICT src,
 | 
			
		||||
		float *noise, uint32_t n_channels, uint32_t n_samples)
 | 
			
		||||
| 
						 | 
				
			
			@ -629,9 +630,9 @@ conv_f32d_to_s32_1s_noise_sse2(struct convert *conv, void * SPA_RESTRICT dst, co
 | 
			
		|||
	uint32_t n, unrolled;
 | 
			
		||||
	__m128 in[1];
 | 
			
		||||
	__m128i out[4];
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S24_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S24_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S24_MAX);
 | 
			
		||||
	__m128 scale = _mm_set1_ps(S25_SCALE);
 | 
			
		||||
	__m128 int_min = _mm_set1_ps(S25_MIN);
 | 
			
		||||
	__m128 int_max = _mm_set1_ps(S25_MAX);
 | 
			
		||||
 | 
			
		||||
	if (SPA_IS_ALIGNED(s, 16))
 | 
			
		||||
		unrolled = n_samples & ~3;
 | 
			
		||||
| 
						 | 
				
			
			@ -643,7 +644,7 @@ conv_f32d_to_s32_1s_noise_sse2(struct convert *conv, void * SPA_RESTRICT dst, co
 | 
			
		|||
		in[0] = _mm_add_ps(in[0], _mm_load_ps(&noise[n]));
 | 
			
		||||
		in[0] = _MM_CLAMP_PS(in[0], int_min, int_max);
 | 
			
		||||
		out[0] = _mm_cvtps_epi32(in[0]);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 8);
 | 
			
		||||
		out[0] = _mm_slli_epi32(out[0], 7);
 | 
			
		||||
		out[1] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(0, 3, 2, 1));
 | 
			
		||||
		out[2] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(1, 0, 3, 2));
 | 
			
		||||
		out[3] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(2, 1, 0, 3));
 | 
			
		||||
| 
						 | 
				
			
			@ -659,7 +660,7 @@ conv_f32d_to_s32_1s_noise_sse2(struct convert *conv, void * SPA_RESTRICT dst, co
 | 
			
		|||
		in[0] = _mm_mul_ss(in[0], scale);
 | 
			
		||||
		in[0] = _mm_add_ss(in[0], _mm_load_ss(&noise[n]));
 | 
			
		||||
		in[0] = _MM_CLAMP_SS(in[0], int_min, int_max);
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 8;
 | 
			
		||||
		*d = _mm_cvtss_si32(in[0]) << 7;
 | 
			
		||||
		d += n_channels;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -123,8 +123,8 @@
 | 
			
		|||
#define S32_MAX			(S24_MAX * 256)
 | 
			
		||||
#define S32_TO_F32(v)		ITOF(int32_t, S32_TO_S24_32(v), S24_SCALE, 0.0f)
 | 
			
		||||
#define S32S_TO_F32(v)		S32_TO_F32(bswap_32(v))
 | 
			
		||||
#define F32_TO_S32(v)		S24_32_TO_S32(F32_TO_S24_32(v))
 | 
			
		||||
#define F32_TO_S32_D(v,d)	S24_32_TO_S32(F32_TO_S24_32_D(v,d))
 | 
			
		||||
#define F32_TO_S32_D(v,d)	S25_32_TO_S32(F32_TO_S25_32_D(v,d))
 | 
			
		||||
#define F32_TO_S32(v)		F32_TO_S32_D(v, 0.0f)
 | 
			
		||||
#define F32_TO_S32S(v)		bswap_32(F32_TO_S32(v))
 | 
			
		||||
#define F32_TO_S32S_D(v,d)	bswap_32(F32_TO_S32_D(v,d))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -298,16 +298,15 @@ static void test_f32_s32(void)
 | 
			
		|||
		1.0f/0x40000000, -1.0f/0x40000000, 1.0f/0x80000000, -1.0f/0x80000000,
 | 
			
		||||
		1.0f/0x100000000, -1.0f/0x100000000, 1.0f/0x200000000, -1.0f/0x200000000,
 | 
			
		||||
	};
 | 
			
		||||
	static const int32_t out[] = { 0x00000000, 0x7fffff00, 0x80000000,
 | 
			
		||||
		0x40000000, 0xc0000000, 0x7fffff00, 0x80000000, 0x00000100,
 | 
			
		||||
		0xffffff00, 0x00000100, 0xffffff00, 0x00000000, 0x00000000,
 | 
			
		||||
	static const int32_t out[] = { 0x00000000, 0x7fffff80, 0x80000000,
 | 
			
		||||
		0x40000000, 0xc0000000, 0x7fffff80, 0x80000000, 0x00000100,
 | 
			
		||||
		0xffffff00, 0x00000100, 0xffffff00, 0x00000080, 0xffffff80,
 | 
			
		||||
		0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
 | 
			
		||||
		0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
 | 
			
		||||
		0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
 | 
			
		||||
		0x00000000, 0x00000000, 0x00000000,
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	run_test("test_f32_s32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
 | 
			
		||||
			true, true, conv_f32_to_s32_c);
 | 
			
		||||
	run_test("test_f32d_s32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
 | 
			
		||||
| 
						 | 
				
			
			@ -665,21 +664,16 @@ static void test_lossless_s25_32_to_s32_to_f32_to_s32_to_s25_32_XFAIL(void)
 | 
			
		|||
	spa_assert_se(max_abs_err == 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void test_lossless_s25_32_to_f32_to_s32_to_s25_32_XFAIL(void)
 | 
			
		||||
static void test_lossless_s25_32_to_f32_to_s32_to_s25_32(void)
 | 
			
		||||
{
 | 
			
		||||
	int32_t i;
 | 
			
		||||
 | 
			
		||||
	int all_lossless = 1;
 | 
			
		||||
	int32_t max_abs_err = -1;
 | 
			
		||||
	fprintf(stderr, "test %s:\n", __func__);
 | 
			
		||||
	for (i = S25_MIN; i <= S25_MAX; i+=1) {
 | 
			
		||||
		float v = S25_32_TO_F32(i);
 | 
			
		||||
		int32_t t = S32_TO_S25_32(F32_TO_S32(v));
 | 
			
		||||
		all_lossless &= i == t;
 | 
			
		||||
		max_abs_err = SPA_MAX(max_abs_err, SPA_ABS(i - t));
 | 
			
		||||
		spa_assert_se(i == t);
 | 
			
		||||
	}
 | 
			
		||||
	spa_assert_se(!all_lossless);
 | 
			
		||||
	spa_assert_se(max_abs_err == 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void test_lossless_s32(void)
 | 
			
		||||
| 
						 | 
				
			
			@ -883,7 +877,7 @@ int main(int argc, char *argv[])
 | 
			
		|||
	test_lossless_s25_32_to_f32_to_s25_32();
 | 
			
		||||
	test_lossless_s25_32_to_s32_to_f32_to_s25_32_XFAIL();
 | 
			
		||||
	test_lossless_s25_32_to_s32_to_f32_to_s32_to_s25_32_XFAIL();
 | 
			
		||||
	test_lossless_s25_32_to_f32_to_s32_to_s25_32_XFAIL();
 | 
			
		||||
	test_lossless_s25_32_to_f32_to_s32_to_s25_32();
 | 
			
		||||
	test_lossless_s32();
 | 
			
		||||
	test_lossless_s32_lossless_subset();
 | 
			
		||||
	test_lossless_u32();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue