Skip to content

Instantly share code, notes, and snippets.

@nzjrs nzjrs/Makefile
Created Feb 11, 2012

Embed
What would you like to do?
Testing ORC - The Oil Runtime Compiler
Quick test of using ORC to calculate the absolute difference of two arrays.
http://code.entropywave.com/projects/orc/
One can efficiently do this by using subtract with unsigned saturate and then
OR'ing the result
ref:
http://software.intel.com/en-us/articles/absolute-difference-motion-estimation-for-intel-pentiumr-4-processors/
http://stackoverflow.com/questions/3380785/compute-the-absolute-difference-between-unsigned-integers-using-sse
http://www.tommesani.com/SSEPrimer.html
http://www.tommesani.com/MMXArithmetic.html
.function absdiff_u8
.dest 1 d1 char
.source 1 s1 char
.source 1 s2 char
.temp 1 t1
.temp 1 t2
subusb t1, s1, s2
subusb t2, s2, s1
orb d1, t1, t2
all: testc testorc
clean:
rm -f testc testorc out.c out.h
testc: out.c test.c
$(CC) -DDISABLE_ORC=1 -o $@ $^
testorc: out.c test.c
$(CC) -o $@ $^ `pkg-config --cflags --libs orc-0.4`
out.c: example1.orc
orcc --header --target sse $<
orcc --implementation --target sse $<
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "test.h"
#include "out.h"
#define CPU_TIME (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + \
ruse.ru_stime.tv_sec + 1e-6 * \
(ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec))
int
main (int argc, char *argv[])
{
int i;
time_t start, end;
double first, second;
struct rusage ruse;
unsigned char *a,*b,*c;
a = (unsigned char *)malloc(TESTSIZE * sizeof(unsigned char));
b = (unsigned char *)malloc(TESTSIZE * sizeof(unsigned char));
c = (unsigned char *)malloc(TESTSIZE * sizeof(unsigned char));
/* Create some data in the source arrays */
for(i=0;i < TESTSIZE;i++){
a[i] = 120;
b[i] = (i%2 ? 100 : 140);
}
time(&start);
first = CPU_TIME;
/* Call a function that uses Orc */;
absdiff_u8 ((unsigned char *)c, a, b, TESTSIZE);
time(&end);
second = CPU_TIME;
/* Print the results
for(i=0;i < TESTSIZE;i+=TESTSIZE/21){
printf("%u: %u %u -> %u\n", i, a[i], b[i], c[i]);
} */
printf("cpu : %f secs\n", second - first);
printf("user : %d secs\n", (int)(end - start));
free(a);
free(b);
free(c);
return 0;
}
#define TESTSIZE 200000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.