xref: /haiku/src/system/libroot/os/arch/ppc/byteorder.S (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1/*
2** Copyright 2003, Axel D�rfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the OpenBeOS License.
4*/
5
6#define FUNCTION(x) .global x; .type x,@function; x
7
8.text
9
10/* uint16 __swap_int16(uint16 value)
11 *                     r3
12 */
13FUNCTION(__swap_int16):
14		rlwinm	%r4, %r3, 8, 16, 23		// byte 4 -> byte 3 (clear other bits)
15		rlwimi	%r4, %r3, 24, 24, 31	// byte 3 -> byte 4 (copy into)
16		mr		%r3, %r4				// copy to result register
17		blr
18
19
20/* uint32 __swap_int32(uint32 value)
21 *                     r3
22 */
23FUNCTION(__swap_int32):
24		rlwinm	%r4, %r3, 24, 0, 31		// byte 4 to 1, byte 2 to 3
25		rlwimi	%r4, %r3, 8, 8, 15		// byte 3 to 2
26		rlwimi	%r4, %r3, 8, 24, 31		// byte 1 to 4
27		mr		%r3, %r4
28		blr
29
30
31/* uint64 __swap_int64(uint64 value)
32 *                     r3/r4
33 */
34FUNCTION(__swap_int64):
35		rlwinm	%r5, %r3, 24, 0, 31		// byte 4 to 5, byte 2 to 7
36		rlwimi	%r5, %r3, 8, 8, 15		// byte 3 to 6
37		rlwimi	%r5, %r3, 8, 24, 31		// byte 1 to 8
38		rlwinm	%r3, %r4, 24, 0, 31		// byte 8 to 1, byte 6 to 3
39		rlwimi	%r3, %r4, 8, 8, 15		// byte 7 to 2
40		rlwimi	%r3, %r4, 8, 24, 31		// byte 5 to 4
41		mr		%r4, %r5				// copy lower 32 bits
42		blr
43
44