]> git.sur5r.net Git - cc65/commitdiff
Added Duff's Device to tests.
authorChris Cacciatore <chris.cacciatore@gmail.com>
Mon, 15 Aug 2016 18:26:03 +0000 (11:26 -0700)
committerChris Cacciatore <chris.cacciatore@gmail.com>
Mon, 15 Aug 2016 18:26:03 +0000 (11:26 -0700)
test/val/duffs-device.c [new file with mode: 0644]

diff --git a/test/val/duffs-device.c b/test/val/duffs-device.c
new file mode 100644 (file)
index 0000000..effb33b
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+  !!DESCRIPTION!! Implementation of Duff's device (loop unrolling).
+  !!ORIGIN!!      
+  !!LICENCE!!     GPL, read COPYING.GPL
+*/
+
+#include <stdio.h>
+#include <limits.h>
+
+#define ASIZE (100)
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+#ifdef SUPPORT_BIT_TYPES
+bit bit0 = 0;
+#endif
+
+void done()
+{
+  dummy++;
+}
+
+int acmp(char* a, char* b, int count)
+{
+  int i;
+
+  for(i = 0; i < count; i++) {
+    if(a[i] != b[i]) {
+      return 1;
+    }
+  }
+  return 0;
+}
+
+void duffit (char* to, char* from, int count) 
+{
+  int n = (count + 7) / 8;
+
+  switch(count % 8) {
+    case 0: do {    *to++ = *from++;
+    case 7:         *to++ = *from++;
+    case 6:         *to++ = *from++;
+    case 5:         *to++ = *from++;
+    case 4:         *to++ = *from++;
+    case 3:         *to++ = *from++;
+    case 2:         *to++ = *from++;
+    case 1:         *to++ = *from++;
+    } while(--n > 0);
+  }
+}
+
+int main(void)
+{
+  char a[ASIZE] = {1};
+  char b[ASIZE] = {2};
+  
+  /* a and b should be different */
+  if(!acmp(a, b, ASIZE)) {
+    failures++;
+  }
+  
+  duffit(a, b, ASIZE);
+  
+  /* a and b should be the same */
+  if(acmp(a, b, ASIZE)) {
+    failures++;
+  }
+
+  success=failures;
+  done();
+  printf("failures: %d\n",failures);
+
+  return failures;
+}