summaryrefslogtreecommitdiffhomepage
path: root/ir/be/mips
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2017-01-22 16:06:59 +0100
committerChristoph Mallon <christoph.mallon@gmx.de>2017-01-22 16:18:25 +0100
commit00a041acd751a105d8f97d1054c1b68b0b620dd7 (patch)
tree7007909763cc3202c9568bb3f30cb03c3f06a5a2 /ir/be/mips
parentb4d418261cbf8ec17de07549e65e4b0359141b32 (diff)
mips: Factor out code to sign/zero extend values.
Diffstat (limited to 'ir/be/mips')
-rw-r--r--ir/be/mips/mips_transform.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/ir/be/mips/mips_transform.c b/ir/be/mips/mips_transform.c
index 6ae0d19..6d401de 100644
--- a/ir/be/mips/mips_transform.c
+++ b/ir/be/mips/mips_transform.c
@@ -123,6 +123,26 @@ static ir_node *make_address(ir_node const *const node, ir_entity *const ent, in
return new_bd_mips_addiu(dbgi, block, lui, ent, val);
}
+static ir_node *make_extension(dbg_info *const dbgi, ir_node *const op, unsigned const to_size)
+{
+ ir_node *const new_op = be_transform_node(op);
+ ir_mode *const op_mode = get_irn_mode(op);
+ unsigned const op_size = get_mode_size_bits(op_mode);
+ if (op_size >= to_size)
+ return new_op;
+
+ assert(op_size <= 16);
+ ir_node *const block = get_nodes_block(new_op);
+ if (mode_is_signed(op_mode)) {
+ int32_t const val = MIPS_MACHINE_SIZE - op_size;
+ ir_node *const sll = new_bd_mips_sll(dbgi, block, new_op, NULL, val);
+ ir_node *const sra = new_bd_mips_sra(dbgi, block, sll, NULL, val);
+ return sra;
+ } else {
+ return new_bd_mips_andi(dbgi, block, new_op, NULL, (1U << op_size) - 1);
+ }
+}
+
static void mips_parse_constraint_letter(void const *const env, be_asm_constraint_t* const c, char const l)
{
(void)env;
@@ -597,21 +617,8 @@ static ir_node *gen_Conv(ir_node *const node)
ir_mode *const op_mode = get_irn_mode(op);
ir_mode *const mode = get_irn_mode(node);
if (be_mode_needs_gp_reg(op_mode) && be_mode_needs_gp_reg(mode)) {
- ir_node *const new_op = be_transform_node(op);
- unsigned const op_size = get_mode_size_bits(op_mode);
- if (op_size >= get_mode_size_bits(mode))
- return new_op;
- assert(op_size <= 16);
- dbg_info *const dbgi = get_irn_dbg_info(node);
- ir_node *const block = be_transform_nodes_block(node);
- if (mode_is_signed(op_mode)) {
- int32_t const val = MIPS_MACHINE_SIZE - op_size;
- ir_node *const sll = new_bd_mips_sll(dbgi, block, new_op, NULL, val);
- ir_node *const sra = new_bd_mips_sra(dbgi, block, sll, NULL, val);
- return sra;
- } else {
- return new_bd_mips_andi(dbgi, block, new_op, NULL, (1U << op_size) - 1);
- }
+ dbg_info *const dbgi = get_irn_dbg_info(node);
+ return make_extension(dbgi, op, get_mode_size_bits(mode));
}
TODO(node);
}