Debian Codegraph @

regressions/ck_pr/validate/ck_pr_faa.c

raw
1 /*
2 * Copyright 2009 Samy Al Bahra.
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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <inttypes.h>
28 #include <stdbool.h>
29 #include <stdio.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33
34 #include <ck_pr.h>
35
36 #include "../../common.h"
37 #ifndef R_REPEAT
38 #define R_REPEAT 200000
39 #endif
40
41 #define CK_PR_FAA_T(w, v, d) \
42 { \
43 uint##w##_t r, t = v; \
44 r = ck_pr_faa_##w(&t, d); \
45 if ((t != (uint##w##_t)(v + d)) || (r != v)) { \
46 printf("FAIL ["); \
47 printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w \
48 " (%" PRIu##w ")]\n", \
49 (uint##w##_t)v, d, t, r); \
50 exit(EXIT_FAILURE); \
51 } \
52 }
53
54 #define CK_PR_FAA_B(w) \
55 { \
56 unsigned int __ck_i = 0; \
57 printf("ck_pr_faa_" #w ": "); \
58 if (w < 10) \
59 printf(" "); \
60 for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
61 uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
62 uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
63 CK_PR_FAA_T(w, a, b); \
64 } \
65 rg_width(w); \
66 printf(" SUCCESS\n"); \
67 }
68
69 #define CK_PR_FAA_W(m, w) \
70 { \
71 uint##m##_t t = -1, r = -1 & ~(uint##m##_t)(uint##w##_t)-1; \
72 ck_pr_faa_##w((uint##w##_t *)(void *)&t, 1); \
73 if (t != r) { \
74 printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
75 exit(EXIT_FAILURE); \
76 } \
77 t = 0, r = (uint##m##_t)(uint##w##_t)-1; \
78 ck_pr_faa_##w((uint##w##_t *)(void *)&t, -1); \
79 if (t != r) { \
80 printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
81 exit(EXIT_FAILURE); \
82 } \
83 }
84
85 static void
86 rg_width(int m)
87 {
88
89 /* Other architectures are bi-endian. */
90 #if !defined(__x86__) && !defined(__x86_64__)
91 return;
92 #endif
93
94 #ifdef CK_F_PR_FAA_64
95 if (m == 64) {
96 #if defined(CK_F_PR_FAA_32)
97 CK_PR_FAA_W(64, 32);
98 #endif
99 #if defined(CK_PR_FAA_16)
100 CK_PR_FAA_W(64, 16);
101 #endif
102 #if defined(CK_PR_FAA_8)
103 CK_PR_FAA_W(64, 8);
104 #endif
105 }
106 #endif /* CK_PR_FAA_64 */
107
108 #ifdef CK_F_PR_FAA_32
109 if (m == 32) {
110 #if defined(CK_F_PR_FAA_16)
111 CK_PR_FAA_W(32, 16);
112 #endif
113 #if defined(CK_PR_FAA_8)
114 CK_PR_FAA_W(32, 8);
115 #endif
116 }
117 #endif /* CK_PR_FAA_32 */
118
119 #if defined(CK_F_PR_FAA_16) && defined(CK_PR_FAA_8)
120 if (m == 16) {
121 CK_PR_FAA_W(16, 8);
122 }
123 #endif /* CK_PR_FAA_16 && CK_PR_FAA_8 */
124
125 return;
126 }
127
128 int
129 main(void)
130 {
131
132 common_srand((unsigned int)getpid());
133
134 #ifdef CK_F_PR_FAA_64
135 CK_PR_FAA_B(64);
136 #endif
137
138 #ifdef CK_F_PR_FAA_32
139 CK_PR_FAA_B(32);
140 #endif
141
142 #ifdef CK_F_PR_FAA_16
143 CK_PR_FAA_B(16);
144 #endif
145
146 #ifdef CK_F_PR_FAA_8
147 CK_PR_FAA_B(8);
148 #endif
149
150 return (0);
151 }
152