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

CeriumGrep start
author masa
date Thu, 28 Jan 2016 21:14:34 +0900
parents
children 6640b0d5bf13
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/regexParser/cerium/ppe/Exec.cc	Thu Jan 28 21:14:34 2016 +0900
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <string.h>
+#include "Exec.h"
+#include "Func.h"
+
+/* これは必須 */
+SchedDefineTask1(Exec,blockedGrep);
+
+TSValue stateNothing(TSValue tsv) {
+    return tsv;
+}
+
+TSValue stateSkip(TSValue tsv) {
+    tsv.buff.matchBegin = tsv.buff.buffptr;
+    return tsv;
+}
+
+TSValue stateMatch(TSValue tsv) {
+    ResultPtr r = NEW(Result);
+    r->begin = tsv.buff.matchBegin;
+    r->end = tsv.buff.buffptr;
+    *tsv.resultEnd = r;
+    r->next = NULL;
+    tsv.resultEnd = &r->next;
+    tsv.current = tsv.tg->stateList->tState;
+    tsv.buff.buffptr--;
+    tsv = stateSkip(tsv);
+    return tsv;
+}
+
+TSValue threadedSearch(TransitionGeneratorPtr tg,Buffer buff) {
+    TSValue tsv;
+    tsv.buff = buff;
+    tsv.tg = tg;
+    tsv.result = NULL;
+    tsv.resultEnd = &tsv.result;
+    tsv.current = generateTState(tg->anyState);
+    tsv.tg->stateSkip = stateSkip;
+    tsv.tg->stateMatch = stateMatch;
+    tsv.tg->stateNothing = stateNothing;
+    unsigned char *end = buff.buffend;
+    buff.buffend = buff.buff+1;
+    tSearch(tsv);
+    tsv.blockBegin = tsv.current;
+    buff.buffend = end;
+    tSearch(tsv);
+    tsv.blockEnd = tsv.current;
+    if (tsv.blockEnd->bi.bitContainer != 1) {
+        ResultPtr r = NEW(Result);
+        r->begin = tsv.buff.matchBegin;
+        r->end = NULL;
+        *tsv.resultEnd = r;
+        r->next = NULL;
+        tsv.resultEnd = &r->next;
+    }
+    return tsv;
+}
+
+static int
+blockedGrep(SchedTask *s, void *rbuf, void *wbuf)
+{
+    long task_spwaned = (long)s->get_param(0);
+    long division_size = (long)s->get_param(1);
+    long length = (long)s->get_param(2);
+    long out_size = (long)s->get_param(3);
+    MapReduce *w = (MapReduce*)s->get_param(4);
+    long allocation = task_spwaned + (long)s->x;
+    char* i_data;
+    unsigned long long* o_data;
+    if (division_size) {
+        i_data = (char*)s->get_input(rbuf,0) + allocation*division_size;
+        o_data = (unsigned long long*)s->get_output(wbuf,1) + allocation*out_size;
+    } else {
+        i_data = (char*)s->get_input(0);
+        o_data = (unsigned long long*)s->get_output(0);
+    }
+    TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global;
+    StatePtr startState = tg->anyState;
+    Buffer buff;
+    buff.buff = buff.buffptr = buff.matchBegin = i_data;
+    buff.buffend = buff.buff + division_size;
+    TSValue tsv = threadedSearch(tg,buff);
+    o_data[0] = (void*)tsv.result;
+    o_data[1] = (void*)tsv.blockBegin;
+    o_data[2] = (void*)tsv.blockEnd;
+    return 0;
+}