comparison regexParser/cerium/ppe/Exec.cc @ 266:e51cac73e42a

CeriumGrep start
author masa
date Thu, 28 Jan 2016 21:14:34 +0900
parents
children 6640b0d5bf13
comparison
equal deleted inserted replaced
265:1e2c12ec25b7 266:e51cac73e42a
1 #include <stdio.h>
2 #include <string.h>
3 #include "Exec.h"
4 #include "Func.h"
5
6 /* これは必須 */
7 SchedDefineTask1(Exec,blockedGrep);
8
9 TSValue stateNothing(TSValue tsv) {
10 return tsv;
11 }
12
13 TSValue stateSkip(TSValue tsv) {
14 tsv.buff.matchBegin = tsv.buff.buffptr;
15 return tsv;
16 }
17
18 TSValue stateMatch(TSValue tsv) {
19 ResultPtr r = NEW(Result);
20 r->begin = tsv.buff.matchBegin;
21 r->end = tsv.buff.buffptr;
22 *tsv.resultEnd = r;
23 r->next = NULL;
24 tsv.resultEnd = &r->next;
25 tsv.current = tsv.tg->stateList->tState;
26 tsv.buff.buffptr--;
27 tsv = stateSkip(tsv);
28 return tsv;
29 }
30
31 TSValue threadedSearch(TransitionGeneratorPtr tg,Buffer buff) {
32 TSValue tsv;
33 tsv.buff = buff;
34 tsv.tg = tg;
35 tsv.result = NULL;
36 tsv.resultEnd = &tsv.result;
37 tsv.current = generateTState(tg->anyState);
38 tsv.tg->stateSkip = stateSkip;
39 tsv.tg->stateMatch = stateMatch;
40 tsv.tg->stateNothing = stateNothing;
41 unsigned char *end = buff.buffend;
42 buff.buffend = buff.buff+1;
43 tSearch(tsv);
44 tsv.blockBegin = tsv.current;
45 buff.buffend = end;
46 tSearch(tsv);
47 tsv.blockEnd = tsv.current;
48 if (tsv.blockEnd->bi.bitContainer != 1) {
49 ResultPtr r = NEW(Result);
50 r->begin = tsv.buff.matchBegin;
51 r->end = NULL;
52 *tsv.resultEnd = r;
53 r->next = NULL;
54 tsv.resultEnd = &r->next;
55 }
56 return tsv;
57 }
58
59 static int
60 blockedGrep(SchedTask *s, void *rbuf, void *wbuf)
61 {
62 long task_spwaned = (long)s->get_param(0);
63 long division_size = (long)s->get_param(1);
64 long length = (long)s->get_param(2);
65 long out_size = (long)s->get_param(3);
66 MapReduce *w = (MapReduce*)s->get_param(4);
67 long allocation = task_spwaned + (long)s->x;
68 char* i_data;
69 unsigned long long* o_data;
70 if (division_size) {
71 i_data = (char*)s->get_input(rbuf,0) + allocation*division_size;
72 o_data = (unsigned long long*)s->get_output(wbuf,1) + allocation*out_size;
73 } else {
74 i_data = (char*)s->get_input(0);
75 o_data = (unsigned long long*)s->get_output(0);
76 }
77 TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global;
78 StatePtr startState = tg->anyState;
79 Buffer buff;
80 buff.buff = buff.buffptr = buff.matchBegin = i_data;
81 buff.buffend = buff.buff + division_size;
82 TSValue tsv = threadedSearch(tg,buff);
83 o_data[0] = (void*)tsv.result;
84 o_data[1] = (void*)tsv.blockBegin;
85 o_data[2] = (void*)tsv.blockEnd;
86 return 0;
87 }