diff options
-rw-r--r-- | Alc/ALc.c | 6 | ||||
-rw-r--r-- | Alc/helpers.c | 24 | ||||
-rw-r--r-- | Alc/mixer.c | 6 | ||||
-rw-r--r-- | Alc/mixer_defs.h | 2 | ||||
-rw-r--r-- | Alc/mixer_sse2.c | 62 | ||||
-rw-r--r-- | Alc/mixer_sse3.c | 93 | ||||
-rw-r--r-- | CMakeLists.txt | 25 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 5 | ||||
-rw-r--r-- | alsoftrc.sample | 4 | ||||
-rw-r--r-- | config.h.in | 1 | ||||
-rw-r--r-- | utils/alsoft-config/mainwindow.cpp | 3 | ||||
-rw-r--r-- | utils/alsoft-config/mainwindow.ui | 22 |
12 files changed, 173 insertions, 80 deletions
@@ -955,7 +955,9 @@ static void alc_initconfig(void) capfilter = 0; #if defined(HAVE_SSE4_1) - capfilter |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE4_1; + capfilter |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3 | CPU_CAP_SSE4_1; +#elif defined(HAVE_SSE3) + capfilter |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3; #elif defined(HAVE_SSE2) capfilter |= CPU_CAP_SSE | CPU_CAP_SSE2; #elif defined(HAVE_SSE) @@ -989,6 +991,8 @@ static void alc_initconfig(void) capfilter &= ~CPU_CAP_SSE; else if(len == 4 && strncasecmp(str, "sse2", len) == 0) capfilter &= ~CPU_CAP_SSE2; + else if(len == 4 && strncasecmp(str, "sse3", len) == 0) + capfilter &= ~CPU_CAP_SSE3; else if(len == 6 && strncasecmp(str, "sse4.1", len) == 0) capfilter &= ~CPU_CAP_SSE4_1; else if(len == 4 && strncasecmp(str, "neon", len) == 0) diff --git a/Alc/helpers.c b/Alc/helpers.c index dac29296..c789a426 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -152,8 +152,12 @@ void FillCPUCaps(ALuint capfilter) if((cpuinf[0].regs[3]&(1<<26))) { caps |= CPU_CAP_SSE2; - if((cpuinf[0].regs[2]&(1<<19))) - caps |= CPU_CAP_SSE4_1; + if((cpuinf[0].regs[2]&(1<<0))) + { + caps |= CPU_CAP_SSE3; + if((cpuinf[0].regs[2]&(1<<19))) + caps |= CPU_CAP_SSE4_1; + } } } } @@ -196,8 +200,12 @@ void FillCPUCaps(ALuint capfilter) if((cpuinf[0].regs[3]&(1<<26))) { caps |= CPU_CAP_SSE2; - if((cpuinf[0].regs[2]&(1<<19))) - caps |= CPU_CAP_SSE4_1; + if((cpuinf[0].regs[2]&(1<<0))) + { + caps |= CPU_CAP_SSE3; + if((cpuinf[0].regs[2]&(1<<19))) + caps |= CPU_CAP_SSE4_1; + } } } } @@ -206,7 +214,10 @@ void FillCPUCaps(ALuint capfilter) /* Assume support for whatever's supported if we can't check for it */ #if defined(HAVE_SSE4_1) #warning "Assuming SSE 4.1 run-time support!" - caps |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE4_1; + caps |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3 | CPU_CAP_SSE4_1; +#elif defined(HAVE_SSE3) +#warning "Assuming SSE 3 run-time support!" + caps |= CPU_CAP_SSE | CPU_CAP_SSE2 | CPU_CAP_SSE3; #elif defined(HAVE_SSE2) #warning "Assuming SSE 2 run-time support!" caps |= CPU_CAP_SSE | CPU_CAP_SSE2; @@ -220,9 +231,10 @@ void FillCPUCaps(ALuint capfilter) caps |= CPU_CAP_NEON; #endif - TRACE("Extensions:%s%s%s%s%s\n", + TRACE("Extensions:%s%s%s%s%s%s\n", ((capfilter&CPU_CAP_SSE) ? ((caps&CPU_CAP_SSE) ? " +SSE" : " -SSE") : ""), ((capfilter&CPU_CAP_SSE2) ? ((caps&CPU_CAP_SSE2) ? " +SSE2" : " -SSE2") : ""), + ((capfilter&CPU_CAP_SSE3) ? ((caps&CPU_CAP_SSE3) ? " +SSE3" : " -SSE3") : ""), ((capfilter&CPU_CAP_SSE4_1) ? ((caps&CPU_CAP_SSE4_1) ? " +SSE4.1" : " -SSE4.1") : ""), ((capfilter&CPU_CAP_NEON) ? ((caps&CPU_CAP_NEON) ? " +Neon" : " -Neon") : ""), ((!capfilter) ? " -none-" : "") diff --git a/Alc/mixer.c b/Alc/mixer.c index fa060958..8061ab73 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -122,9 +122,9 @@ static inline ResamplerFunc SelectResampler(enum Resampler resampler) if((CPUCapFlags&CPU_CAP_SSE4_1)) return Resample_fir4_32_SSE41; #endif -#ifdef HAVE_SSE2 - if((CPUCapFlags&CPU_CAP_SSE2)) - return Resample_fir4_32_SSE2; +#ifdef HAVE_SSE3 + if((CPUCapFlags&CPU_CAP_SSE3)) + return Resample_fir4_32_SSE3; #endif return Resample_fir4_32_C; case FIR6Resampler: diff --git a/Alc/mixer_defs.h b/Alc/mixer_defs.h index 4c94954f..bba8e9a1 100644 --- a/Alc/mixer_defs.h +++ b/Alc/mixer_defs.h @@ -55,7 +55,7 @@ const ALfloat *Resample_lerp32_SSE2(const ALfloat *src, ALuint frac, ALuint incr const ALfloat *Resample_lerp32_SSE41(const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint numsamples); -const ALfloat *Resample_fir4_32_SSE2(const ALfloat *src, ALuint frac, ALuint increment, +const ALfloat *Resample_fir4_32_SSE3(const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint numsamples); const ALfloat *Resample_fir4_32_SSE41(const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint numsamples); diff --git a/Alc/mixer_sse2.c b/Alc/mixer_sse2.c index 1321f5f2..6759f795 100644 --- a/Alc/mixer_sse2.c +++ b/Alc/mixer_sse2.c @@ -76,65 +76,3 @@ const ALfloat *Resample_lerp32_SSE2(const ALfloat *src, ALuint frac, ALuint incr } return dst; } - -const ALfloat *Resample_fir4_32_SSE2(const ALfloat *src, ALuint frac, ALuint increment, - ALfloat *restrict dst, ALuint numsamples) -{ - const __m128i increment4 = _mm_set1_epi32(increment*4); - const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK); - alignas(16) union { ALuint i[4]; float f[4]; } pos_; - alignas(16) union { ALuint i[4]; float f[4]; } frac_; - __m128i frac4, pos4; - ALuint pos; - ALuint i; - - InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4); - - frac4 = _mm_castps_si128(_mm_load_ps(frac_.f)); - pos4 = _mm_castps_si128(_mm_load_ps(pos_.f)); - - --src; - for(i = 0;numsamples-i > 3;i += 4) - { - const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]); - const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]); - const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]); - const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]); - __m128 k0 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[0]]); - __m128 k1 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[1]]); - __m128 k2 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[2]]); - __m128 k3 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[3]]); - __m128 out; - - k0 = _mm_mul_ps(k0, val0); - k1 = _mm_mul_ps(k1, val1); - k2 = _mm_mul_ps(k2, val2); - k3 = _mm_mul_ps(k3, val3); - _MM_TRANSPOSE4_PS(k0, k1, k2, k3); - k0 = _mm_add_ps(k0, k1); - k2 = _mm_add_ps(k2, k3); - out = _mm_add_ps(k0, k2); - - _mm_store_ps(&dst[i], out); - - frac4 = _mm_add_epi32(frac4, increment4); - pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS)); - frac4 = _mm_and_si128(frac4, fracMask4); - - _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4)); - _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4)); - } - - pos = pos_.i[0]; - frac = frac_.i[0]; - - for(;i < numsamples;i++) - { - dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], frac); - - frac += increment; - pos += frac>>FRACTIONBITS; - frac &= FRACTIONMASK; - } - return dst; -} diff --git a/Alc/mixer_sse3.c b/Alc/mixer_sse3.c new file mode 100644 index 00000000..ced90593 --- /dev/null +++ b/Alc/mixer_sse3.c @@ -0,0 +1,93 @@ +/** + * OpenAL cross platform audio library, SSE3 mixer functions + * + * Copyright (C) 2014 by Timothy Arceri <[email protected]>. + * Copyright (C) 2015 by Chris Robinson <[email protected]>. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include <xmmintrin.h> +#include <emmintrin.h> +#include <pmmintrin.h> + +#include "alu.h" +#include "mixer_defs.h" + + +const ALfloat *Resample_fir4_32_SSE3(const ALfloat *src, ALuint frac, ALuint increment, + ALfloat *restrict dst, ALuint numsamples) +{ + const __m128i increment4 = _mm_set1_epi32(increment*4); + const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK); + alignas(16) union { ALuint i[4]; float f[4]; } pos_; + alignas(16) union { ALuint i[4]; float f[4]; } frac_; + __m128i frac4, pos4; + ALuint pos; + ALuint i; + + InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4); + + frac4 = _mm_castps_si128(_mm_load_ps(frac_.f)); + pos4 = _mm_castps_si128(_mm_load_ps(pos_.f)); + + --src; + for(i = 0;numsamples-i > 3;i += 4) + { + const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]); + const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]); + const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]); + const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]); + __m128 k0 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[0]]); + __m128 k1 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[1]]); + __m128 k2 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[2]]); + __m128 k3 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[3]]); + __m128 out; + + k0 = _mm_mul_ps(k0, val0); + k1 = _mm_mul_ps(k1, val1); + k2 = _mm_mul_ps(k2, val2); + k3 = _mm_mul_ps(k3, val3); + k0 = _mm_hadd_ps(k0, k1); + k2 = _mm_hadd_ps(k2, k3); + out = _mm_hadd_ps(k0, k2); + + _mm_store_ps(&dst[i], out); + + frac4 = _mm_add_epi32(frac4, increment4); + pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS)); + frac4 = _mm_and_si128(frac4, fracMask4); + + _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4)); + _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4)); + } + + pos = pos_.i[0]; + frac = frac_.i[0]; + + for(;i < numsamples;i++) + { + dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], frac); + + frac += increment; + pos += frac>>FRACTIONBITS; + frac &= FRACTIONMASK; + } + return dst; +} diff --git a/CMakeLists.txt b/CMakeLists.txt index ea2d5150..af9e961a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,6 +325,10 @@ IF(NOT MSVC) IF(HAVE_MSSE2_SWITCH) SET(SSE2_SWITCH "-msse2") ENDIF() + CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH) + IF(HAVE_MSSE3_SWITCH) + SET(SSE3_SWITCH "-msse3") + ENDIF() CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH) IF(HAVE_MSSE4_1_SWITCH) SET(SSE4_1_SWITCH "-msse4.1") @@ -592,6 +596,7 @@ SET(ALC_OBJS Alc/ALc.c SET(CPU_EXTS "Default") SET(HAVE_SSE 0) SET(HAVE_SSE2 0) +SET(HAVE_SSE3 0) SET(HAVE_SSE4_1 0) SET(HAVE_NEON 0) @@ -652,6 +657,26 @@ IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2) MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions") ENDIF() +OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF) +CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}") +IF(HAVE_EMMINTRIN_H) + OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON) + IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3) + IF(ALIGN_DECL OR HAVE_C11_ALIGNAS) + SET(HAVE_SSE3 1) + SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c) + IF(SSE2_SWITCH) + SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES + COMPILE_FLAGS "${SSE3_SWITCH}") + ENDIF() + SET(CPU_EXTS "${CPU_EXTS}, SSE3") + ENDIF() + ENDIF() +ENDIF() +IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3) + MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions") +ENDIF() + OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF) CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}") IF(HAVE_SMMINTRIN_H) diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 523b63c1..67360e53 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -966,8 +966,9 @@ extern ALuint CPUCapFlags; enum { CPU_CAP_SSE = 1<<0, CPU_CAP_SSE2 = 1<<1, - CPU_CAP_SSE4_1 = 1<<2, - CPU_CAP_NEON = 1<<3, + CPU_CAP_SSE3 = 1<<2, + CPU_CAP_SSE4_1 = 1<<3, + CPU_CAP_NEON = 1<<4, }; void FillCPUCaps(ALuint capfilter); diff --git a/alsoftrc.sample b/alsoftrc.sample index e1ab22e4..4dc2cd06 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -32,8 +32,8 @@ # Disables use of specialized methods that use specific CPU intrinsics. # Certain methods may utilize CPU extensions for improved performance, and # this option is useful for preventing some or all of those methods from being -# used. The available extensions are: sse, sse2, sse4.1, and neon. Specifying -# 'all' disables use of all such specialized methods. +# used. The available extensions are: sse, sse2, sse3, sse4.1, and neon. +# Specifying 'all' disables use of all such specialized methods. #disable-cpu-exts = ## drivers: (global) diff --git a/config.h.in b/config.h.in index 863b5e6e..a7f7ccab 100644 --- a/config.h.in +++ b/config.h.in @@ -26,6 +26,7 @@ /* Define if we have SSE CPU extensions */ #cmakedefine HAVE_SSE #cmakedefine HAVE_SSE2 +#cmakedefine HAVE_SSE3 #cmakedefine HAVE_SSE4_1 /* Define if we have ARM Neon CPU extensions */ diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 24372688..73773836 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -362,6 +362,7 @@ void MainWindow::loadConfig(const QString &fname) disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed)); ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive)); ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive)); + ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive)); ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive)); ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive)); @@ -527,6 +528,8 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("sse"); if(!ui->enableSSE2CheckBox->isChecked()) strlist.append("sse2"); + if(!ui->enableSSE3CheckBox->isChecked()) + strlist.append("sse3"); if(!ui->enableSSE41CheckBox->isChecked()) strlist.append("sse4.1"); if(!ui->enableNeonCheckBox->isChecked()) diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 0612a385..7747f16f 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -711,7 +711,7 @@ value currently possible is 4.</string> <x>10</x> <y>150</y> <width>511</width> - <height>91</height> + <height>121</height> </rect> </property> <property name="toolTip"> @@ -757,8 +757,8 @@ be useful for preventing those extensions from being used.</string> <widget class="QCheckBox" name="enableNeonCheckBox"> <property name="geometry"> <rect> - <x>260</x> - <y>50</y> + <x>180</x> + <y>80</y> <width>71</width> <height>31</height> </rect> @@ -786,6 +786,22 @@ be useful for preventing those extensions from being used.</string> <bool>true</bool> </property> </widget> + <widget class="QCheckBox" name="enableSSE3CheckBox"> + <property name="geometry"> + <rect> + <x>260</x> + <y>50</y> + <width>71</width> + <height>31</height> + </rect> + </property> + <property name="text"> + <string>SSE3</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> </widget> </widget> <widget class="QWidget" name="tab"> |