Mercurial > hg > Members > kono > Cerium
diff example/word_count/spe/Exec.cc @ 666:4615489c5faa
simplify word_count
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 03 Dec 2009 02:11:31 +0900 |
parents | 8a807e2f64f8 |
children | ccf78a465459 |
line wrap: on
line diff
--- a/example/word_count/spe/Exec.cc Thu Dec 03 01:16:34 2009 +0900 +++ b/example/word_count/spe/Exec.cc Thu Dec 03 02:11:31 2009 +0900 @@ -6,66 +6,45 @@ /* これは必須 */ SchedDefineTask(Exec); -// typedef char *cvector __attribute__ ((vector_size (16))); -typedef char *cvector; - static int run(SchedTask *s, void *rbuf, void *wbuf) { - cvector i_data ; - i_data = (cvector)s->get_input(rbuf, 0); + char *i_data = (char*)s->get_input(rbuf, 0); unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); - int length = (long)s->get_param(0); - int word_flag = (long)s->get_param(1); + long length = (long)s->get_param(0); + long word_flag = 1-(long)s->get_param(1); int word_num = 0; int line_num = 0; - int i; - static char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20}; - cvector space = (cvector)spaces; - static char newlines []= {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; - cvector newline = (cvector)newlines; - + int i ; - /*先頭の文字まで、飛ぶルーチン*/ - for(i = 0; i < length; i++) { - if ((i_data[i] != space[i%16]) && (i_data[i] != newline[i%16])) { - //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); - break; - } - //s->printf("[SPE%d]%c",id,i_data[start_num]); - word_num += word_flag; - word_flag = 0; - line_num += (i_data[i] == newline[i%16]); - } + word_num -= word_flag; - word_flag = 0; - - for (; i < length; i++) { + for (i=0; i < length; i++) { //s->printf("[SPE%d]%c",id,i_data[i]); + if((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { + //s->printf("文字 数 = %d\n", word_num + word_flag); + word_num += word_flag; + word_flag = 0; + } - if (i_data[i] == space[i%16]) { - //s->printf("スペース\n"); + if (i_data[i] == 0x20) { + //printf("スペース\n"); word_flag = 1; } - else if (i_data[i] == newline[i%16]) { - //s->printf("改行\n"); + if (i_data[i] == 0x0A) { + //printf("改行\n"); line_num += 1; word_flag = 1; } - else { - word_num += word_flag; - word_flag = 0; - } - } word_num += word_flag; - //s->printf("%d %d\n",word_num,line_num); + // printf("PPE word %d line %d\n",word_num,line_num); o_data[0] = (unsigned long long)word_num; o_data[1] = (unsigned long long)line_num;