Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / utl / src / BL_Endian.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: BL_Endian.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23#ifndef __BL_Endian_h__
24#define __BL_Endian_h__
25
26#include "BL_Types.h"
27
28// endianess_convert_xx() flips the endianess of value v where xx is
29// the number of bits in the value, followed by u for unsigned or s
30// for signed value.
31
32uint16_t endianess_convert_16u( uint16_t h )
33{
34 return (h << 8) | (h >> 8);
35}
36
37int16_t endianess_convert_16s( int16_t h )
38{
39 return int16_t(endianess_convert_16u(h));
40}
41
42uint32_t endianess_convert_32u( uint32_t w )
43{
44 return (w << 24) | ((w & 0xff00) << 8) | ((w >> 8) & 0xff00) | (w >> 24);
45}
46
47int32_t endianess_convert_32s( int32_t w )
48{
49 return int32_t(endianess_convert_32u(w));
50}
51
52uint64_t endianess_convert_64( uint64_t x )
53{
54 return ( x << 56) | ( x >> 56)
55 | ((x & 0x0000ff00) << 40) | ((x >> 40) & 0x0000ff00)
56 | ((x & 0x00ff0000) << 24) | ((x >> 24) & 0x00ff0000)
57 | ((x & 0xff000000) << 8) | ((x >> 8) & 0xff000000);
58}
59
60#endif
61