inline unary ops: fix sc_floor for non-sse4.1
[supercollider.git] / external_libraries / boost_endian / libs / integer / test / endian_test.cpp
blobdbd6e0e986ef26780680ebbb2c8325e1b6e5d196
1 // endian_test.cpp ---------------------------------------------------------//
3 // Copyright Beman Dawes 1999-2008
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // See library home page at http://www.boost.org/libs/endian
10 //----------------------------------------------------------------------------//
12 // This test probes for correct endianess, size, and value.
14 // See endian_operations_test for tests of operator correctness and interaction
15 // between operand types.
17 //----------------------------------------------------------------------------//
19 #include <boost/integer/endian.hpp>
20 #include <boost/cstdint.hpp>
21 #include <boost/progress.hpp>
23 #include <iostream>
24 #include <limits>
25 #include <climits>
26 #include <cstdlib> // for atoi(), exit()
27 #include <cstring> // for memcmp()
29 using namespace std; // Not the best programming practice, but I
30 using namespace boost; // want to verify this combination of using
31 using namespace boost::integer; // namespaces works. See endian_operations_test
32 // // for tests that don't do "using namespace".
34 #define VERIFY(predicate) verify( predicate, __LINE__ )
35 #define VERIFY_SIZE(actual, expected) verify_size( actual, expected, __LINE__ )
36 #define VERIFY_VALUE_AND_OPS(endian_t,expected_t,expected) verify_value_and_ops<endian_t, expected_t>( expected, __LINE__ )
37 #define VERIFY_BIG_REPRESENTATION(t) verify_representation<t>( true, __LINE__ )
38 #define VERIFY_LITTLE_REPRESENTATION(t) verify_representation<t>( false, __LINE__ )
39 #define VERIFY_NATIVE_REPRESENTATION(t) verify_native_representation<t>( __LINE__ )
41 namespace
43 int err_count;
45 void verify( bool x, int line )
47 if ( x ) return;
48 ++err_count;
49 cout << "Error: verify failed on line " << line << endl;
52 void verify_size( size_t actual, size_t expected, int line )
54 if ( actual == expected ) return;
55 ++err_count;
56 cout << "Error: verify size failed on line " << line << endl;
57 cout << " A structure with an expected sizeof() " << expected
58 << " had an actual sizeof() " << actual
59 << "\n This will cause common uses of <boost/endian.hpp> to fail\n";
62 template <class Endian, class Base>
63 void verify_value_and_ops( const Base & expected, int line )
65 Endian v( expected );
66 verify( v == expected, line );
68 Endian v2;
69 v2.operator=( expected );
70 verify( v2 == expected, line );
72 ++v; // verify integer_cover_operators being applied to this type -
73 // will fail to compile if no endian<> specialization is present
76 const char * big_rep = "\x12\x34\x56\x78\x9A\xBC\xDE\xF0";
77 const char * little_rep = "\xF0\xDE\xBC\x9A\x78\x56\x34\x12";
79 template <class Endian>
80 void verify_representation( bool is_big, int line )
82 int silence = 0;
83 Endian x ( static_cast<typename Endian::value_type>
84 (0x123456789abcdef0LL + silence) ); // will truncate
86 if ( is_big )
87 verify( memcmp( &x,
88 reinterpret_cast<const char*>(big_rep)+8-sizeof(Endian),
89 sizeof(Endian) ) == 0, line );
90 else
91 verify( memcmp( &x, little_rep, sizeof(Endian) ) == 0, line );
94 template <class Endian>
95 inline void verify_native_representation( int line )
97 # ifdef BOOST_BIG_ENDIAN
98 verify_representation<Endian>( true, line );
99 # else
100 verify_representation<Endian>( false, line );
101 # endif
104 // detect_endianness -----------------------------------------------------//
106 void detect_endianness()
108 union View
110 long long i;
111 unsigned char c[8];
114 View v = { 0x0102030405060708LL }; // initialize v.i
116 if ( memcmp( v.c, "\10\7\6\5\4\3\2\1", 8) == 0 )
118 cout << "This machine is little-endian.\n";
119 # ifdef BOOST_BIG_INTEGER_OPERATORS
120 cout << "yet boost/detail/endian.hpp defines BOOST_BIG_INTEGER_OPERATORS.\n"
121 "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
122 "Please report the fix to the Boost mailing list.\n";
123 exit(1);
124 # endif
126 else if ( memcmp( v.c, "\1\2\3\4\5\6\7\10", 8) == 0 )
128 cout << "This machine is big-endian.\n";
129 # ifdef BOOST_LITTLE_INTEGER_OPERATORS
130 cout << "yet boost/detail/endian.hpp defines BOOST__LITTLE_INTEGER_OPERATORS.\n"
131 "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
132 "Please report the fix to the Boost mailing list.\n";
133 exit(1);
134 # endif
136 else
138 cout << "This machine is neither strict big-endian nor strict little-endian\n"
139 "You must modify boost/endian.hpp for it to work correctly.\n";
140 exit(1);
142 cout << "That should not matter and is presented for your information only.\n";
143 } // detect_endianness
145 // check_size ------------------------------------------------------------//
147 void check_size()
149 VERIFY( numeric_limits<signed char>::digits == 7 );
150 VERIFY( numeric_limits<unsigned char>::digits == 8 );
152 VERIFY_SIZE( sizeof( big8_t ), 1 );
153 VERIFY_SIZE( sizeof( big16_t ), 2 );
154 VERIFY_SIZE( sizeof( big24_t ), 3 );
155 VERIFY_SIZE( sizeof( big32_t ), 4 );
156 VERIFY_SIZE( sizeof( big40_t ), 5 );
157 VERIFY_SIZE( sizeof( big48_t ), 6 );
158 VERIFY_SIZE( sizeof( big56_t ), 7 );
159 VERIFY_SIZE( sizeof( big64_t ), 8 );
161 VERIFY_SIZE( sizeof( ubig8_t ), 1 );
162 VERIFY_SIZE( sizeof( ubig16_t ), 2 );
163 VERIFY_SIZE( sizeof( ubig24_t ), 3 );
164 VERIFY_SIZE( sizeof( ubig32_t ), 4 );
165 VERIFY_SIZE( sizeof( ubig40_t ), 5 );
166 VERIFY_SIZE( sizeof( ubig48_t ), 6 );
167 VERIFY_SIZE( sizeof( ubig56_t ), 7 );
168 VERIFY_SIZE( sizeof( ubig64_t ), 8 );
170 VERIFY_SIZE( sizeof( little8_t ), 1 );
171 VERIFY_SIZE( sizeof( little16_t ), 2 );
172 VERIFY_SIZE( sizeof( little24_t ), 3 );
173 VERIFY_SIZE( sizeof( little32_t ), 4 );
174 VERIFY_SIZE( sizeof( little40_t ), 5 );
175 VERIFY_SIZE( sizeof( little48_t ), 6 );
176 VERIFY_SIZE( sizeof( little56_t ), 7 );
177 VERIFY_SIZE( sizeof( little64_t ), 8 );
179 VERIFY_SIZE( sizeof( ulittle8_t ), 1 );
180 VERIFY_SIZE( sizeof( ulittle16_t ), 2 );
181 VERIFY_SIZE( sizeof( ulittle24_t ), 3 );
182 VERIFY_SIZE( sizeof( ulittle32_t ), 4 );
183 VERIFY_SIZE( sizeof( ulittle40_t ), 5 );
184 VERIFY_SIZE( sizeof( ulittle48_t ), 6 );
185 VERIFY_SIZE( sizeof( ulittle56_t ), 7 );
186 VERIFY_SIZE( sizeof( ulittle64_t ), 8 );
188 VERIFY_SIZE( sizeof( native8_t ), 1 );
189 VERIFY_SIZE( sizeof( native16_t ), 2 );
190 VERIFY_SIZE( sizeof( native24_t ), 3 );
191 VERIFY_SIZE( sizeof( native32_t ), 4 );
192 VERIFY_SIZE( sizeof( native40_t ), 5 );
193 VERIFY_SIZE( sizeof( native48_t ), 6 );
194 VERIFY_SIZE( sizeof( native56_t ), 7 );
195 VERIFY_SIZE( sizeof( native64_t ), 8 );
197 VERIFY_SIZE( sizeof( unative8_t ), 1 );
198 VERIFY_SIZE( sizeof( unative16_t ), 2 );
199 VERIFY_SIZE( sizeof( unative24_t ), 3 );
200 VERIFY_SIZE( sizeof( unative32_t ), 4 );
201 VERIFY_SIZE( sizeof( unative40_t ), 5 );
202 VERIFY_SIZE( sizeof( unative48_t ), 6 );
203 VERIFY_SIZE( sizeof( unative56_t ), 7 );
204 VERIFY_SIZE( sizeof( unative64_t ), 8 );
206 VERIFY_SIZE( sizeof( aligned_big16_t ), 2 );
207 VERIFY_SIZE( sizeof( aligned_big32_t ), 4 );
208 VERIFY_SIZE( sizeof( aligned_big64_t ), 8 );
210 VERIFY_SIZE( sizeof( aligned_ubig16_t ), 2 );
211 VERIFY_SIZE( sizeof( aligned_ubig32_t ), 4 );
212 VERIFY_SIZE( sizeof( aligned_ubig64_t ), 8 );
214 VERIFY_SIZE( sizeof( aligned_little16_t ), 2 );
215 VERIFY_SIZE( sizeof( aligned_little32_t ), 4 );
216 VERIFY_SIZE( sizeof( aligned_little64_t ), 8 );
218 VERIFY_SIZE( sizeof( aligned_ulittle16_t ), 2 );
219 VERIFY_SIZE( sizeof( aligned_ulittle32_t ), 4 );
220 VERIFY_SIZE( sizeof( aligned_ulittle64_t ), 8 );
221 } // check_size
223 // check_alignment -------------------------------------------------------//
225 void check_alignment()
227 // structs with offsets % 2 == 1 for type of size > 1 to ensure no alignment
228 // bytes added for any size > 1
230 struct big_struct
232 big8_t v0;
233 big16_t v1;
234 big24_t v3;
235 char v6;
236 big32_t v7;
237 big40_t v11;
238 char v16;
239 big48_t v17;
240 big56_t v23;
241 char v30;
242 big64_t v31;
245 struct ubig_struct
247 ubig8_t v0;
248 ubig16_t v1;
249 ubig24_t v3;
250 char v6;
251 ubig32_t v7;
252 ubig40_t v11;
253 char v16;
254 ubig48_t v17;
255 ubig56_t v23;
256 char v30;
257 ubig64_t v31;
260 struct little_struct
262 little8_t v0;
263 little16_t v1;
264 little24_t v3;
265 char v6;
266 little32_t v7;
267 little40_t v11;
268 char v16;
269 little48_t v17;
270 little56_t v23;
271 char v30;
272 little64_t v31;
275 struct ulittle_struct
277 ulittle8_t v0;
278 ulittle16_t v1;
279 ulittle24_t v3;
280 char v6;
281 ulittle32_t v7;
282 ulittle40_t v11;
283 char v16;
284 ulittle48_t v17;
285 ulittle56_t v23;
286 char v30;
287 ulittle64_t v31;
290 struct native_struct
292 native8_t v0;
293 native16_t v1;
294 native24_t v3;
295 char v6;
296 native32_t v7;
297 native40_t v11;
298 char v16;
299 native48_t v17;
300 native56_t v23;
301 char v30;
302 native64_t v31;
305 struct unative_struct
307 unative8_t v0;
308 unative16_t v1;
309 unative24_t v3;
310 char v6;
311 unative32_t v7;
312 unative40_t v11;
313 char v16;
314 unative48_t v17;
315 unative56_t v23;
316 char v30;
317 unative64_t v31;
320 int saved_err_count = err_count;
322 VERIFY_SIZE( sizeof(big_struct), 39 );
323 VERIFY_SIZE( sizeof(ubig_struct), 39 );
324 VERIFY_SIZE( sizeof(little_struct), 39 );
325 VERIFY_SIZE( sizeof(ulittle_struct), 39 );
326 VERIFY_SIZE( sizeof(native_struct), 39 );
327 VERIFY_SIZE( sizeof(unative_struct), 39 );
329 if ( saved_err_count == err_count )
331 cout <<
332 "Size and alignment for structures of endian types are as expected.\n";
334 } // check_alignment
336 // check_representation_and_range_and_ops --------------------------------//
338 void check_representation_and_range_and_ops()
341 VERIFY_BIG_REPRESENTATION( big8_t );
342 VERIFY_VALUE_AND_OPS( big8_t, int_least8_t, 0x7f );
343 VERIFY_VALUE_AND_OPS( big8_t, int_least8_t, -0x80 );
345 VERIFY_BIG_REPRESENTATION( big16_t );
346 VERIFY_VALUE_AND_OPS( big16_t, int_least16_t, 0x7fff );
347 VERIFY_VALUE_AND_OPS( big16_t, int_least16_t, -0x8000 );
349 VERIFY_BIG_REPRESENTATION( big24_t );
350 VERIFY_VALUE_AND_OPS( big24_t, int_least32_t, 0x7fffff );
351 VERIFY_VALUE_AND_OPS( big24_t, int_least32_t, -0x800000 );
353 VERIFY_BIG_REPRESENTATION( big32_t );
354 VERIFY_VALUE_AND_OPS( big32_t, int_least32_t, 0x7fffffff );
355 VERIFY_VALUE_AND_OPS( big32_t, int_least32_t, -0x7fffffff-1 );
357 VERIFY_BIG_REPRESENTATION( big40_t );
358 VERIFY_VALUE_AND_OPS( big40_t, int_least64_t, 0x7fffffffffLL );
359 VERIFY_VALUE_AND_OPS( big40_t, int_least64_t, -0x8000000000LL );
361 VERIFY_BIG_REPRESENTATION( big48_t );
362 VERIFY_VALUE_AND_OPS( big48_t, int_least64_t, 0x7fffffffffffLL );
363 VERIFY_VALUE_AND_OPS( big48_t, int_least64_t, -0x800000000000LL );
365 VERIFY_BIG_REPRESENTATION( big56_t );
366 VERIFY_VALUE_AND_OPS( big56_t, int_least64_t, 0x7fffffffffffffLL );
367 VERIFY_VALUE_AND_OPS( big56_t, int_least64_t, -0x80000000000000LL );
369 VERIFY_BIG_REPRESENTATION( big64_t );
370 VERIFY_VALUE_AND_OPS( big64_t, int_least64_t, 0x7fffffffffffffffLL );
371 VERIFY_VALUE_AND_OPS( big64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
373 VERIFY_BIG_REPRESENTATION( ubig8_t );
374 VERIFY_VALUE_AND_OPS( ubig8_t, uint_least8_t, 0xff );
376 VERIFY_BIG_REPRESENTATION( ubig16_t );
377 VERIFY_VALUE_AND_OPS( ubig16_t, uint_least16_t, 0xffff );
379 VERIFY_BIG_REPRESENTATION( ubig24_t );
380 VERIFY_VALUE_AND_OPS( ubig24_t, uint_least32_t, 0xffffff );
382 VERIFY_BIG_REPRESENTATION( ubig32_t );
383 VERIFY_VALUE_AND_OPS( ubig32_t, uint_least32_t, 0xffffffff );
385 VERIFY_BIG_REPRESENTATION( ubig40_t );
386 VERIFY_VALUE_AND_OPS( ubig40_t, uint_least64_t, 0xffffffffffLL );
388 VERIFY_BIG_REPRESENTATION( ubig48_t );
389 VERIFY_VALUE_AND_OPS( ubig48_t, uint_least64_t, 0xffffffffffffLL );
391 VERIFY_BIG_REPRESENTATION( ubig56_t );
392 VERIFY_VALUE_AND_OPS( ubig56_t, uint_least64_t, 0xffffffffffffffLL );
394 VERIFY_BIG_REPRESENTATION( ubig64_t );
395 VERIFY_VALUE_AND_OPS( ubig64_t, uint_least64_t, 0xffffffffffffffffLL );
397 VERIFY_LITTLE_REPRESENTATION( little8_t );
398 VERIFY_VALUE_AND_OPS( little8_t, int_least8_t, 0x7f );
399 VERIFY_VALUE_AND_OPS( little8_t, int_least8_t, -0x80 );
401 VERIFY_LITTLE_REPRESENTATION( little16_t );
402 VERIFY_VALUE_AND_OPS( little16_t, int_least16_t, 0x7fff );
403 VERIFY_VALUE_AND_OPS( little16_t, int_least16_t, -0x8000 );
405 VERIFY_LITTLE_REPRESENTATION( little24_t );
406 VERIFY_VALUE_AND_OPS( little24_t, int_least32_t, 0x7fffff );
407 VERIFY_VALUE_AND_OPS( little24_t, int_least32_t, -0x800000 );
409 VERIFY_LITTLE_REPRESENTATION( little32_t );
410 VERIFY_VALUE_AND_OPS( little32_t, int_least32_t, 0x7fffffff );
411 VERIFY_VALUE_AND_OPS( little32_t, int_least32_t, -0x7fffffff-1 );
413 VERIFY_LITTLE_REPRESENTATION( little40_t );
414 VERIFY_VALUE_AND_OPS( little40_t, int_least64_t, 0x7fffffffffLL );
415 VERIFY_VALUE_AND_OPS( little40_t, int_least64_t, -0x8000000000LL );
417 VERIFY_LITTLE_REPRESENTATION( little48_t );
418 VERIFY_VALUE_AND_OPS( little48_t, int_least64_t, 0x7fffffffffffLL );
419 VERIFY_VALUE_AND_OPS( little48_t, int_least64_t, -0x800000000000LL );
421 VERIFY_LITTLE_REPRESENTATION( little56_t );
422 VERIFY_VALUE_AND_OPS( little56_t, int_least64_t, 0x7fffffffffffffLL );
423 VERIFY_VALUE_AND_OPS( little56_t, int_least64_t, -0x80000000000000LL );
425 VERIFY_LITTLE_REPRESENTATION( little64_t );
426 VERIFY_VALUE_AND_OPS( little64_t, int_least64_t, 0x7fffffffffffffffLL );
427 VERIFY_VALUE_AND_OPS( little64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
429 VERIFY_LITTLE_REPRESENTATION( ulittle8_t );
430 VERIFY_VALUE_AND_OPS( ulittle8_t, uint_least8_t, 0xff );
432 VERIFY_LITTLE_REPRESENTATION( ulittle16_t );
433 VERIFY_VALUE_AND_OPS( ulittle16_t, uint_least16_t, 0xffff );
435 VERIFY_LITTLE_REPRESENTATION( ulittle24_t );
436 VERIFY_VALUE_AND_OPS( ulittle24_t, uint_least32_t, 0xffffff );
438 VERIFY_LITTLE_REPRESENTATION( ulittle32_t );
439 VERIFY_VALUE_AND_OPS( ulittle32_t, uint_least32_t, 0xffffffff );
441 VERIFY_LITTLE_REPRESENTATION( ulittle40_t );
442 VERIFY_VALUE_AND_OPS( ulittle40_t, uint_least64_t, 0xffffffffffLL );
444 VERIFY_LITTLE_REPRESENTATION( ulittle48_t );
445 VERIFY_VALUE_AND_OPS( ulittle48_t, uint_least64_t, 0xffffffffffffLL );
447 VERIFY_LITTLE_REPRESENTATION( ulittle56_t );
448 VERIFY_VALUE_AND_OPS( ulittle56_t, uint_least64_t, 0xffffffffffffffLL );
450 VERIFY_LITTLE_REPRESENTATION( ulittle64_t );
451 VERIFY_VALUE_AND_OPS( ulittle64_t, uint_least64_t, 0xffffffffffffffffLL );
453 VERIFY_NATIVE_REPRESENTATION( native8_t );
454 VERIFY_VALUE_AND_OPS( native8_t, int_least8_t, 0x7f );
455 VERIFY_VALUE_AND_OPS( native8_t, int_least8_t, -0x80 );
457 VERIFY_NATIVE_REPRESENTATION( native16_t );
458 VERIFY_VALUE_AND_OPS( native16_t, int_least16_t, 0x7fff );
459 VERIFY_VALUE_AND_OPS( native16_t, int_least16_t, -0x8000 );
461 VERIFY_NATIVE_REPRESENTATION( native24_t );
462 VERIFY_VALUE_AND_OPS( native24_t, int_least32_t, 0x7fffff );
463 VERIFY_VALUE_AND_OPS( native24_t, int_least32_t, -0x800000 );
465 VERIFY_NATIVE_REPRESENTATION( native32_t );
466 VERIFY_VALUE_AND_OPS( native32_t, int_least32_t, 0x7fffffff );
467 VERIFY_VALUE_AND_OPS( native32_t, int_least32_t, -0x7fffffff-1 );
469 VERIFY_NATIVE_REPRESENTATION( native40_t );
470 VERIFY_VALUE_AND_OPS( native40_t, int_least64_t, 0x7fffffffffLL );
471 VERIFY_VALUE_AND_OPS( native40_t, int_least64_t, -0x8000000000LL );
473 VERIFY_NATIVE_REPRESENTATION( native48_t );
474 VERIFY_VALUE_AND_OPS( native48_t, int_least64_t, 0x7fffffffffffLL );
475 VERIFY_VALUE_AND_OPS( native48_t, int_least64_t, -0x800000000000LL );
477 VERIFY_NATIVE_REPRESENTATION( native56_t );
478 VERIFY_VALUE_AND_OPS( native56_t, int_least64_t, 0x7fffffffffffffLL );
479 VERIFY_VALUE_AND_OPS( native56_t, int_least64_t, -0x80000000000000LL );
481 VERIFY_NATIVE_REPRESENTATION( native64_t );
482 VERIFY_VALUE_AND_OPS( native64_t, int_least64_t, 0x7fffffffffffffffLL );
483 VERIFY_VALUE_AND_OPS( native64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
485 VERIFY_NATIVE_REPRESENTATION( unative8_t );
486 VERIFY_VALUE_AND_OPS( unative8_t, uint_least8_t, 0xff );
488 VERIFY_NATIVE_REPRESENTATION( unative16_t );
489 VERIFY_VALUE_AND_OPS( unative16_t, uint_least16_t, 0xffff );
491 VERIFY_NATIVE_REPRESENTATION( unative24_t );
492 VERIFY_VALUE_AND_OPS( unative24_t, uint_least32_t, 0xffffff );
494 VERIFY_NATIVE_REPRESENTATION( unative32_t );
495 VERIFY_VALUE_AND_OPS( unative32_t, uint_least32_t, 0xffffffff );
497 VERIFY_NATIVE_REPRESENTATION( unative40_t );
498 VERIFY_VALUE_AND_OPS( unative40_t, uint_least64_t, 0xffffffffffLL );
500 VERIFY_NATIVE_REPRESENTATION( unative48_t );
501 VERIFY_VALUE_AND_OPS( unative48_t, uint_least64_t, 0xffffffffffffLL );
503 VERIFY_NATIVE_REPRESENTATION( unative56_t );
504 VERIFY_VALUE_AND_OPS( unative56_t, uint_least64_t, 0xffffffffffffffLL );
506 VERIFY_NATIVE_REPRESENTATION( unative64_t );
507 VERIFY_VALUE_AND_OPS( unative64_t, uint_least64_t, 0xffffffffffffffffLL );
509 VERIFY_BIG_REPRESENTATION( aligned_big16_t );
510 VERIFY_VALUE_AND_OPS( aligned_big16_t, int_least16_t, 0x7fff );
511 VERIFY_VALUE_AND_OPS( aligned_big16_t, int_least16_t, -0x8000 );
513 VERIFY_BIG_REPRESENTATION( aligned_big32_t );
514 VERIFY_VALUE_AND_OPS( aligned_big32_t, int_least32_t, 0x7fffffff );
515 VERIFY_VALUE_AND_OPS( aligned_big32_t, int_least32_t, -0x7fffffff-1 );
517 VERIFY_BIG_REPRESENTATION( aligned_big64_t );
518 VERIFY_VALUE_AND_OPS( aligned_big64_t, int_least64_t, 0x7fffffffffffffffLL );
519 VERIFY_VALUE_AND_OPS( aligned_big64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
521 VERIFY_BIG_REPRESENTATION( aligned_ubig16_t );
522 VERIFY_VALUE_AND_OPS( aligned_ubig16_t, uint_least16_t, 0xffff );
524 VERIFY_BIG_REPRESENTATION( aligned_ubig32_t );
525 VERIFY_VALUE_AND_OPS( aligned_ubig32_t, uint_least32_t, 0xffffffff );
527 VERIFY_BIG_REPRESENTATION( aligned_ubig64_t );
528 VERIFY_VALUE_AND_OPS( aligned_ubig64_t, uint_least64_t, 0xffffffffffffffffLL );
530 VERIFY_LITTLE_REPRESENTATION( aligned_little16_t );
531 VERIFY_VALUE_AND_OPS( aligned_little16_t, int_least16_t, 0x7fff );
532 VERIFY_VALUE_AND_OPS( aligned_little16_t, int_least16_t, -0x8000 );
534 VERIFY_LITTLE_REPRESENTATION( aligned_little32_t );
535 VERIFY_VALUE_AND_OPS( aligned_little32_t, int_least32_t, 0x7fffffff );
536 VERIFY_VALUE_AND_OPS( aligned_little32_t, int_least32_t, -0x7fffffff-1 );
538 VERIFY_LITTLE_REPRESENTATION( aligned_little64_t );
539 VERIFY_VALUE_AND_OPS( aligned_little64_t, int_least64_t, 0x7fffffffffffffffLL );
540 VERIFY_VALUE_AND_OPS( aligned_little64_t, int_least64_t, -0x7fffffffffffffffLL-1 );
542 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle16_t );
543 VERIFY_VALUE_AND_OPS( aligned_ulittle16_t, uint_least16_t, 0xffff );
545 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle32_t );
546 VERIFY_VALUE_AND_OPS( aligned_ulittle32_t, uint_least32_t, 0xffffffff );
548 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle64_t );
549 VERIFY_VALUE_AND_OPS( aligned_ulittle64_t, uint_least64_t, 0xffffffffffffffffLL );
551 } // check_representation_and_range
553 long iterations = 10000000;
555 template< class Endian >
556 Endian timing_test( const char * s)
558 cout << s << " timing test, " << iterations << " iterations: ";
559 progress_timer t;
561 Endian v = 1;
562 for ( long i = 0; i < iterations; ++i )
564 v += 1;
565 v *= 3;
566 ++v;
567 v *= i;
568 if ( i == 0 ) VERIFY_VALUE_AND_OPS( Endian, typename Endian::value_type, 21 );
570 return v;
573 } // unnamed namespace
575 int main( int argc, char * argv[] )
577 cout << "Usage: "
578 << argv[0] << " [#],\n where # specifies iteration count\n"
579 " default iteration count is 1000000" << endl;
581 if ( argc > 1 )
582 iterations = atol( argv[1] );
583 if ( iterations < 1 ) iterations = 1;
585 detect_endianness();
586 check_size();
587 check_alignment();
588 check_representation_and_range_and_ops();
590 //timing_test<big32_t> ( "big32_t" );
591 //timing_test<aligned_big32_t>( "aligned_big32_t" );
592 //timing_test<little32_t> ( "little32_t" );
593 //timing_test<aligned_little32_t>( "aligned_little32_t" );
595 cout << "\n" << err_count << " errors detected\nTest "
596 << (err_count==0 ? "passed\n\n" : "failed\n\n");
598 return err_count ? 1 : 0;
599 } // main