summaryrefslogtreecommitdiffstats
path: root/regressions/ck_pr/validate
diff options
context:
space:
mode:
Diffstat (limited to 'regressions/ck_pr/validate')
-rw-r--r--regressions/ck_pr/validate/Makefile84
-rw-r--r--regressions/ck_pr/validate/ck_pr_add.c151
-rw-r--r--regressions/ck_pr/validate/ck_pr_and.c147
-rw-r--r--regressions/ck_pr/validate/ck_pr_bin.c94
-rw-r--r--regressions/ck_pr/validate/ck_pr_btc.c96
-rw-r--r--regressions/ck_pr/validate/ck_pr_btr.c97
-rw-r--r--regressions/ck_pr/validate/ck_pr_bts.c97
-rw-r--r--regressions/ck_pr/validate/ck_pr_btx.c112
-rw-r--r--regressions/ck_pr/validate/ck_pr_cas.c158
-rw-r--r--regressions/ck_pr/validate/ck_pr_dec.c143
-rw-r--r--regressions/ck_pr/validate/ck_pr_faa.c152
-rw-r--r--regressions/ck_pr/validate/ck_pr_fas.c148
-rw-r--r--regressions/ck_pr/validate/ck_pr_fax.c121
-rw-r--r--regressions/ck_pr/validate/ck_pr_inc.c143
-rw-r--r--regressions/ck_pr/validate/ck_pr_load.c149
-rw-r--r--regressions/ck_pr/validate/ck_pr_n.c90
-rw-r--r--regressions/ck_pr/validate/ck_pr_or.c149
-rw-r--r--regressions/ck_pr/validate/ck_pr_store.c150
-rw-r--r--regressions/ck_pr/validate/ck_pr_sub.c151
-rw-r--r--regressions/ck_pr/validate/ck_pr_unary.c117
-rw-r--r--regressions/ck_pr/validate/ck_pr_xor.c147
21 files changed, 2696 insertions, 0 deletions
diff --git a/regressions/ck_pr/validate/Makefile b/regressions/ck_pr/validate/Makefile
new file mode 100644
index 0000000..9e4a82d
--- /dev/null
+++ b/regressions/ck_pr/validate/Makefile
@@ -0,0 +1,84 @@
+.PHONY: check clean distribution
+
+OBJECTS=ck_pr_cas ck_pr_faa ck_pr_inc ck_pr_dec ck_pr_bts \
+ ck_pr_btr ck_pr_btc ck_pr_load ck_pr_store \
+ ck_pr_and ck_pr_or ck_pr_xor ck_pr_add ck_pr_sub \
+ ck_pr_fas ck_pr_bin ck_pr_btx ck_pr_fax ck_pr_n \
+ ck_pr_unary
+
+all: $(OBJECTS)
+
+check: all
+ for d in $(OBJECTS) ; do \
+ echo $$d; \
+ ./$$d || exit 1; \
+ done;
+
+ck_pr_cas: ck_pr_cas.c
+ $(CC) $(CFLAGS) -o ck_pr_cas ck_pr_cas.c
+
+ck_pr_inc: ck_pr_inc.c
+ $(CC) $(CFLAGS) -o ck_pr_inc ck_pr_inc.c
+
+ck_pr_dec: ck_pr_dec.c
+ $(CC) $(CFLAGS) -o ck_pr_dec ck_pr_dec.c
+
+ck_pr_faa: ck_pr_faa.c
+ $(CC) $(CFLAGS) -o ck_pr_faa ck_pr_faa.c
+
+ck_pr_btc: ck_pr_btc.c
+ $(CC) $(CFLAGS) -o ck_pr_btc ck_pr_btc.c
+
+ck_pr_btr: ck_pr_btr.c
+ $(CC) $(CFLAGS) -o ck_pr_btr ck_pr_btr.c
+
+ck_pr_bts: ck_pr_bts.c
+ $(CC) $(CFLAGS) -o ck_pr_bts ck_pr_bts.c
+
+ck_pr_load: ck_pr_load.c
+ $(CC) $(CFLAGS) -o ck_pr_load ck_pr_load.c
+
+ck_pr_store: ck_pr_store.c
+ $(CC) $(CFLAGS) -o ck_pr_store ck_pr_store.c
+
+ck_pr_and: ck_pr_and.c
+ $(CC) $(CFLAGS) -o ck_pr_and ck_pr_and.c
+
+ck_pr_or: ck_pr_or.c
+ $(CC) $(CFLAGS) -o ck_pr_or ck_pr_or.c
+
+ck_pr_xor: ck_pr_xor.c
+ $(CC) $(CFLAGS) -o ck_pr_xor ck_pr_xor.c
+
+ck_pr_add: ck_pr_add.c
+ $(CC) $(CFLAGS) -o ck_pr_add ck_pr_add.c
+
+ck_pr_sub: ck_pr_sub.c
+ $(CC) $(CFLAGS) -o ck_pr_sub ck_pr_sub.c
+
+ck_pr_fas: ck_pr_fas.c
+ $(CC) $(CFLAGS) -o ck_pr_fas ck_pr_fas.c
+
+ck_tp: ck_tp.c
+ $(CC) $(CFLAGS) -o ck_tp ck_tp.c
+
+ck_pr_bin: ck_pr_bin.c
+ $(CC) $(CFLAGS) -o ck_pr_bin ck_pr_bin.c
+
+ck_pr_btx: ck_pr_btx.c
+ $(CC) $(CFLAGS) -o ck_pr_btx ck_pr_btx.c
+
+ck_pr_fax: ck_pr_fax.c
+ $(CC) $(CFLAGS) -o ck_pr_fax ck_pr_fax.c
+
+ck_pr_n: ck_pr_n.c
+ $(CC) $(CFLAGS) -o ck_pr_n ck_pr_n.c
+
+ck_pr_unary: ck_pr_unary.c
+ $(CC) $(CFLAGS) -o ck_pr_unary ck_pr_unary.c
+
+clean:
+ rm -rf *~ *.o $(OBJECTS) *.dSYM *.exe
+
+include ../../../build/regressions.build
+CFLAGS+=-D_GNU_SOURCE
diff --git a/regressions/ck_pr/validate/ck_pr_add.c b/regressions/ck_pr/validate/ck_pr_add.c
new file mode 100644
index 0000000..31f1893
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_add.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_ADD_T(w, v, d) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_add_##w(&t, d); \
+ if (t != (uint##w##_t)(v + d)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w "]\n",\
+ (uint##w##_t)v, d, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_ADD_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_add_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
+ uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
+ CK_PR_ADD_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_ADD_W(m, w) \
+ { \
+ uint##m##_t t = -1, r = -1 & ~(uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_add_##w((uint##w##_t *)(void *)&t, 1); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ t = 0, r = (uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_add_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_ADD_64
+ if (m == 64) {
+#if defined(CK_F_PR_ADD_32)
+ CK_PR_ADD_W(64, 32);
+#endif
+#if defined(CK_PR_ADD_16)
+ CK_PR_ADD_W(64, 16);
+#endif
+#if defined(CK_PR_ADD_8)
+ CK_PR_ADD_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_ADD_64 */
+
+#ifdef CK_F_PR_ADD_32
+ if (m == 32) {
+#if defined(CK_F_PR_ADD_16)
+ CK_PR_ADD_W(32, 16);
+#endif
+#if defined(CK_PR_ADD_8)
+ CK_PR_ADD_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_ADD_32 */
+
+#if defined(CK_F_PR_ADD_16) && defined(CK_PR_ADD_8)
+ if (m == 16) {
+ CK_PR_ADD_W(16, 8);
+ }
+#endif /* CK_PR_ADD_16 && CK_PR_ADD_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_ADD_64
+ CK_PR_ADD_B(64);
+#endif
+
+#ifdef CK_F_PR_ADD_32
+ CK_PR_ADD_B(32);
+#endif
+
+#ifdef CK_F_PR_ADD_16
+ CK_PR_ADD_B(16);
+#endif
+
+#ifdef CK_F_PR_ADD_8
+ CK_PR_ADD_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_and.c b/regressions/ck_pr/validate/ck_pr_and.c
new file mode 100644
index 0000000..4c569bb
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_and.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define BM(m, w) ((uint##m##_t)-1 << (w))
+
+#define CK_PR_AND_T(w, v, d) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_and_##w(&t, d); \
+ if (t != (uint##w##_t)(v & d)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w "]\n",\
+ (uint##w##_t)v, d, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_AND_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_and_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = (uint##w##_t)common_rand(); \
+ uint##w##_t b = (uint##w##_t)common_rand(); \
+ CK_PR_AND_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_AND_W(m, w) \
+ { \
+ uint##m##_t t = -1; \
+ ck_pr_and_##w((uint##w##_t *)(void *)&t, 0); \
+ if (t != BM(m, w)) { \
+ printf(" FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, BM(m, w)); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_AND_64
+ if (m == 64) {
+#if defined(CK_F_PR_AND_32)
+ CK_PR_AND_W(64, 32);
+#endif
+#if defined(CK_PR_AND_16)
+ CK_PR_AND_W(64, 16);
+#endif
+#if defined(CK_PR_AND_8)
+ CK_PR_AND_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_AND_64 */
+
+#ifdef CK_F_PR_AND_32
+ if (m == 32) {
+#if defined(CK_F_PR_AND_16)
+ CK_PR_AND_W(32, 16);
+#endif
+#if defined(CK_PR_AND_8)
+ CK_PR_AND_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_AND_32 */
+
+#if defined(CK_F_PR_AND_16) && defined(CK_PR_AND_8)
+ if (m == 16) {
+ CK_PR_AND_W(16, 8);
+ }
+#endif /* CK_PR_AND_16 && CK_PR_AND_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_AND_64
+ CK_PR_AND_B(64);
+#endif
+
+#ifdef CK_F_PR_AND_32
+ CK_PR_AND_B(32);
+#endif
+
+#ifdef CK_F_PR_AND_16
+ CK_PR_AND_B(16);
+#endif
+
+#ifdef CK_F_PR_AND_8
+ CK_PR_AND_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_bin.c b/regressions/ck_pr/validate/ck_pr_bin.c
new file mode 100644
index 0000000..31868f4
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_bin.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2011 David Joseph.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ck_pr.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../common.h"
+#define REPEAT 2000000
+
+#define TEST_BINARY(K, S, T, P, D) \
+ static void \
+ run_test_##K##_##S(void) \
+ { \
+ int i, r; \
+ T serial_result = 65535; \
+ T ck_result = 65535; \
+ \
+ puts("***TESTING ck_pr_" #K "_" #S "***"); \
+ common_srand((unsigned int)getpid()); \
+ for (i = 0; i < REPEAT; ++i) { \
+ r = common_rand(); \
+ serial_result = serial_result P r; \
+ ck_pr_##K##_##S(&ck_result, r); \
+ } \
+ \
+ printf("Value of operation " #K " on 2000000 " \
+ "random numbers\n\tusing " #P ": %" #D ",\n" \
+ "\tusing ck_pr_"#K"_"#S": %" #D "\n", \
+ serial_result, ck_result); \
+ (serial_result == ck_result) ? puts("SUCCESS.") \
+ : puts("FAILURE."); \
+ \
+ return; \
+ } \
+
+#define GENERATE_TEST(K, P) \
+ TEST_BINARY(K, int, int, P, d) \
+ TEST_BINARY(K, uint, unsigned int, P, u) \
+ static void \
+ run_test_##K(void) \
+ { \
+ run_test_##K##_int(); \
+ run_test_##K##_uint(); \
+ \
+ return; \
+ }
+
+GENERATE_TEST(add, +)
+GENERATE_TEST(sub, -)
+GENERATE_TEST(and, &)
+GENERATE_TEST(or, |)
+GENERATE_TEST(xor, ^)
+
+#undef GENERATE_TEST
+#undef TEST_BINARY
+
+int
+main(void)
+{
+ run_test_add();
+ run_test_sub();
+ run_test_and();
+ run_test_or();
+ run_test_xor();
+
+ return (0);
+}
+
+
diff --git a/regressions/ck_pr/validate/ck_pr_btc.c b/regressions/ck_pr/validate/ck_pr_btc.c
new file mode 100644
index 0000000..0edec98
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_btc.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+/*
+ * Bit selector.
+ */
+#define BM(v, b) (((v) >> (b)) & 1)
+
+#define CK_PR_BTC_T(w, v) \
+ { \
+ unsigned int j; \
+ uint##w##_t r = v; \
+ bool t; \
+ for (j = 0; j < (w); j++) { \
+ t = ck_pr_btc_##w(&r, j); \
+ if ((t && !BM(v, j)) || ((BM(v, j) + BM(r, j)) != 1)) { \
+ printf("FAIL [%" PRIx##w ":%u]\n", r, j); \
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ }
+
+#define CK_PR_BTC_B(w) \
+ { \
+ uint##w##_t o; \
+ unsigned int i; \
+ printf("ck_pr_btc_" #w ": "); \
+ for (i = 0; i < R_REPEAT; i++) { \
+ o = (uint##w##_t)common_rand(); \
+ CK_PR_BTC_T(w, o); \
+ } \
+ printf(" SUCCESS\n"); \
+ }
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_BTC_64
+ CK_PR_BTC_B(64);
+#endif
+
+#ifdef CK_F_PR_BTC_32
+ CK_PR_BTC_B(32);
+#endif
+
+#ifdef CK_F_PR_BTC_16
+ CK_PR_BTC_B(16);
+#endif
+
+#ifdef CK_F_PR_BTC_8
+ CK_PR_BTC_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_btr.c b/regressions/ck_pr/validate/ck_pr_btr.c
new file mode 100644
index 0000000..91abb30
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_btr.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+/*
+ * Bit selector.
+ */
+#define BM(v, b) (((v) >> (b)) & 1)
+
+#define CK_PR_BTR_T(w, v) \
+ { \
+ unsigned int j; \
+ uint##w##_t r = v, c = v; \
+ bool t; \
+ for (j = 0; j < (w); j++) { \
+ c &= (uint##w##_t)-1 ^ (1 << j); \
+ t = ck_pr_btr_##w(&r, j); \
+ if ((t && !BM(v, j)) || (r != c)) { \
+ printf("FAIL [%" PRIx##w ":%u != %" PRIx##w ":%u]\n", r, j, c, j); \
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ }
+
+#define CK_PR_BTR_B(w) \
+ { \
+ uint##w##_t o; \
+ unsigned int i; \
+ printf("ck_pr_btr_" #w ": "); \
+ for (i = 0; i < R_REPEAT; i++) { \
+ o = (uint##w##_t)common_rand(); \
+ CK_PR_BTR_T(w, o); \
+ } \
+ printf(" SUCCESS\n"); \
+ }
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_BTR_64
+ CK_PR_BTR_B(64);
+#endif
+
+#ifdef CK_F_PR_BTR_32
+ CK_PR_BTR_B(32);
+#endif
+
+#ifdef CK_F_PR_BTR_16
+ CK_PR_BTR_B(16);
+#endif
+
+#ifdef CK_F_PR_BTR_8
+ CK_PR_BTR_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_bts.c b/regressions/ck_pr/validate/ck_pr_bts.c
new file mode 100644
index 0000000..1e62165
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_bts.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+/*
+ * Bit selector.
+ */
+#define BM(v, b) (((v) >> (b)) & 1)
+
+#define CK_PR_BTS_T(w, v) \
+ { \
+ unsigned int j; \
+ uint##w##_t r = v, c = v; \
+ bool t; \
+ for (j = 0; j < (w); j++) { \
+ c |= (uint##w##_t)1 << j; \
+ t = ck_pr_bts_##w(&r, j); \
+ if ((t && !BM(v, j)) || (r != c)) { \
+ printf("FAIL [%" PRIx##w ":%u != %" PRIx##w ":%u]\n", r, j, c, j); \
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ }
+
+#define CK_PR_BTS_B(w) \
+ { \
+ uint##w##_t o; \
+ unsigned int i; \
+ printf("ck_pr_bts_" #w ": "); \
+ for (i = 0; i < R_REPEAT; i++) { \
+ o = (uint##w##_t)common_rand(); \
+ CK_PR_BTS_T(w, o); \
+ } \
+ printf(" SUCCESS\n"); \
+ }
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_BTS_64
+ CK_PR_BTS_B(64);
+#endif
+
+#ifdef CK_F_PR_BTS_32
+ CK_PR_BTS_B(32);
+#endif
+
+#ifdef CK_F_PR_BTS_16
+ CK_PR_BTS_B(16);
+#endif
+
+#ifdef CK_F_PR_BTS_8
+ CK_PR_BTS_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_btx.c b/regressions/ck_pr/validate/ck_pr_btx.c
new file mode 100644
index 0000000..2bb3964
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_btx.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2011 David Joseph.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <ck_pr.h>
+
+#include "../../common.h"
+#define REPEAT 2000000
+
+#define TEST_BTX(K, S, M, T, L, P, D, R) \
+ static bool \
+ test_##K##_##S(M *target, int offset) \
+ { \
+ T previous; \
+ const L change = R (0x01 << offset); \
+ \
+ previous = (T)*target; \
+ *target = previous P change; \
+ return ((previous >> offset) & 0x01); \
+ } \
+ static void \
+ run_test_##K##_##S(void) \
+ { \
+ int i, offset, m; \
+ bool serial_t, ck_pr_t; \
+ T x = 65535, y = 65535; \
+ \
+ common_srand((unsigned int)getpid()); \
+ m = sizeof(T) * 8; \
+ \
+ puts("***TESTING ck_pr_"#K"_"#S"***"); \
+ for (i = 0; i < REPEAT; ++i) { \
+ offset = common_rand() % m; \
+ serial_t = test_##K##_##S(&x, offset); \
+ ck_pr_t = ck_pr_##K##_##S(&y, offset); \
+ \
+ if (serial_t != ck_pr_t || x != y ) { \
+ printf("Serial(%"#D") and ck_pr(%"#D")" \
+ #K"_"#S " do not match.\n" \
+ "FAILURE.\n", \
+ serial_t, ck_pr_t); \
+ \
+ return; \
+ } \
+ } \
+ printf("\tserial_"#K"_"#S": %"#D"\n" \
+ "\tck_pr_"#K"_"#S": %"#D"\n" \
+ "SUCCESS.\n", \
+ x, y); \
+ \
+ return; \
+ }
+
+#define TEST_BTX_S(K, S, T, P, D, R) TEST_BTX(K, S, T, T, T, P, D, R)
+
+#define GENERATE_TEST(K, P, R) \
+ TEST_BTX_S(K, int, int, P, d, R) \
+ TEST_BTX_S(K, uint, unsigned int, P, u, R) \
+ static void \
+ run_test_##K(void) \
+ { \
+ run_test_##K##_int(); \
+ run_test_##K##_uint(); \
+ \
+ return; \
+ }
+
+GENERATE_TEST(btc, ^, 0+)
+GENERATE_TEST(btr, &, ~)
+GENERATE_TEST(bts, |, 0+)
+
+#undef GENERATE_TEST
+#undef TEST_BTX_S
+#undef TEST_BTX
+
+int
+main(void)
+{
+ run_test_btc();
+ run_test_btr();
+ run_test_bts();
+
+ return (0);
+}
+
+
diff --git a/regressions/ck_pr/validate/ck_pr_cas.c b/regressions/ck_pr/validate/ck_pr_cas.c
new file mode 100644
index 0000000..132d1e5
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_cas.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define W(w, x) (uint##w##_t)((x) & (uint##w##_t)~0)
+
+#define CK_PR_CAS_T(w, v, c, s) \
+ { \
+ uint##w##_t t = v; \
+ bool r; \
+ r = ck_pr_cas_##w(&t, c, s); \
+ if (((c == v) && (r == false)) || ((c != v) && (r == true)) || \
+ ((r == true) && (W(w, s) != t))) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w " -> %" PRIu##w ")" \
+ " -> %" PRIu##w "]\n", \
+ (uint##w##_t)(v), (uint##w##_t)(c), W(w, s), (uint##w##_t)(t)); \
+ } \
+ }
+
+#define CK_PR_CAS_B(w) \
+ { \
+ unsigned int __ck_i; \
+ printf("ck_pr_cas_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % (uint##w##_t)-1; \
+ CK_PR_CAS_T(w, a, a + 1, (a - 1)); \
+ CK_PR_CAS_T(w, a, a, (a - 1)); \
+ CK_PR_CAS_T(w, a, a + 1, a); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_CAS_W(m, w) \
+ { \
+ uint##m##_t t = -1, r = -1 & ~(uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_cas_##w((uint##w##_t *)(void *)&t, (uint##w##_t)t, 0); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", \
+ (uint##m##_t)t, (uint##m##_t)r); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_CAS_64
+ if (m == 64) {
+#if defined(CK_F_PR_CAS_32)
+ CK_PR_CAS_W(64, 32);
+#endif
+#if defined(CK_PR_CAS_16)
+ CK_PR_CAS_W(64, 16);
+#endif
+#if defined(CK_PR_CAS_8)
+ CK_PR_CAS_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_CAS_64 */
+
+#ifdef CK_F_PR_CAS_32
+ if (m == 32) {
+#if defined(CK_F_PR_CAS_16)
+ CK_PR_CAS_W(32, 16);
+#endif
+#if defined(CK_PR_CAS_8)
+ CK_PR_CAS_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_CAS_32 */
+
+#if defined(CK_F_PR_CAS_16) && defined(CK_PR_CAS_8)
+ if (m == 16) {
+ CK_PR_CAS_W(16, 8);
+ }
+#endif /* CK_PR_CAS_16 && CK_PR_CAS_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_CAS_64
+ CK_PR_CAS_B(64);
+#endif
+
+#ifdef CK_F_PR_CAS_32
+ CK_PR_CAS_B(32);
+#endif
+
+#ifdef CK_F_PR_CAS_16
+ CK_PR_CAS_B(16);
+#endif
+
+#ifdef CK_F_PR_CAS_8
+ CK_PR_CAS_B(8);
+#endif
+
+#ifdef CK_F_PR_CAS_64_VALUE
+ uint64_t a = 0xffffffffaaaaaaaa, b = 0x8888888800000000;
+
+ printf("%" PRIx64 " (%" PRIx64 ") -> ", b, a);
+ ck_pr_cas_64_value(&a, a, b, &b);
+ printf("%" PRIx64 " (%" PRIx64 ")\n", b, a);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_dec.c b/regressions/ck_pr/validate/ck_pr_dec.c
new file mode 100644
index 0000000..86ce088
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_dec.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_DEC_T(w, v) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_dec_##w(&t); \
+ if ((t != (uint##w##_t)(v - 1))) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " -> %" PRIu##w "]\n", (uint##w##_t)v, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_DEC_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_dec_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % ((uint##w##_t)-1); \
+ CK_PR_DEC_T(w, a); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_DEC_W(m, w) \
+ { \
+ uint##m##_t t = 0, r = (uint##w##_t)-1; \
+ ck_pr_dec_##w((uint##w##_t *)(void *)&t); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_DEC_64
+ if (m == 64) {
+#if defined(CK_F_PR_DEC_32)
+ CK_PR_DEC_W(64, 32);
+#endif
+#if defined(CK_PR_DEC_16)
+ CK_PR_DEC_W(64, 16);
+#endif
+#if defined(CK_PR_DEC_8)
+ CK_PR_DEC_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_DEC_64 */
+
+#ifdef CK_F_PR_DEC_32
+ if (m == 32) {
+#if defined(CK_F_PR_DEC_16)
+ CK_PR_DEC_W(32, 16);
+#endif
+#if defined(CK_PR_DEC_8)
+ CK_PR_DEC_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_DEC_32 */
+
+#if defined(CK_F_PR_DEC_16) && defined(CK_PR_DEC_8)
+ if (m == 16) {
+ CK_PR_DEC_W(16, 8);
+ }
+#endif /* CK_PR_DEC_16 && CK_PR_DEC_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_DEC_64
+ CK_PR_DEC_B(64);
+#endif
+
+#ifdef CK_F_PR_DEC_32
+ CK_PR_DEC_B(32);
+#endif
+
+#ifdef CK_F_PR_DEC_16
+ CK_PR_DEC_B(16);
+#endif
+
+#ifdef CK_F_PR_DEC_8
+ CK_PR_DEC_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_faa.c b/regressions/ck_pr/validate/ck_pr_faa.c
new file mode 100644
index 0000000..1d10bb9
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_faa.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_FAA_T(w, v, d) \
+ { \
+ uint##w##_t r, t = v; \
+ r = ck_pr_faa_##w(&t, d); \
+ if ((t != (uint##w##_t)(v + d)) || (r != v)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w \
+ " (%" PRIu##w ")]\n", \
+ (uint##w##_t)v, d, t, r); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_FAA_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_faa_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
+ uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
+ CK_PR_FAA_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_FAA_W(m, w) \
+ { \
+ uint##m##_t t = -1, r = -1 & ~(uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_faa_##w((uint##w##_t *)(void *)&t, 1); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ t = 0, r = (uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_faa_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_FAA_64
+ if (m == 64) {
+#if defined(CK_F_PR_FAA_32)
+ CK_PR_FAA_W(64, 32);
+#endif
+#if defined(CK_PR_FAA_16)
+ CK_PR_FAA_W(64, 16);
+#endif
+#if defined(CK_PR_FAA_8)
+ CK_PR_FAA_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_FAA_64 */
+
+#ifdef CK_F_PR_FAA_32
+ if (m == 32) {
+#if defined(CK_F_PR_FAA_16)
+ CK_PR_FAA_W(32, 16);
+#endif
+#if defined(CK_PR_FAA_8)
+ CK_PR_FAA_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_FAA_32 */
+
+#if defined(CK_F_PR_FAA_16) && defined(CK_PR_FAA_8)
+ if (m == 16) {
+ CK_PR_FAA_W(16, 8);
+ }
+#endif /* CK_PR_FAA_16 && CK_PR_FAA_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_FAA_64
+ CK_PR_FAA_B(64);
+#endif
+
+#ifdef CK_F_PR_FAA_32
+ CK_PR_FAA_B(32);
+#endif
+
+#ifdef CK_F_PR_FAA_16
+ CK_PR_FAA_B(16);
+#endif
+
+#ifdef CK_F_PR_FAA_8
+ CK_PR_FAA_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_fas.c b/regressions/ck_pr/validate/ck_pr_fas.c
new file mode 100644
index 0000000..00cef4e
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_fas.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define BM(m, w) ((uint##m##_t)(uint##w##_t)(-1))
+
+#define CK_PR_FAS_T(w, v, d) \
+ { \
+ uint##w##_t r, t = v; \
+ r = ck_pr_fas_##w(&t, d); \
+ if ((t != d) || (r != v)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w \
+ " (%" PRIu##w ")]\n", \
+ (uint##w##_t)v, d, t, r); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_FAS_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_fas_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand(); \
+ uint##w##_t b = common_rand(); \
+ CK_PR_FAS_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_FAS_W(m, w) \
+ { \
+ uint##m##_t t = 0; \
+ ck_pr_fas_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != BM(m, w)) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, BM(m, w)); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_FAS_64
+ if (m == 64) {
+#if defined(CK_F_PR_FAS_32)
+ CK_PR_FAS_W(64, 32);
+#endif
+#if defined(CK_PR_FAS_16)
+ CK_PR_FAS_W(64, 16);
+#endif
+#if defined(CK_PR_FAS_8)
+ CK_PR_FAS_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_FAS_64 */
+
+#ifdef CK_F_PR_FAS_32
+ if (m == 32) {
+#if defined(CK_F_PR_FAS_16)
+ CK_PR_FAS_W(32, 16);
+#endif
+#if defined(CK_PR_FAS_8)
+ CK_PR_FAS_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_FAS_32 */
+
+#if defined(CK_F_PR_FAS_16) && defined(CK_PR_FAS_8)
+ if (m == 16) {
+ CK_PR_FAS_W(16, 8);
+ }
+#endif /* CK_PR_FAS_16 && CK_PR_FAS_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_FAS_64
+ CK_PR_FAS_B(64);
+#endif
+
+#ifdef CK_F_PR_FAS_32
+ CK_PR_FAS_B(32);
+#endif
+
+#ifdef CK_F_PR_FAS_16
+ CK_PR_FAS_B(16);
+#endif
+
+#ifdef CK_F_PR_FAS_8
+ CK_PR_FAS_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_fax.c b/regressions/ck_pr/validate/ck_pr_fax.c
new file mode 100644
index 0000000..9d8c94f
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_fax.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2011 David Joseph.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ck_pr.h>
+
+#include "../../common.h"
+#define REPEAT 2000000
+
+#define TEST_FAX_FN(S, T, M) \
+ static T \
+ test_faa_##S(M *target, T delta) \
+ { \
+ T previous = (T)*target; \
+ *target = (T)*target + delta; \
+ \
+ return (previous); \
+ } \
+ static T \
+ test_fas_##S(M *target, T update) \
+ { \
+ T previous = *target; \
+ *target = update; \
+ \
+ return (previous); \
+ }
+
+#define TEST_FAX_FN_S(S, T) TEST_FAX_FN(S, T, T)
+
+TEST_FAX_FN_S(int, int)
+TEST_FAX_FN_S(uint, unsigned int)
+
+#undef TEST_FAX_FN_S
+#undef TEST_FAX_FN
+
+#define TEST_FAX(K, S, T, D) \
+ static void \
+ run_test_##K##_##S(void) \
+ { \
+ int i, r; \
+ T x = 0, y = 0, x_b, y_b; \
+ \
+ puts("***TESTING ck_pr_"#K"_"#S"***"); \
+ common_srand((unsigned int)getpid()); \
+ for (i = 0; i < REPEAT; ++i) { \
+ r = common_rand(); \
+ x_b = test_##K##_##S(&x, r); \
+ y_b = ck_pr_##K##_##S(&y, r); \
+ \
+ if (x_b != y_b) { \
+ printf("Serial fetch does not match ck_pr fetch.\n" \
+ "\tSerial: %"#D"\n" \
+ "\tck_pr: %"#D"\n", \
+ x_b, y_b); \
+ \
+ return; \
+ } \
+ } \
+ \
+ printf("Final result:\n" \
+ "\tSerial: %"#D"\n" \
+ "\tck_pr: %"#D"\n", \
+ x, y); \
+ (x == y) ? puts("SUCCESS.") \
+ : puts("FAILURE."); \
+ \
+ return; \
+ } \
+
+
+#define GENERATE_TEST(K) \
+ TEST_FAX(K, int, int, d) \
+ TEST_FAX(K, uint, unsigned int, u) \
+ static void \
+ run_test_##K(void) \
+ { \
+ run_test_##K##_int(); \
+ run_test_##K##_uint(); \
+ }
+
+GENERATE_TEST(faa)
+GENERATE_TEST(fas)
+
+#undef GENERATE_TEST
+#undef TEST_FAX
+
+int
+main(void)
+{
+ run_test_faa();
+ run_test_fas();
+
+ return (0);
+}
+
+
diff --git a/regressions/ck_pr/validate/ck_pr_inc.c b/regressions/ck_pr/validate/ck_pr_inc.c
new file mode 100644
index 0000000..e8524a5
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_inc.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_INC_T(w, v) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_inc_##w(&t); \
+ if ((t != (uint##w##_t)(v + 1))) { \
+ printf("FAIL [%" PRIu##w " -> %" PRIu##w "]\n", \
+ (uint##w##_t)v, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_INC_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_inc_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % ((uint##w##_t)-1); \
+ CK_PR_INC_T(w, a); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_INC_W(m, w) \
+ { \
+ uint##m##_t t = -1, r = -1 & ~(uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_inc_##w((uint##w##_t *)(void *)&t); \
+ if (t != r) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_INC_64
+ if (m == 64) {
+#if defined(CK_F_PR_INC_32)
+ CK_PR_INC_W(64, 32);
+#endif
+#if defined(CK_PR_INC_16)
+ CK_PR_INC_W(64, 16);
+#endif
+#if defined(CK_PR_INC_8)
+ CK_PR_INC_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_INC_64 */
+
+#ifdef CK_F_PR_INC_32
+ if (m == 32) {
+#if defined(CK_F_PR_INC_16)
+ CK_PR_INC_W(32, 16);
+#endif
+#if defined(CK_PR_INC_8)
+ CK_PR_INC_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_INC_32 */
+
+#if defined(CK_F_PR_INC_16) && defined(CK_PR_INC_8)
+ if (m == 16) {
+ CK_PR_INC_W(16, 8);
+ }
+#endif /* CK_PR_INC_16 && CK_PR_INC_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_INC_64
+ CK_PR_INC_B(64);
+#endif
+
+#ifdef CK_F_PR_INC_32
+ CK_PR_INC_B(32);
+#endif
+
+#ifdef CK_F_PR_INC_16
+ CK_PR_INC_B(16);
+#endif
+
+#ifdef CK_F_PR_INC_8
+ CK_PR_INC_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_load.c b/regressions/ck_pr/validate/ck_pr_load.c
new file mode 100644
index 0000000..a15acd0
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_load.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_LOAD_B(w) \
+ { \
+ uint##w##_t t = (uint##w##_t)-1, a = 0; \
+ unsigned int i; \
+ printf("ck_pr_load_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ a = ck_pr_load_##w(&t); \
+ if (a != t) { \
+ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ for (i = 0; i < R_REPEAT; i++) { \
+ t = (uint##w##_t)common_rand(); \
+ a = ck_pr_load_##w(&t); \
+ if (a != t) { \
+ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_LOAD_W(m, w) \
+ { \
+ uint##m##_t f = 0; \
+ uint##w##_t j = (uint##w##_t)-1; \
+ f = ck_pr_load_##w(&j); \
+ if (f != j) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##w "]\n", f, j);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_LOAD_64
+ if (m == 64) {
+#if defined(CK_F_PR_LOAD_32)
+ CK_PR_LOAD_W(64, 32);
+#endif
+#if defined(CK_PR_LOAD_16)
+ CK_PR_LOAD_W(64, 16);
+#endif
+#if defined(CK_PR_LOAD_8)
+ CK_PR_LOAD_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_LOAD_64 */
+
+#ifdef CK_F_PR_LOAD_32
+ if (m == 32) {
+#if defined(CK_F_PR_LOAD_16)
+ CK_PR_LOAD_W(32, 16);
+#endif
+#if defined(CK_PR_LOAD_8)
+ CK_PR_LOAD_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_LOAD_32 */
+
+#if defined(CK_F_PR_LOAD_16) && defined(CK_PR_LOAD_8)
+ if (m == 16)
+ CK_PR_LOAD_W(16, 8);
+#endif /* CK_PR_LOAD_16 && CK_PR_LOAD_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_LOAD_64
+ CK_PR_LOAD_B(64);
+#endif
+
+#ifdef CK_F_PR_LOAD_32
+ CK_PR_LOAD_B(32);
+#endif
+
+#ifdef CK_F_PR_LOAD_16
+ CK_PR_LOAD_B(16);
+#endif
+
+#ifdef CK_F_PR_LOAD_8
+ CK_PR_LOAD_B(8);
+#endif
+
+#if 0
+ uint64_t a[2] = {0, 0}, b[2] = {0x1111111144444444, 0x2222222266666666};
+ printf("%" PRIx64 ":%" PRIx64 " -> ", a[0], a[1]);
+ ck_pr_load_64_2(&b, &a);
+ printf("%" PRIx64 ":%" PRIx64 "\n", a[0], a[1]);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_n.c b/regressions/ck_pr/validate/ck_pr_n.c
new file mode 100644
index 0000000..81e3639
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_n.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2011 David Joseph.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ck_pr.h>
+
+#include "../../common.h"
+#define REPEAT 2000000
+
+#define TEST_N(K, S, T, P, D) \
+ static void \
+ run_test_##K##_##S(void) \
+ { \
+ int i, r; \
+ T x = 0, y = 0; \
+ \
+ puts("***TESTING ck_pr_"#K"_"#S"***"); \
+ common_srand((unsigned int)getpid()); \
+ for (i = 0; i < REPEAT; ++i) { \
+ r = common_rand(); \
+ x += r; \
+ x = P x; \
+ y += r; \
+ ck_pr_##K##_##S(&y); \
+ } \
+ \
+ printf("Value of operation "#K" on 2000000 " \
+ "random numbers\n" \
+ "\tusing "#P": %"#D",\n" \
+ "\tusing ck_pr_"#K"_"#S": %"#D",\n", \
+ x, y); \
+ (x == y) ? puts("SUCCESS.") \
+ : puts("FAILURE."); \
+ \
+ return; \
+ }
+
+#define GENERATE_TEST(K, P) \
+ TEST_N(K, int, int, P, d) \
+ TEST_N(K, uint, unsigned int, P, u) \
+ static void \
+ run_test_##K(void) \
+ { \
+ run_test_##K##_int(); \
+ run_test_##K##_uint(); \
+ \
+ return; \
+ }
+
+GENERATE_TEST(not, ~)
+GENERATE_TEST(neg, -)
+
+#undef GENERATE_TEST
+#undef TEST_N
+
+int
+main(void)
+{
+ run_test_not();
+ run_test_neg();
+
+ return (0);
+}
+
+
diff --git a/regressions/ck_pr/validate/ck_pr_or.c b/regressions/ck_pr/validate/ck_pr_or.c
new file mode 100644
index 0000000..27580c3
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_or.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define BM(m, w) (uint##m##_t)(uint##w##_t)-1
+
+#define CK_PR_OR_T(w, v, d) \
+ { \
+ uint##w##_t t; \
+ ck_pr_or_##w(&t, 1ULL << (w - 1)); \
+ t = v; \
+ ck_pr_or_##w(&t, d); \
+ if (t != (uint##w##_t)(v | d)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w "]\n",\
+ (uint##w##_t)v, d, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_OR_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_or_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = (uint##w##_t)common_rand(); \
+ uint##w##_t b = (uint##w##_t)common_rand(); \
+ CK_PR_OR_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_OR_W(m, w) \
+ { \
+ uint##m##_t t = 0; \
+ ck_pr_or_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != BM(m, w)) { \
+ printf(" FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, BM(m, w)); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_OR_64
+ if (m == 64) {
+#if defined(CK_F_PR_OR_32)
+ CK_PR_OR_W(64, 32);
+#endif
+#if defined(CK_PR_OR_16)
+ CK_PR_OR_W(64, 16);
+#endif
+#if defined(CK_PR_OR_8)
+ CK_PR_OR_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_OR_64 */
+
+#ifdef CK_F_PR_OR_32
+ if (m == 32) {
+#if defined(CK_F_PR_OR_16)
+ CK_PR_OR_W(32, 16);
+#endif
+#if defined(CK_PR_OR_8)
+ CK_PR_OR_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_OR_32 */
+
+#if defined(CK_F_PR_OR_16) && defined(CK_PR_OR_8)
+ if (m == 16) {
+ CK_PR_OR_W(16, 8);
+ }
+#endif /* CK_PR_OR_16 && CK_PR_OR_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_OR_64
+ CK_PR_OR_B(64);
+#endif
+
+#ifdef CK_F_PR_OR_32
+ CK_PR_OR_B(32);
+#endif
+
+#ifdef CK_F_PR_OR_16
+ CK_PR_OR_B(16);
+#endif
+
+#ifdef CK_F_PR_OR_8
+ CK_PR_OR_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_store.c b/regressions/ck_pr/validate/ck_pr_store.c
new file mode 100644
index 0000000..e4b852b
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_store.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "../../common.h"
+#include <ck_pr.h>
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_STORE_B(w) \
+ { \
+ uint##w##_t t = (uint##w##_t)-1, a = 0, b; \
+ ck_pr_store_##w(&b, 1ULL << (w - 1)); \
+ unsigned int i; \
+ printf("ck_pr_store_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ ck_pr_store_##w(&a, t); \
+ if (a != t) { \
+ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ for (i = 0; i < R_REPEAT; i++) { \
+ t = (uint##w##_t)common_rand(); \
+ ck_pr_store_##w(&a, t); \
+ if (a != t) { \
+ printf("FAIL [%#" PRIx##w " != %#" PRIx##w "]\n", a, t);\
+ exit(EXIT_FAILURE); \
+ } \
+ } \
+ rg_width(w); \
+ printf("SUCCESS\n"); \
+ }
+
+#define CK_PR_STORE_W(m, w) \
+ { \
+ uint##m##_t f = 0; \
+ uint##w##_t j = (uint##w##_t)-1; \
+ ck_pr_store_##w((uint##w##_t *)(void *)&f, j); \
+ if (f != j) { \
+ printf("FAIL [%#" PRIx##m " != %#" PRIx##w "]\n", f, j);\
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_STORE_64
+ if (m == 64) {
+#if defined(CK_F_PR_STORE_32)
+ CK_PR_STORE_W(64, 32);
+#endif
+#if defined(CK_PR_STORE_16)
+ CK_PR_STORE_W(64, 16);
+#endif
+#if defined(CK_PR_STORE_8)
+ CK_PR_STORE_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_STORE_64 */
+
+#ifdef CK_F_PR_STORE_32
+ if (m == 32) {
+#if defined(CK_F_PR_STORE_16)
+ CK_PR_STORE_W(32, 16);
+#endif
+#if defined(CK_PR_STORE_8)
+ CK_PR_STORE_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_STORE_32 */
+
+#if defined(CK_F_PR_STORE_16) && defined(CK_PR_STORE_8)
+ if (m == 16)
+ CK_PR_STORE_W(16, 8);
+#endif /* CK_PR_STORE_16 && CK_PR_STORE_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+#if defined(CK_F_PR_STORE_DOUBLE) && defined(CK_F_PR_LOAD_DOUBLE)
+ double d;
+
+ ck_pr_store_double(&d, 0.0);
+ if (ck_pr_load_double(&d) != 0.0) {
+ ck_error("Stored 0 in double, did not find 0.\n");
+ }
+#endif
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_STORE_64
+ CK_PR_STORE_B(64);
+#endif
+
+#ifdef CK_F_PR_STORE_32
+ CK_PR_STORE_B(32);
+#endif
+
+#ifdef CK_F_PR_STORE_16
+ CK_PR_STORE_B(16);
+#endif
+
+#ifdef CK_F_PR_STORE_8
+ CK_PR_STORE_B(8);
+#endif
+
+ return (0);
+}
diff --git a/regressions/ck_pr/validate/ck_pr_sub.c b/regressions/ck_pr/validate/ck_pr_sub.c
new file mode 100644
index 0000000..f515914
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_sub.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define CK_PR_SUB_T(w, v, d) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_sub_##w(&t, d); \
+ if (t != (uint##w##_t)(v - d)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w "]\n", \
+ (uint##w##_t)v, d, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_SUB_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_sub_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = common_rand() % ((uint##w##_t)-1 / 2); \
+ uint##w##_t b = common_rand() % ((uint##w##_t)-1 / 2); \
+ CK_PR_SUB_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_SUB_W(m, w) \
+ { \
+ uint##m##_t t = 0, r = (uint##m##_t)(uint##w##_t)-1; \
+ ck_pr_sub_##w((uint##w##_t *)(void *)&t, 1); \
+ if (t != r) { \
+ printf(" FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, r); \
+ exit(EXIT_FAILURE); \
+ } \
+ t = 0; \
+ ck_pr_sub_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != 1) { \
+ printf(" FAIL [%#" PRIx##m " != 1]\n", t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_SUB_64
+ if (m == 64) {
+#if defined(CK_F_PR_SUB_32)
+ CK_PR_SUB_W(64, 32);
+#endif
+#if defined(CK_PR_SUB_16)
+ CK_PR_SUB_W(64, 16);
+#endif
+#if defined(CK_PR_SUB_8)
+ CK_PR_SUB_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_SUB_64 */
+
+#ifdef CK_F_PR_SUB_32
+ if (m == 32) {
+#if defined(CK_F_PR_SUB_16)
+ CK_PR_SUB_W(32, 16);
+#endif
+#if defined(CK_PR_SUB_8)
+ CK_PR_SUB_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_SUB_32 */
+
+#if defined(CK_F_PR_SUB_16) && defined(CK_PR_SUB_8)
+ if (m == 16) {
+ CK_PR_SUB_W(16, 8);
+ }
+#endif /* CK_PR_SUB_16 && CK_PR_SUB_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_SUB_64
+ CK_PR_SUB_B(64);
+#endif
+
+#ifdef CK_F_PR_SUB_32
+ CK_PR_SUB_B(32);
+#endif
+
+#ifdef CK_F_PR_SUB_16
+ CK_PR_SUB_B(16);
+#endif
+
+#ifdef CK_F_PR_SUB_8
+ CK_PR_SUB_B(8);
+#endif
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_unary.c b/regressions/ck_pr/validate/ck_pr_unary.c
new file mode 100644
index 0000000..b2300cd
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_unary.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2011 David Joseph.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ck_pr.h>
+
+#define REPEAT 2000000
+
+#define TEST_UNARY(K, S, M, T, P, D, H) \
+ static void \
+ test_##K##_##S(M *target) \
+ { \
+ *target = *target P 1; \
+ \
+ return; \
+ } \
+ static void \
+ test_##K##_##S##_zero(M *target, bool *zero) \
+ { \
+ *zero = *target == H; \
+ *target = *target P 1; \
+ \
+ return; \
+ } \
+ static void \
+ run_test_##K##_##S(bool use_zero) \
+ { \
+ int i; \
+ T x = 1, y = 1; \
+ bool zero_x = false, zero_y = false; \
+ \
+ use_zero ? puts("***TESTING ck_pr_"#K"_"#S"_zero***") \
+ : puts("***TESTING ck_pr_"#K"_"#S"***"); \
+ for (i = 0; i < REPEAT; ++i) { \
+ if (use_zero) { \
+ test_##K##_##S##_zero(&x, &zero_x); \
+ ck_pr_##K##_##S##_zero(&y, &zero_y); \
+ } \
+ else { \
+ test_##K##_##S(&x); \
+ ck_pr_##K##_##S(&y); \
+ } \
+ \
+ if (x != y || zero_x != zero_y) { \
+ printf("Serial(%"#D") and ck_pr(%"#D")" \
+ #K"_"#S" do not match.\n" \
+ "FAILURE.\n", \
+ x, y); \
+ \
+ return; \
+ } \
+ \
+ if (zero_x) \
+ printf("Variables are zero at iteration %d\n", i); \
+ } \
+ \
+ \
+ printf("\tserial_"#K"_"#S": %"#D"\n" \
+ "\tck_pr_"#K"_"#S": %"#D"\n" \
+ "SUCCESS.\n", \
+ x, y); \
+ \
+ return; \
+ }
+
+#define GENERATE_TEST(K, P, Y, Z) \
+ TEST_UNARY(K, int, int, int, P, d, Y) \
+ TEST_UNARY(K, uint, unsigned int, unsigned int, P, u, Z) \
+ static void \
+ run_test_##K(void) \
+ { \
+ run_test_##K##_int(false); \
+ run_test_##K##_int(true); \
+ run_test_##K##_uint(false); \
+ run_test_##K##_uint(true); \
+ }
+
+GENERATE_TEST(inc, +, -1, UINT_MAX)
+GENERATE_TEST(dec, -, 1, 1)
+
+#undef GENERATE_TEST
+#undef TEST_UNARY
+
+int
+main(void)
+{
+ run_test_inc();
+ run_test_dec();
+
+ return (0);
+}
+
diff --git a/regressions/ck_pr/validate/ck_pr_xor.c b/regressions/ck_pr/validate/ck_pr_xor.c
new file mode 100644
index 0000000..4515cc4
--- /dev/null
+++ b/regressions/ck_pr/validate/ck_pr_xor.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2009 Samy Al Bahra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+#ifndef R_REPEAT
+#define R_REPEAT 200000
+#endif
+
+#define BM(m, w) ((uint##m##_t)-1 << (w))
+
+#define CK_PR_XOR_T(w, v, d) \
+ { \
+ uint##w##_t t = v; \
+ ck_pr_xor_##w(&t, d); \
+ if (t != (uint##w##_t)(v ^ d)) { \
+ printf("FAIL ["); \
+ printf("%" PRIu##w " (%" PRIu##w ") -> %" PRIu##w "]\n",\
+ (uint##w##_t)v, d, t); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+#define CK_PR_XOR_B(w) \
+ { \
+ unsigned int __ck_i = 0; \
+ printf("ck_pr_xor_" #w ": "); \
+ if (w < 10) \
+ printf(" "); \
+ for (__ck_i = 0; __ck_i < R_REPEAT; __ck_i++) { \
+ uint##w##_t a = (uint##w##_t)common_rand(); \
+ uint##w##_t b = (uint##w##_t)common_rand(); \
+ CK_PR_XOR_T(w, a, b); \
+ } \
+ rg_width(w); \
+ printf(" SUCCESS\n"); \
+ }
+
+#define CK_PR_XOR_W(m, w) \
+ { \
+ uint##m##_t t = -1; \
+ ck_pr_xor_##w((uint##w##_t *)(void *)&t, -1); \
+ if (t != BM(m, w)) { \
+ printf(" FAIL [%#" PRIx##m " != %#" PRIx##m "]\n", t, BM(m, w)); \
+ exit(EXIT_FAILURE); \
+ } \
+ }
+
+static void
+rg_width(int m)
+{
+
+ /* Other architectures are bi-endian. */
+#if !defined(__x86__) && !defined(__x86_64__)
+ return;
+#endif
+
+#ifdef CK_F_PR_XOR_64
+ if (m == 64) {
+#if defined(CK_F_PR_XOR_32)
+ CK_PR_XOR_W(64, 32);
+#endif
+#if defined(CK_PR_XOR_16)
+ CK_PR_XOR_W(64, 16);
+#endif
+#if defined(CK_PR_XOR_8)
+ CK_PR_XOR_W(64, 8);
+#endif
+ }
+#endif /* CK_PR_XOR_64 */
+
+#ifdef CK_F_PR_XOR_32
+ if (m == 32) {
+#if defined(CK_F_PR_XOR_16)
+ CK_PR_XOR_W(32, 16);
+#endif
+#if defined(CK_PR_XOR_8)
+ CK_PR_XOR_W(32, 8);
+#endif
+ }
+#endif /* CK_PR_XOR_32 */
+
+#if defined(CK_F_PR_XOR_16) && defined(CK_PR_XOR_8)
+ if (m == 16) {
+ CK_PR_XOR_W(16, 8);
+ }
+#endif /* CK_PR_XOR_16 && CK_PR_XOR_8 */
+
+ return;
+}
+
+int
+main(void)
+{
+
+ common_srand((unsigned int)getpid());
+
+#ifdef CK_F_PR_XOR_64
+ CK_PR_XOR_B(64);
+#endif
+
+#ifdef CK_F_PR_XOR_32
+ CK_PR_XOR_B(32);
+#endif
+
+#ifdef CK_F_PR_XOR_16
+ CK_PR_XOR_B(16);
+#endif
+
+#ifdef CK_F_PR_XOR_8
+ CK_PR_XOR_B(8);
+#endif
+
+ return (0);
+}
+