2 * Copyright 2003-2007 Marcus Overhagen
3 * Copyright 2007 Haiku Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
10 #include <ByteOrder.h>
11 #include <MediaDefs.h>
13 #include "MixerDebug.h"
16 static void swap_float(void *buffer
, size_t bytecount
);
17 static void swap_int32(void *buffer
, size_t bytecount
);
18 static void swap_int16(void *buffer
, size_t bytecount
);
19 static void do_nothing(void *buffer
, size_t bytecount
);
22 ByteSwap::ByteSwap(uint32 format
)
25 case media_raw_audio_format::B_AUDIO_FLOAT
:
28 case media_raw_audio_format::B_AUDIO_INT
:
31 case media_raw_audio_format::B_AUDIO_SHORT
:
47 do_nothing(void *buffer
, size_t bytecount
)
53 // #pragma mark - optimized for IA32 platform
57 swap_float(void *buffer
, size_t bytecount
)
59 // XXX Should be optimized
60 swap_data(B_FLOAT_TYPE
, buffer
, bytecount
, B_SWAP_ALWAYS
);
65 swap_int32(void *buffer
, size_t bytecount
)
67 // XXX Should be optimized
68 swap_data(B_INT32_TYPE
, buffer
, bytecount
, B_SWAP_ALWAYS
);
73 swap_int16(void *buffer
, size_t bytecount
)
75 // GCC FAQ: To write an asm which modifies an input operand but does
76 // not output anything usable, specify that operand as an
77 // output operand outputting to an unused dummy variable.
80 // GCC is way too smart and will remove the complete asm statement
81 // if we do not specify it as __volatile__. Don't remove that!
82 __asm__
__volatile__ (
84 "movl %%eax, %%ebx \n\t"
85 "movl %%edx, %%eax \n\t"
86 "andl $0xFFFFFFE0,%%eax \n\t"
89 "rolw $8,-32(%%ebx,%%eax) \n\t"
90 "rolw $8,-30(%%ebx,%%eax) \n\t"
91 "rolw $8,-28(%%ebx,%%eax) \n\t"
92 "rolw $8,-26(%%ebx,%%eax) \n\t"
93 "rolw $8,-24(%%ebx,%%eax) \n\t"
94 "rolw $8,-22(%%ebx,%%eax) \n\t"
95 "rolw $8,-20(%%ebx,%%eax) \n\t"
96 "rolw $8,-18(%%ebx,%%eax) \n\t"
97 "rolw $8,-16(%%ebx,%%eax) \n\t"
98 "rolw $8,-14(%%ebx,%%eax) \n\t"
99 "rolw $8,-12(%%ebx,%%eax) \n\t"
100 "rolw $8,-10(%%ebx,%%eax) \n\t"
101 "rolw $8,-8(%%ebx,%%eax) \n\t"
102 "rolw $8,-6(%%ebx,%%eax) \n\t"
103 "rolw $8,-4(%%ebx,%%eax) \n\t"
104 "rolw $8,-2(%%ebx,%%eax) \n\t"
105 "subl $32,%%eax \n\t"
106 "jnz .L_swap_loop \n\t"
108 "addl %%eax,%%ebx \n\t"
109 "andl $0x1F,%%edx \n\t"
110 "jz .L_swap_end \n\t"
111 "addl %%ebx, %%edx \n\t"
112 ".L_swap_loop_2: \n\t"
113 "rolw $8,(%%ebx) \n\t"
115 "cmpl %%edx,%%ebx \n\t"
116 "jne .L_swap_loop_2 \n\t"
119 : "=a" (dummy1
), "=d" (dummy2
)
120 : "d" (bytecount
), "a" (buffer
)
126 // #pragma mark - generic versions
130 swap_float(void *buffer
, size_t bytecount
)
132 swap_data(B_FLOAT_TYPE
, buffer
, bytecount
, B_SWAP_ALWAYS
);
137 swap_int32(void *buffer
, size_t bytecount
)
139 swap_data(B_INT32_TYPE
, buffer
, bytecount
, B_SWAP_ALWAYS
);
144 swap_int16(void *buffer
, size_t bytecount
)
146 swap_data(B_INT16_TYPE
, buffer
, bytecount
, B_SWAP_ALWAYS
);