[Mono-devel-list] [PATCH] Constant folding signed div
Paolo Molaro
lupus at ximian.com
Fri Nov 26 10:19:28 EST 2004
On 11/23/04 Torstensson, Patrik wrote:
> +/* divide cfold helper */
> +MINI_OP(OP_DIV_CFOLD, "op_div_cfold")
I don't like the OP_DIV_CFOLD name. Maybe OP_DIV_POWER2_IMM?
Any better suggestions?
> +reg: OP_DIV_CFOLD (reg, OP_ICONST) {
> + MonoInst *not_signed;
> + int imm = state->right->tree->inst_c0;
> +
> + MONO_NEW_LABEL (s, not_signed);
> +
> + MONO_EMIT_NEW_BIALU_IMM (s, OP_COMPARE_IMM, state->left->reg1, state->left->reg1, 0);
> + MONO_EMIT_NEW_BRANCH_LABEL (s, CEE_BGE, not_signed);
> + if (imm == 1)
> + MONO_EMIT_NEW_BIALU_IMM (s, OP_ADC_IMM, state->left->reg1, state->left->reg1, 1);
> + else
> + MONO_EMIT_NEW_BIALU_IMM (s, OP_ADD_IMM, state->left->reg1, state->left->reg1, (1 << imm) - 1);
> +
> + mono_bblock_add_inst (s->cbb, not_signed);
> +
> + MONO_EMIT_NEW_BIALU_IMM (s, OP_SHR_IMM, state->left->reg1, state->left->reg1, imm);
> + MONO_EMIT_NEW_UNALU (s, OP_MOVE, state->reg1, state->left->reg1);
> +}
This needs to be forced in its own tree, but there is no good way to do it
when the code in cfold.c runs:-(
Maybe it's better to just introduce the OP_DIV_POWER2_IMM opcode
and let the backend code optionally implement it.
Thanks,
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list