bytesex_asm.h

Go to the documentation of this file.
00001 /*
00002     $Id: bytesex__asm_8h-source.html,v 1.9 2006/10/27 11:16:41 rocky Exp $
00003 
00004     Copyright (C) 2001 Sven Ottemann <ac-logic@freenet.de>
00005                   2001, 2004, 2005 Herbert Valerio Riedel <hvr@gnu.org>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00029 #ifndef __CDIO_BYTESEX_ASM_H__
00030 #define __CDIO_BYTESEX_ASM_H__
00031 #if !defined(DISABLE_ASM_OPTIMIZE)
00032 
00033 #include <cdio/types.h>
00034 
00035 #if defined(__powerpc__) && defined(__GNUC__)
00036 
00037 inline static
00038 uint32_t uint32_swap_le_be_asm(const uint32_t a)
00039 {
00040   uint32_t b;
00041 
00042   __asm__ ("lwbrx %0,0,%1"
00043            :"=r"(b)
00044            :"r"(&a), "m"(a));
00045 
00046   return b;
00047 }
00048 
00049 inline static
00050 uint16_t uint16_swap_le_be_asm(const uint16_t a)
00051 {
00052   uint32_t b;
00053 
00054   __asm__ ("lhbrx %0,0,%1"
00055            :"=r"(b)
00056            :"r"(&a), "m"(a));
00057 
00058   return b;
00059 }
00060 
00061 #define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
00062 #define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
00063 
00064 #elif defined(__mc68000__) &&  defined(__STORMGCC__)
00065 
00066 inline static 
00067 uint32_t uint32_swap_le_be_asm(uint32_t a __asm__("d0"))
00068 {
00069   /* __asm__("rolw #8,%0; swap %0; rolw #8,%0" : "=d" (val) : "0" (val)); */
00070 
00071   __asm__("move.l %1,d0;rol.w #8,d0;swap d0;rol.w #8,d0;move.l d0,%0"
00072           :"=r"(a)
00073           :"r"(a));
00074 
00075   return(a);
00076 }
00077 
00078 inline static
00079 uint16_t uint16_swap_le_be_asm(uint16_t a __asm__("d0"))
00080 {
00081   __asm__("move.l %1,d0;rol.w #8,d0;move.l d0,%0"
00082           :"=r"(a)
00083           :"r"(a));
00084   
00085   return(a);
00086 }
00087 
00088 #define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
00089 #define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
00090 
00091 #elif 0 && defined(__i386__) && defined(__GNUC__)
00092 
00093 inline static 
00094 uint32_t uint32_swap_le_be_asm(uint32_t a)
00095 {
00096   __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
00097           "rorl $16,%0\n\t"       /* swap words           */
00098           "xchgb %b0,%h0"         /* swap higher bytes    */
00099           :"=q" (a)
00100           : "0" (a));
00101 
00102   return(a);
00103 }
00104 
00105 inline static
00106 uint16_t uint16_swap_le_be_asm(uint16_t a)
00107 {
00108   __asm__("xchgb %b0,%h0"         /* swap bytes           */ 
00109           : "=q" (a) 
00110           :  "0" (a));
00111   
00112   return(a);
00113 }
00114 
00115 #define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
00116 #define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
00117 
00118 #endif
00119 
00120 #endif /* !defined(DISABLE_ASM_OPTIMIZE) */
00121 #endif /* __CDIO_BYTESEX_ASM_H__ */
00122 
00123 
00124 /* 
00125  * Local variables:
00126  *  c-file-style: "gnu"
00127  *  tab-width: 8
00128  *  indent-tabs-mode: nil
00129  * End:
00130  */

Generated on Fri Oct 27 06:38:08 2006 for libcdio by  doxygen 1.4.6