Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
206f8441
Commit
206f8441
authored
Feb 13, 2016
by
Matthias Braun
Browse files
Rename is_po2() to is_po2_or_zero()
The function also returns true for zero even though that is not a power of two.
parent
8c9e32f4
Changes
9
Hide whitespace changes
Inline
Side-by-side
ir/adt/bitfiddle.h
View file @
206f8441
...
...
@@ -158,9 +158,9 @@ static inline uint32_t ceil_po2(uint32_t x)
}
/**
*
Tests whether @
p x is a power of
2
*
Returns true if \
p x is a power of
two or zero.
*/
static
inline
bool
is_po2
(
unsigned
x
)
static
inline
bool
is_po2
_or_zero
(
unsigned
x
)
{
return
(
x
&
(
x
-
1
))
==
0
;
}
...
...
ir/ana/dca.c
View file @
206f8441
...
...
@@ -82,7 +82,7 @@ static ir_tarval *create_modulo_shift_mask(ir_mode *mode, ir_mode *dest_mode)
if
(
modulo_shift
==
0
)
return
NULL
;
assert
(
is_po2
(
modulo_shift
));
assert
(
is_po2
_or_zero
(
modulo_shift
));
return
new_tarval_from_long
(
modulo_shift
-
1
,
dest_mode
);
}
...
...
ir/be/begnuas.c
View file @
206f8441
...
...
@@ -1500,7 +1500,7 @@ static void emit_global(be_main_env_t const *const main_env,
/* alignment */
unsigned
alignment
=
get_effective_entity_alignment
(
entity
);
if
(
!
is_po2
(
alignment
))
if
(
!
is_po2
_or_zero
(
alignment
))
panic
(
"alignment not a power of 2"
);
if
(
alignment
>
1
)
{
emit_align
(
alignment
);
...
...
ir/be/beprefalloc.c
View file @
206f8441
...
...
@@ -1085,7 +1085,7 @@ static void solve_lpp(ir_nodeset_t *live_nodes, ir_node *node,
static
bool
is_aligned
(
unsigned
num
,
unsigned
alignment
)
{
unsigned
mask
=
alignment
-
1
;
assert
(
is_po2
(
alignment
));
assert
(
is_po2
_or_zero
(
alignment
));
return
(
num
&
mask
)
==
0
;
}
...
...
ir/be/bespillutil.c
View file @
206f8441
...
...
@@ -929,7 +929,7 @@ static void assure_different_constraints(ir_node *irn, ir_node *skipped_irn, con
if
(
req
->
should_be_same
!=
0
)
{
const
unsigned
same
=
req
->
should_be_same
;
if
(
is_po2
(
other
)
&&
is_po2
(
same
))
{
if
(
is_po2
_or_zero
(
other
)
&&
is_po2
_or_zero
(
same
))
{
int
idx_other
=
ntz
(
other
);
int
idx_same
=
ntz
(
same
);
...
...
ir/lower/lower_dw.c
View file @
206f8441
...
...
@@ -783,7 +783,7 @@ static void lower_shr_helper(ir_node *node, ir_mode *mode,
||
modulo_shift2
<<
1
!=
modulo_shift
)
{
panic
(
"Shr lowering only implemented for modulo shift shr operations"
);
}
if
(
!
is_po2
(
modulo_shift
)
||
!
is_po2
(
modulo_shift2
))
{
if
(
!
is_po2
_or_zero
(
modulo_shift
)
||
!
is_po2
_or_zero
(
modulo_shift2
))
{
panic
(
"Shr lowering only implemented for power-of-2 modes"
);
}
/* without 2-complement the -x instead of (bit_width-x) trick won't work */
...
...
@@ -899,7 +899,7 @@ static void lower_Shl(ir_node *node, ir_mode *mode)
||
modulo_shift2
<<
1
!=
modulo_shift
)
{
panic
(
"Shl lowering only implemented for modulo shift shl operations"
);
}
if
(
!
is_po2
(
modulo_shift
)
||
!
is_po2
(
modulo_shift2
))
{
if
(
!
is_po2
_or_zero
(
modulo_shift
)
||
!
is_po2
_or_zero
(
modulo_shift2
))
{
panic
(
"Shl lowering only implemented for power-of-2 modes"
);
}
/* without 2-complement the -x instead of (bit_width-x) trick won't work */
...
...
ir/opt/iropt.c
View file @
206f8441
...
...
@@ -5862,7 +5862,7 @@ static ir_node *transform_node_shift(ir_node *n)
assert
(
get_mode_arithmetic
(
count_mode
)
==
irma_twos_complement
);
/* modulo shifts should always be a power of 2 (otherwise modulo_mask
* above will be invalid) */
assert
(
is_po2
(
modulo_shf
));
assert
(
is_po2
_or_zero
(
modulo_shf
));
tv1
=
tarval_and
(
tv1
,
modulo_mask
);
tv2
=
tarval_and
(
tv2
,
modulo_mask
);
...
...
@@ -6014,7 +6014,7 @@ static ir_node *transform_node_shift_modulo(ir_node *n,
return
n
;
if
(
get_mode_arithmetic
(
mode
)
!=
irma_twos_complement
)
return
n
;
if
(
!
is_po2
(
modulo
))
if
(
!
is_po2
_or_zero
(
modulo
))
return
n
;
ir_graph
*
irg
=
get_irn_irg
(
n
);
...
...
@@ -6091,7 +6091,7 @@ static ir_node *transform_node_shift_and(ir_node *n, new_shift_func new_shift)
if
(
!
is_And
(
amount
))
return
n
;
assert
(
is_po2
(
modulo_shift
));
assert
(
is_po2
_or_zero
(
modulo_shift
));
ir_mode
*
amount_mode
=
get_irn_mode
(
amount
);
ir_tarval
*
all_one
=
get_mode_all_one
(
amount_mode
);
unsigned
shift
=
get_mode_size_bits
(
amount_mode
)
...
...
ir/opt/ldstopt.c
View file @
206f8441
...
...
@@ -2120,7 +2120,7 @@ again:;
if
(
get_mode_arithmetic
(
store_mode
)
!=
irma_twos_complement
)
continue
;
unsigned
store_size
=
get_mode_size_bits
(
store_mode
);
if
(
store_size
>=
machine_size
||
!
is_po2
(
store_size
))
if
(
store_size
>=
machine_size
||
!
is_po2
_or_zero
(
store_size
))
continue
;
ir_mode
*
mode_unsigned
=
find_unsigned_mode
(
store_mode
);
if
(
mode_unsigned
==
NULL
)
...
...
ir/tv/strcalc.c
View file @
206f8441
...
...
@@ -769,7 +769,7 @@ void init_strcalc(unsigned precision)
{
if
(
output_buffer
==
NULL
)
{
/* round up to multiple of SC_BITS */
assert
(
is_po2
(
SC_BITS
));
assert
(
is_po2
_or_zero
(
SC_BITS
));
precision
=
(
precision
+
(
SC_BITS
-
1
))
&
~
(
SC_BITS
-
1
);
bit_pattern_size
=
precision
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment