diff options
author | David Schleef <ds@schleef.org> | 2009-06-01 00:29:50 +0400 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2009-06-01 00:29:50 +0400 |
commit | 732cb8162bc4010c9c9fb8fbab5f218463edc1b5 (patch) | |
tree | 1132344e610c2286e866a1545e98685caa87ef14 /examples | |
parent | fd98d146079cf3ae2db3a81358379df42b331bc3 (diff) |
doc: documentation work
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 6 | ||||
-rw-r--r-- | examples/example1.c | 74 | ||||
-rw-r--r-- | examples/jit.c | 89 | ||||
-rw-r--r-- | examples/mt19937ar.c | 32 | ||||
-rw-r--r-- | examples/simple.c | 613 |
5 files changed, 102 insertions, 712 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index 3216bf5..11e04cd 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,10 +1,6 @@ -orcbin_PROGRAMS = jit simple mt19937ar +orcbin_PROGRAMS = example1 mt19937ar AM_LDFLAGS = $(ORC_LIBS) AM_CFLAGS = $(ORC_CFLAGS) -jit_SOURCES = jit.c - -simple_SOURCES = simple.c - diff --git a/examples/example1.c b/examples/example1.c new file mode 100644 index 0000000..f4ef1b2 --- /dev/null +++ b/examples/example1.c @@ -0,0 +1,74 @@ + + +#include <stdio.h> + +#include <orc/orcprogram.h> + +#define N 10 + +int16_t a[N]; +int16_t b[N]; +int16_t c[N]; + +void add_s16(int16_t *dest, int16_t *src1, int16_t *src2, int n); + + +int +main (int argc, char *argv[]) +{ + int i; + + /* orc_init() must be called before any other Orc function */ + orc_init (); + + /* Create some data in the source arrays */ + for(i=0;i<N;i++){ + a[i] = i; + b[i] = 100; + } + + /* Call a function that uses Orc */ + add_s16 (c, a, b, N); + + /* Print the results */ + for(i=0;i<N;i++){ + printf("%d: %d %d -> %d\n", i, a[i], b[i], c[i]); + } + + return 0; +} + +void +add_s16(int16_t *dest, int16_t *src1, int16_t *src2, int n) +{ + static OrcProgram *p = NULL; + OrcExecutor _ex; + OrcExecutor *ex = &_ex; + + if (p == NULL) { + /* First time through, create the program */ + + /* Create a new program with two sources and one destination. + * Size of the members of each array is 2. */ + p = orc_program_new_dss (2, 2, 2); + + /* Append an instruction to add the 2-byte values s1 and s2 (which + * are the source arrays created above), and place the result in + * the destination array d1, which was also create above. */ + orc_program_append_str (p, "addw", "d1", "s1", "s2"); + + /* Compile the program. Ignore the very important result. */ + orc_program_compile (p); + } + + /* Set the values on the executor structure */ + orc_executor_set_n (ex, n); + orc_executor_set_array_str (ex, "s1", src1); + orc_executor_set_array_str (ex, "s2", src2); + orc_executor_set_array_str (ex, "d1", dest); + + /* Run the program. This calls the code that was generated above, + * or, if the compilation failed, will emulate the program. */ + orc_executor_run (ex); +} + diff --git a/examples/jit.c b/examples/jit.c deleted file mode 100644 index d7f313a..0000000 --- a/examples/jit.c +++ /dev/null @@ -1,89 +0,0 @@ - -#include "config.h" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <orc/orcprogram.h> - -#define N 19 - -int16_t src1[N]; -int16_t src2[N]; -int16_t dest[N]; - -void test(OrcExecutor *ex); - -int -main (int argc, char *argv[]) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, d1, offset, shift; - int t1; - - orc_init (); - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 2, "d1"); - s1 = orc_program_add_source (p, 2, "s1"); - s2 = orc_program_add_source (p, 2, "s2"); - t1 = orc_program_add_temporary (p, 2, "t1"); - offset = orc_program_add_constant (p, 2, 1, "offset"); - shift = orc_program_add_constant (p, 2, 1, "shift"); - - orc_program_append (p, "addw", t1, s1, s2); - orc_program_append (p, "addw", t1, t1, offset); - orc_program_append (p, "shrsw", d1, t1, shift); - - orc_program_compile (p); - - if (1) { - int i; - - for(i=0;i<N;i++){ - src1[i] = rand()&0xf; - src2[i] = rand()&0xf; - } - - ex = orc_executor_new (p); - - orc_executor_set_n (ex, N-4); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src2); - orc_executor_set_array (ex, d1, dest); - - printf("#code exec %p\n", ex->program->code_exec); - - orc_executor_run (ex); - //orc_executor_emulate (ex); - - for(i=0;i<N;i++){ - printf("# %4d %4d %4d %4d\n", src1[i], src2[i], dest[i], - (src1[i] + src2[i] + 1) >> 1); - } - - orc_executor_free (ex); - } - - orc_program_free (p); - - return 0; -} - - - -void -test1 (int16_t *dest, int16_t *src1, int16_t *src2, int n) -{ - int i; - int16_t t1, t2; - for(i=0;i<n;i++){ - t1 = src1[i] + src2[i]; - t2 = t1 + 1; - dest[i] = t2>>1; - } -} - diff --git a/examples/mt19937ar.c b/examples/mt19937ar.c index d939913..f23b50e 100644 --- a/examples/mt19937ar.c +++ b/examples/mt19937ar.c @@ -90,7 +90,7 @@ mt19937_ref (uint32_t *d, uint32_t *mt) } -OrcProgram *p1, *p2, *p3; +OrcProgram *p1, *p2; void create_programs (void) @@ -107,7 +107,6 @@ create_programs (void) orc_program_add_constant (p1, 4, UPPER_MASK, "c1"); orc_program_add_constant (p1, 4, LOWER_MASK, "c2"); orc_program_add_constant (p1, 4, 1, "c3"); - orc_program_add_constant (p1, 4, 31, "c5"); orc_program_add_constant (p1, 4, MATRIX_A, "c6"); orc_program_append_str (p1, "andl", "t1", "s1", "c1"); @@ -117,14 +116,37 @@ create_programs (void) orc_program_append_str (p1, "shrul", "t1", "y", "c3"); orc_program_append_str (p1, "xorl", "t2", "s3", "t1"); orc_program_append_str (p1, "andl", "y", "y", "c3"); - orc_program_append_str (p1, "shll", "y", "y", "c5"); - orc_program_append_str (p1, "shrsl", "y", "y", "c5"); + orc_program_append_str (p1, "cmpeql", "y", "y", "c3"); orc_program_append_str (p1, "andl", "y", "y", "c6"); orc_program_append_str (p1, "xorl", "d1", "t2", "y"); orc_program_compile (p1); - printf("%s", orc_program_get_asm_code (p1)); + + p2 = orc_program_new (); + orc_program_add_destination (p2, 4, "d1"); + orc_program_add_temporary (p2, 4, "y"); + orc_program_add_temporary (p2, 4, "t1"); + + orc_program_add_constant (p2, 4, 11, "c11"); + orc_program_add_constant (p2, 4, 7, "c7"); + orc_program_add_constant (p2, 4, 0x9d2c5680, "x1"); + orc_program_add_constant (p2, 4, 15, "c15"); + orc_program_add_constant (p2, 4, 0xefc60000, "x2"); + orc_program_add_constant (p2, 4, 15, "c18"); + + orc_program_append_str (p2, "shrul", "t1", "d1", "c11"); + orc_program_append_str (p2, "xorl", "y", "d1", "t1"); + orc_program_append_str (p2, "shll", "t1", "y", "c7"); + orc_program_append_str (p2, "andl", "t1", "t1", "x1"); + orc_program_append_str (p2, "xorl", "y", "y", "t1"); + orc_program_append_str (p2, "shll", "t1", "y", "c15"); + orc_program_append_str (p2, "andl", "t1", "t1", "x2"); + orc_program_append_str (p2, "xorl", "y", "y", "t1"); + orc_program_append_str (p2, "shrul", "t1", "y", "c18"); + orc_program_append_str (p2, "xorl", "d1", "y", "t1"); + + orc_program_compile (p2); } diff --git a/examples/simple.c b/examples/simple.c deleted file mode 100644 index b620e13..0000000 --- a/examples/simple.c +++ /dev/null @@ -1,613 +0,0 @@ - -#include "config.h" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <orc/orcprogram.h> - -#define N 100 - -int16_t src1[N+4]; -int16_t src2[N]; -int16_t dest_test[N]; -int16_t dest_ref[N]; -int16_t dest[N]; - -uint8_t bsrc1[N+4]; -uint8_t bsrc2[N]; -uint8_t bdest_test[N]; -uint8_t bdest_ref[N]; -uint8_t bdest[N]; - -void test1(void); -void test2(void); -void test3(void); -void test4(void); -void test5(void); -void test6(void); -void test7(void); -void test8(void); -void test9(void); - -int -main (int argc, char *argv[]) -{ - orc_init (); - - test1(); - - exit(0); -} - -void -test1(void) -{ - OrcProgram *p; - OrcExecutor *ex; - - p = orc_program_new_dss (2, 2, 2); - - orc_program_append_str (p, "addw", "d1", "s1", "s2"); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N - 4); - orc_executor_set_array_str (ex, "s1", src1); - orc_executor_set_array_str (ex, "s2", src2); - orc_executor_set_array_str (ex, "d1", dest); - - if (1) { - int i; - - for(i=0;i<N;i++){ - src1[i] = rand()&0xf; - src2[i] = rand()&0xf; - } - - orc_executor_run (ex); - //orc_executor_emulate (ex); - - for(i=0;i<N;i++){ - printf("# %4d %4d %4d %4d\n", src1[i], src2[i], dest[i], - src1[i] + src2[i]); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test2(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, s3, s4, d1; - int t1, t2; - int c1, c2, c3; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 2, "d1"); - //p->vars[d1].is_uncached = TRUE; - s1 = orc_program_add_source (p, 2, "s1"); - s2 = orc_program_add_source (p, 2, "s2"); - s3 = orc_program_add_source (p, 2, "s3"); - s4 = orc_program_add_source (p, 2, "s4"); - c1 = orc_program_add_constant (p, 2, 3, "c1"); - c2 = orc_program_add_constant (p, 2, 4, "c2"); - c3 = orc_program_add_constant (p, 2, 3, "c3"); - t1 = orc_program_add_temporary (p, 2, "t1"); - t2 = orc_program_add_temporary (p, 2, "t2"); - - orc_program_append (p, "addw", t1, s2, s3); - orc_program_append (p, "addw", t2, s1, s4); - orc_program_append (p, "mullw", t1, t1, c1); - orc_program_append (p, "subw", t1, t1, t2); - orc_program_append (p, "addw", t1, t1, c2); - orc_program_append (p, "shrsw", d1, t1, c3); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src1 + 1); - orc_executor_set_array (ex, s3, src1 + 2); - orc_executor_set_array (ex, s4, src1 + 3); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n+3;i++){ - src1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 1 - for(i=0;i<n;i++){ - dest_ref[i] = (3*(src1[i+1]+src1[i+2])-(src1[i]+src1[i+3])+4)>>3; - } -#endif - - orc_executor_set_array (ex, d1, dest_test + 1); - orc_executor_run (ex); - - printf("# %d: %p %d %d %d\n", - n, ex->arrays[0], ex->counter1, ex->counter2, ex->counter3); - - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, src1[i], dest_ref[i], dest_test[i+1], - (dest_ref[i] == dest_test[i+1])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test3(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, d1; - int t1, t2; - int c1, c2; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 2, "d1"); - s1 = orc_program_add_source (p, 2, "s1"); - s2 = orc_program_add_source (p, 2, "s2"); - c1 = orc_program_add_constant (p, 2, -1, "c1"); - c2 = orc_program_add_constant (p, 2, 1, "c2"); - t1 = orc_program_add_temporary (p, 2, "t1"); - t2 = orc_program_add_temporary (p, 2, "t2"); - - orc_program_append (p, "addw", t1, s1, s2); - orc_program_append (p, "addw", t2, t1, c1); - orc_program_append (p, "shrsw", d1, t2, c2); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src1 + 1); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n+1;i++){ - src1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 1 - for(i=0;i<n;i++){ - dest_ref[i] = (src1[i+1]+src1[i]-1)>>1; - } -#endif - - orc_executor_set_array (ex, d1, dest_test); - orc_executor_run (ex); - - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, src1[i], dest_ref[i], dest_test[i], - (dest_ref[i] == dest_test[i])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - - -void -test4(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int n; - - p = orc_program_new_dss (1, 1, 1); - - orc_program_append_str (p, "addb", "d1", "s1", "s2"); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N - 4); - orc_executor_set_array_str (ex, "s1", bsrc1); - orc_executor_set_array_str (ex, "s2", bsrc2); - orc_executor_set_array_str (ex, "d1", bdest); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n;i++){ - bsrc1[i] = rand()&0xf; - bsrc2[i] = rand()&0xf; - } - for(i=0;i<n+4;i++){ - bdest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array_str (ex, "d1", bdest_ref); - orc_executor_emulate (ex); - - orc_executor_set_array_str (ex, "d1", bdest_test); - orc_executor_run (ex); - - for(i=0;i<n+4;i++){ - printf("# %4d %4d %4d %4d %c\n", bsrc1[i], bsrc2[i], bdest_ref[i], - bdest_test[i], - (bdest_ref[i] == bdest_test[i])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test5(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, d1; - int t1; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 2, "d1"); - s1 = orc_program_add_source (p, 2, "s1"); - s2 = orc_program_add_source (p, 2, "s2"); - t1 = orc_program_add_temporary (p, 2, "t1"); - - orc_program_append (p, "absw", t1, s1, s2); - orc_program_append (p, "addw", t1, s1, s2); - orc_program_append (p, "addssw", t1, s1, s2); - orc_program_append (p, "addusw", t1, s1, s2); - orc_program_append (p, "andw", t1, s1, s2); - orc_program_append (p, "andnw", t1, s1, s2); - //orc_program_append (p, "avgsw", t1, s1, s2); - orc_program_append (p, "avguw", t1, s1, s2); - orc_program_append (p, "cmpeqw", t1, s1, s2); - orc_program_append (p, "cmpgtsw", t1, s1, s2); - orc_program_append (p, "maxsw", t1, s1, s2); - //orc_program_append (p, "maxuw", t1, s1, s2); - orc_program_append (p, "minsw", t1, s1, s2); - //orc_program_append (p, "minuw", t1, s1, s2); - orc_program_append (p, "mullw", t1, s1, s2); - orc_program_append (p, "mulhsw", t1, s1, s2); - orc_program_append (p, "mulhuw", t1, s1, s2); - orc_program_append (p, "orw", t1, s1, s2); - orc_program_append (p, "signw", t1, s1, s2); - orc_program_append (p, "subw", t1, s1, s2); - orc_program_append (p, "subssw", t1, s1, s2); - orc_program_append (p, "subusw", t1, s1, s2); - orc_program_append (p, "xorw", t1, s1, s2); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src1 + 1); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n+1;i++){ - src1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 1 - for(i=0;i<n;i++){ - dest_ref[i] = (src1[i+1]+src1[i]-1)>>1; - } -#endif - - orc_executor_set_array (ex, d1, dest_test); - //orc_executor_run (ex); - - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, src1[i], dest_ref[i], dest_test[i], - (dest_ref[i] == dest_test[i])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test6(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, d1; - int t1; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 1, "d1"); - s1 = orc_program_add_source (p, 1, "s1"); - s2 = orc_program_add_source (p, 1, "s2"); - t1 = orc_program_add_temporary (p, 1, "t1"); - - orc_program_append (p, "absb", t1, s1, s2); - orc_program_append (p, "addb", t1, s1, s2); - orc_program_append (p, "addssb", t1, s1, s2); - orc_program_append (p, "addusb", t1, s1, s2); - orc_program_append (p, "andb", t1, s1, s2); - orc_program_append (p, "andnb", t1, s1, s2); - //orc_program_append (p, "avgsb", t1, s1, s2); - orc_program_append (p, "avgub", t1, s1, s2); - orc_program_append (p, "cmpeqb", t1, s1, s2); - orc_program_append (p, "cmpgtsb", t1, s1, s2); - //orc_program_append (p, "maxsb", t1, s1, s2); - orc_program_append (p, "maxub", t1, s1, s2); - //orc_program_append (p, "minsb", t1, s1, s2); - orc_program_append (p, "minub", t1, s1, s2); - //orc_program_append (p, "mullb", t1, s1, s2); - //orc_program_append (p, "mulhsb", t1, s1, s2); - //orc_program_append (p, "mulhub", t1, s1, s2); - orc_program_append (p, "orb", t1, s1, s2); - orc_program_append (p, "signb", t1, s1, s2); - orc_program_append (p, "subb", t1, s1, s2); - orc_program_append (p, "subssb", t1, s1, s2); - orc_program_append (p, "subusb", t1, s1, s2); - orc_program_append (p, "xorb", t1, s1, s2); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src1 + 1); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n+1;i++){ - src1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 1 - for(i=0;i<n;i++){ - dest_ref[i] = (src1[i+1]+src1[i]-1)>>1; - } -#endif - - orc_executor_set_array (ex, d1, dest_test); - //orc_executor_run (ex); - - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, src1[i], dest_ref[i], dest_test[i], - (dest_ref[i] == dest_test[i])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test7(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, s2, d1; - int t1; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 1, "d1"); - s1 = orc_program_add_source (p, 1, "s1"); - s2 = orc_program_add_source (p, 1, "s2"); - t1 = orc_program_add_temporary (p, 1, "t1"); - - orc_program_append (p, "absl", t1, s1, s2); - orc_program_append (p, "addl", t1, s1, s2); - //orc_program_append (p, "addssl", t1, s1, s2); - //orc_program_append (p, "addusl", t1, s1, s2); - orc_program_append (p, "andl", t1, s1, s2); - orc_program_append (p, "andnl", t1, s1, s2); - //orc_program_append (p, "avgsl", t1, s1, s2); - //orc_program_append (p, "avgul", t1, s1, s2); - orc_program_append (p, "cmpeql", t1, s1, s2); - orc_program_append (p, "cmpgtsl", t1, s1, s2); - //orc_program_append (p, "maxsl", t1, s1, s2); - //orc_program_append (p, "maxul", t1, s1, s2); - //orc_program_append (p, "minsl", t1, s1, s2); - //orc_program_append (p, "minul", t1, s1, s2); - //orc_program_append (p, "mulll", t1, s1, s2); - //orc_program_append (p, "mulhsl", t1, s1, s2); - //orc_program_append (p, "mulhul", t1, s1, s2); - orc_program_append (p, "orl", t1, s1, s2); - orc_program_append (p, "signl", t1, s1, s2); - orc_program_append (p, "subl", t1, s1, s2); - //orc_program_append (p, "subssl", t1, s1, s2); - //orc_program_append (p, "subusl", t1, s1, s2); - orc_program_append (p, "xorl", t1, s1, s2); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, src1); - orc_executor_set_array (ex, s2, src1 + 1); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n+1;i++){ - src1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 1 - for(i=0;i<n;i++){ - dest_ref[i] = (src1[i+1]+src1[i]-1)>>1; - } -#endif - - orc_executor_set_array (ex, d1, dest_test); - //orc_executor_run (ex); - - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, src1[i], dest_ref[i], dest_test[i], - (dest_ref[i] == dest_test[i])?' ':'*'); - } - } - - orc_executor_free (ex); - orc_program_free (p); -} - - - -void -test8(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int s1, d1; - int n; - - p = orc_program_new (); - - d1 = orc_program_add_destination (p, 2, "d1"); - s1 = orc_program_add_source (p, 1, "s1"); - - orc_program_append_ds (p, "convubw", d1, s1); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N); - orc_executor_set_array (ex, s1, bsrc1); - - for(n=0;n<20;n++) { - int i; - - for(i=0;i<n;i++){ - bsrc1[i] = rand()&0xff; - } - for(i=0;i<n+4;i++){ - dest[i] = 0; - } - - orc_executor_set_n (ex, n); - orc_executor_set_array (ex, d1, dest_ref); - orc_executor_emulate (ex); -#if 0 - for(i=0;i<n;i++){ - dest_ref[i] = bsrc1[i]; - } -#endif - - orc_executor_set_array (ex, d1, dest_test); - orc_executor_run (ex); - -#if 1 - for(i=0;i<n+4;i++){ - printf("# %d: %4d %4d %4d %c\n", i, bsrc1[i], dest_ref[i], dest_test[i], - (dest_ref[i] == dest_test[i])?' ':'*'); - } -#endif - } - - orc_executor_free (ex); - orc_program_free (p); -} - - -void -test9(void) -{ - OrcProgram *p; - OrcExecutor *ex; - int value = 1; - - p = orc_program_new_ds (2, 2); - orc_program_add_parameter (p, 2, "p1"); - - orc_program_append_str (p, "shrsw", "d1", "s1", "p1"); - - orc_program_compile (p); - - ex = orc_executor_new (p); - orc_executor_set_n (ex, N - 4); - orc_executor_set_array_str (ex, "s1", src1); - orc_executor_set_param_str (ex, "p1", value); - orc_executor_set_array_str (ex, "d1", dest); - - if (1) { - int i; - - for(i=0;i<N;i++){ - src1[i] = rand()&0xf; - } - - orc_executor_run (ex); - //orc_executor_emulate (ex); - - for(i=0;i<N;i++){ - printf("# %4d %4d %4d\n", src1[i], dest[i], - src1[i] >> value); - } - } - - printf("%s", orc_program_get_asm_code (p)); - - orc_executor_free (ex); - orc_program_free (p); -} - - |