2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
4 * This software may be freely used, copied, modified, and distributed
5 * provided that the above copyright notice is preserved in all copies of the
10 * angel_bytesex.c - Code to support byte-sex independence
11 * Copyright: (C) 1991, Advanced RISC Machines Ltd., Cambridge, England.
19 #include "angel_bytesex.h"
21 static int reversing_bytes = 0;
23 void bytesex_reverse(yes_or_no)
25 { reversing_bytes = yes_or_no;
28 int bytesex_reversing()
30 return reversing_bytes;
33 int32 bytesex_hostval(v)
35 { /* Return v with the same endian-ness as the host */
36 /* This mess generates better ARM code than the more obvious mess */
37 /* and may eventually peephole to optimal code... */
40 /* t = v ^ (v ror 16) */
41 t = v ^ ((v << 16) | (((unsigned32)v) >> 16));
44 v = (v << 24) | (((unsigned32)v) >> 8);
50 int32 bytesex_hostval_16(v)
53 if (reversing_bytes) {
54 v = ((v >> 8) & 0xff) | ((v << 8) & 0xff00);