* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: BL_Endian.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
// endianess_convert_xx() flips the endianess of value v where xx is
// the number of bits in the value, followed by u for unsigned or s
uint16_t endianess_convert_16u( uint16_t h
)
return (h
<< 8) | (h
>> 8);
int16_t endianess_convert_16s( int16_t h
)
return int16_t(endianess_convert_16u(h
));
uint32_t endianess_convert_32u( uint32_t w
)
return (w
<< 24) | ((w
& 0xff00) << 8) | ((w
>> 8) & 0xff00) | (w
>> 24);
int32_t endianess_convert_32s( int32_t w
)
return int32_t(endianess_convert_32u(w
));
uint64_t endianess_convert_64( uint64_t x
)
return ( x
<< 56) | ( x
>> 56)
| ((x
& 0x0000ff00) << 40) | ((x
>> 40) & 0x0000ff00)
| ((x
& 0x00ff0000) << 24) | ((x
>> 24) & 0x00ff0000)
| ((x
& 0xff000000) << 8) | ((x
>> 8) & 0xff000000);