Example #1
0
void generate_RETURN(quad *q){
	SymbolTableEntry *f;
	instruction * t = (instruction *) malloc (sizeof(instruction));
	q->taddress = NEXTINSTRUCTIONLABEL;
	t->srcLine= q->line;
	t->opcode = assign_v;
	if(q->result) make_operand(q->result, &(t->arg1));
	make_retvaloperand(&(t->result));
	emit_t(t);

	f = top_func(funcStack);
	LIST_INSERT(f->returnList, LABELSTATEMENT(NEXTINSTRUCTIONLABEL), returnElem, ADD_2_BACK);

	t = (instruction *) malloc (sizeof(instruction));
	t->opcode = jump_v;
	RESET_OPERAND(&(t->arg1));
	RESET_OPERAND(&(t->arg2));
	t->result.type = label_a;
	emit_t(t);
}
Example #2
0
void generate_RETURN(quad *q)
{
	q->taddress = nextinstructionlabel();
	instruction t1, t2;
	init_instruction(&t1);
	init_instruction(&t2);
	
	t1.srcLine = q->line;
	t1.opcode = assign_v;
	make_retvaloperand(t1.result);
	make_operand(q->arg1, t1.arg1);
	emit_icode(t1);

	SymbolTableEntry *f = top_func(funcstack);
	append(f->returnList, nextinstructionlabel());

	t2.opcode = jump_v;
	t2.srcLine = q->line;

	t2.result->type = label_a;
	emit_icode(t2);
}
Example #3
0
int
main ()
{
  top_func ();
  return 0;
}
Func opticalFlow_estimate (Func stBasis, uint8_t nAngle, uint8_t * orders, \
                           Expr filterthreshold, Expr divisionthreshold,\
                           Expr divisionthreshold2) {
// This function estimates components of optical flow fields as well as its speed and direction of movement
// basis: from spatio-temporal filters, angle: number of considered angles
    // orders: x (spatial index), y ( spatial index ), t (time index) and s ?
// ColorMgather function in MATLAB
// Pipeline:
// 1. Compute oriented filter basis at a particular angle
// {
//     basis -> X
//           -> Y
//           -> T
//           -> Xrg
//           -> Yrg
//           -> Trg
//           -> Xk
//           -> Yk
//           -> Tk
// }
    // Expr M0,M1,M2,M3,temp_a,temp_b,Tkd;
    // Expr M0 = cast<float>(0.0f);
    // Expr M1 = cast<float>(0.0f);
    // Expr M2 = cast<float>(0.0f);
    // Expr M3 = cast<float>(0.0f);
    // Expr temp_a = cast<float>(0.0f);
    // Expr temp_b = cast<float>(0.0f);
    // Expr Tkd = cast<float>(0.0f);

    // Expr D0 = cast<float>(0.0f);
    // Expr D1 = cast<float>(0.0f);
    // Expr D2 = cast<float>(0.0f);
    // Expr D3 = cast<float>(0.0f);
    // Expr N0 = cast<float>(0.0f);
    // Expr N1 = cast<float>(0.0f);
    // Expr N2 = cast<float>(0.0f);
    // Expr N3 = cast<float>(0.0f);
    // Expr A0 = cast<float>(0.0f);
    // Expr A1 = cast<float>(0.0f);
    // Expr A2 = cast<float>(0.0f);
    // Expr A3 = cast<float>(0.0f);
    Func Tkd;
    Func fA0; fA0(x,y,t) = Expr(0.0f);
    Func fA1; fA1(x,y,t) = Expr(0.0f);
    Func fA2; fA2(x,y,t) = Expr(0.0f);
    Func fA3; fA3(x,y,t) = Expr(0.0f);
    Func fD0; fD0(x,y,t) = Expr(0.0f);
    Func fD1; fD1(x,y,t) = Expr(0.0f);
    Func fD2; fD2(x,y,t) = Expr(0.0f);
    Func fD3; fD3(x,y,t) = Expr(0.0f);
    Func fN0; fN0(x,y,t) = Expr(0.0f);
    Func fN1; fN1(x,y,t) = Expr(0.0f);
    Func fN2; fN2(x,y,t) = Expr(0.0f);
    Func fN3; fN3(x,y,t) = Expr(0.0f);

    // std::vector<Expr> basisAtAngleExpr(5,cast<float>(0.0f));
    // Tuple basisAtAngle = Tuple(basisAtAngleExpr);
    Func basisAtAngle[nAngle/2];

// Compute spatial-temporal basis
    for (int iA = 0; iA <= nAngle / 2 - 1; iA++) {
        float aAngle = 2*iA*M_PI/nAngle;
        basisAtAngle[iA] = ColorMgather(stBasis, aAngle, orders, filterthreshold,
                                        divisionthreshold, divisionthreshold2);
        basisAtAngle[iA].compute_root();

        Expr M0,M1,M2,M3;
        M0 = basisAtAngle[iA](x,y,t)[0]; M1 = basisAtAngle[iA](x,y,t)[1];
        M2 = basisAtAngle[iA](x,y,t)[2]; M3 = basisAtAngle[iA](x,y,t)[3];

        fD0(x,y,t) += M0 * M0;
        fD1(x,y,t) += M0 * M2;
        fD2(x,y,t) += M2 * M0;
        fD3(x,y,t) += M2 * M2;
        fN0(x,y,t) += M1 * M0;
        fN1(x,y,t) += M1 * M2;
        fN2(x,y,t) += M3 * M0;
        fN3(x,y,t) += M3 * M2;
        // temp_a = abs(M0) * M1;
        // temp_b = abs(M2) * M3;
        Expr cosaAngle((float) cos(aAngle));
        Expr sinaAngle((float) sin(aAngle));
        // A0  += temp_a  * cosaAngle;
        // A1  += temp_b  * sinaAngle;
        // A2  += temp_a  * sinaAngle;
        // A3  += temp_b  * cosaAngle;
        // fA0(x,y,c,t) += abs(M0) * M1 * cosaAngle;
        fA0(x,y,t) += abs(M0) * M1 * cosaAngle;
        fA1(x,y,t) += abs(M2) * M3 * sinaAngle;
        fA2(x,y,t) += abs(M0) * M1 * sinaAngle;
        fA3(x,y,t) += abs(M2) * M3 * cosaAngle;
    }

    Tkd(x,y,t) = basisAtAngle[nAngle/2-1](x,y,t)[4];
    // return basisAtAngle[0]; // 4 debug
    // // Schedule basis
    // for (int iA = 0; iA <= nAngle / 2 - 1; iA++) {
    //     fD0.update(iA);
    //     fD1.update(iA);
    //     fD2.update(iA);
    //     fD3.update(iA);
    //     fN0.update(iA);
    //     fN1.update(iA);
    //     fN2.update(iA);
    //     fN3.update(iA);
    //     fA0.update(iA);
    //     fA1.update(iA);
    //     fA2.update(iA);
    //     fA3.update(iA);
    // }

    fD0.compute_root();
    fD1.compute_root();
    fD2.compute_root();
    fD3.compute_root();
    fN0.compute_root();
    fN1.compute_root();
    fN2.compute_root();
    fN3.compute_root();
    fA0.compute_root();
    fA1.compute_root();
    fA2.compute_root();
    fA3.compute_root();
    Tkd.compute_root();

    Func top_func;
    Func bottom_func;
    Expr speed0;
    Expr speed1;

// Polar fig ?
    top_func(x,y,t) = fN0(x,y,t) * fN3(x,y,t) - fN1(x,y,t) * fN2(x,y,t);
    top_func.compute_root();
    bottom_func(x,y,t) = fD0(x,y,t)  * fD3(x,y,t)  - fD1(x,y,t)  * fD2(x,y,t);
    bottom_func.compute_root();

    speed0 = sqrt(sqrt(abs(Mdefdiv(top_func(x,y,t) , bottom_func(x,y,t), Expr(0.0f)))));
    speed1 = Manglecalc(fA0(x,y,t) , fA1(x,y,t) , fA2(x,y,t) , fA3(x,y,t));
// Display the results ?
    speed0 = select(abs(Tkd(x,y,t)) > filterthreshold,speed0,Expr(0.0f));
    speed1 = select(abs(Tkd(x,y,t)) > filterthreshold,speed1,Expr(0.0f));

    Func speed("speed"); speed(x,y,t) = Tuple(speed0,speed1);
    return speed;

//Bimg = [T0n speed0 speed1] ?
//    Func img = outputvelocity(T0n,Func(speed0),Func(speed1),16, speedthreshold, filterthreshold);
}