[PATCH 2/3] [aarch64] Implement support for __builtin_load_no_speculate.

Jeff Law law@redhat.com
Fri Jan 5 16:31:00 GMT 2018


On 01/05/2018 03:48 AM, Richard Earnshaw (lists) wrote:
> On 05/01/18 09:51, Richard Biener wrote:
>> On Thu, Jan 4, 2018 at 2:58 PM, Richard Earnshaw
>> <Richard.Earnshaw@arm.com> wrote:
>>>
>>> This patch implements support for __builtin_load_no_speculate on
>>> AArch64.  On this architecture we inhibit speclation by emitting a
>>> combination of CSEL and a hint instruction that ensures the CSEL is
>>> full resolved when the operands to the CSEL may involve a speculative
>>> load.
>>
>> Missing a high-level exlanation here but it looks like you do sth like
>>
>>   if (access is not in bounds)
>>     no-speculate-access;
>>   else
>>      regular access;
> 
> For aarch64 we end up with a sequence like
> 
> 	CMP	'bounds'
> 	B<cond> out-of-range
> 	LDR	x1, [ptr]
> out-of-range:
> 	CSEL	x1, FAILVAL, x1, <cond>
> 	CSDB
> 
> The CSEL+CSDB combination ensures that even if we do fetch x1 from an
> out-of-range location the value won't persist beyond the end of the code
> sequence and thus can't be used for further speculation.
If I try to look at this architecture independently the code starting at
out-of-range is just a conditional move and fence.  Given those
primitives any target ought to be able to define
__builtin_load_no_speculate -- which is obviously important :-)

Jeff



More information about the Gcc-patches mailing list