Commit 1d5ecdf0 authored by yb9976's avatar yb9976
Browse files

Implement and use tarval_ornot.

parent 2817c296
......@@ -523,6 +523,16 @@ FIRM_API ir_tarval *tarval_andnot(ir_tarval *a, ir_tarval *b);
*/
FIRM_API ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b);
/**
* Bitwise or not of two integer tarvals.
*
* @param a the first tarval
* @param b the second tarval
*
* @return a | ~b or tarval_bad
*/
FIRM_API ir_tarval *tarval_ornot(ir_tarval *a, ir_tarval *b);
/**
* Bitwise exclusive or of two integer tarvals.
*
......
......@@ -664,9 +664,9 @@ ir_relation ir_get_possible_cmp_relations(const ir_node *left,
ir_tarval *const r_z = br->z;
if (get_mode_arithmetic(mode) == irma_twos_complement) {
/* Compute min/max values of operands. */
ir_tarval *l_max = tarval_andnot(l_z, tarval_andnot(min, l_o));
ir_tarval *l_max = tarval_and(l_z, tarval_ornot(l_o, min));
ir_tarval *l_min = tarval_or(l_o, tarval_and(l_z, min));
ir_tarval *r_max = tarval_andnot(r_z, tarval_andnot(min, r_o));
ir_tarval *r_max = tarval_and(r_z, tarval_ornot(r_o, min));
ir_tarval *r_min = tarval_or(r_o, tarval_and(r_z, min));
if (!(tarval_cmp(l_max, r_min) & ir_relation_greater)) {
......
......@@ -63,6 +63,12 @@ void sc_or(const sc_word *val1, const sc_word *val2, sc_word *buffer)
buffer[counter] = val1[counter] | val2[counter];
}
void sc_ornot(const sc_word *val1, const sc_word *val2, sc_word *buffer)
{
for (unsigned counter = 0; counter < calc_buffer_size; ++counter)
buffer[counter] = val1[counter] | (SC_MASK ^ val2[counter]);
}
void sc_xor(const sc_word *val1, const sc_word *val2, sc_word *buffer)
{
for (unsigned counter = 0; counter<calc_buffer_size; counter++)
......
......@@ -64,6 +64,11 @@ void sc_andnot(const sc_word *value1, const sc_word *value2, sc_word *buffer);
*/
void sc_or(const sc_word *value1, const sc_word *value2, sc_word *buffer);
/**
* buffer = value1 | ~value2
*/
void sc_ornot(const sc_word *value1, const sc_word *value2, sc_word *buffer);
/**
* buffer = value1 ^ value2
*/
......
......@@ -1172,6 +1172,29 @@ ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b)
panic("invalid mode sort");
}
ir_tarval *tarval_ornot(ir_tarval *a, ir_tarval *b)
{
assert(a->mode == b->mode);
switch (get_mode_sort(a->mode)) {
case irms_internal_boolean:
return a == tarval_b_true || b == tarval_b_false ? tarval_b_true : tarval_b_false;
case irms_reference:
case irms_int_number: {
sc_word *buffer = ALLOCAN(sc_word, sc_value_length);
sc_ornot(a->value, b->value, buffer);
return get_tarval(buffer, sc_value_length, a->mode);
}
case irms_auxiliary:
case irms_data:
case irms_float_number:
panic("operation not defined on mode");
}
panic("invalid mode sort");
}
ir_tarval *tarval_eor(ir_tarval *a, ir_tarval *b)
{
assert((a->mode == b->mode));
......
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