Пример #1
0
int main() { 
	static unsigned insn[1000];
	v_reg_type r;
	struct v_cstate c;
	v_vptr vp;

	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_getreg(&r, V_I, V_TEMP);

	v_push_init(&c);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
	v_seti(r, 10);
	v_push_argi(&c, r);
	v_seti(r,20);
	v_push_argi(&c, r);
	v_seti(r,30);
	v_push_argi(&c, r);
	v_seti(r,40);
	v_push_argi(&c, r);
	v_ccallv(&c, (v_vptr)printf);
	vp = v_end(0).v;
#if 0
	v_dump((void*)vp);
#endif
	vp();

	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_push_init(&c);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
	v_push_argii(&c, 10);
	v_push_argii(&c, 20);
	v_push_argii(&c, 30);
	v_push_argii(&c, 40);
	v_ccallv(&c, (v_vptr)printf);
	vp = v_end(0).v;
#if 0
	v_dump((void*)vp);
#endif
	vp();

#if 0
	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
#endif
	return 0;
}
Пример #2
0
  void
  dumpable_t::dump (dumper_t *d) const
  {
    d->begin_obj (get_obj_name (), static_cast<const void *> (this), 
		  dump_get_lineno());
    v_dump (d);
    d->end_obj ();
  }
Пример #3
0
/* driver */
static void scale(int n, data_t **a, data_t **b, data_t c) {
	struct v_reg  dst,src, src_end, v0, v1, al[10];
	struct v_label  loop1; 
	static unsigned insn[1024];
	v_vptr vp;

	/* simple unroll */
	/* assert(n >= 4 && (n % 4) == 0); */

	v_lambda("foo", "%p%p", al, V_LEAF, insn);

	/* row & c come in as parameters */
	dst 	= al[0];
	src 	= al[1];
	if(!v_getreg(&src_end, V_P, V_TEMP))
		v_fatal("scale: out of registers\n");
	if(!v_getreg(&v0, V_U, V_TEMP))
		v_fatal("scale: out of registers\n");
	if(!v_getreg(&v1, V_U, V_TEMP))
		v_fatal("scale: out of registers\n");

	loop1	= v_genlabel();

	/* relies on contigous memory */
	v_raw_load(v_ldpi(src, src, (0)), 1);	/* perform loads without interlocks */
	v_raw_load(v_ldpi(dst, dst, (0)), 1);
	v_addpi(src_end, src, (n * n) * sizeof **a);

	v_label(loop1);
		/* load 2 to get rid of delay slots */
		v_raw_load(v_ldui(v0, src, (0 * sizeof **a)), 1);
		v_raw_load(v_ldui(v1, src, (1 * sizeof **a)), 1);

		/* multiplies will be strength reduced */
		if(strength_reduce) cmuli(v0, v0, c);
		else		   v_mului(v0, v0, c);

		v_addpi(dst, dst, (2 * sizeof **a));

		if(strength_reduce) cmuli(v1, v1, c);
		else		   v_mului(v1, v1, c);

		v_stui(v0, dst, -(2 * sizeof **a));
		v_addpi(src, src, (2 * sizeof **a));
	/* schedule delay slot instructions */
	v_schedule_delay(
		v_bltp(src, src_end, loop1),
		v_stui(v1, dst, -(1 * sizeof **a))
	);

	vp = v_end().v;
	if(disass)
		v_dump((void *)vp);
	if(!pixie)
		vp(a,b);	/* perform multiplication */
}
Пример #4
0
void e () {
     i_local_t a,b,c,d,e,f,g,h,i,j,k,l;
     int (*ip)(int (*)(int,int),int,int,int,int,int,int,int,int,int);
     
     i_init(100);

     a = i_paramk(I_I,1);
     b = i_paramk(I_I,2);
     c = i_param(I_I);
     d = i_param(I_I);
     e = i_param(I_I);
     g = i_param(I_I);
     h = i_param(I_I);
     i = i_param(I_I);
     j = i_param(I_I);
     k = i_local(0,I_I);
     l = i_local(0,I_I);
     f = i_paramk(I_P,0);

     i_argi(a);
     i_argi(b);
     i_calli(k, f);
     i_argi(c);
     i_argi(d);
     i_calli(d, f);
     i_addi(k,k,d);
     i_argi(e);
     i_argi(g);
     i_calli(g, f);
     i_addi(k,k,g);
     i_argi(h);
     i_argi(i);
     i_calli(i, f);
     i_addi(k,k,i);
     i_addi(k,k,j);
     i_addii(l,k,3);
     i_reti(l);
     i_end();

     i_unparse();
     ip = (int (*)(int (*)(int,int),int,int,int,int,int,int,int,int,int))
	  i_emit().i;
     v_dump((void*)ip);
     printf("**48=%d\n", (*ip)(gg,1,2,3,4,5,6,7,8,9));
}
Пример #5
0
int main(void) {
	static v_code insn[1000]; 	/* Memory to hold code in. */

        /* Test jump and link instruction */
        v_lambda("jump-and-link", "", 0, V_NLEAF, insn, sizeof insn);
        {
                static v_code *linked_addr;
                v_reg_type rdp, rr;
                v_label_type l;

		/* Allocate two registers persistent accross procedure calls. */
                v_getreg(&rdp, V_P, V_VAR);
		/* Allocate register to hold return pointer */
                v_getreg(&rr, V_P, V_VAR);

                l = v_genlabel(); 	  /* Allocate label */
                v_dlabel(&linked_addr, l); /* mark memory to hold target address */
                v_setp(rdp, &linked_addr); /* Load address */
                v_ldpi(rdp, rdp, 0);

                v_scallv((v_vptr)printf, "%P", "Jumping!\n");
                v_jalp(rr, rdp); 	   /* Jump to it. */

                v_scallv((v_vptr)printf, "%P", "Returning!\n");
                v_retv();		/* Done */

                v_label(l);
                        v_scallv((v_vptr)printf, "%P", "Jumping back!\n");
                        v_jp(rr);	/* Jump back to caller. */
        }
        v_end(0).v();
#if 0
{
	v_vptr vp = v_end(0).v;
	v_dump(vp);
	vp();
}
#endif

	return 0;
}
Пример #6
0
void b () {
     i_local_t f;
     i_label_t L1;
     v_pptr pp;
     
     i_init(100);

     L1 = i_mklabel();
     f = i_local(0, I_P);
     i_setp(f, gg);
     i_nop();
     i_nop();
     i_nop();
     i_nop();
     i_retp(f);
     i_end();

     i_unparse();
     pp = i_emit().p;
     v_dump((void*)pp);
     printf("**3=%d\n", (*(int (*)(int, int))((*pp)()))(1,2));
}
Пример #7
0
void d () {
     i_local_t a,b;
     v_iptr ip;
     
     i_init(100);

     a = i_local(0, I_I);
     b = i_local(0, I_I);

     i_seti(a, 1);
     i_seti(b, 2);  
     i_argi(a);
     i_argi(b);
     i_callii(a, gg);
     i_reti(a);
     i_end();

     i_unparse();
     ip = i_emit().i;
     v_dump((void*)ip);
     printf("**3=%d\n", (*ip)());
}
Пример #8
0
int main() { 
	static v_code insn[1000];
	v_iptr ip;

        /* jal reg  */
        v_lambda("v_jal", "", 0, V_NLEAF, insn, sizeof insn);
        {
        	static void * linked_addr;
        	v_reg_type rdp;
        	v_reg_type rr;
		v_label_type l;

		v_getreg(&rdp, V_P, V_VAR);
		v_getreg(&rr, V_P, V_VAR);

                l = v_genlabel();
                v_dmark(&linked_addr, l);

                v_ldpi(rdp, v_zero, (unsigned long)&linked_addr);
		v_scallv((v_vptr)printf, "%P", "Jumping!\n");
                v_jalp(rr, rdp);
		v_scallv((v_vptr)printf, "%P", "Returning.\n");	
               	v_retii(13);

                v_label(l);
			v_scallv((v_vptr)printf, "%P", "Jumping back!\n");
			v_jp(rr);
        }
	printf("Testing jalr\n");
	ip = v_end(0).i;
#if 0
	v_dump((void*)ip);
#endif
        if(ip() != 13)
		demand(0, bogus value!);
	return 0;
}
Пример #9
0
Файл: vm.c Проект: berkus/lang-e
int main() { 
	static unsigned insn[100];
	v_iptr ip;
	v_reg_type arg_list[10];
	v_label_type l;
	unsigned s2u, s1u;

	s1u =  3422929224;
	s2u = 4205332841;

        /* reg <- (reg < imm) */
        v_lambda("bltuli", "%u", arg_list, V_LEAF, insn, sizeof insn);
                l = v_genlabel();
                v_bltui(arg_list[0], s2u, l);
                        v_retii(0);
                v_label(l);
                        v_retii(1);

        ip = v_end(0).i;

	v_dump((void*)ip);
	printf("ip returned %d, should be %d\n", ((int (*)(unsigned))ip)(s1u), s1u < s2u);
	return 0;
}
Пример #10
0
void a () {
     i_local_t a,b,c,d,e,f,g,h,i,j,w,z,func,cnt;
     i_label_t L1;
     v_iptr ip;
     
     i_init(100);

     L1 = i_mklabel();
/*     func = i_local(0, I_P);*/
     cnt = i_local(0, I_P);
     a = i_local(0, I_I);
     b = i_local(0, I_I);
     c = i_local(0, I_I);
     d = i_local(0, I_I);
     e = i_local(0, I_I);
     f = i_local(0, I_I);
     g = i_local(0, I_I);
     h = i_local(0, I_I);
     i = i_local(0, I_I);
     j = i_local(0, I_I);
     z = i_local(0, I_I);
     w = i_local(0, I_I);

/*     i_setp(func, ff);*/
     i_seti(a, 1);
     i_seti(b, 2);
     i_seti(c, 3);
     i_seti(d, 4);
     i_seti(e, 5);
     i_seti(f, 6);
     i_seti(g, 7);
     i_seti(h, 8);
     i_seti(i, 9);
     i_seti(j, 0);
     i_seti(z, 0);
     i_seti(cnt, 0);
     i_label(L1);
     i_argi(a);
     i_argi(b);
     i_argi(c);
     i_argi(d);
     i_argi(e);
     i_argi(f);
     i_argi(g);
     i_argi(h);
     i_argi(i);
     i_argi(j);
     i_callii(w, ff);
     i_addi(z,z,w);
     i_addii(cnt,cnt,1);
     i_bltii(cnt,2,L1);
     i_addi(z, z, a);
     i_addi(z, z, b);
     i_addi(z, z, c);
     i_addi(z, z, d);
     i_addi(z, z, e);
     i_addi(z, z, f);
     i_addi(z, z, g);
     i_addi(z, z, h);
     i_addi(z, z, i);
     i_addi(z, z, j);
     i_reti(z);			/* (9*10/2)*3 = 135 */
     i_end();

     i_unparse();
     ip = i_emit().i;
     v_dump((void*)ip);
     printf("**135=%d\n", (*ip)());
}