2 * Copyright (c) 2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <jeffpc/int.h>
24 #include <jeffpc/types.h>
36 static const struct run runs
[] = {
45 .in
= 0xffffffffffffffff,
49 .out64
= 0xffffffffffffffff,
52 .in
= 0x123456789abcdef0,
56 .out64
= 0xf0debc9a78563412,
59 .in
= 0x8080808080808080,
63 .out64
= 0x8080808080808080,
67 #define CHECK(iter, size, fmt, in, exp) \
69 uint##size##_t got = bswap_##size(in); \
71 fprintf(stderr, "%d: expected: %#"fmt"\n", iter, exp); \
72 fprintf(stderr, "%d: got: %#"fmt"\n", iter, got); \
78 static void __test(int iter
, const struct run
*run
)
80 fprintf(stderr
, "%d: input: %#"PRIx64
"\n", iter
, run
->in
);
81 CHECK(iter
, 8, PRIx8
, run
->in
& 0xff, run
->out8
);
82 CHECK(iter
, 16, PRIx16
, run
->in
& 0xffff, run
->out16
);
83 CHECK(iter
, 32, PRIx32
, run
->in
& 0xffffffff, run
->out32
);
84 CHECK(iter
, 64, PRIx64
, run
->in
, run
->out64
);
85 fprintf(stderr
, "%d: ok.\n", iter
);
92 for (i
= 0; i
< ARRAY_LEN(runs
) ; i
++)