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