Example #1
0
void unroll_this(pTHX_ OP* op) {
    struct sljit_compiler* compiler = sljit_create_compiler();
    HV* seenops = newHV();

#ifdef DEBUG
    if (getenv("RUNOPS_OPTIMIZED_DEBUG")) {
        CV *runcv = Perl_find_runcv(NULL);
        sljit_compiler_verbose(compiler, stderr);

        DEBUGf(("Unroll %s::%s cv=%p, op=%p (%s)\n", HvNAME_get(CvSTASH(runcv)),
                GvENAME(CvGV(runcv)), runcv, op, sljit_get_platform_name()));
    }
#endif

    sljit_emit_enter(compiler, 0, 2, 1, 0);
    unroll_tree(compiler, seenops, op, NULL);
    fixup_jumps(compiler, needjumps, labels);
    // This is needed for things that drop off the runloop without a
    // return, e.g. S_sortcv. TODO: Make conditional?
    sljit_emit_return(compiler, SLJIT_MEM, (sljit_w) &PL_op);

    op->op_ppaddr = sljit_generate_code(compiler);
    op->op_spare = 3;
    DEBUGf(("Code at %p\n", op->op_ppaddr));

    labels = NULL;
    needjumps = NULL;
    SvREFCNT_dec(seenops);
    sljit_free_compiler(compiler);
}
Example #2
0
static int add3(long a, long b, long c)
{
	void *code;
	unsigned long len;
	func3_t func;

	/* Create a SLJIT compiler */
	struct sljit_compiler *C = sljit_create_compiler();

	/* Start a context(function entry), have 3 arguments, discuss later */
	sljit_emit_enter(C, 0,  3,  1, 3, 0, 0, 0);

	/* The first arguments of function is register SLJIT_S0, 2nd, SLJIT_S1, etc.  */
	/* R0 = first */
	sljit_emit_op1(C, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0);

	/* R0 = R0 + second */
	sljit_emit_op2(C, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0);

	/* R0 = R0 + third */
	sljit_emit_op2(C, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0);

	/* This statement mov R0 to RETURN REG and return */
	/* in fact, R0 is RETURN REG itself */
	sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0);

	/* Generate machine code */
	code = sljit_generate_code(C);
	len = sljit_get_generated_code_size(C);

	/* Execute code */
	func = (func3_t)code;
	printf("func return %ld\n", func(a, b, c));

	/* dump_code(code, len); */

	/* Clean up */
	sljit_free_compiler(C);
	sljit_free_code(code);
	return 0;
}