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