Mercurial > hg > Members > kono > Cerium
annotate example/word_count/spe/Exec.cc @ 653:94c6b7ea87c2
vectorize word_count.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Dec 2009 10:39:04 +0900 |
parents | ab866bc8a624 |
children | 6929d888fd69 |
rev | line source |
---|---|
393 | 1 #include <stdio.h> |
2 #include <string.h> | |
3 #include "Exec.h" | |
4 #include "Func.h" | |
5 | |
6 /* これは必須 */ | |
7 SchedDefineTask(Exec); | |
8 | |
653 | 9 // typedef char *cvector __attribute__ ((vector_size (16))); |
10 // | |
11 typedef char *cvector; | |
12 | |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
13 static int |
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
14 run(SchedTask *s, void *rbuf, void *wbuf) |
393 | 15 { |
653 | 16 cvector i_data ; |
17 i_data = (cvector)s->get_input(rbuf, 0); | |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
18 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); |
626
ab866bc8a624
64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
19 int length = (long)s->get_param(0); |
ab866bc8a624
64bit mode compatibility on Cell
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
467
diff
changeset
|
20 int word_flag = (long)s->get_param(1); |
393 | 21 int word_num = 0; |
22 int line_num = 0; | |
23 int i; | |
653 | 24 static char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; |
25 cvector space = (cvector)spaces; | |
26 static char newlines []= {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; | |
27 cvector newline = (cvector)newlines; | |
28 | |
393 | 29 |
30 /*先頭の文字まで、飛ぶルーチン*/ | |
31 for(i = 0; i < length; i++) { | |
653 | 32 if ((i_data[i] != space[i%16]) && (i_data[i] != newline[i%16])) { |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
33 //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); |
393 | 34 break; |
35 } | |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
36 //s->printf("[SPE%d]%c",id,i_data[start_num]); |
393 | 37 word_num += word_flag; |
38 word_flag = 0; | |
653 | 39 line_num += (i_data[i] == newline[i%16]); |
393 | 40 } |
41 | |
42 word_flag = 0; | |
43 | |
653 | 44 for (; i < length; i++) { |
393 | 45 |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
46 //s->printf("[SPE%d]%c",id,i_data[i]); |
393 | 47 |
48 | |
653 | 49 if (i_data[i] == space[i%16]) { |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
50 //s->printf("スペース\n"); |
393 | 51 word_flag = 1; |
52 } | |
53 | |
653 | 54 else if (i_data[i] == newline[i%16]) { |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
55 //s->printf("改行\n"); |
393 | 56 line_num += 1; |
57 word_flag = 1; | |
58 } | |
59 | |
60 else { | |
61 word_num += word_flag; | |
62 word_flag = 0; | |
63 } | |
64 | |
65 } | |
66 | |
67 word_num += word_flag; | |
68 | |
467
44c0bce54dcf
fix all examples. test_render is not working now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
394
diff
changeset
|
69 //s->printf("%d %d\n",word_num,line_num); |
393 | 70 |
71 o_data[0] = (unsigned long long)word_num; | |
72 o_data[1] = (unsigned long long)line_num; | |
73 | |
74 return 0; | |
75 } |