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 3 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, see <http://www.gnu.org/licenses/>. 17 18 */ 19 20 21 #ifndef N 22 #error "N must be #defined" 23 #endif 24 25 /* NOTE: See end of file for #undef */ 26 #define unsigned_N XCONCAT2(unsigned_,N) 27 #define endian_t2h_N XCONCAT2(endian_t2h_,N) 28 #define endian_h2t_N XCONCAT2(endian_h2t_,N) 29 #define _SWAP_N XCONCAT2(_SWAP_,N) 30 #define swap_N XCONCAT2(swap_,N) 31 #define endian_h2be_N XCONCAT2(endian_h2be_,N) 32 #define endian_be2h_N XCONCAT2(endian_be2h_,N) 33 #define endian_h2le_N XCONCAT2(endian_h2le_,N) 34 #define endian_le2h_N XCONCAT2(endian_le2h_,N) 35 36 37 INLINE_PSIM_ENDIAN\ 38 (unsigned_N) 39 endian_t2h_N(unsigned_N raw_in) 40 { 41 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { 42 return raw_in; 43 } 44 else { 45 _SWAP_N(return,raw_in); 46 } 47 } 48 49 50 INLINE_PSIM_ENDIAN\ 51 (unsigned_N) 52 endian_h2t_N(unsigned_N raw_in) 53 { 54 if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) { 55 return raw_in; 56 } 57 else { 58 _SWAP_N(return,raw_in); 59 } 60 } 61 62 63 INLINE_PSIM_ENDIAN\ 64 (unsigned_N) 65 swap_N(unsigned_N raw_in) 66 { 67 _SWAP_N(return,raw_in); 68 } 69 70 71 72 INLINE_PSIM_ENDIAN\ 73 (unsigned_N) 74 endian_h2be_N(unsigned_N raw_in) 75 { 76 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { 77 return raw_in; 78 } 79 else { 80 _SWAP_N(return,raw_in); 81 } 82 } 83 84 85 INLINE_PSIM_ENDIAN\ 86 (unsigned_N) 87 endian_be2h_N(unsigned_N raw_in) 88 { 89 if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) { 90 return raw_in; 91 } 92 else { 93 _SWAP_N(return,raw_in); 94 } 95 } 96 97 98 INLINE_PSIM_ENDIAN\ 99 (unsigned_N) 100 endian_h2le_N(unsigned_N raw_in) 101 { 102 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { 103 return raw_in; 104 } 105 else { 106 _SWAP_N(return,raw_in); 107 } 108 } 109 110 111 INLINE_PSIM_ENDIAN\ 112 (unsigned_N) 113 endian_le2h_N(unsigned_N raw_in) 114 { 115 if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) { 116 return raw_in; 117 } 118 else { 119 _SWAP_N(return,raw_in); 120 } 121 } 122 123 124 /* NOTE: See start of file for #define */ 125 #undef unsigned_N 126 #undef endian_t2h_N 127 #undef endian_h2t_N 128 #undef _SWAP_N 129 #undef swap_N 130 #undef endian_h2be_N 131 #undef endian_be2h_N 132 #undef endian_h2le_N 133 #undef endian_le2h_N 134