gem5  v20.1.0.0
byteswap.test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 The Regents of the University of California
3  * All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <gtest/gtest.h>
30 
31 #include "sim/byteswap.hh"
32 
33 TEST(ByteswapTest, swap_byte64)
34 {
35  EXPECT_EQ(0x0123456789abcdef, swap_byte64(0xefcdab8967452301));
36  EXPECT_EQ(0xfedcba9876543210, swap_byte64(0x1032547698badcfe));
37  EXPECT_EQ(0x0b1cb071b77141b1, swap_byte64(0xb14171b771b01c0b));
38  EXPECT_EQ(0x00000000ffffffff, swap_byte64(0xffffffff00000000));
39  EXPECT_EQ(0x5555555555555555, swap_byte64(0x5555555555555555));
40  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, swap_byte64(0xa0a0a0a0a0a0a0a0));
41 }
42 
43 TEST(ByteswapTest, swap_byte32)
44 {
45  EXPECT_EQ(0x0123cdef, swap_byte32(0xefcd2301));
46  EXPECT_EQ(0xfedc3210, swap_byte32(0x1032dcfe));
47  EXPECT_EQ(0x0b1c41b1, swap_byte32(0xb1411c0b));
48  EXPECT_EQ(0x0000ffff, swap_byte32(0xffff0000));
49  EXPECT_EQ(0x55555555, swap_byte32(0x55555555));
50  EXPECT_EQ(0xa0a0a0a0, swap_byte32(0xa0a0a0a0));
51 }
52 
53 TEST(ByteswapTest, swap_byte16)
54 {
55  EXPECT_EQ(0x01ef, swap_byte16(0xef01));
56  EXPECT_EQ(0xfe10, swap_byte16(0x10fe));
57  EXPECT_EQ(0x0bb1, swap_byte16(0xb10b));
58  EXPECT_EQ(0x00ff, swap_byte16(0xff00));
59  EXPECT_EQ(0x5555, swap_byte16(0x5555));
60  EXPECT_EQ(0xa0a0, swap_byte16(0xa0a0));
61 }
62 
63 TEST(ByteswapTest, swap_byte)
64 {
65  EXPECT_EQ(0x0123456789abcdef, swap_byte((uint64_t)0xefcdab8967452301));
66  EXPECT_EQ(0xfedcba9876543210, swap_byte((uint64_t)0x1032547698badcfe));
67  EXPECT_EQ(0x0b1cb071b77141b1, swap_byte((uint64_t)0xb14171b771b01c0b));
68  EXPECT_EQ(0x00000000ffffffff, swap_byte((uint64_t)0xffffffff00000000));
69  EXPECT_EQ(0x5555555555555555, swap_byte((uint64_t)0x5555555555555555));
70  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, swap_byte((uint64_t)0xa0a0a0a0a0a0a0a0));
71  EXPECT_EQ(0x0123cdef, swap_byte((uint32_t)0xefcd2301));
72  EXPECT_EQ(0xfedc3210, swap_byte((uint32_t)0x1032dcfe));
73  EXPECT_EQ(0x0b1c41b1, swap_byte((uint32_t)0xb1411c0b));
74  EXPECT_EQ(0x0000ffff, swap_byte((uint32_t)0xffff0000));
75  EXPECT_EQ(0x55555555, swap_byte((uint32_t)0x55555555));
76  EXPECT_EQ(0xa0a0a0a0, swap_byte((uint32_t)0xa0a0a0a0));
77  EXPECT_EQ(0x01ef, swap_byte((uint16_t)0xef01));
78  EXPECT_EQ(0xfe10, swap_byte((uint16_t)0x10fe));
79  EXPECT_EQ(0x0bb1, swap_byte((uint16_t)0xb10b));
80  EXPECT_EQ(0x00ff, swap_byte((uint16_t)0xff00));
81  EXPECT_EQ(0x5555, swap_byte((uint16_t)0x5555));
82  EXPECT_EQ(0xa0a0, swap_byte((uint16_t)0xa0a0));
83 }
84 
85 TEST(ByteswapTest, htog)
86 {
87 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
88  EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301,
89  ByteOrder::big));
90  EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe,
91  ByteOrder::big));
92  EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b,
93  ByteOrder::big));
94  EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000,
95  ByteOrder::big));
96  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
97  ByteOrder::big));
98  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
99  ByteOrder::big));
100  EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::big));
101  EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::big));
102  EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::big));
103  EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::big));
104  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big));
105  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
106  EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::big));
107  EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::big));
108  EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::big));
109  EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::big));
110  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big));
111  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big));
112  EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301,
113  ByteOrder::little));
114  EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe,
115  ByteOrder::little));
116  EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b,
117  ByteOrder::little));
118  EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000,
119  ByteOrder::little));
120  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
121  ByteOrder::little));
122  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
123  ByteOrder::little));
124  EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::little));
125  EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::little));
126  EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::little));
127  EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::little));
128  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little));
129  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
130  EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::little));
131  EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::little));
132  EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::little));
133  EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::little));
134  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little));
135  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little));
136 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
137  EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301,
138  ByteOrder::big));
139  EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe,
140  ByteOrder::big));
141  EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b,
142  ByteOrder::big));
143  EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000,
144  ByteOrder::big));
145  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
146  ByteOrder::big));
147  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
148  ByteOrder::big));
149  EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::big));
150  EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::big));
151  EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::big));
152  EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::big));
153  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big));
154  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
155  EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::big));
156  EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::big));
157  EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::big));
158  EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::big));
159  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big));
160  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big));
161  EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301,
162  ByteOrder::little));
163  EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe,
164  ByteOrder::little));
165  EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b,
166  ByteOrder::little));
167  EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000,
168  ByteOrder::little));
169  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
170  ByteOrder::little));
171  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
172  ByteOrder::little));
173  EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::little));
174  EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::little));
175  EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::little));
176  EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::little));
177  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little));
178  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
179  EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::little));
180  EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::little));
181  EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::little));
182  EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::little));
183  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little));
184  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little));
185 #else
186  #error Invalid Endianess
187 #endif
188 }
189 
190 TEST(ByteswapTest, gtoh)
191 {
192 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
193  EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301,
194  ByteOrder::big));
195  EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe,
196  ByteOrder::big));
197  EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b,
198  ByteOrder::big));
199  EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000,
200  ByteOrder::big));
201  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
202  ByteOrder::big));
203  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
204  ByteOrder::big));
205  EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::big));
206  EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
207  EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
208  EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::big));
209  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big));
210  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
211  EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::big));
212  EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::big));
213  EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::big));
214  EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::big));
215  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big));
216  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big));
217  EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301,
218  ByteOrder::little));
219  EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe,
220  ByteOrder::little));
221  EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b,
222  ByteOrder::little));
223  EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000,
224  ByteOrder::little));
225  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
226  ByteOrder::little));
227  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
228  ByteOrder::little));
229  EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::little));
230  EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
231  EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
232  EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::little));
233  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little));
234  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
235  EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::little));
236  EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::little));
237  EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::little));
238  EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::little));
239  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little));
240  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little));
241 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
242  EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301,
243  ByteOrder::big));
244  EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe,
245  ByteOrder::big));
246  EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b,
247  ByteOrder::big));
248  EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000,
249  ByteOrder::big));
250  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
251  ByteOrder::big));
252  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
253  ByteOrder::big));
254  EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::big));
255  EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
256  EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
257  EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::big));
258  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big));
259  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
260  EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::big));
261  EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::big));
262  EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::big));
263  EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::big));
264  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big));
265  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big));
266  EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301,
267  ByteOrder::little));
268  EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe,
269  ByteOrder::little));
270  EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b,
271  ByteOrder::little));
272  EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000,
273  ByteOrder::little));
274  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
275  ByteOrder::little));
276  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
277  ByteOrder::little));
278  EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::little));
279  EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
280  EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
281  EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::little));
282  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little));
283  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
284  EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::little));
285  EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::little));
286  EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::little));
287  EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::little));
288  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little));
289  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little));
290 #else
291  #error Invalid Endianess
292 #endif
293 }
294 
295 TEST(ByteswapTest, betole)
296 {
297  EXPECT_EQ(0x0123456789abcdef, betole((uint64_t)0xefcdab8967452301));
298  EXPECT_EQ(0xfedcba9876543210, betole((uint64_t)0x1032547698badcfe));
299  EXPECT_EQ(0x0b1cb071b77141b1, betole((uint64_t)0xb14171b771b01c0b));
300  EXPECT_EQ(0x00000000ffffffff, betole((uint64_t)0xffffffff00000000));
301  EXPECT_EQ(0x5555555555555555, betole((uint64_t)0x5555555555555555));
302  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, betole((uint64_t)0xa0a0a0a0a0a0a0a0));
303  EXPECT_EQ(0x0123cdef, betole((uint32_t)0xefcd2301));
304  EXPECT_EQ(0xfedc3210, betole((uint32_t)0x1032dcfe));
305  EXPECT_EQ(0x0b1c41b1, betole((uint32_t)0xb1411c0b));
306  EXPECT_EQ(0x0000ffff, betole((uint32_t)0xffff0000));
307  EXPECT_EQ(0x55555555, betole((uint32_t)0x55555555));
308  EXPECT_EQ(0xa0a0a0a0, betole((uint32_t)0xa0a0a0a0));
309  EXPECT_EQ(0x01ef, betole((uint16_t)0xef01));
310  EXPECT_EQ(0xfe10, betole((uint16_t)0x10fe));
311  EXPECT_EQ(0x0bb1, betole((uint16_t)0xb10b));
312  EXPECT_EQ(0x00ff, betole((uint16_t)0xff00));
313  EXPECT_EQ(0x5555, betole((uint16_t)0x5555));
314  EXPECT_EQ(0xa0a0, betole((uint16_t)0xa0a0));
315 }
316 
317 TEST(ByteswapTest, letobe)
318 {
319  EXPECT_EQ(0x0123456789abcdef, letobe((uint64_t)0xefcdab8967452301));
320  EXPECT_EQ(0xfedcba9876543210, letobe((uint64_t)0x1032547698badcfe));
321  EXPECT_EQ(0x0b1cb071b77141b1, letobe((uint64_t)0xb14171b771b01c0b));
322  EXPECT_EQ(0x00000000ffffffff, letobe((uint64_t)0xffffffff00000000));
323  EXPECT_EQ(0x5555555555555555, letobe((uint64_t)0x5555555555555555));
324  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, letobe((uint64_t)0xa0a0a0a0a0a0a0a0));
325  EXPECT_EQ(0x0123cdef, letobe((uint32_t)0xefcd2301));
326  EXPECT_EQ(0xfedc3210, letobe((uint32_t)0x1032dcfe));
327  EXPECT_EQ(0x0b1c41b1, letobe((uint32_t)0xb1411c0b));
328  EXPECT_EQ(0x0000ffff, letobe((uint32_t)0xffff0000));
329  EXPECT_EQ(0x55555555, letobe((uint32_t)0x55555555));
330  EXPECT_EQ(0xa0a0a0a0, letobe((uint32_t)0xa0a0a0a0));
331  EXPECT_EQ(0x01ef, letobe((uint16_t)0xef01));
332  EXPECT_EQ(0xfe10, letobe((uint16_t)0x10fe));
333  EXPECT_EQ(0x0bb1, letobe((uint16_t)0xb10b));
334  EXPECT_EQ(0x00ff, letobe((uint16_t)0xff00));
335  EXPECT_EQ(0x5555, letobe((uint16_t)0x5555));
336  EXPECT_EQ(0xa0a0, letobe((uint16_t)0xa0a0));
337 }
TEST
TEST(ByteswapTest, swap_byte64)
Definition: byteswap.test.cc:33
letobe
T letobe(T value)
Definition: byteswap.hh:134
swap_byte32
uint32_t swap_byte32(uint32_t x)
Definition: byteswap.hh:78
swap_byte16
uint16_t swap_byte16(uint16_t x)
Definition: byteswap.hh:92
EXPECT_EQ
#define EXPECT_EQ(lhs, rhs)
A macro which verifies that lhs and rhs are equal to each other.
Definition: unittest.hh:110
htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:155
swap_byte64
uint64_t swap_byte64(uint64_t x)
Definition: byteswap.hh:59
swap_byte
vring_used_elem swap_byte(vring_used_elem v)
Definition: base.hh:68
betole
T betole(T value)
Definition: byteswap.hh:133
gtoh
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:162
byteswap.hh

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17