Mercurial > hg > Game > Cerium
annotate example/regex/spe/Exec.cc.vector @ 1259:52667b4c31e0 draft
merge
author | Daichi Toma <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 19 Nov 2011 07:41:45 +0900 |
parents | 2abd68a1ac2a |
children |
rev | line source |
---|---|
1198
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #include <stdio.h> |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 #include <string.h> |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 #include "Exec.h" |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 #include "Func.h" |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 /* これは必須 */ |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 SchedDefineTask(Exec); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 typedef char *cvector __attribute__ ((vector_size (16))); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // vectorize だと結果がよろしくない... |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 // |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 // typedef char *cvector; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 static int |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 run(SchedTask *s, void *rbuf, void *wbuf) |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 { |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #ifdef SIMPLE_TASK |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 cvector i_data = (cvector)rbuf; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 char* i_data0 = (char*)rbuf; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 unsigned long long *o_data = (unsigned long long*)wbuf; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 unsigned long long *head_tail_flag = o_data +2; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 int length = s->read_size(); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #else |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 cvector i_data = (cvector)s->get_input(rbuf, 0); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 char* i_data0 = (char*)s->get_input(rbuf, 0); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 int length = (long)s->get_param(0); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 #endif |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 cvector const space = (cvector)spaces; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 cvector const newline = (cvector)newlines; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 int word_flag = 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 int word_num = 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 int line_num = 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 int i = 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 /*文字なら1,スペースか改行なら0*/ |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 char top = i_data0[0]; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 head_tail_flag[0] = ((top != 0x20) && (top != 0x0a)); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 word_num -= 1-head_tail_flag[0]; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 for (; i < length; i++) { |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 if (i_data[i] == space[i%16]) { |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 //s->printf("スペース\n"); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 word_flag = 1; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 } else if (i_data[i] == newline[i%16]) { |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 //s->printf("改行\n"); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 line_num += 1; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 word_flag = 1; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 } else { |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 word_num += word_flag; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 word_flag = 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 } |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 } |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 word_num += word_flag; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 /*文字なら1,スペースか改行なら0*/ |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 //printf("last word %c",i_data[i-1]); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 char end = i_data0[i-1]; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 head_tail_flag[1] = ((end != 0x20) && (end != 0x0a)); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 // s->printf("SPU word %d line %d\n",word_num,line_num); |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 o_data[0] = (unsigned long long)word_num; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 o_data[1] = (unsigned long long)line_num; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 return 0; |
2abd68a1ac2a
add example/regex
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |