Commit be10d142 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

be: Factorise code to extract 32 bits from a tarval.

parent f6005c76
......@@ -813,3 +813,13 @@ void be_get_allocatable_regs(ir_graph const *const irg,
rbitset_set(raw_bitset, i);
}
}
uint32_t be_get_tv_bits32(ir_tarval *const tv, unsigned const offset)
{
uint32_t val;
val = (uint32_t)get_tarval_sub_bits(tv, offset);
val |= (uint32_t)get_tarval_sub_bits(tv, offset + 1) << 8;
val |= (uint32_t)get_tarval_sub_bits(tv, offset + 2) << 16;
val |= (uint32_t)get_tarval_sub_bits(tv, offset + 3) << 24;
return val;
}
......@@ -143,4 +143,6 @@ void be_free_stackorder(be_stackorder_t *env);
*/
void be_add_parameter_entity_stores(ir_graph *irg);
uint32_t be_get_tv_bits32(ir_tarval *tv, unsigned offset);
#endif
......@@ -209,10 +209,7 @@ static bool is_simple_sse_Const(ir_node *node)
return true;
#ifdef CONSTRUCT_SSE_CONST
if (mode == ia32_mode_float64) {
unsigned val = get_tarval_sub_bits(tv, 0) |
(get_tarval_sub_bits(tv, 1) << 8) |
(get_tarval_sub_bits(tv, 2) << 16) |
(get_tarval_sub_bits(tv, 3) << 24);
unsigned const val = be_get_tv_bits32(tv, 0);
if (val == 0)
/* lower 32bit are zero, really a 32bit constant */
return true;
......@@ -374,10 +371,7 @@ static ir_node *gen_Const(ir_node *node)
#endif /* CONSTRUCT_SSE_CONST */
} else if (mode == ia32_mode_float32) {
/* we can place any 32bit constant by using a movd gp, sse */
unsigned val = get_tarval_sub_bits(tv, 0) |
(get_tarval_sub_bits(tv, 1) << 8) |
(get_tarval_sub_bits(tv, 2) << 16) |
(get_tarval_sub_bits(tv, 3) << 24);
unsigned const val = be_get_tv_bits32(tv, 0);
ir_node *cnst = new_bd_ia32_Const(dbgi, block, NULL, 0, val);
load = new_bd_ia32_xMovd(dbgi, block, cnst);
set_ia32_ls_mode(load, mode);
......@@ -385,19 +379,12 @@ static ir_node *gen_Const(ir_node *node)
} else {
#ifdef CONSTRUCT_SSE_CONST
if (mode == ia32_mode_float64) {
unsigned val = get_tarval_sub_bits(tv, 0) |
(get_tarval_sub_bits(tv, 1) << 8) |
(get_tarval_sub_bits(tv, 2) << 16) |
(get_tarval_sub_bits(tv, 3) << 24);
if (val == 0) {
if (be_get_tv_bits32(tv, 0) == 0) {
ir_node *imm32 = ia32_create_Immediate(irg, 32);
ir_node *cnst, *psllq;
/* fine, lower 32bit are zero, produce 32bit value */
val = get_tarval_sub_bits(tv, 4) |
(get_tarval_sub_bits(tv, 5) << 8) |
(get_tarval_sub_bits(tv, 6) << 16) |
(get_tarval_sub_bits(tv, 7) << 24);
unsigned const val = be_get_tv_bits32(tv, 4);
cnst = new_bd_ia32_Const(dbgi, block, NULL, 0, val);
load = new_bd_ia32_xMovd(dbgi, block, cnst);
set_ia32_ls_mode(load, mode);
......@@ -2772,10 +2759,7 @@ static ir_node *gen_float_const_Store(ir_node *node, ir_node *cns)
unsigned delta;
ir_mode *mode;
if (size >= 4) {
val= (unsigned)get_tarval_sub_bits(tv, ofs) |
((unsigned)get_tarval_sub_bits(tv, ofs + 1) << 8) |
((unsigned)get_tarval_sub_bits(tv, ofs + 2) << 16) |
((unsigned)get_tarval_sub_bits(tv, ofs + 3) << 24);
val = be_get_tv_bits32(tv, ofs);
delta = 4;
mode = ia32_mode_gp;
} else if (size >= 2) {
......
......@@ -1929,16 +1929,10 @@ static void bitcast_float_to_int(dbg_info *dbgi, ir_node *block,
int bits = get_mode_size_bits(float_mode);
if (is_Const(value)) {
ir_tarval *tv = get_Const_tarval(value);
int32_t val = get_tarval_sub_bits(tv, 0) |
(get_tarval_sub_bits(tv, 1) << 8) |
(get_tarval_sub_bits(tv, 2) << 16) |
(get_tarval_sub_bits(tv, 3) << 24);
int32_t const val = be_get_tv_bits32(tv, 0);
ir_node *valc = create_int_const(block, val);
if (bits == 64) {
int32_t val2 = get_tarval_sub_bits(tv, 4) |
(get_tarval_sub_bits(tv, 5) << 8) |
(get_tarval_sub_bits(tv, 6) << 16) |
(get_tarval_sub_bits(tv, 7) << 24);
int32_t const val2 = be_get_tv_bits32(tv, 4);
ir_node *valc2 = create_int_const(block, val2);
result[0] = valc2;
result[1] = valc;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment