# HG changeset patch # User Shinji KONO # Date 1259770594 -32400 # Node ID 4470ff271c5afe86488cde73b2ada3ca7d0ee53b # Parent 7405d92733a8b7bb68dcceca5f6ddbbc3e7b7f63 word_count_test diff -r 7405d92733a8 -r 4470ff271c5a TaskManager/Makefile.def --- a/TaskManager/Makefile.def Thu Dec 03 00:20:28 2009 +0900 +++ b/TaskManager/Makefile.def Thu Dec 03 01:16:34 2009 +0900 @@ -32,8 +32,8 @@ # SIMPLE_TASK=-DSIMPLE_TASK SIMPLE_TASK= -# OPT = -O9 -OPT = -g +OPT = -O9 -g +# OPT = -g CC = g++ CFLAGS = $(SIMPLE_TASK) -Wall `sdl-config --cflags` -m$(ABIBIT) $(OPT) diff -r 7405d92733a8 -r 4470ff271c5a example/word_count/Makefile.def --- a/example/word_count/Makefile.def Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count/Makefile.def Thu Dec 03 01:16:34 2009 +0900 @@ -1,14 +1,15 @@ TARGET = word_count # include/library path -# ex: macosx +# ex macosx #CERIUM = /Users/gongo/Source/Cerium -# ex: linux/ps3 +# ex linux/ps3 CERIUM = ../../../Cerium +OPT = -O9 CC = g++ -CFLAGS = -g -Wall -O9 +CFLAGS = -Wall -O9 INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. LIBS = -L${CERIUM}/TaskManager diff -r 7405d92733a8 -r 4470ff271c5a example/word_count/spe/Makefile --- a/example/word_count/spe/Makefile Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count/spe/Makefile Thu Dec 03 01:16:34 2009 +0900 @@ -7,7 +7,7 @@ OBJS = $(SRCS:.cc=.o) CC = spu-g++ -CFLAGS = -g -Wall -fno-exceptions -fno-rtti #-DDEBUG +CFLAGS = -g -Wall -fno-exceptions -fno-rtti $(OPT) #-DDEBUG INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. LIBS = -L../${CERIUM}/TaskManager -lspemanager @@ -23,4 +23,4 @@ clean: rm -f $(TARGET) $(OBJS) - rm -f *~ \#* \ No newline at end of file + rm -f *~ \#* diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/Makefile.def --- a/example/word_count_test/Makefile.def Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count_test/Makefile.def Thu Dec 03 01:16:34 2009 +0900 @@ -7,8 +7,9 @@ # ex linux/ps3 CERIUM = ../../../Cerium +OPT = -O9 CC = g++ -CFLAGS = -g -Wall # -O9 +CFLAGS = -Wall $(OPT) INCLUDE = -I${CERIUM}/include/TaskManager -I. -I.. LIBS = -L${CERIUM}/TaskManager diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/main.cc --- a/example/word_count_test/main.cc Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count_test/main.cc Thu Dec 03 01:16:34 2009 +0900 @@ -128,7 +128,7 @@ } -static int blocks = 16; +static int blocks = 192; static void run_start(TaskManager *manager, char *filename) diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/ppe/Exec.cc --- a/example/word_count_test/ppe/Exec.cc Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count_test/ppe/Exec.cc Thu Dec 03 01:16:34 2009 +0900 @@ -17,22 +17,11 @@ int word_flag = 0; int word_num = 0; int line_num = 0; - int i; + int i = 0; /*文字なら1,スペースか改行なら0*/ head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); - - - /*先頭の文字まで、飛ぶルーチン*/ - for(i = 0; i < length; i++) { - if ((i_data[i] != 0x20) && (i_data[i] != 0x0A)) { - //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); - break; - } - //s->printf("[SPE%d]%c",id,i_data[start_num]); - - line_num += (i_data[i] == 0x0A); - } + word_num -= 1- head_tail_flag[0]; for (; i < length; i++) { diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/spe/Exec.cc --- a/example/word_count_test/spe/Exec.cc Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count_test/spe/Exec.cc Thu Dec 03 01:16:34 2009 +0900 @@ -6,54 +6,34 @@ /* これは必須 */ SchedDefineTask(Exec); -typedef char *cvector __attribute__ ((vector_size (16))); -// typedef char *cvector; - static int run(SchedTask *s, void *rbuf, void *wbuf) { - cvector 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); /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); int length = (long)s->get_param(0); - - static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ; - cvector const space = (cvector)spaces; - static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; - cvector const newline = (cvector)newlines; - int word_flag = 0; int word_num = 0; int line_num = 0; int i = 0; /*文字なら1,スペースか改行なら0*/ - head_tail_flag[0] = (i_data[0] != space[i%4]) && (i_data[0] != newline[i%4]); - - - /*先頭の文字まで、飛ぶルーチン*/ - for(i = 0; i < length; i++) { - if ((i_data[i] != space[i%4]) && (i_data[i] != newline[i%4])) { - //s->printf("[SPE%d] break[%d] %d\n",id,i,i_data[i]); - break; - } - //s->printf("[SPE%d]%c",id,i_data[start_num]); - - line_num += (i_data[i] == newline[i%4]); - } + head_tail_flag[0] = (i_data[0] != 0x20) && (i_data[0] != 0x0A); + word_num -= 1-head_tail_flag[0]; for (; i < length; i++) { //s->printf("[SPE%d]%c",id,i_data[i]); - if (i_data[i] == space[i%4]) { + if (i_data[i] == 0x20) { //s->printf("スペース\n"); word_flag = 1; } - else if (i_data[i] == newline[i%4]) { + else if (i_data[i] == 0x0A) { //s->printf("改行\n"); line_num += 1; word_flag = 1; @@ -69,9 +49,9 @@ word_num += word_flag; /*文字なら1,スペースか改行なら0*/ //printf("last word %c",i_data[i-1]); - head_tail_flag[1] = (i_data[i-1] != space[i%4]) && (i_data[i-1] != newline[i%4]); + head_tail_flag[1] = (i_data[i-1] != 0x20) && (i_data[i-1] != 0x0A); - s->printf("SPU word %d line %d\n",word_num,line_num); + // s->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; diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/spe/Exec.cc.vector --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/word_count_test/spe/Exec.cc.vector Thu Dec 03 01:16:34 2009 +0900 @@ -0,0 +1,65 @@ +#include +#include +#include "Exec.h" +#include "Func.h" + +/* これは必須 */ +SchedDefineTask(Exec); + +// typedef char *cvector __attribute__ ((vector_size (16))); +// vectorize だと結果がよろしくない... +// +typedef char *cvector; + +static int +run(SchedTask *s, void *rbuf, void *wbuf) +{ + cvector i_data = (cvector)s->get_input(rbuf, 0); + char* i_data0 = (char*)s->get_input(rbuf, 0); + unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0); + /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/ + unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1); + int length = (long)s->get_param(0); + + static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ; + cvector const space = (cvector)spaces; + static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a}; + cvector const newline = (cvector)newlines; + + int word_flag = 0; + int word_num = 0; + int line_num = 0; + int i = 0; + + /*文字なら1,スペースか改行なら0*/ + char top = i_data0[0]; + head_tail_flag[0] = ((top != 0x20) && (top != 0x0a)); + word_num -= 1-head_tail_flag[0]; + + for (; i < length; i++) { + if (i_data[i] == space[i%16]) { + //s->printf("スペース\n"); + word_flag = 1; + } else if (i_data[i] == newline[i%16]) { + //s->printf("改行\n"); + line_num += 1; + word_flag = 1; + } else { + word_num += word_flag; + word_flag = 0; + } + } + + word_num += word_flag; + /*文字なら1,スペースか改行なら0*/ + //printf("last word %c",i_data[i-1]); + char end = i_data0[i-1]; + head_tail_flag[1] = ((end != 0x20) && (end != 0x0a)); + + // s->printf("SPU 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; + + return 0; +} diff -r 7405d92733a8 -r 4470ff271c5a example/word_count_test/spe/Makefile --- a/example/word_count_test/spe/Makefile Thu Dec 03 00:20:28 2009 +0900 +++ b/example/word_count_test/spe/Makefile Thu Dec 03 01:16:34 2009 +0900 @@ -7,7 +7,7 @@ OBJS = $(SRCS:.cc=.o) CC = spu-g++ -CFLAGS = -g -Wall -fno-exceptions -fno-rtti -O9 #-DDEBUG +CFLAGS = -Wall -fno-exceptions -fno-rtti $(OPT) #-DDEBUG INCLUDE = -I../${CERIUM}/include/TaskManager -I. -I.. LIBS = -L../${CERIUM}/TaskManager -lspemanager