Commit 2af27301 by Richard Guenther Committed by Richard Biener

stor-layout.c (bit_from_pos): Document.

2012-05-09  Richard Guenther  <rguenther@suse.de>

	* stor-layout.c (bit_from_pos): Document.
	(byte_from_pos): Likewise.  Optimize.
	(pos_from_bit): Likewise.
	(normalize_offset): Use pos_from_bit instead of replicating it.

From-SVN: r187317
parent 570a374a
2012-05-09 Richard Guenther <rguenther@suse.de>
* stor-layout.c (bit_from_pos): Document.
(byte_from_pos): Likewise. Optimize.
(pos_from_bit): Likewise.
(normalize_offset): Use pos_from_bit instead of replicating it.
2012-05-09 Alan Modra <amodra@gmail.com> 2012-05-09 Alan Modra <amodra@gmail.com>
PR target/53271 PR target/53271
......
...@@ -785,8 +785,8 @@ start_record_layout (tree t) ...@@ -785,8 +785,8 @@ start_record_layout (tree t)
return rli; return rli;
} }
/* These four routines perform computations that convert between /* Return the combined bit position for the byte offset OFFSET and the
the offset/bitpos forms and byte and bit offsets. */ bit position BITPOS. */
tree tree
bit_from_pos (tree offset, tree bitpos) bit_from_pos (tree offset, tree bitpos)
...@@ -797,25 +797,46 @@ bit_from_pos (tree offset, tree bitpos) ...@@ -797,25 +797,46 @@ bit_from_pos (tree offset, tree bitpos)
bitsize_unit_node)); bitsize_unit_node));
} }
/* Return the combined truncated byte position for the byte offset OFFSET and
the bit position BITPOS. */
tree tree
byte_from_pos (tree offset, tree bitpos) byte_from_pos (tree offset, tree bitpos)
{ {
return size_binop (PLUS_EXPR, offset, tree bytepos;
fold_convert (sizetype, if (TREE_CODE (bitpos) == MULT_EXPR
size_binop (TRUNC_DIV_EXPR, bitpos, && tree_int_cst_equal (TREE_OPERAND (bitpos, 1), bitsize_unit_node))
bitsize_unit_node))); bytepos = TREE_OPERAND (bitpos, 0);
else
bytepos = size_binop (TRUNC_DIV_EXPR, bitpos, bitsize_unit_node);
return size_binop (PLUS_EXPR, offset, fold_convert (sizetype, bytepos));
} }
/* Split the bit position POS into a byte offset *POFFSET and a bit
position *PBITPOS with the byte offset aligned to OFF_ALIGN bits. */
void void
pos_from_bit (tree *poffset, tree *pbitpos, unsigned int off_align, pos_from_bit (tree *poffset, tree *pbitpos, unsigned int off_align,
tree pos) tree pos)
{ {
*poffset = size_binop (MULT_EXPR, tree toff_align = bitsize_int (off_align);
fold_convert (sizetype, if (TREE_CODE (pos) == MULT_EXPR
size_binop (FLOOR_DIV_EXPR, pos, && tree_int_cst_equal (TREE_OPERAND (pos, 1), toff_align))
bitsize_int (off_align))), {
size_int (off_align / BITS_PER_UNIT)); *poffset = size_binop (MULT_EXPR,
*pbitpos = size_binop (FLOOR_MOD_EXPR, pos, bitsize_int (off_align)); fold_convert (sizetype, TREE_OPERAND (pos, 0)),
size_int (off_align / BITS_PER_UNIT));
*pbitpos = bitsize_zero_node;
}
else
{
*poffset = size_binop (MULT_EXPR,
fold_convert (sizetype,
size_binop (FLOOR_DIV_EXPR, pos,
toff_align)),
size_int (off_align / BITS_PER_UNIT));
*pbitpos = size_binop (FLOOR_MOD_EXPR, pos, toff_align);
}
} }
/* Given a pointer to bit and byte offsets and an offset alignment, /* Given a pointer to bit and byte offsets and an offset alignment,
...@@ -828,17 +849,10 @@ normalize_offset (tree *poffset, tree *pbitpos, unsigned int off_align) ...@@ -828,17 +849,10 @@ normalize_offset (tree *poffset, tree *pbitpos, unsigned int off_align)
downwards. */ downwards. */
if (compare_tree_int (*pbitpos, off_align) >= 0) if (compare_tree_int (*pbitpos, off_align) >= 0)
{ {
tree extra_aligns = size_binop (FLOOR_DIV_EXPR, *pbitpos, tree offset, bitpos;
bitsize_int (off_align)); pos_from_bit (&offset, &bitpos, off_align, *pbitpos);
*poffset = size_binop (PLUS_EXPR, *poffset, offset);
*poffset *pbitpos = bitpos;
= size_binop (PLUS_EXPR, *poffset,
size_binop (MULT_EXPR,
fold_convert (sizetype, extra_aligns),
size_int (off_align / BITS_PER_UNIT)));
*pbitpos
= size_binop (FLOOR_MOD_EXPR, *pbitpos, bitsize_int (off_align));
} }
} }
......
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