Constexpr in intrinsics?
Marc Glisse
marc.glisse@inria.fr
Mon Mar 28 09:02:00 GMT 2016
On Mon, 28 Mar 2016, Allan Sandfeld Jensen wrote:
> On Sunday 27 March 2016, Marc Glisse wrote:
>> On Sun, 27 Mar 2016, Allan Sandfeld Jensen wrote:
>>> Would it be possible to add constexpr to the intrinsics headers?
>>>
>>> For instance _mm_set_XX and _mm_setzero intrinsics.
>>
>> Already suggested here:
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65197
>>
>> A patch would be welcome (I started doing it at some point, I don't
>> remember if it was functional, the patch is attached).
>>
> That looks very similar to the patch I experimented with, and that at least
> works for using them in C++11 constexpr functions.
>
>>> Ideally it could also be added all intrinsics that can be evaluated at
>>> compile time, but it is harder to tell which those are.
>>>
>>> Does gcc have a C extension we can use to set constexpr?
>>
>> What for?
>
> To have similar functionality in C. For instance to explicitly allow those
> functions to be evaluated at compile time, and values with similar attributes
> be optimized completely out.
Those intrinsics that are implemented without builtins can already be
evaluated at compile time.
#include <x86intrin.h>
__m128d f(){
__m128d a=_mm_set_pd(1,2);
__m128d b=_mm_setr_pd(4,3);
return _mm_add_pd(a, b);
}
The generated asm is just
movapd .LC0(%rip), %xmm0
ret
For the more esoteric intrinsics, what is missing is not in the parser, it
is a folder that understands the behavior of each particular intrinsic.
> And of course avoid using precompiler noise, in
> shared C/C++ headers like these are.
--
Marc Glisse
More information about the Gcc
mailing list