On Mon, Nov 16, 2020 at 01:50:20PM -0500, Paul Koning wrote: > > On Nov 16, 2020, at 6:57 AM, Jakub Jelinek via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > > Working virtually out of Baker Island - AoE timezone. > > > > The following patch implements __builtin_clear_padding builtin that clears > > the padding bits in object representation (but preserves value > > representation). Inside of unions it clears only those padding bits that > > are padding for all the union members (so that it never alters value > > representation). > > > > It handles trailing padding, padding in the middle of structs including > > bitfields (PDP11 unhandled, I've never figured out how those bitfields > > work), etc. > > That reminds me of a similar comment on a commit a while ago. I'd like to > take care of this, but I'm not sure what questions need to be answered to > do so. Can you point me in the right direction?
There are now many of them. grep -C3 '\(BYTES\|WORDS\)_BIG_ENDIAN [!=]= \(BYTES\|WORDS\)_BIG_ENDIAN' gcc/{,*/}*.{c,h,cc} will show various cases (ignore the ones mentioning FLOAT_*). Some are just optimizations, so they can be ignored, others in features not really supported on pdp11 anyway (e.g. asan), but e.g. this __builtin_clear_padding I've just checked in today, or the __builtin_bit_cast that is pending review need extra work for PDP11. And if you can figure out what to do with the optimizations too, e.g. sccvn can now on big end little endian but not pdp endian handle propagation of constants through memory including bitfields. Or e.g. store merging too. In the __builtin_clear_padding case, basically all that is needed is find out which bits in the target memory order are padding bits and which are occupied by bitfields. The code has the FIELD_DECL and needs to set certain bits in the target memory image to 0 for bits in the bitfield and keep other bits set if they are parts of other bitfields or padding. For big and little endian, the code uses int_byte_position (field) to find the starting byte, tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)) % BITS_PER_UNIT to determine how many (perhaps padding) bits are before that bitfield in the first byte and TYPE_PRECISION (TREE_TYPE (field)) to determine the bitsize of the bitfield. I have no idea what needs to be done for PDP11 endian, the testsuite already includes testcases that could cover it, or new ones similar to the existing ones can be added if there are other special cases that need to be checked (such as e.g. char : N bitfields if they are handled differently etc.). Jakub