sim-endian-n.h 2.6 KB

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