1/* 2** Copyright 2003, Axel D�fler, 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 */ 12FUNCTION(__swap_int16): 13 moveq.l #0,%d0 14 move.b (5,%a7),%d0 15 lsl.w #8,%d0 16 move.b (4,%a7),%d0 17 rts 18 19 20/* uint32 __swap_int32(uint32 value) 21 */ 22FUNCTION(__swap_int32): 23/* moveq.l #0,%d0*/ 24 move.b (7,%a7),%d0 25 lsl.w #8,%d0 26 move.b (6,%a7),%d0 27 lsl.w #8,%d0 28 move.b (5,%a7),%d0 29 lsl.w #8,%d0 30 move.b (4,%a7),%d0 31 rts 32 33 34/* uint64 __swap_int64(uint64 value) 35 */ 36FUNCTION(__swap_int64): 37/* moveq.l #0,%d0*/ 38 move.b (7,%a7),%d0 39 lsl.w #8,%d0 40 move.b (6,%a7),%d0 41 lsl.w #8,%d0 42 move.b (5,%a7),%d0 43 lsl.w #8,%d0 44 move.b (4,%a7),%d0 45 move.l %d0,(%a0) 46 move.b (11,%a7),%d0 47 lsl.w #8,%d0 48 move.b (10,%a7),%d0 49 lsl.w #8,%d0 50 move.b (9,%a7),%d0 51 lsl.w #8,%d0 52 move.b (8,%a7),%d0 53 move.l %d0,(4,%a0) 54 rts 55 56 57/* TODO: The following functions can surely be optimized. A simple optimization 58 * would be to define macros with the contents of the __swap_int{32,64} 59 * functions and use those instead of calling the functions. 60 */ 61 62/* float __swap_float(float value) 63 * f1 64 */ 65FUNCTION(__swap_float): 66XXX: TODO 67 // push a stack frame 68 stwu %r1, -32(%r1) 69 mflr %r0 70 stw %r0, 36(%r1) 71 72 // %f1 -> %r3 73 stfs %f1, 20(%r1) 74 lwz %r3, 20(%r1) 75 76 // let __swap_int32 convert %r3 77 bl __swap_int32 78 79 // %r3 -> %f1 80 stw %r3, 20(%r1) 81 lfs %f1, 20(%r1) 82 83 // pop the stack frame 84 lwz %r0, 36(%r1) 85 mtlr %r0 86 addi %r1, %r1, 32 87 blr 88 89/* double __swap_double(double value) 90 * f1 91 */ 92FUNCTION(__swap_double): 93XXX: TODO 94 // push a stack frame 95 stwu %r1, -32(%r1) 96 mflr %r0 97 stw %r0, 36(%r1) 98 99 // %f1 -> (%r3:%r4) 100 stfd %f1, 20(%r1) 101 lwz %r3, 20(%r1) 102 lwz %r4, 24(%r1) 103 104 // let __swap_int64 convert %r3:%r4 105 bl __swap_int64 106 107 // (%r3:%r4) -> %f1 108 stw %r3, 20(%r1) 109 stw %r4, 24(%r1) 110 lfd %f1, 20(%r1) 111 112 // pop the stack frame 113 lwz %r0, 36(%r1) 114 mtlr %r0 115 addi %r1, %r1, 32 116 blr 117