665
|
1 #include <stdio.h>
|
|
2 #include <string.h>
|
|
3 #include "Exec.h"
|
|
4 #include "Func.h"
|
|
5
|
|
6 /* これは必須 */
|
|
7 SchedDefineTask(Exec);
|
|
8
|
|
9 // typedef char *cvector __attribute__ ((vector_size (16)));
|
|
10 // vectorize だと結果がよろしくない...
|
|
11 //
|
|
12 typedef char *cvector;
|
|
13
|
|
14 static int
|
|
15 run(SchedTask *s, void *rbuf, void *wbuf)
|
|
16 {
|
|
17 cvector i_data = (cvector)s->get_input(rbuf, 0);
|
|
18 char* i_data0 = (char*)s->get_input(rbuf, 0);
|
|
19 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
|
|
20 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/
|
|
21 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1);
|
|
22 int length = (long)s->get_param(0);
|
|
23
|
|
24 static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ;
|
|
25 cvector const space = (cvector)spaces;
|
|
26 static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
|
|
27 cvector const newline = (cvector)newlines;
|
|
28
|
|
29 int word_flag = 0;
|
|
30 int word_num = 0;
|
|
31 int line_num = 0;
|
|
32 int i = 0;
|
|
33
|
|
34 /*文字なら1,スペースか改行なら0*/
|
|
35 char top = i_data0[0];
|
|
36 head_tail_flag[0] = ((top != 0x20) && (top != 0x0a));
|
|
37 word_num -= 1-head_tail_flag[0];
|
|
38
|
|
39 for (; i < length; i++) {
|
|
40 if (i_data[i] == space[i%16]) {
|
|
41 //s->printf("スペース\n");
|
|
42 word_flag = 1;
|
|
43 } else if (i_data[i] == newline[i%16]) {
|
|
44 //s->printf("改行\n");
|
|
45 line_num += 1;
|
|
46 word_flag = 1;
|
|
47 } else {
|
|
48 word_num += word_flag;
|
|
49 word_flag = 0;
|
|
50 }
|
|
51 }
|
|
52
|
|
53 word_num += word_flag;
|
|
54 /*文字なら1,スペースか改行なら0*/
|
|
55 //printf("last word %c",i_data[i-1]);
|
|
56 char end = i_data0[i-1];
|
|
57 head_tail_flag[1] = ((end != 0x20) && (end != 0x0a));
|
|
58
|
|
59 // s->printf("SPU word %d line %d\n",word_num,line_num);
|
|
60
|
|
61 o_data[0] = (unsigned long long)word_num;
|
|
62 o_data[1] = (unsigned long long)line_num;
|
|
63
|
|
64 return 0;
|
|
65 }
|