1/* This file is part of the program psim. 2 3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 22#ifndef N 23#error "N must be #defined" 24#endif 25 26/* NOTE: See end of file for #undef */ 27#define unsigned_N XCONCAT2(unsigned_,N) 28#define endian_t2h_N XCONCAT2(endian_t2h_,N) 29#define endian_h2t_N XCONCAT2(endian_h2t_,N) 30#define _SWAP_N XCONCAT2(_SWAP_,N) 31#define swap_N XCONCAT2(swap_,N) 32#define endian_h2be_N XCONCAT2(endian_h2be_,N) 33#define endian_be2h_N XCONCAT2(endian_be2h_,N) 34#define endian_h2le_N XCONCAT2(endian_h2le_,N) 35#define endian_le2h_N XCONCAT2(endian_le2h_,N) 36 37 38INLINE_PSIM_ENDIAN\ 39(unsigned_N) 40endian_t2h_N(unsigned_N raw_in) 41{ 42 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { 43 return raw_in; 44 } 45 else { 46 _SWAP_N(return,raw_in); 47 } 48} 49 50 51INLINE_PSIM_ENDIAN\ 52(unsigned_N) 53endian_h2t_N(unsigned_N raw_in) 54{ 55 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { 56 return raw_in; 57 } 58 else { 59 _SWAP_N(return,raw_in); 60 } 61} 62 63 64INLINE_PSIM_ENDIAN\ 65(unsigned_N) 66swap_N(unsigned_N raw_in) 67{ 68 _SWAP_N(return,raw_in); 69} 70 71 72 73INLINE_PSIM_ENDIAN\ 74(unsigned_N) 75endian_h2be_N(unsigned_N raw_in) 76{ 77 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { 78 return raw_in; 79 } 80 else { 81 _SWAP_N(return,raw_in); 82 } 83} 84 85 86INLINE_PSIM_ENDIAN\ 87(unsigned_N) 88endian_be2h_N(unsigned_N raw_in) 89{ 90 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { 91 return raw_in; 92 } 93 else { 94 _SWAP_N(return,raw_in); 95 } 96} 97 98 99INLINE_PSIM_ENDIAN\ 100(unsigned_N) 101endian_h2le_N(unsigned_N raw_in) 102{ 103 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { 104 return raw_in; 105 } 106 else { 107 _SWAP_N(return,raw_in); 108 } 109} 110 111 112INLINE_PSIM_ENDIAN\ 113(unsigned_N) 114endian_le2h_N(unsigned_N raw_in) 115{ 116 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { 117 return raw_in; 118 } 119 else { 120 _SWAP_N(return,raw_in); 121 } 122} 123 124 125/* NOTE: See start of file for #define */ 126#undef unsigned_N 127#undef endian_t2h_N 128#undef endian_h2t_N 129#undef _SWAP_N 130#undef swap_N 131#undef endian_h2be_N 132#undef endian_be2h_N 133#undef endian_h2le_N 134#undef endian_le2h_N 135