OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [sim/] [common/] [sim-n-endian.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*  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
#include "symcat.h"
27
 
28
/* NOTE: See end of file for #undef */
29
#define unsigned_N XCONCAT2(unsigned_,N)
30
#define endian_t2h_N XCONCAT2(endian_t2h_,N)
31
#define endian_h2t_N XCONCAT2(endian_h2t_,N)
32
#define _SWAP_N XCONCAT2(_SWAP_,N)
33
#define swap_N XCONCAT2(swap_,N)
34
#define endian_h2be_N XCONCAT2(endian_h2be_,N)
35
#define endian_be2h_N XCONCAT2(endian_be2h_,N)
36
#define endian_h2le_N XCONCAT2(endian_h2le_,N)
37
#define endian_le2h_N XCONCAT2(endian_le2h_,N)
38
#define offset_N XCONCAT2(offset_,N)
39
 
40
/* TAGS: endian_t2h_1 endian_t2h_2 endian_t2h_4 endian_t2h_8 endian_t2h_16 */
41
 
42
INLINE_SIM_ENDIAN\
43
(unsigned_N)
44
endian_t2h_N(unsigned_N raw_in)
45
{
46
  if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) {
47
    return raw_in;
48
  }
49
  else {
50
    _SWAP_N(return,raw_in);
51
  }
52
}
53
 
54
/* TAGS: endian_h2t_1 endian_h2t_2 endian_h2t_4 endian_h2t_8 endian_h2t_16 */
55
 
56
INLINE_SIM_ENDIAN\
57
(unsigned_N)
58
endian_h2t_N(unsigned_N raw_in)
59
{
60
  if (CURRENT_TARGET_BYTE_ORDER == CURRENT_HOST_BYTE_ORDER) {
61
    return raw_in;
62
  }
63
  else {
64
    _SWAP_N(return,raw_in);
65
  }
66
}
67
 
68
/* TAGS: swap_1 swap_2 swap_4 swap_8 swap_16 */
69
 
70
INLINE_SIM_ENDIAN\
71
(unsigned_N)
72
swap_N(unsigned_N raw_in)
73
{
74
  _SWAP_N(return,raw_in);
75
}
76
 
77
/* TAGS: endian_h2be_1 endian_h2be_2 endian_h2be_4 endian_h2be_8 endian_h2be_16 */
78
 
79
INLINE_SIM_ENDIAN\
80
(unsigned_N)
81
endian_h2be_N(unsigned_N raw_in)
82
{
83
  if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) {
84
    return raw_in;
85
  }
86
  else {
87
    _SWAP_N(return,raw_in);
88
  }
89
}
90
 
91
/* TAGS: endian_be2h_1 endian_be2h_2 endian_be2h_4 endian_be2h_8 endian_be2h_16 */
92
 
93
INLINE_SIM_ENDIAN\
94
(unsigned_N)
95
endian_be2h_N(unsigned_N raw_in)
96
{
97
  if (CURRENT_HOST_BYTE_ORDER == BIG_ENDIAN) {
98
    return raw_in;
99
  }
100
  else {
101
    _SWAP_N(return,raw_in);
102
  }
103
}
104
 
105
/* TAGS: endian_h2le_1 endian_h2le_2 endian_h2le_4 endian_h2le_8 endian_h2le_16 */
106
 
107
INLINE_SIM_ENDIAN\
108
(unsigned_N)
109
endian_h2le_N(unsigned_N raw_in)
110
{
111
  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) {
112
    return raw_in;
113
  }
114
  else {
115
    _SWAP_N(return,raw_in);
116
  }
117
}
118
 
119
/* TAGS: endian_le2h_1 endian_le2h_2 endian_le2h_4 endian_le2h_8 endian_le2h_16 */
120
 
121
INLINE_SIM_ENDIAN\
122
(unsigned_N)
123
endian_le2h_N(unsigned_N raw_in)
124
{
125
  if (CURRENT_HOST_BYTE_ORDER == LITTLE_ENDIAN) {
126
    return raw_in;
127
  }
128
  else {
129
    _SWAP_N(return,raw_in);
130
  }
131
}
132
 
133
/* TAGS: offset_1 offset_2 offset_4 offset_8 offset_16 */
134
 
135
INLINE_SIM_ENDIAN\
136
(void*)
137
offset_N (unsigned_N *x,
138
          unsigned sizeof_word,
139
          unsigned word)
140
{
141
  char *in = (char*)x;
142
  char *out;
143
  unsigned offset = sizeof_word * word;
144
  ASSERT (offset + sizeof_word <= sizeof(unsigned_N));
145
  ASSERT (word < (sizeof (unsigned_N) / sizeof_word));
146
  ASSERT ((sizeof (unsigned_N) % sizeof_word) == 0);
147
  if (WITH_HOST_BYTE_ORDER == LITTLE_ENDIAN)
148
    {
149
      out = in + sizeof (unsigned_N) - offset - sizeof_word;
150
    }
151
  else
152
    {
153
      out = in + offset;
154
    }
155
  return out;
156
}
157
 
158
 
159
/* NOTE: See start of file for #define */
160
#undef unsigned_N
161
#undef endian_t2h_N
162
#undef endian_h2t_N
163
#undef _SWAP_N
164
#undef swap_N
165
#undef endian_h2be_N
166
#undef endian_be2h_N
167
#undef endian_h2le_N
168
#undef endian_le2h_N
169
#undef offset_N

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.