gem5  v22.0.0.2
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 using namespace gem5;
34 
35 TEST(ByteswapTest, swap_byte64)
36 {
37  EXPECT_EQ(0x0123456789abcdef, swap_byte64(0xefcdab8967452301));
38  EXPECT_EQ(0xfedcba9876543210, swap_byte64(0x1032547698badcfe));
39  EXPECT_EQ(0x0b1cb071b77141b1, swap_byte64(0xb14171b771b01c0b));
40  EXPECT_EQ(0x00000000ffffffff, swap_byte64(0xffffffff00000000));
41  EXPECT_EQ(0x5555555555555555, swap_byte64(0x5555555555555555));
42  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, swap_byte64(0xa0a0a0a0a0a0a0a0));
43 }
44 
45 TEST(ByteswapTest, swap_byte32)
46 {
47  EXPECT_EQ(0x0123cdef, swap_byte32(0xefcd2301));
48  EXPECT_EQ(0xfedc3210, swap_byte32(0x1032dcfe));
49  EXPECT_EQ(0x0b1c41b1, swap_byte32(0xb1411c0b));
50  EXPECT_EQ(0x0000ffff, swap_byte32(0xffff0000));
51  EXPECT_EQ(0x55555555, swap_byte32(0x55555555));
52  EXPECT_EQ(0xa0a0a0a0, swap_byte32(0xa0a0a0a0));
53 }
54 
55 TEST(ByteswapTest, swap_byte16)
56 {
57  EXPECT_EQ(0x01ef, swap_byte16(0xef01));
58  EXPECT_EQ(0xfe10, swap_byte16(0x10fe));
59  EXPECT_EQ(0x0bb1, swap_byte16(0xb10b));
60  EXPECT_EQ(0x00ff, swap_byte16(0xff00));
61  EXPECT_EQ(0x5555, swap_byte16(0x5555));
62  EXPECT_EQ(0xa0a0, swap_byte16(0xa0a0));
63 }
64 
65 TEST(ByteswapTest, swap_byte)
66 {
67  EXPECT_EQ(0x0123456789abcdef, swap_byte((uint64_t)0xefcdab8967452301));
68  EXPECT_EQ(0xfedcba9876543210, swap_byte((uint64_t)0x1032547698badcfe));
69  EXPECT_EQ(0x0b1cb071b77141b1, swap_byte((uint64_t)0xb14171b771b01c0b));
70  EXPECT_EQ(0x00000000ffffffff, swap_byte((uint64_t)0xffffffff00000000));
71  EXPECT_EQ(0x5555555555555555, swap_byte((uint64_t)0x5555555555555555));
72  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, swap_byte((uint64_t)0xa0a0a0a0a0a0a0a0));
73  EXPECT_EQ(0x0123cdef, swap_byte((uint32_t)0xefcd2301));
74  EXPECT_EQ(0xfedc3210, swap_byte((uint32_t)0x1032dcfe));
75  EXPECT_EQ(0x0b1c41b1, swap_byte((uint32_t)0xb1411c0b));
76  EXPECT_EQ(0x0000ffff, swap_byte((uint32_t)0xffff0000));
77  EXPECT_EQ(0x55555555, swap_byte((uint32_t)0x55555555));
78  EXPECT_EQ(0xa0a0a0a0, swap_byte((uint32_t)0xa0a0a0a0));
79  EXPECT_EQ(0x01ef, swap_byte((uint16_t)0xef01));
80  EXPECT_EQ(0xfe10, swap_byte((uint16_t)0x10fe));
81  EXPECT_EQ(0x0bb1, swap_byte((uint16_t)0xb10b));
82  EXPECT_EQ(0x00ff, swap_byte((uint16_t)0xff00));
83  EXPECT_EQ(0x5555, swap_byte((uint16_t)0x5555));
84  EXPECT_EQ(0xa0a0, swap_byte((uint16_t)0xa0a0));
85 }
86 
87 TEST(ByteswapTest, htog)
88 {
89 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
90  EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301,
91  ByteOrder::big));
92  EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe,
93  ByteOrder::big));
94  EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b,
95  ByteOrder::big));
96  EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000,
97  ByteOrder::big));
98  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
99  ByteOrder::big));
100  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
101  ByteOrder::big));
102  EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::big));
103  EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::big));
104  EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::big));
105  EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::big));
106  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big));
107  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
108  EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::big));
109  EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::big));
110  EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::big));
111  EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::big));
112  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big));
113  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big));
114  EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301,
115  ByteOrder::little));
116  EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe,
117  ByteOrder::little));
118  EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b,
119  ByteOrder::little));
120  EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000,
121  ByteOrder::little));
122  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
123  ByteOrder::little));
124  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
125  ByteOrder::little));
126  EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::little));
127  EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::little));
128  EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::little));
129  EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::little));
130  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little));
131  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
132  EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::little));
133  EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::little));
134  EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::little));
135  EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::little));
136  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little));
137  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little));
138 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
139  EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301,
140  ByteOrder::big));
141  EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe,
142  ByteOrder::big));
143  EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b,
144  ByteOrder::big));
145  EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000,
146  ByteOrder::big));
147  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
148  ByteOrder::big));
149  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
150  ByteOrder::big));
151  EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::big));
152  EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::big));
153  EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::big));
154  EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::big));
155  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big));
156  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
157  EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::big));
158  EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::big));
159  EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::big));
160  EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::big));
161  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big));
162  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big));
163  EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301,
164  ByteOrder::little));
165  EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe,
166  ByteOrder::little));
167  EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b,
168  ByteOrder::little));
169  EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000,
170  ByteOrder::little));
171  EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555,
172  ByteOrder::little));
173  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0,
174  ByteOrder::little));
175  EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::little));
176  EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::little));
177  EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::little));
178  EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::little));
179  EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little));
180  EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
181  EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::little));
182  EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::little));
183  EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::little));
184  EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::little));
185  EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little));
186  EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little));
187 #else
188  #error Invalid Endianess
189 #endif
190 }
191 
192 TEST(ByteswapTest, gtoh)
193 {
194 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
195  EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301,
196  ByteOrder::big));
197  EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe,
198  ByteOrder::big));
199  EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b,
200  ByteOrder::big));
201  EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000,
202  ByteOrder::big));
203  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
204  ByteOrder::big));
205  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
206  ByteOrder::big));
207  EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::big));
208  EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
209  EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
210  EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::big));
211  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big));
212  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
213  EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::big));
214  EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::big));
215  EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::big));
216  EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::big));
217  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big));
218  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big));
219  EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301,
220  ByteOrder::little));
221  EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe,
222  ByteOrder::little));
223  EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b,
224  ByteOrder::little));
225  EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000,
226  ByteOrder::little));
227  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
228  ByteOrder::little));
229  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
230  ByteOrder::little));
231  EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::little));
232  EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
233  EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
234  EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::little));
235  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little));
236  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
237  EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::little));
238  EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::little));
239  EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::little));
240  EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::little));
241  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little));
242  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little));
243 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
244  EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301,
245  ByteOrder::big));
246  EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe,
247  ByteOrder::big));
248  EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b,
249  ByteOrder::big));
250  EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000,
251  ByteOrder::big));
252  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
253  ByteOrder::big));
254  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
255  ByteOrder::big));
256  EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::big));
257  EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
258  EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
259  EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::big));
260  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big));
261  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
262  EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::big));
263  EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::big));
264  EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::big));
265  EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::big));
266  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big));
267  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big));
268  EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301,
269  ByteOrder::little));
270  EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe,
271  ByteOrder::little));
272  EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b,
273  ByteOrder::little));
274  EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000,
275  ByteOrder::little));
276  EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555,
277  ByteOrder::little));
278  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
279  ByteOrder::little));
280  EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::little));
281  EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
282  EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
283  EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::little));
284  EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little));
285  EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
286  EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::little));
287  EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::little));
288  EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::little));
289  EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::little));
290  EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little));
291  EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little));
292 #else
293  #error Invalid Endianess
294 #endif
295 }
296 
297 TEST(ByteswapTest, betole)
298 {
299  EXPECT_EQ(0x0123456789abcdef, betole((uint64_t)0xefcdab8967452301));
300  EXPECT_EQ(0xfedcba9876543210, betole((uint64_t)0x1032547698badcfe));
301  EXPECT_EQ(0x0b1cb071b77141b1, betole((uint64_t)0xb14171b771b01c0b));
302  EXPECT_EQ(0x00000000ffffffff, betole((uint64_t)0xffffffff00000000));
303  EXPECT_EQ(0x5555555555555555, betole((uint64_t)0x5555555555555555));
304  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, betole((uint64_t)0xa0a0a0a0a0a0a0a0));
305  EXPECT_EQ(0x0123cdef, betole((uint32_t)0xefcd2301));
306  EXPECT_EQ(0xfedc3210, betole((uint32_t)0x1032dcfe));
307  EXPECT_EQ(0x0b1c41b1, betole((uint32_t)0xb1411c0b));
308  EXPECT_EQ(0x0000ffff, betole((uint32_t)0xffff0000));
309  EXPECT_EQ(0x55555555, betole((uint32_t)0x55555555));
310  EXPECT_EQ(0xa0a0a0a0, betole((uint32_t)0xa0a0a0a0));
311  EXPECT_EQ(0x01ef, betole((uint16_t)0xef01));
312  EXPECT_EQ(0xfe10, betole((uint16_t)0x10fe));
313  EXPECT_EQ(0x0bb1, betole((uint16_t)0xb10b));
314  EXPECT_EQ(0x00ff, betole((uint16_t)0xff00));
315  EXPECT_EQ(0x5555, betole((uint16_t)0x5555));
316  EXPECT_EQ(0xa0a0, betole((uint16_t)0xa0a0));
317 }
318 
319 TEST(ByteswapTest, letobe)
320 {
321  EXPECT_EQ(0x0123456789abcdef, letobe((uint64_t)0xefcdab8967452301));
322  EXPECT_EQ(0xfedcba9876543210, letobe((uint64_t)0x1032547698badcfe));
323  EXPECT_EQ(0x0b1cb071b77141b1, letobe((uint64_t)0xb14171b771b01c0b));
324  EXPECT_EQ(0x00000000ffffffff, letobe((uint64_t)0xffffffff00000000));
325  EXPECT_EQ(0x5555555555555555, letobe((uint64_t)0x5555555555555555));
326  EXPECT_EQ(0xa0a0a0a0a0a0a0a0, letobe((uint64_t)0xa0a0a0a0a0a0a0a0));
327  EXPECT_EQ(0x0123cdef, letobe((uint32_t)0xefcd2301));
328  EXPECT_EQ(0xfedc3210, letobe((uint32_t)0x1032dcfe));
329  EXPECT_EQ(0x0b1c41b1, letobe((uint32_t)0xb1411c0b));
330  EXPECT_EQ(0x0000ffff, letobe((uint32_t)0xffff0000));
331  EXPECT_EQ(0x55555555, letobe((uint32_t)0x55555555));
332  EXPECT_EQ(0xa0a0a0a0, letobe((uint32_t)0xa0a0a0a0));
333  EXPECT_EQ(0x01ef, letobe((uint16_t)0xef01));
334  EXPECT_EQ(0xfe10, letobe((uint16_t)0x10fe));
335  EXPECT_EQ(0x0bb1, letobe((uint16_t)0xb10b));
336  EXPECT_EQ(0x00ff, letobe((uint16_t)0xff00));
337  EXPECT_EQ(0x5555, letobe((uint16_t)0x5555));
338  EXPECT_EQ(0xa0a0, letobe((uint16_t)0xa0a0));
339 }
gem5::swap_byte16
uint16_t swap_byte16(uint16_t x)
Definition: byteswap.hh:101
TEST
TEST(ByteswapTest, swap_byte64)
Definition: byteswap.test.cc:35
gem5::swap_byte64
uint64_t swap_byte64(uint64_t x)
Definition: byteswap.hh:68
gem5::gtoh
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:194
gem5::htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:187
gem5::swap_byte32
uint32_t swap_byte32(uint32_t x)
Definition: byteswap.hh:87
gem5::betole
T betole(T value)
Definition: byteswap.hh:165
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::swap_byte
std::enable_if_t< std::is_same_v< T, vring_used_elem >, T > swap_byte(T v)
Definition: base.hh:76
gem5::letobe
T letobe(T value)
Definition: byteswap.hh:166
byteswap.hh

Generated on Thu Jul 28 2022 13:32:36 for gem5 by doxygen 1.8.17