From 7dbdc89b8cd79ea31ec59ea1cd6c333f8c4c2eef Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 19 Jun 2006 02:53:14 +0000 Subject: [PATCH] Fix misaligned load/store. Also, these are little endian so merge the low order bytes first. Since this code _is_ portable, I can test it on x86 linux. --- stepmania/src/archutils/Darwin/VectorHelper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stepmania/src/archutils/Darwin/VectorHelper.cpp b/stepmania/src/archutils/Darwin/VectorHelper.cpp index 5b8ae41f7f..f6a3204d46 100644 --- a/stepmania/src/archutils/Darwin/VectorHelper.cpp +++ b/stepmania/src/archutils/Darwin/VectorHelper.cpp @@ -406,7 +406,7 @@ void Vector::FastSoundWrite( int32_t *dest, const int16_t *src, unsigned size, s if( size == 0 ) return; ASSERT_M( (intptr_t(dest) & 0x7) == 0, ssprintf("dest = %p", dest) ); - if( intptr_t(dest) & 0xF ) + while( (intptr_t(dest) & 0xF) && size ) { // Misaligned stores are slow. *(dest++) += *(src++) * volume; @@ -422,8 +422,8 @@ void Vector::FastSoundWrite( int32_t *dest, const int16_t *src, unsigned size, s __m128i data = _mm_loadu_si128( (__m128i *)src ); __m128i hi = _mm_mulhi_epi16( data, vol ); __m128i low = _mm_mullo_epi16( data, vol ); - __m128i result1 = _mm_unpacklo_epi16( hi, low ); - __m128i result2 = _mm_unpackhi_epi16( hi, low ); + __m128i result1 = _mm_unpacklo_epi16( low, hi ); + __m128i result2 = _mm_unpackhi_epi16( low, hi ); result1 = _mm_add_epi32( result1, *(__m128i *)(dest + 0) ); result2 = _mm_add_epi32( result2, *(__m128i *)(dest + 4) );