[07/23] Add a class that multiplexes two pointer types

Richard Sandiford richard.sandiford@arm.com
Thu Nov 26 16:15:32 GMT 2020


Jeff Law <law@redhat.com> writes:
> On 11/13/20 1:14 AM, Richard Sandiford via Gcc-patches wrote:
>> This patch adds a pointer_mux<T1, T2> class that provides similar
>> functionality to:
>>
>>     union { T1 *a; T2 *b; };
>>     ...
>>     bool is_b_rather_than_a;
>>
>> except that the is_b_rather_than_a tag is stored in the low bit
>> of the pointer.  See the comments in the patch for a comparison
>> between the two approaches and why this one can be more efficient.
>>
>> I've tried to microoptimise the class a fair bit, since a later
>> patch uses it extensively in order to keep the sizes of data
>> structures down.
>>
>> gcc/
>> 	* mux-utils.h: New file.
> Do we have any potentially bootstrappable targets where we can't
> guarantee pointer alignment of at least 16 bits?  I see what look like
> suitable asserts, and presumably if we trigger them, then we're going to
> need to rethink this and fall back to a separate bit?

Like you say, the asserts should trap that if it happens.  I think the
fix would be to increase the alignment of the data types involved (which
we can now do in a standard way -- probably wouldn't have been possible
before the switch to C++11, at least not without using extensions).

Thanks,
Richard


More information about the Gcc-patches mailing list