diff -up ClanLib-2.1.1/Sources/Sound/sound_sse.cpp.sse2 ClanLib-2.1.1/Sources/Sound/sound_sse.cpp --- ClanLib-2.1.1/Sources/Sound/sound_sse.cpp.sse2 2009-10-02 16:08:46.000000000 +0200 +++ ClanLib-2.1.1/Sources/Sound/sound_sse.cpp 2010-05-30 09:49:16.000000000 +0200 @@ -28,7 +28,10 @@ #include "Sound/precomp.h" #include "API/Sound/sound_sse.h" +#include <stdlib.h> +#ifdef CL_SSE2 #include <emmintrin.h> +#endif void *CL_SoundSSE::aligned_alloc(int size) { @@ -58,6 +61,7 @@ void CL_SoundSSE::aligned_free(void *ptr void CL_SoundSSE::unpack_16bit_stereo(short *input, int size, float *output[2]) { +#ifdef CL_SSE2 int sse_size = (size/8)*8; __m128i zero = _mm_setzero_si128(); @@ -77,6 +81,9 @@ void CL_SoundSSE::unpack_16bit_stereo(sh _mm_storeu_ps(output[0]+i/2, tmp0); _mm_storeu_ps(output[1]+i/2, tmp1); } +#else + const int sse_size = 0; +#endif // unpack remaining for (int i = sse_size; i < size; i+=2) @@ -88,6 +95,7 @@ void CL_SoundSSE::unpack_16bit_stereo(sh void CL_SoundSSE::unpack_16bit_mono(short *input, int size, float *output) { +#ifdef CL_SSE2 int sse_size = (size/8)*8; __m128i zero = _mm_setzero_si128(); @@ -102,6 +110,9 @@ void CL_SoundSSE::unpack_16bit_mono(shor _mm_storeu_ps(output+i+0, samples0); _mm_storeu_ps(output+i+4, samples1); } +#else + const int sse_size = 0; +#endif // unpack remaining for (int i = sse_size; i < size; i++) @@ -112,6 +123,7 @@ void CL_SoundSSE::unpack_16bit_mono(shor void CL_SoundSSE::unpack_8bit_stereo(unsigned char *input, int size, float *output[2]) { +#ifdef CL_SSE2 int sse_size = (size/16)*16; __m128i zero = _mm_setzero_si128(); @@ -142,6 +154,9 @@ void CL_SoundSSE::unpack_8bit_stereo(uns _mm_storeu_ps(output[0]+i/2+4, tmp2); _mm_storeu_ps(output[1]+i/2+4, tmp3); } +#else + const int sse_size = 0; +#endif // unpack remaining for (int i = sse_size; i < size; i+=2) @@ -156,6 +171,7 @@ void CL_SoundSSE::unpack_8bit_stereo(uns void CL_SoundSSE::unpack_8bit_mono(unsigned char *input, int size, float *output) { +#ifdef CL_SSE2 int sse_size = (size/16)*16; __m128i zero = _mm_setzero_si128(); @@ -179,17 +195,21 @@ void CL_SoundSSE::unpack_8bit_mono(unsig _mm_storeu_ps(output+i+8, samples2); _mm_storeu_ps(output+i+12, samples3); } +#else + const int sse_size = 0; +#endif // unpack remaining for (int i = sse_size; i < size; i++) { - int value = input[0]; + int value = input[i]; output[i] = ((float) (value - 128)) / 128.0f; } } void CL_SoundSSE::pack_16bit_stereo(float *input[2], int size, short *output) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; __m128 constant1 = _mm_set1_ps(32767); @@ -207,6 +227,9 @@ void CL_SoundSSE::pack_16bit_stereo(floa __m128i isamples = _mm_packs_epi32(isamples0, isamples1); _mm_storeu_si128((__m128i*)(output+i*2), isamples); } +#else + const int sse_size = 0; +#endif // Pack remaining for (int i = sse_size; i < size; i++) @@ -218,6 +241,7 @@ void CL_SoundSSE::pack_16bit_stereo(floa void CL_SoundSSE::pack_float_stereo(float *input[2], int size, float *output) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; for (int i = 0; i < sse_size; i+=4) @@ -230,6 +254,9 @@ void CL_SoundSSE::pack_float_stereo(floa _mm_storeu_ps(output+i*2, tmp0); _mm_storeu_ps(output+i*2+4, tmp1); } +#else + const int sse_size = 0; +#endif // Pack remaining for (int i = sse_size; i < size; i++) @@ -241,6 +268,7 @@ void CL_SoundSSE::pack_float_stereo(floa void CL_SoundSSE::copy_float(float *input, int size, float *output) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; for (int i = 0; i < sse_size; i+=4) @@ -248,6 +276,9 @@ void CL_SoundSSE::copy_float(float *inpu __m128 s = _mm_loadu_ps(input+i); _mm_storeu_ps(output+i, s); } +#else + const int sse_size = 0; +#endif // Copy remaining for (int i = sse_size; i < size; i++) @@ -256,6 +287,7 @@ void CL_SoundSSE::copy_float(float *inpu void CL_SoundSSE::multiply_float(float *channel, int size, float volume) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; __m128 volume0 = _mm_set1_ps(volume); @@ -265,6 +297,9 @@ void CL_SoundSSE::multiply_float(float * s = _mm_mul_ps(s, volume0); _mm_storeu_ps(channel+i, s); } +#else + const int sse_size = 0; +#endif for (int i = sse_size; i < size; i++) channel[i] *= volume; @@ -272,6 +307,7 @@ void CL_SoundSSE::multiply_float(float * void CL_SoundSSE::set_float(float *channel, int size, float value) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; __m128 value0 = _mm_set1_ps(value); @@ -279,6 +315,9 @@ void CL_SoundSSE::set_float(float *chann { _mm_storeu_ps(channel+i, value0); } +#else + const int sse_size = 0; +#endif for (int i = sse_size; i < size; i++) channel[i] = value; @@ -286,6 +325,7 @@ void CL_SoundSSE::set_float(float *chann void CL_SoundSSE::mix_one_to_one(float *input, int size, float *output, float volume) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; __m128 volume0 = _mm_set1_ps(volume); for (int i = 0; i < sse_size; i+=4) @@ -294,6 +334,9 @@ void CL_SoundSSE::mix_one_to_one(float * __m128 sample1 = _mm_loadu_ps(output+i); _mm_storeu_ps(output+i, _mm_add_ps(_mm_mul_ps(sample0, volume0), sample1)); } +#else + const int sse_size = 0; +#endif for (int i = sse_size; i < size; i++) { @@ -303,6 +346,7 @@ void CL_SoundSSE::mix_one_to_one(float * void CL_SoundSSE::mix_one_to_many(float *input, int size, float **output, float *volume, int channels) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; for (int i = 0; i < sse_size; i+=4) { @@ -314,6 +358,9 @@ void CL_SoundSSE::mix_one_to_many(float _mm_storeu_ps(output[j]+i, _mm_add_ps(_mm_mul_ps(sample0, volume0), sample1)); } } +#else + const int sse_size = 0; +#endif for (int i = sse_size; i < size; i++) { @@ -327,6 +374,7 @@ void CL_SoundSSE::mix_one_to_many(float void CL_SoundSSE::mix_many_to_one(float **input, float *volume, int channels, int size, float *output) { +#ifdef CL_SSE2 int sse_size = (size/4)*4; for (int i = 0; i < sse_size; i+=4) { @@ -339,6 +387,9 @@ void CL_SoundSSE::mix_many_to_one(float } _mm_storeu_ps(output+i, sample0); } +#else + const int sse_size = 0; +#endif for (int i = sse_size; i < size; i++) { diff -up ClanLib-2.1.1/configure.ac.sse2 ClanLib-2.1.1/configure.ac --- ClanLib-2.1.1/configure.ac.sse2 2009-12-07 17:16:24.000000000 +0100 +++ ClanLib-2.1.1/configure.ac 2010-05-30 09:47:50.000000000 +0200 @@ -500,8 +500,12 @@ if test "$enable_clanSound" != "no"; the echo "Checking for clanSound stuff" echo "============================" - dnl Note, ClanLib only supports SSE2 for clanSound - CLANLIB_CHECK_LIB(SSE2, [`cat $srcdir/Setup/Tests/sse2.cpp`], clanSound, [ *** Compliler does not support SSE2 ], [ ], [ -msse2 ] ) + OLD_CXXFLAGS="$CXXFLAGS"; CXXFLAGS="-msse2"; + AC_MSG_CHECKING([for SSE2]) + AC_LINK_IFELSE([`cat $srcdir/Setup/Tests/sse2.cpp`], + AC_MSG_RESULT(yes); clanSound_CXXFLAGS=-msse2; AC_DEFINE(CL_SSE2), + AC_MSG_RESULT(no); clanSound_CXXFLAGS=) + CXXFLAGS="$OLD_CXXFLAGS" if test "$WIN32" = "yes"; then CLANLIB_CHECK_LIB(dsound,[#include <dsound.h> @@ -527,10 +531,8 @@ if test "$enable_clanSound" != "no"; the fi if test "$enable_clanSound" = "auto"; then enable_clanSound=yes; fi - if test "$enable_clanSound" = "yes"; then - clanSound_CXXFLAGS=-msse2 - AC_SUBST(clanSound_CXXFLAGS) - fi + + AC_SUBST(clanSound_CXXFLAGS) fi if test "$enable_clanSound" != "no"; then