1598
|
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 #ifdef SIMPLE_TASK
|
|
18 cvector i_data = (cvector)rbuf;
|
|
19 char* i_data0 = (char*)rbuf;
|
|
20 unsigned long long *o_data = (unsigned long long*)wbuf;
|
|
21 unsigned long long *head_tail_flag = o_data +2;
|
|
22 int length = s->read_size();
|
|
23 #else
|
|
24 cvector i_data = (cvector)s->get_input(rbuf, 0);
|
|
25 char* i_data0 = (char*)s->get_input(rbuf, 0);
|
|
26 unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf, 0);
|
|
27 /*担当範囲の先頭、末尾が「改行、スペース」か、「それ以外の文字」かのフラグ*/
|
|
28 unsigned long long *head_tail_flag = (unsigned long long*)s->get_output(wbuf,1);
|
|
29 int length = (long)s->get_param(0);
|
|
30 #endif
|
|
31
|
|
32 static const char spaces[] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20} ;
|
|
33 cvector const space = (cvector)spaces;
|
|
34 static const char newlines[] = {0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
|
|
35 cvector const newline = (cvector)newlines;
|
|
36
|
|
37 int word_flag = 0;
|
|
38 int word_num = 0;
|
|
39 int line_num = 0;
|
|
40 int i = 0;
|
|
41
|
|
42 /*文字なら1,スペースか改行なら0*/
|
|
43 char top = i_data0[0];
|
|
44 head_tail_flag[0] = ((top != 0x20) && (top != 0x0a));
|
|
45 word_num -= 1-head_tail_flag[0];
|
|
46
|
|
47 for (; i < length; i++) {
|
|
48 if (i_data[i] == space[i%16]) {
|
|
49 //s->printf("スペース\n");
|
|
50 word_flag = 1;
|
|
51 } else if (i_data[i] == newline[i%16]) {
|
|
52 //s->printf("改行\n");
|
|
53 line_num += 1;
|
|
54 word_flag = 1;
|
|
55 } else {
|
|
56 word_num += word_flag;
|
|
57 word_flag = 0;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 word_num += word_flag;
|
|
62 /*文字なら1,スペースか改行なら0*/
|
|
63 //printf("last word %c",i_data[i-1]);
|
|
64 char end = i_data0[i-1];
|
|
65 head_tail_flag[1] = ((end != 0x20) && (end != 0x0a));
|
|
66
|
|
67 // s->printf("SPU word %d line %d\n",word_num,line_num);
|
|
68
|
|
69 o_data[0] = (unsigned long long)word_num;
|
|
70 o_data[1] = (unsigned long long)line_num;
|
|
71
|
|
72 return 0;
|
|
73 }
|