void defun(Context *ctx, Cons *cons) { const char *name = cons->str; cons = cons->cdr; Cons *args = cons->car; cons = cons->cdr; Func *func = newFunc(name, args, genCall); func->rtype = VT_INT; ctx->putFunc(func); CodeBuilder cb(ctx, func, false, true); if(cons == NULL) { cb.createIConst(0, 0); func->rtype = VT_BOOLEAN; } else { while(cons != NULL) { func->rtype = codegen(cons, &cb, func->argc); cons = cons->cdr; } } cb.createRet(func->argc); cb.createEnd(); func->code = cb.getCode(); func->codeLength = cb.getCodeLength(); codeopt(ctx, func); }
X86FuncNode* X86Compiler::addFunc(const FuncPrototype& p) { X86FuncNode* func = newFunc(p); if (func == NULL) { setLastError(kErrorNoHeapMemory); return NULL; } ASMJIT_ASSERT(_func == NULL); _func = func; addNode(func); // Add function node. addNode(func->getEntryNode()); // Add function entry. HLNode* cursor = getCursor(); addNode(func->getExitNode()); // Add function exit / epilog marker. addNode(func->getEnd()); // Add function end. setCursor(cursor); return func; }
void addDefaultFuncs(Context *ctx) { ctx->putFunc(newFunc("+" , NULL, genAdd)); ctx->putFunc(newFunc("-" , NULL, genSub)); ctx->putFunc(newFunc("*" , NULL, genMul)); ctx->putFunc(newFunc("/" , NULL, genDiv)); ctx->putFunc(newFunc("mod" , NULL, genMod)); ctx->putFunc(newFunc("<" , NULL, genLT)); ctx->putFunc(newFunc(">" , NULL, genGT)); ctx->putFunc(newFunc("<=", NULL, genLE)); ctx->putFunc(newFunc(">=", NULL, genGE)); ctx->putFunc(newFunc("=", NULL, genEQ)); ctx->putFunc(newFunc("eq", NULL, genEQ)); ctx->putFunc(newFunc("equal", NULL, genEQ)); ctx->putFunc(newFunc("!=", NULL, genNE)); ctx->putFunc(newFunc("if", NULL, genIf)); ctx->putFunc(newFunc("setq", NULL, genSetq)); ctx->putFunc(newFunc("defun", NULL, genDefun)); }
/** Spawn another Object which uses the same parameters but with an updated transformation function*/ KMeansFunctor bind(const std::function<arma::mat (const arma::mat& )> & trans) { KMeansFunctor newFunc(params_, trans); return newFunc; }
void measure_cyclecounter(float mhz) { unsigned int high_s, low_s, high_e, low_e; unsigned int high_s1, low_s1, high_e1, low_e1; unsigned int high_s2, low_s2, high_e2, low_e2; unsigned int high_s3, low_s3, high_e3, low_e3; unsigned int high_s4, low_s4, high_e4, low_e4; unsigned int high_s5, low_s5, high_e5, low_e5; unsigned int high_s6, low_s6, high_e6, low_e6; unsigned int high_s7, low_s7, high_e7, low_e7; unsigned int high_s0, low_s0, high_e0, low_e0; unsigned int passed, t; size_t nbytes; float latency_with_read, latency_no_read; float latency_with_func0; float latency_with_func1; float latency_with_func2; float latency_with_func3; float latency_with_func4; float latency_with_func5; float latency_with_func6; float latency_with_func7; float latency_with_func0_in, taskCreationTime, taskCreationTime2, taskCreationTime3, taskCreationProcess; unsigned int beforeFunction, afterFunction, functionTime, t1, t2, t3, start1, start2, start3, start4, start5, temp; float baseFunctionTime; // warm up all the caches by exercising the functions access_counter(&high_s, &low_s); // read(5, buf, 4); DO_SYSCALL; access_counter(&high_e, &low_e); // now do it for real access_counter(&high_s, &low_s); DO_SYSCALL; access_counter(&high_e, &low_e); latency_with_read = ((float) (low_e - low_s) / mhz); access_counter(&high_s, &low_s); access_counter(&high_e, &low_e); latency_no_read = ((float) (low_e - low_s) / mhz); // now do it for real // access_counter(&high_s0, &low_s0); // passed = procedure_call0(); // access_counter(&high_e0, &low_e0); // latency_with_func0 = ((float) (low_e0 - low_s0) / mhz); // latency_with_func0_in = ((float) (passed - low_s0) / mhz); // now do it for real access_counter(&high_s1, &low_s1); procedure_call1(1); access_counter(&high_e1, &low_e1); latency_with_func1 = ((float) (low_e1 - low_s1) / mhz); // now do it for real access_counter(&high_s2, &low_s2); procedure_call2(1,1); access_counter(&high_e2, &low_e2); latency_with_func2 = ((float) (low_e2 - low_s2) / mhz); // now do it for real access_counter(&high_s3, &low_s3); procedure_call3(1,1,1); access_counter(&high_e3, &low_e3); latency_with_func3 = ((float) (low_e3 - low_s3) / mhz); // now do it for real access_counter(&high_s4, &low_s4); procedure_call4(1,1,1,1); access_counter(&high_e4, &low_e4); latency_with_func4 = ((float) (low_e4 - low_s4) / mhz); // now do it for real access_counter(&high_s5, &low_s5); procedure_call5(1,1,1,1,1); access_counter(&high_e5, &low_e5); latency_with_func5 = ((float) (low_e5 - low_s5) / mhz); // now do it for real access_counter(&high_s6, &low_s6); procedure_call6(1,1,1,1,1,1); access_counter(&high_e6, &low_e6); latency_with_func6 = ((float) (low_e6 - low_s6) / mhz); // now do it for real access_counter(&high_s7, &low_s7); procedure_call7(1,1,1,1,1,1,1); access_counter(&high_e7, &low_e7); latency_with_func7 = ((float) (low_e7 - low_s7) / mhz); access_counter(&t, &beforeFunction); functionTime = newFunc(); access_counter(&t, &afterFunction); baseFunctionTime = ((afterFunction - beforeFunction) - functionTime) / mhz; access_counter(&t1,&start1); pid_t pID= fork(); if (pID == 0) { access_counter(&t2,&start2); // access_counter(&t3,&start3); taskCreationTime = ((float) (start2 - start1) / mhz); taskCreationProcess = taskCreationTime - latency_no_read; } else { access_counter(&t3,&start3); // access_counter(&t3,&start3); taskCreationTime2 = ((float) (start3 - start1) / mhz); taskCreationProcess = taskCreationTime2 - latency_no_read; } if (pID != 0) { pthread_t thread; access_counter(&t1,&start4); int rc = pthread_create(&thread,NULL,procedure_call0,NULL); access_counter(&t2,&start5); taskCreationTime3 = ((float) (start5 - start4) / mhz); printf("%f %f \n", taskCreationProcess, taskCreationTime3 - latency_no_read - (latency_with_func4 - latency_no_read)); pthread_exit(NULL); } }