libcdio
0.82
|
00001 /* 00002 $Id: bytesex_asm.h,v 1.3 2008/03/25 15:59:08 karl Exp $ 00003 00004 Copyright (C) 2008 Rocky Bernstein <rocky@gnu.org> 00005 2001, 2004, 2005 Herbert Valerio Riedel <hvr@gnu.org> 00006 2001 Sven Ottemann <ac-logic@freenet.de> 00007 00008 This program is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 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 */