You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2014/08/01 22:44:19 UTC

[06/20] TS-2950: Initial commit of libck.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pflock/benchmark/throughput.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pflock/benchmark/throughput.c b/lib/ck/regressions/ck_pflock/benchmark/throughput.c
new file mode 100644
index 0000000..6c0ed6c
--- /dev/null
+++ b/lib/ck/regressions/ck_pflock/benchmark/throughput.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2011-2014 Samy Al Bahra.
+ * Copyright 2013 John Wittrock.
+ * 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 OTHEPFISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ck_pflock.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../common.h"
+
+#ifndef STEPS
+#define STEPS 1000000
+#endif
+
+static int barrier;
+static int threads;
+static unsigned int flag CK_CC_CACHELINE;
+static ck_pflock_t pflock = CK_PFLOCK_INITIALIZER;
+static struct affinity affinity;
+
+static void *
+thread_pflock(void *pun)
+{
+	uint64_t s_b, e_b, a, i;
+	uint64_t *value = pun;
+
+	if (aff_iterate(&affinity) != 0) {
+		perror("ERROR: Could not affine thread");
+		exit(EXIT_FAILURE);
+	}
+
+	ck_pr_inc_int(&barrier);
+	while (ck_pr_load_int(&barrier) != threads)
+		ck_pr_stall();
+
+	for (i = 1, a = 0;; i++) {
+		s_b = rdtsc();
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		ck_pflock_read_lock(&pflock);
+		ck_pflock_read_unlock(&pflock);
+		e_b = rdtsc();
+
+		a += (e_b - s_b) >> 4;
+
+		if (ck_pr_load_uint(&flag) == 1)
+			break;
+	}
+
+	ck_pr_inc_int(&barrier);
+	while (ck_pr_load_int(&barrier) != threads * 2)
+		ck_pr_stall();
+
+	*value = (a / i);
+	return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+	int t;
+	pthread_t *p;
+	uint64_t *latency;
+
+	if (argc != 3) {
+		ck_error("Usage: throughput <delta> <threads>\n");
+	}
+
+	threads = atoi(argv[2]);
+	if (threads <= 0) {
+		ck_error("ERROR: Threads must be a value > 0.\n");
+	}
+
+	p = malloc(sizeof(pthread_t) * threads);
+	if (p == NULL) {
+		ck_error("ERROR: Failed to initialize thread.\n");
+	}
+
+	latency = malloc(sizeof(uint64_t) * threads);
+	if (latency == NULL) {
+		ck_error("ERROR: Failed to create latency buffer.\n");
+	}
+
+	affinity.delta = atoi(argv[1]);
+	affinity.request = 0;
+
+	fprintf(stderr, "Creating threads (pflock)...");
+	for (t = 0; t < threads; t++) {
+		if (pthread_create(&p[t], NULL, thread_pflock, latency + t) != 0) {
+			ck_error("ERROR: Could not create thread %d\n", t);
+		}
+	}
+	fprintf(stderr, "done\n");
+
+	common_sleep(10);
+	ck_pr_store_uint(&flag, 1);
+
+	fprintf(stderr, "Waiting for threads to finish acquisition regression...");
+	for (t = 0; t < threads; t++)
+		pthread_join(p[t], NULL);
+	fprintf(stderr, "done\n\n");
+
+	for (t = 1; t <= threads; t++)
+		printf("%10u %20" PRIu64 "\n", t, latency[t - 1]);
+
+	return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pflock/validate/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pflock/validate/Makefile b/lib/ck/regressions/ck_pflock/validate/Makefile
new file mode 100644
index 0000000..eea9d02
--- /dev/null
+++ b/lib/ck/regressions/ck_pflock/validate/Makefile
@@ -0,0 +1,17 @@
+.PHONY: check clean distribution
+
+OBJECTS=validate
+
+all: $(OBJECTS)
+
+validate: validate.c ../../../include/ck_pflock.h
+	$(CC) $(CFLAGS) -o validate validate.c
+
+check: all
+	./validate $(CORES) 1
+
+clean:
+	rm -rf *.dSYM *.exe *~ *.o $(OBJECTS)
+
+include ../../../build/regressions.build
+CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pflock/validate/validate.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pflock/validate/validate.c b/lib/ck/regressions/ck_pflock/validate/validate.c
new file mode 100644
index 0000000..5a1c906
--- /dev/null
+++ b/lib/ck/regressions/ck_pflock/validate/validate.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2011-2014 Samy Al Bahra, John Wittrock.
+ * 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 <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <ck_pr.h>
+#include <ck_pflock.h>
+
+#include "../../common.h"
+
+#ifndef ITERATE
+#define ITERATE 1000000
+#endif
+
+static struct affinity a;
+static unsigned int locked;
+static int nthr;
+static ck_pflock_t lock = CK_PFLOCK_INITIALIZER;
+
+static void *
+thread(void *null CK_CC_UNUSED)
+{
+	int i = ITERATE;
+	unsigned int l;
+
+        if (aff_iterate(&a)) {
+                perror("ERROR: Could not affine thread");
+                exit(EXIT_FAILURE);
+        }
+
+	while (i--) {
+		ck_pflock_write_lock(&lock);
+		{
+			l = ck_pr_load_uint(&locked);
+			if (l != 0) {
+				ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
+			}
+
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+			ck_pr_inc_uint(&locked);
+
+			l = ck_pr_load_uint(&locked);
+			if (l != 8) {
+				ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l);
+			}
+
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+			ck_pr_dec_uint(&locked);
+
+			l = ck_pr_load_uint(&locked);
+			if (l != 0) {
+				ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
+			}
+		}
+		ck_pflock_write_unlock(&lock);
+
+		ck_pflock_read_lock(&lock);
+		{
+			l = ck_pr_load_uint(&locked);
+			if (l != 0) {
+				ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l);
+			}
+		}
+		ck_pflock_read_unlock(&lock);
+	}
+
+	return NULL;
+}
+
+int
+main(int argc, char *argv[])
+{
+	pthread_t *threads;
+	int i;
+
+	if (argc != 3) {
+		ck_error("Usage: validate <number of threads> <affinity delta>\n");
+	}
+
+	nthr = atoi(argv[1]);
+	if (nthr <= 0) {
+		ck_error("ERROR: Number of threads must be greater than 0\n");
+	}
+
+	threads = malloc(sizeof(pthread_t) * nthr);
+	if (threads == NULL) {
+		ck_error("ERROR: Could not allocate thread structures\n");
+	}
+
+	a.delta = atoi(argv[2]);
+
+	fprintf(stderr, "Creating threads (mutual exclusion)...");
+	for (i = 0; i < nthr; i++) {
+		if (pthread_create(&threads[i], NULL, thread, NULL)) {
+			ck_error("ERROR: Could not create thread %d\n", i);
+		}
+	}
+	fprintf(stderr, "done\n");
+
+	fprintf(stderr, "Waiting for threads to finish correctness regression...");
+	for (i = 0; i < nthr; i++)
+		pthread_join(threads[i], NULL);
+	fprintf(stderr, "done (passed)\n");
+
+	return 0;
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/benchmark/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/benchmark/Makefile b/lib/ck/regressions/ck_pr/benchmark/Makefile
new file mode 100644
index 0000000..6b6116e
--- /dev/null
+++ b/lib/ck/regressions/ck_pr/benchmark/Makefile
@@ -0,0 +1,18 @@
+.PHONY: clean
+
+all: ck_pr_cas_64 ck_pr_fas_64 ck_pr_cas_64_2
+
+ck_pr_cas_64_2: ck_pr_cas_64_2.c
+	$(CC) $(CFLAGS) -o ck_pr_cas_64_2 ck_pr_cas_64_2.c -lm
+
+ck_pr_cas_64: ck_pr_cas_64.c
+	$(CC) $(CFLAGS) -o ck_pr_cas_64 ck_pr_cas_64.c -lm
+
+ck_pr_fas_64: ck_pr_fas_64.c
+	$(CC) $(CFLAGS) -o ck_pr_fas_64 ck_pr_fas_64.c -lm
+
+clean:
+	rm -rf ck_pr_cas_64 ck_pr_fas_64 ck_pr_cas_64_2 *.dSYM *.exe
+
+include ../../../build/regressions.build
+CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/benchmark/benchmark.h
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/benchmark/benchmark.h b/lib/ck/regressions/ck_pr/benchmark/benchmark.h
new file mode 100644
index 0000000..24cd42c
--- /dev/null
+++ b/lib/ck/regressions/ck_pr/benchmark/benchmark.h
@@ -0,0 +1,130 @@
+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <ck_pr.h>
+
+#include "../../common.h"
+
+/* 8! = 40320, evenly divide 1 .. 8 processor workload. */
+#define WORKLOAD (40320 * 2056)
+
+struct block {
+	unsigned int tid;
+};
+
+static struct affinity a;
+static unsigned int ready;
+static uint64_t *count;
+static uint64_t nthr;
+
+static uint64_t object[2] CK_CC_CACHELINE;
+
+static void *
+fairness(void *null)
+{
+	struct block *context = null;
+	unsigned int i = context->tid;
+
+        if (aff_iterate(&a)) {
+                perror("ERROR: Could not affine thread");
+                exit(EXIT_FAILURE);
+        }
+
+	while (ck_pr_load_uint(&ready) == 0);
+	while (ready) {
+		ATOMIC;
+		ATOMIC;
+		ATOMIC;
+		ATOMIC;
+		ck_pr_store_64(count + i, count[i] + 1);
+	}
+
+	return (NULL);
+}
+
+int
+main(int argc, char *argv[])
+{
+	uint64_t v, d;
+	unsigned int i;
+	pthread_t *threads;
+	struct block *context;
+
+	if (argc != 3) {
+		ck_error("Usage: " ATOMIC_STRING " <number of threads> <affinity delta>\n");
+		exit(EXIT_FAILURE);
+	}
+
+	nthr = atoi(argv[1]);
+	if (nthr <= 0) {
+		ck_error("ERROR: Number of threads must be greater than 0\n");
+		exit(EXIT_FAILURE);
+	}
+
+	threads = malloc(sizeof(pthread_t) * nthr);
+	if (threads == NULL) {
+		ck_error("ERROR: Could not allocate thread structures\n");
+		exit(EXIT_FAILURE);
+	}
+
+	context = malloc(sizeof(struct block) * nthr);
+	if (context == NULL) {
+		ck_error("ERROR: Could not allocate thread contexts\n");
+		exit(EXIT_FAILURE);
+	}
+
+	a.delta = atoi(argv[2]);
+	a.request = 0;
+
+	count = malloc(sizeof(uint64_t) * nthr);
+	if (count == NULL) {
+		ck_error("ERROR: Could not create acquisition buffer\n");
+		exit(EXIT_FAILURE);
+	}
+	memset(count, 0, sizeof(uint64_t) * nthr);
+
+	fprintf(stderr, "Creating threads (fairness)...");
+	for (i = 0; i < nthr; i++) {
+		context[i].tid = i;
+		if (pthread_create(&threads[i], NULL, fairness, context + i)) {
+			ck_error("ERROR: Could not create thread %d\n", i);
+			exit(EXIT_FAILURE);
+		}
+	}
+	fprintf(stderr, "done\n");
+
+	ck_pr_store_uint(&ready, 1);
+	common_sleep(10);
+	ck_pr_store_uint(&ready, 0);
+
+	fprintf(stderr, "Waiting for threads to finish acquisition regression...");
+	for (i = 0; i < nthr; i++)
+		pthread_join(threads[i], NULL);
+	fprintf(stderr, "done\n\n");
+
+	for (i = 0, v = 0; i < nthr; i++) {
+		printf("%d %15" PRIu64 "\n", i, count[i]);
+		v += count[i];
+	}
+
+	printf("\n# total       : %15" PRIu64 "\n", v);
+	printf("# throughput  : %15" PRIu64 " a/s\n", (v /= nthr) / 10);
+
+	for (i = 0, d = 0; i < nthr; i++)
+		d += (count[i] - v) * (count[i] - v);
+
+	printf("# average     : %15" PRIu64 "\n", v);
+	printf("# deviation   : %.2f (%.2f%%)\n\n", sqrt(d / nthr), (sqrt(d / nthr) / v) * 100.00);
+
+	return (0);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64.c b/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64.c
new file mode 100644
index 0000000..90dcb64
--- /dev/null
+++ b/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64.c
@@ -0,0 +1,16 @@
+#include <ck_pr.h>
+
+#ifdef CK_F_PR_CAS_64
+#define ATOMIC ck_pr_cas_64(object, 1, 1)
+#define ATOMIC_STRING "ck_pr_cas_64"
+#include "benchmark.h"
+#else
+#warning Did not find CAS_64 implementation.
+#include <stdlib.h>
+
+int
+main(void)
+{
+	exit(EXIT_FAILURE);
+}
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64_2.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64_2.c b/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64_2.c
new file mode 100644
index 0000000..e959b39
--- /dev/null
+++ b/lib/ck/regressions/ck_pr/benchmark/ck_pr_cas_64_2.c
@@ -0,0 +1,17 @@
+#include <ck_pr.h>
+
+#ifdef CK_F_PR_CAS_64_2
+#define ATOMIC { uint64_t z[2] = {1, 2}; ck_pr_cas_64_2(object, z, z); }
+#define ATOMIC_STRING "ck_pr_cas_64_2"
+#include "benchmark.h"
+#else
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(void)
+{
+	fprintf(stderr, "Unsupported.\n");
+	return 0;
+}
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/benchmark/ck_pr_fas_64.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/benchmark/ck_pr_fas_64.c b/lib/ck/regressions/ck_pr/benchmark/ck_pr_fas_64.c
new file mode 100644
index 0000000..facd759
--- /dev/null
+++ b/lib/ck/regressions/ck_pr/benchmark/ck_pr_fas_64.c
@@ -0,0 +1,17 @@
+#include <ck_pr.h>
+
+#ifdef CK_F_PR_FAS_64
+#define ATOMIC ck_pr_fas_64(object, 1)
+#define ATOMIC_STRING "ck_pr_fas_64"
+#include "benchmark.h"
+#else
+#warning Did not find FAS_64 implementation.
+#include <stdlib.h>
+
+int
+main(void)
+{
+
+	return 0;
+}
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/Makefile
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/Makefile b/lib/ck/regressions/ck_pr/validate/Makefile
new file mode 100644
index 0000000..9e4a82d
--- /dev/null
+++ b/lib/ck/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

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_add.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_add.c b/lib/ck/regressions/ck_pr/validate/ck_pr_add.c
new file mode 100644
index 0000000..31f1893
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_and.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_and.c b/lib/ck/regressions/ck_pr/validate/ck_pr_and.c
new file mode 100644
index 0000000..4c569bb
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_bin.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_bin.c b/lib/ck/regressions/ck_pr/validate/ck_pr_bin.c
new file mode 100644
index 0000000..31868f4
--- /dev/null
+++ b/lib/ck/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);
+}
+
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_btc.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_btc.c b/lib/ck/regressions/ck_pr/validate/ck_pr_btc.c
new file mode 100644
index 0000000..0edec98
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_btr.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_btr.c b/lib/ck/regressions/ck_pr/validate/ck_pr_btr.c
new file mode 100644
index 0000000..91abb30
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_bts.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_bts.c b/lib/ck/regressions/ck_pr/validate/ck_pr_bts.c
new file mode 100644
index 0000000..1e62165
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_btx.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_btx.c b/lib/ck/regressions/ck_pr/validate/ck_pr_btx.c
new file mode 100644
index 0000000..2bb3964
--- /dev/null
+++ b/lib/ck/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);
+}
+
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_cas.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_cas.c b/lib/ck/regressions/ck_pr/validate/ck_pr_cas.c
new file mode 100644
index 0000000..132d1e5
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_dec.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_dec.c b/lib/ck/regressions/ck_pr/validate/ck_pr_dec.c
new file mode 100644
index 0000000..86ce088
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_faa.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_faa.c b/lib/ck/regressions/ck_pr/validate/ck_pr_faa.c
new file mode 100644
index 0000000..1d10bb9
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_fas.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_fas.c b/lib/ck/regressions/ck_pr/validate/ck_pr_fas.c
new file mode 100644
index 0000000..00cef4e
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_fax.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_fax.c b/lib/ck/regressions/ck_pr/validate/ck_pr_fax.c
new file mode 100644
index 0000000..9d8c94f
--- /dev/null
+++ b/lib/ck/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);
+}
+
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_inc.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_inc.c b/lib/ck/regressions/ck_pr/validate/ck_pr_inc.c
new file mode 100644
index 0000000..e8524a5
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_load.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_load.c b/lib/ck/regressions/ck_pr/validate/ck_pr_load.c
new file mode 100644
index 0000000..a15acd0
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_n.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_n.c b/lib/ck/regressions/ck_pr/validate/ck_pr_n.c
new file mode 100644
index 0000000..81e3639
--- /dev/null
+++ b/lib/ck/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);
+}
+
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_or.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_or.c b/lib/ck/regressions/ck_pr/validate/ck_pr_or.c
new file mode 100644
index 0000000..27580c3
--- /dev/null
+++ b/lib/ck/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);
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_store.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_store.c b/lib/ck/regressions/ck_pr/validate/ck_pr_store.c
new file mode 100644
index 0000000..e4b852b
--- /dev/null
+++ b/lib/ck/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);
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f098175e/lib/ck/regressions/ck_pr/validate/ck_pr_sub.c
----------------------------------------------------------------------
diff --git a/lib/ck/regressions/ck_pr/validate/ck_pr_sub.c b/lib/ck/regressions/ck_pr/validate/ck_pr_sub.c
new file mode 100644
index 0000000..f515914
--- /dev/null
+++ b/lib/ck/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);
+}
+