Mercurial > hg > Game > Cerium
annotate example/word_count_test/spe/Exec.cc @ 664:beb0f17c19f9 draft
word count
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 00:20:28 +0900 |
parents | ad4b6b556483 |
children | 77d9e3bc25b2 |
rev | line source |
---|---|
658 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 | |
6 /* これは必須 */ | |
7 SchedDefineTask(Exec); | |
8 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
9 typedef char *cvector __attribute__ ((vector_size (16))); |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
10 // typedef char *cvector; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
11 |
658 | 12 static int |
13 run(SchedTask *s, void *rbuf, void *wbuf) | |
14 { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
15 cvector i_data = (cvector)s->get_input(rbuf, 0); |
658 | 16 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
17 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ | |
18 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); | |
19 int length = (long)s->get_param(0); | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
20 |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
21 static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
22 cvector const space = (cvector)spaces; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
23 static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
24 cvector const newline = (cvector)newlines; |
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
25 |
658 | 26 int word_flag = 0; |
27 int word_num = 0; | |
28 int line_num = 0; | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
29 int i = 0; |
658 | 30 |
31 /*文字なら1,スペースか改行なら0*/ | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
32 head_tail_flag[0] = (i_data[0] != space[i%4]) && (i_data[0] != newline[i%4]); |
658 | 33 |
34 | |
35 /*先頭の文字まで、飛ぶルーチン*/ | |
36 for(i = 0; i < length; i++) { | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
37 if ((i_data[i] != space[i%4]) && (i_data[i] != newline[i%4])) { |
658 | 38 //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); |
39 break; | |
40 } | |
41 //s->printf("[SPE%d]%c",id,i_data[start_num]); | |
42 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
43 line_num += (i_data[i] == newline[i%4]); |
658 | 44 } |
45 | |
46 for (; i < length; i++) { | |
47 | |
48 //s->printf("[SPE%d]%c",id,i_data[i]); | |
49 | |
50 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
51 if (i_data[i] == space[i%4]) { |
658 | 52 //s->printf("スペース\n"); |
53 word_flag = 1; | |
54 } | |
55 | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
56 else if (i_data[i] == newline[i%4]) { |
658 | 57 //s->printf("改行\n"); |
58 line_num += 1; | |
59 word_flag = 1; | |
60 } | |
61 | |
62 else { | |
63 word_num += word_flag; | |
64 word_flag = 0; | |
65 } | |
66 | |
67 } | |
68 | |
69 word_num += word_flag; | |
70 /*文字なら1,スペースか改行なら0*/ | |
71 //printf("last word %c",i_data[i-1]); | |
663
ad4b6b556483
incremental task creation on word count_test
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
658
diff
changeset
|
72 head_tail_flag[1] = (i_data[i-1] != space[i%4]) && (i_data[i-1] != newline[i%4]); |
658 | 73 |
664 | 74 s->printf("SPU word %d line %d\n",word_num,line_num); |
658 | 75 |
76 o_data[0] = (unsigned long long)word_num; | |
77 o_data[1] = (unsigned long long)line_num; | |
78 | |
79 return 0; | |
80 } |