Commit dada81ac authored by Matthias Braun's avatar Matthias Braun
Browse files

Use round_up2() more often and cleanup its implementation

parent 206f8441
......@@ -99,18 +99,6 @@ static inline uint32_t log2_ceil(uint32_t x)
return 32 - nlz(x - 1);
}
/**
* Round up to the next multiple of a power of two.
* @param x A value.
* @param pot A power of two.
* @return x rounded up to the next multiple of pot.
*/
static inline unsigned round_up2(unsigned x, unsigned pot)
{
unsigned pot_m1 = pot-1;
return (x + pot_m1) & ~pot_m1;
}
/**
* Returns the biggest power of 2 that is equal or smaller than @p x
* (see hackers delight power-of-2 boundaries, page 48)
......@@ -165,4 +153,18 @@ static inline bool is_po2_or_zero(unsigned x)
return (x & (x-1)) == 0;
}
/**
* Round up to the next multiple of a power of two.
* @param x A value.
* @param pot A power of two.
* @return x rounded up to the next multiple of pot.
*/
static inline unsigned round_up2(unsigned x, unsigned po2)
{
assert(is_po2_or_zero(po2) && po2 > 0);
unsigned const po2_minus_one = po2-1;
unsigned const po2_mask = ~po2_minus_one;
return (x + po2_minus_one) & po2_mask;
}
#endif
......@@ -18,6 +18,7 @@
#include "array.h"
#include "beemitter.h"
#include "begnuas.h"
#include "bitfiddle.h"
#include "compiler.h"
#include "entity_t.h"
#include "obst.h"
......@@ -117,9 +118,8 @@ static void layout_fragments(ir_jit_function_t *const function,
assert(fragment->address == ~0u);
assert(fragment->len != ~0u);
unsigned const align = 1 << fragment->p2align;
unsigned const align_mask = ~(align-1);
unsigned const aligned = (address + align - 1) & align_mask;
unsigned const align = 1 << fragment->p2align;
unsigned const aligned = round_up2(address, align);
if (aligned - address <= fragment->max_skip)
address = aligned;
......
......@@ -351,7 +351,7 @@ void sparc_adjust_stack_entity_offsets(ir_graph *irg)
* frame_size accordingly.
*/
if (!layout->sp_relative) {
frame_size = (frame_size + frame_align-1) & ~(frame_align-1);
frame_size = round_up2(frame_size, frame_align);
} else {
unsigned misalign = (SPARC_MIN_STACKSIZE+frame_size) % frame_align;
frame_size += misalign;
......
......@@ -1119,7 +1119,7 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, unsigned alignment,
unsigned frame_align = get_type_alignment_bytes(frame_type);
int offset;
if (at_start) {
unsigned delta = (size + frame_align - 1) & ~(frame_align - 1);
unsigned delta = round_up2(size, frame_align);
/* fix all offsets so far */
for (size_t i = 0, n = get_compound_n_members(frame_type); i < n; ++i) {
ir_entity *ent = get_compound_member(frame_type, i);
......
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