libcdio 2.1.1
bytesex_asm.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2008, 2012 Rocky Bernstein <rocky@gnu.org>
3 2001, 2004, 2005 Herbert Valerio Riedel <hvr@gnu.org>
4 2001 Sven Ottemann <ac-logic@freenet.de>
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
27#ifndef CDIO_BYTESEX_ASM_H_
28#define CDIO_BYTESEX_ASM_H_
29#if !defined(DISABLE_ASM_OPTIMIZE)
30
31#include <cdio/types.h>
32
33#if !defined CDIO_INLINE
34#if defined(__cplusplus) || defined(inline)
35#define CDIO_INLINE inline
36#elif defined(__GNUC__)
37#define CDIO_INLINE __inline__
38#elif defined(_MSC_VER)
39#define CDIO_INLINE __inline
40#else
41#define CDIO_INLINE
42#endif
43#endif /* CDIO_INLINE */
44
45#if defined(__powerpc__) && defined(__GNUC__)
46
47static CDIO_INLINE
48uint32_t uint32_swap_le_be_asm(const uint32_t a)
49{
50 uint32_t b;
51
52 __asm__ ("lwbrx %0,0,%1"
53 :"=r"(b)
54 :"r"(&a), "m"(a));
55
56 return b;
57}
58
59static CDIO_INLINE
60uint16_t uint16_swap_le_be_asm(const uint16_t a)
61{
62 uint32_t b;
63
64 __asm__ ("lhbrx %0,0,%1"
65 :"=r"(b)
66 :"r"(&a), "m"(a));
67
68 return b;
69}
70
71#define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
72#define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
73
74#elif defined(__mc68000__) && defined(__STORMGCC__)
75
76static CDIO_INLINE
77uint32_t uint32_swap_le_be_asm(uint32_t a __asm__("d0"))
78{
79 /* __asm__("rolw #8,%0; swap %0; rolw #8,%0" : "=d" (val) : "0" (val)); */
80
81 __asm__("move.l %1,d0;rol.w #8,d0;swap d0;rol.w #8,d0;move.l d0,%0"
82 :"=r"(a)
83 :"r"(a));
84
85 return(a);
86}
87
88static CDIO_INLINE
89uint16_t uint16_swap_le_be_asm(uint16_t a __asm__("d0"))
90{
91 __asm__("move.l %1,d0;rol.w #8,d0;move.l d0,%0"
92 :"=r"(a)
93 :"r"(a));
94
95 return(a);
96}
97
98#define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
99#define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
100
101#elif 0 && defined(__i386__) && defined(__GNUC__)
102
103static CDIO_INLINE
104uint32_t uint32_swap_le_be_asm(uint32_t a)
105{
106 __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
107 "rorl $16,%0\n\t" /* swap words */
108 "xchgb %b0,%h0" /* swap higher bytes */
109 :"=q" (a)
110 : "0" (a));
111
112 return(a);
113}
114
115static CDIO_INLINE
116uint16_t uint16_swap_le_be_asm(uint16_t a)
117{
118 __asm__("xchgb %b0,%h0" /* swap bytes */
119 : "=q" (a)
120 : "0" (a));
121
122 return(a);
123}
124
125#define UINT16_SWAP_LE_BE uint16_swap_le_be_asm
126#define UINT32_SWAP_LE_BE uint32_swap_le_be_asm
127
128#endif
129
130#endif /* !defined(DISABLE_ASM_OPTIMIZE) */
131#endif /* CDIO_BYTESEX_ASM_H_ */
132
133
134/*
135 * Local variables:
136 * c-file-style: "gnu"
137 * tab-width: 8
138 * indent-tabs-mode: nil
139 * End:
140 */
#define CDIO_INLINE
Definition bytesex_asm.h:41
Common type definitions used pervasively in libcdio.