summaryrefslogtreecommitdiff
path: root/examples/orc/jit.c
blob: 35df92c5ec09f32184a8039578b72606be0f5c63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

#include "config.h"

#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <orc/orcprogram.h>

#define N 10

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, "s16", "d1");
  s1 = orc_program_add_source (p, "s16", "s1");
  s2 = orc_program_add_source (p, "s16", "s2");
  t1 = orc_program_add_temporary (p, "s16", "t1");
  offset = orc_program_add_constant (p, "s16", 1, "offset");
  shift = orc_program_add_constant (p, "s16", 1, "shift");

  orc_program_append (p, "add_s16", t1, s1, s2);
  orc_program_append (p, "add_s16", t1, t1, offset);
  orc_program_append (p, "rshift_s16", d1, t1, shift);

  ex = orc_executor_new (p);

  orc_executor_set_n (ex, N);
  orc_executor_set_array (ex, s1, src1);
  orc_executor_set_array (ex, s2, src2);
  orc_executor_set_array (ex, d1, dest);

  orc_program_compile_x86 (p);

  if (0) {
    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] + 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;
  for(i=0;i<n;i++){
    dest[i] = (src1[i] + src2[i] + 1)>>1;
  }
}