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
|
#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(OJExecutor *ex);
int
main (int argc, char *argv[])
{
OJProgram *p;
OJExecutor *ex;
int s1, s2, d1, offset, shift;
int t1;
oj_opcode_init ();
p = oj_program_new ();
d1 = oj_program_add_destination (p, "s16", "d1");
s1 = oj_program_add_source (p, "s16", "s1");
s2 = oj_program_add_source (p, "s16", "s2");
t1 = oj_program_add_temporary (p, "s16", "t1");
offset = oj_program_add_constant (p, "s16", 1, "offset");
shift = oj_program_add_constant (p, "s16", 1, "shift");
oj_program_append (p, "add_s16", t1, s1, s2);
oj_program_append (p, "add_s16", t1, t1, offset);
oj_program_append (p, "rshift_s16", d1, t1, shift);
ex = oj_executor_new (p);
oj_executor_set_n (ex, N);
oj_executor_set_array (ex, s1, src1);
oj_executor_set_array (ex, s2, src2);
oj_executor_set_array (ex, d1, dest);
oj_program_compile_x86 (p);
if (0) {
int i;
void (*func) (OJExecutor *);
for(i=0;i<N;i++){
src1[i] = rand()&0xf;
src2[i] = rand()&0xf;
}
func = p->code_exec;
func (ex);
//oj_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);
}
}
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;
}
}
|