Update of /cvsroot/alsa/alsa-lib/src/pcm
In directory sc8-pr-cvs1:/tmp/cvs-serv31645

Modified Files:
        Makefile.am pcm_direct.h pcm_dmix.c pcm_dmix_i386.h 
Added Files:
        pcm_dmix_x86_64.h 
Log Message:
- support of dmix asm code for x86-64.



--- NEW FILE: pcm_dmix_x86_64.h ---
/**
 * \file pcm/pcm_dmix_x86_64.h
 * \ingroup PCM_Plugins
 * \brief PCM Direct Stream Mixing (dmix) Plugin Interface - X86-64 assembler code
 * \author Takashi Iwai <[EMAIL PROTECTED]>
 * \date 2003
 */
/*
 *  PCM - Direct Stream Mixing
 *  Copyright (c) 2003 by Jaroslav Kysela <[EMAIL PROTECTED]>
 *                        Takashi Iwai <[EMAIL PROTECTED]>
 *
 *
 *   This library 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.
 *
 *   This program 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 Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

/*
 *  MMX optimized
 */
static void MIX_AREAS1(unsigned int size,
                       volatile signed short *dst, signed short *src,
                       volatile signed int *sum, size_t dst_step,
                       size_t src_step, size_t sum_step)
{
        /*
         *  ESI - src
         *  EDI - dst
         *  EBX - sum
         *  ECX - old sample
         *  EAX - sample / temporary
         *  EDX - temporary
         */
        __asm__ __volatile__ (
                "\n"

                /*
                 *  initialization, load ESI, EDI, EBX registers
                 */
                "\tmovq %1, %%rdi\n"
                "\tmovq %2, %%rsi\n"
                "\tmovq %3, %%rbx\n"

                /*
                 * while (size-- > 0) {
                 */
                "\tcmpl $0, %0\n"
                "jz 6f\n"

                "\t.p2align 4,,15\n"

                "1:"

                /*
                 *   sample = *src;
                 *   sum_sample = *sum;
                 *   if (cmpxchg(*dst, 0, 1) == 0)
                 *     sample -= sum_sample;
                 *   xadd(*sum, sample);
                 */
                "\tmovw $0, %%ax\n"
                "\tmovw $1, %%cx\n"
                "\tmovl (%%rbx), %%edx\n"
                "\t" LOCK_PREFIX "cmpxchgw %%cx, (%%rdi)\n"
                "\tmovswl (%%rsi), %%ecx\n"
                "\tjnz 2f\n"
                "\tsubl %%edx, %%ecx\n"
                "2:"
                "\t" LOCK_PREFIX "addl %%ecx, (%%rbx)\n"

                /*
                 *   do {
                 *     sample = old_sample = *sum;
                 *     saturate(v);
                 *     *dst = sample;
                 *   } while (v != *sum);
                 */

                "3:"
                "\tmovl (%%rbx), %%ecx\n"
                "\tmovd %%ecx, %%mm0\n"
                "\tpackssdw %%mm1, %%mm0\n"
                "\tmovd %%mm0, %%eax\n"
                "\tmovw %%ax, (%%rdi)\n"
                "\tcmpl %%ecx, (%%rbx)\n"
                "\tjnz 3b\n"

                /*
                 * while (size-- > 0)
                 */
                "\tadd %4, %%rdi\n"
                "\tadd %5, %%rsi\n"
                "\tadd %6, %%rbx\n"
                "\tdecl %0\n"
                "\tjnz 1b\n"
                "\tjmp 6f\n"

                "6:"
                
                "\temms\n"

                : /* no output regs */
                : "m" (size), "m" (dst), "m" (src), "m" (sum), "m" (dst_step), "m" 
(src_step), "m" (sum_step)
                : "rsi", "rdi", "edx", "ecx", "rbx", "eax"
        );
}

/*
 *  32-bit version (24-bit resolution)
 */
static void MIX_AREAS2(unsigned int size,
                       volatile signed int *dst, signed int *src,
                       volatile signed int *sum, size_t dst_step,
                       size_t src_step, size_t sum_step)
{
        /*
         *  ESI - src
         *  EDI - dst
         *  EBX - sum
         *  ECX - old sample
         *  EAX - sample / temporary
         *  EDX - temporary
         */
        __asm__ __volatile__ (
                "\n"

                /*
                 *  initialization, load ESI, EDI, EBX registers
                 */
                "\tmovq %1, %%rdi\n"
                "\tmovq %2, %%rsi\n"
                "\tmovq %3, %%rbx\n"

                /*
                 * while (size-- > 0) {
                 */
                "\tcmpl $0, %0\n"
                "jz 6f\n"

                "\t.p2align 4,,15\n"

                "1:"

                /*
                 *   sample = *src;
                 *   sum_sample = *sum;
                 *   if (cmpxchg(*dst, 0, 1) == 0)
                 *     sample -= sum_sample;
                 *   xadd(*sum, sample);
                 */
                "\tmovl $0, %%eax\n"
                "\tmovl $1, %%ecx\n"
                "\tmovl (%%rbx), %%edx\n"
                "\t" LOCK_PREFIX "cmpxchgl %%ecx, (%%rdi)\n"
                "\tjnz 2f\n"
                "\tmovl (%%rsi), %%ecx\n"
                /* sample >>= 8 */
                "\tsarl $8, %%ecx\n"
                "\tsubl %%edx, %%ecx\n"
                "\tjmp 21f\n"
                "2:"
                "\tmovl (%%rsi), %%ecx\n"
                /* sample >>= 8 */
                "\tsarl $8, %%ecx\n"
                "21:"
                "\t" LOCK_PREFIX "addl %%ecx, (%%rbx)\n"

                /*
                 *   do {
                 *     sample = old_sample = *sum;
                 *     saturate(v);
                 *     *dst = sample;
                 *   } while (v != *sum);
                 */

                "3:"
                "\tmovl (%%rbx), %%ecx\n"
                /*
                 *  if (sample > 0x7fff00)
                 */
                "\tmovl $0x7fffff, %%eax\n"
                "\tcmpl %%eax, %%ecx\n"
                "\tjg 4f\n"
                /*
                 *  if (sample < -0x800000)
                 */
                "\tmovl $-0x800000, %%eax\n"
                "\tcmpl %%eax, %%ecx\n"
                "\tjl 4f\n"
                "\tmovl %%ecx, %%eax\n"
                "4:"
                /*
                 *  sample <<= 8;
                 */
                "\tsall $8, %%eax\n"
                "\tmovl %%eax, (%%rdi)\n"
                "\tcmpl %%ecx, (%%rbx)\n"
                "\tjnz 3b\n"

                /*
                 * while (size-- > 0)
                 */
                "\tadd %4, %%rdi\n"
                "\tadd %5, %%rsi\n"
                "\tadd %6, %%rbx\n"
                "\tdecl %0\n"
                "\tjnz 1b\n"
                // "\tjmp 6f\n"
                
                "6:"
                : /* no output regs */
                : "m" (size), "m" (dst), "m" (src), "m" (sum), "m" (dst_step), "m" 
(src_step), "m" (sum_step)
                : "rsi", "rdi", "edx", "ecx", "rbx", "eax"
        );
}


Index: Makefile.am
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/Makefile.am,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- Makefile.am 18 Mar 2003 20:37:48 -0000      1.48
+++ Makefile.am 17 Sep 2003 17:09:45 -0000      1.49
@@ -14,7 +14,7 @@
                    pcm_symbols.c
 noinst_HEADERS = pcm_local.h pcm_plugin.h mask.h mask_inline.h \
                 interval.h interval_inline.h plugin_ops.h ladspa.h \
-                pcm_direct.h pcm_dmix_i386.h
+                pcm_direct.h pcm_dmix_i386.h pcm_dmix_x86_64.h
 
 alsadir = $(datadir)/alsa
 

Index: pcm_direct.h
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_direct.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- pcm_direct.h        2 Sep 2003 10:32:33 -0000       1.4
+++ pcm_direct.h        17 Sep 2003 17:09:45 -0000      1.5
@@ -33,13 +33,13 @@
 
 typedef void (mix_areas1_t)(unsigned int size,
                        volatile signed short *dst, signed short *src,
-                       volatile signed int *sum, unsigned int dst_step,
-                       unsigned int src_step, unsigned int sum_step);
+                       volatile signed int *sum, size_t dst_step,
+                       size_t src_step, size_t sum_step);
 
 typedef void (mix_areas2_t)(unsigned int size,
                        volatile signed int *dst, signed int *src,
-                       volatile signed int *sum, unsigned int dst_step,
-                       unsigned int src_step, unsigned int sum_step);
+                       volatile signed int *sum, size_t dst_step,
+                       size_t src_step, size_t sum_step);
 
 struct slave_params {
        snd_pcm_format_t format;

Index: pcm_dmix.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_dmix.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- pcm_dmix.c  2 Sep 2003 10:32:33 -0000       1.42
+++ pcm_dmix.c  17 Sep 2003 17:09:45 -0000      1.43
@@ -138,22 +138,20 @@
        char line[255];
        int smp = 0, mmx = 0;
        
-       /* safe settings for all i386 CPUs */
-       dmix->u.dmix.mix_areas1 = mix_areas1_smp;
        /* try to determine, if we have a MMX capable CPU */
        in = fopen("/proc/cpuinfo", "r");
-       if (in == NULL)
-               return;
-       while (!feof(in)) {
-               fgets(line, sizeof(line), in);
-               if (!strncmp(line, "processor", 9))
-                       smp++;
-               else if (!strncmp(line, "flags", 5)) {
-                       if (strstr(line, " mmx"))
-                               mmx = 1;
+       if (in) {
+               while (!feof(in)) {
+                       fgets(line, sizeof(line), in);
+                       if (!strncmp(line, "processor", 9))
+                               smp++;
+                       else if (!strncmp(line, "flags", 5)) {
+                               if (strstr(line, " mmx"))
+                                       mmx = 1;
+                       }
                }
+               fclose(in);
        }
-       fclose(in);
        // printf("MMX: %i, SMP: %i\n", mmx, smp);
        if (mmx) {
                dmix->u.dmix.mix_areas1 = smp > 1 ? mix_areas1_smp_mmx : 
mix_areas1_mmx;
@@ -164,12 +162,54 @@
 }
 #endif
 
+#ifdef __x86_64__
+#define ADD_AND_SATURATE
+
+#define MIX_AREAS1 mix_areas1
+#define MIX_AREAS2 mix_areas2
+#define LOCK_PREFIX ""
+#include "pcm_dmix_x86_64.h"
+#undef MIX_AREAS1
+#undef MIX_AREAS2
+#undef LOCK_PREFIX
+
+#define MIX_AREAS1 mix_areas1_smp
+#define MIX_AREAS2 mix_areas2_smp
+#define LOCK_PREFIX "lock ; "
+#include "pcm_dmix_x86_64.h"
+#undef MIX_AREAS1
+#undef MIX_AREAS2
+#undef LOCK_PREFIX
+ 
+static void mix_select_callbacks(snd_pcm_direct_t *dmix)
+{
+       FILE *in;
+       char line[255];
+       int smp = 0;
+       
+       /* try to determine, if we have SMP */
+       in = fopen("/proc/cpuinfo", "r");
+       if (in) {
+               while (!feof(in)) {
+                       fgets(line, sizeof(line), in);
+                       if (!strncmp(line, "processor", 9))
+                               smp++;
+               }
+               fclose(in);
+       }
+       // printf("SMP: %i\n", smp);
+       dmix->u.dmix.mix_areas1 = smp > 1 ? mix_areas1_smp : mix_areas1;
+       dmix->u.dmix.mix_areas2 = smp > 1 ? mix_areas2_smp : mix_areas2;
+}
+#endif
+
+
 #ifndef ADD_AND_SATURATE
 #warning Please, recode mix_areas1() routine to your architecture...
 static void mix_areas1(unsigned int size,
                       volatile signed short *dst, signed short *src,
-                      volatile signed int *sum, unsigned int dst_step,
-                      unsigned int src_step, unsigned int sum_step)
+                      volatile signed int *sum, size_t dst_step,
+                      size_t src_step, size_t sum_step)
 {
        register signed int sample, old_sample;
 
@@ -198,8 +238,8 @@
 #warning Please, recode mix_areas2() routine to your architecture...
 static void mix_areas2(unsigned int size,
                       volatile signed int *dst, signed int *src,
-                      volatile signed int *sum, unsigned int dst_step,
-                      unsigned int src_step, unsigned int sum_step)
+                      volatile signed int *sum, size_t dst_step,
+                      size_t src_step, size_t sum_step)
 {
        register signed int sample, old_sample;
 

Index: pcm_dmix_i386.h
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_dmix_i386.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pcm_dmix_i386.h     17 Sep 2003 15:39:12 -0000      1.8
+++ pcm_dmix_i386.h     17 Sep 2003 17:09:45 -0000      1.9
@@ -31,8 +31,8 @@
  */
 static void MIX_AREAS1(unsigned int size,
                       volatile signed short *dst, signed short *src,
-                      volatile signed int *sum, unsigned int dst_step,
-                      unsigned int src_step, unsigned int sum_step)
+                      volatile signed int *sum, size_t dst_step,
+                      size_t src_step, size_t sum_step)
 {
        /*
         *  ESI - src
@@ -55,7 +55,7 @@
                /*
                 * while (size-- > 0) {
                 */
-               "\tcmp $0, %0\n"
+               "\tcmpl $0, %0\n"
                "jz 6f\n"
 
                "\t.p2align 4,,15\n"
@@ -154,8 +154,8 @@
  */
 static void MIX_AREAS1_MMX(unsigned int size,
                           volatile signed short *dst, signed short *src,
-                          volatile signed int *sum, unsigned int dst_step,
-                          unsigned int src_step, unsigned int sum_step)
+                          volatile signed int *sum, size_t dst_step,
+                          size_t src_step, size_t sum_step)
 {
        /*
         *  ESI - src
@@ -178,7 +178,7 @@
                /*
                 * while (size-- > 0) {
                 */
-               "\tcmp $0, %0\n"
+               "\tcmpl $0, %0\n"
                "jz 6f\n"
 
                "\t.p2align 4,,15\n"
@@ -244,8 +244,8 @@
  */
 static void MIX_AREAS2(unsigned int size,
                       volatile signed int *dst, signed int *src,
-                      volatile signed int *sum, unsigned int dst_step,
-                      unsigned int src_step, unsigned int sum_step)
+                      volatile signed int *sum, size_t dst_step,
+                      size_t src_step, size_t sum_step)
 {
        /*
         *  ESI - src
@@ -268,7 +268,7 @@
                /*
                 * while (size-- > 0) {
                 */
-               "\tcmp $0, %0\n"
+               "\tcmpl $0, %0\n"
                "jz 6f\n"
 
                "\t.p2align 4,,15\n"



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to