pulseaudio/src/pulsecore/sconv_sse.c

180 lines
6.7 KiB
C
Raw Normal View History

/***
This file is part of PulseAudio.
Copyright 2004-2006 Lennart Poettering
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio 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
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <pulsecore/macro.h>
#include <pulsecore/endianmacros.h>
#include "cpu-x86.h"
#include "sconv.h"
#if !defined(__APPLE__) && defined (__i386__) || defined (__amd64__)
static const PA_DECLARE_ALIGNED (16, float, one[4]) = { 1.0, 1.0, 1.0, 1.0 };
static const PA_DECLARE_ALIGNED (16, float, mone[4]) = { -1.0, -1.0, -1.0, -1.0 };
static const PA_DECLARE_ALIGNED (16, float, scale[4]) = { 0x7fff, 0x7fff, 0x7fff, 0x7fff };
static void pa_sconv_s16le_from_f32ne_sse(unsigned n, const float *a, int16_t *b) {
pa_reg_x86 temp, i;
__asm__ __volatile__ (
" movaps %5, %%xmm5 \n\t"
" movaps %6, %%xmm6 \n\t"
" movaps %7, %%xmm7 \n\t"
" xor %0, %0 \n\t"
" mov %4, %1 \n\t"
" sar $3, %1 \n\t" /* 8 floats at a time */
" cmp $0, %1 \n\t"
" je 2f \n\t"
"1: \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movups (%q2, %0, 2), %%xmm0 \n\t" /* read 8 floats */
" movups 16(%q2, %0, 2), %%xmm2 \n\t"
" minps %%xmm5, %%xmm0 \n\t" /* clamp to 1.0 */
" minps %%xmm5, %%xmm2 \n\t"
" maxps %%xmm6, %%xmm0 \n\t" /* clamp to -1.0 */
" maxps %%xmm6, %%xmm2 \n\t"
" mulps %%xmm7, %%xmm0 \n\t" /* *= 0x7fff */
" mulps %%xmm7, %%xmm2 \n\t"
" cvtps2pi %%xmm0, %%mm0 \n\t" /* low part to int */
" cvtps2pi %%xmm2, %%mm2 \n\t"
" movhlps %%xmm0, %%xmm0 \n\t" /* bring high part in position */
" movhlps %%xmm2, %%xmm2 \n\t"
" cvtps2pi %%xmm0, %%mm1 \n\t" /* high part to int */
" cvtps2pi %%xmm2, %%mm3 \n\t"
" packssdw %%mm1, %%mm0 \n\t" /* pack parts */
" packssdw %%mm3, %%mm2 \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movq %%mm0, (%q3, %0) \n\t"
" movq %%mm2, 8(%q3, %0) \n\t"
" add $16, %0 \n\t"
" dec %1 \n\t"
" jne 1b \n\t"
"2: \n\t"
" mov %4, %1 \n\t" /* prepare for leftovers */
2009-09-02 19:42:17 +02:00
" and $7, %1 \n\t"
" je 4f \n\t"
"3: \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movss (%q2, %0, 2), %%xmm0 \n\t"
" minss %%xmm5, %%xmm0 \n\t"
" maxss %%xmm6, %%xmm0 \n\t"
" mulss %%xmm7, %%xmm0 \n\t"
" cvtss2si %%xmm0, %4 \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movw %w4, (%q3, %0) \n\t"
" add $2, %0 \n\t"
" dec %1 \n\t"
" jne 3b \n\t"
"4: \n\t"
" emms \n\t"
: "=&r" (i), "=&r" (temp)
: "r" (a), "r" (b), "r" ((pa_reg_x86)n), "m" (*one), "m" (*mone), "m" (*scale)
: "cc", "memory"
);
}
static void pa_sconv_s16le_from_f32ne_sse2(unsigned n, const float *a, int16_t *b) {
pa_reg_x86 temp, i;
__asm__ __volatile__ (
" movaps %5, %%xmm5 \n\t"
" movaps %6, %%xmm6 \n\t"
" movaps %7, %%xmm7 \n\t"
" xor %0, %0 \n\t"
" mov %4, %1 \n\t"
" sar $3, %1 \n\t" /* 8 floats at a time */
" cmp $0, %1 \n\t"
" je 2f \n\t"
"1: \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movups (%q2, %0, 2), %%xmm0 \n\t" /* read 8 floats */
" movups 16(%q2, %0, 2), %%xmm2 \n\t"
" minps %%xmm5, %%xmm0 \n\t" /* clamp to 1.0 */
" minps %%xmm5, %%xmm2 \n\t"
" maxps %%xmm6, %%xmm0 \n\t" /* clamp to -1.0 */
" maxps %%xmm6, %%xmm2 \n\t"
" mulps %%xmm7, %%xmm0 \n\t" /* *= 0x7fff */
" mulps %%xmm7, %%xmm2 \n\t"
" cvtps2dq %%xmm0, %%xmm0 \n\t"
" cvtps2dq %%xmm2, %%xmm2 \n\t"
" packssdw %%xmm2, %%xmm0 \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movdqu %%xmm0, (%q3, %0) \n\t"
" add $16, %0 \n\t"
" dec %1 \n\t"
" jne 1b \n\t"
"2: \n\t"
" mov %4, %1 \n\t" /* prepare for leftovers */
2009-09-02 19:42:17 +02:00
" and $7, %1 \n\t"
" je 4f \n\t"
"3: \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movss (%q2, %0, 2), %%xmm0 \n\t"
" minss %%xmm5, %%xmm0 \n\t"
" maxss %%xmm6, %%xmm0 \n\t"
" mulss %%xmm7, %%xmm0 \n\t"
" cvtss2si %%xmm0, %4 \n\t"
svolume_{mmx, sse}, sconv_sse: Fix compilation errors with X32 toolchain From d8b81d5393df36085009bf9f69d41fa85e2ae58a Mon Sep 17 00:00:00 2001 From: Nitin A Kamble <nitin.a.kamble@intel.com> Date: Sat, 10 Dec 2011 09:09:06 +0100 Make assembly syntax compatible to the X32 toolchain and fix the following kind of compilations errors with X32 gcc. | pulsecore/svolume_mmx.c: Assembler messages: | pulsecore/svolume_mmx.c:107: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:135: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:161: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:162: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:180: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:210: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:244: Error: `(%esi,%rdi,4)' is not a valid base/index expression | pulsecore/svolume_mmx.c:245: Error: `8(%esi,%rdi,4)' is not a valid base/index expression | make[3]: *** [libpulsecore_1.1_la-svolume_mmx.lo] Error 1 Originally these assembly lines were written for x86_64 ABI, now they are also compatible with X32 ABI [3][4]. The patch was submitted to the OpenEmbedded-Core list [1][2]. [1] http://lists.linuxtogo.org/pipermail/openembedded-core/2011-December/014189.html [2] http://git.yoctoproject.org/cgit.cgi/poky-contrib/commit/?h=nitin/x32&id=2d8eec54f755c51f2eff600390f5a4b3cc2a7662 [3] https://wiki.yoctoproject.org/wiki/X32_abi [4] http://en.wikipedia.org/wiki/X32_ABI
2011-12-10 10:03:51 +01:00
" movw %w4, (%q3, %0) \n\t"
" add $2, %0 \n\t"
" dec %1 \n\t"
" jne 3b \n\t"
"4: \n\t"
: "=&r" (i), "=&r" (temp)
: "r" (a), "r" (b), "r" ((pa_reg_x86)n), "m" (*one), "m" (*mone), "m" (*scale)
: "cc", "memory"
);
}
#endif /* defined (__i386__) || defined (__amd64__) */
void pa_convert_func_init_sse(pa_cpu_x86_flag_t flags) {
#if !defined(__APPLE__) && defined (__i386__) || defined (__amd64__)
if (flags & PA_CPU_X86_SSE2) {
pa_log_info("Initialising SSE2 optimized conversions.");
pa_set_convert_from_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse2);
} else {
pa_log_info("Initialising SSE optimized conversions.");
pa_set_convert_from_float32ne_function(PA_SAMPLE_S16LE, (pa_convert_func_t) pa_sconv_s16le_from_f32ne_sse);
}
#endif /* defined (__i386__) || defined (__amd64__) */
}