[PATCH] Implement __readeflags and __writeeflags intrinsics

Eric Christopher echristo at gmail.com
Mon Dec 30 09:28:49 PST 2013


On Mon, Dec 30, 2013 at 9:23 AM, Reid Kleckner <rnk at google.com> wrote:
> I can see value in making it cross-platform to allow easier porting of code.
> The only thing I don't like about it is that we'd be vending these
> interfaces under the name <Intrin.h> without the user explicitly requesting
> compatibility with a flag like -fms-extensions.
>

Yeah. I can go with that. I'm a little concerned about it etc. I don't
know that we want to open up all of the intrinsic interfaces for all
platforms.

That said, going with the MS philosophy, anything that causes people
to write fewer lines of inline assembly is probably a good start.

-eric

>
> On Mon, Dec 30, 2013 at 8:12 AM, Eric Christopher <echristo at gmail.com>
> wrote:
>>
>> So why are you wanting to make Intrin.h non-windows? Is there a
>> version of Intrin.h that's cross platform?
>>
>> -eric
>>
>> On Mon, Dec 30, 2013 at 5:35 AM, Alexey Volkov <avolkov.intel at gmail.com>
>> wrote:
>> >   I moved intrinsics to Intrin.h into non-Windows section since Windows
>> > part of header cannot be compiled on Linux.
>> >   I also removed include_next directive for Linux.
>> >
>> > http://llvm-reviews.chandlerc.com/D2468
>> >
>> > CHANGE SINCE LAST DIFF
>> >   http://llvm-reviews.chandlerc.com/D2468?vs=6263&id=6313#toc
>> >
>> > Files:
>> >   lib/Headers/Intrin.h
>> >
>> > Index: lib/Headers/Intrin.h
>> > ===================================================================
>> > --- lib/Headers/Intrin.h
>> > +++ lib/Headers/Intrin.h
>> > @@ -21,17 +21,65 @@
>> >
>> > *===-----------------------------------------------------------------------===
>> >   */
>> >
>> > -/* Only include this if we're compiling for the windows platform. */
>> > -#ifndef _MSC_VER
>> > -#include_next <Intrin.h>
>> > -#else
>> > -
>> >  #ifndef __INTRIN_H
>> >  #define __INTRIN_H
>> >
>> >  /* First include the standard intrinsics. */
>> >  #include <x86intrin.h>
>> >
>> > +#ifndef _MSC_VER
>> > +#ifdef __x86_64__
>> > +static __inline__ unsigned long long __attribute__((__always_inline__,
>> > __nodebug__))
>> > +__readeflags(void)
>> > +{
>> > +  unsigned long long res = 0;
>> > +  __asm__ __volatile__ ("pushf\n\t"
>> > +                        "popq %0\n"
>> > +                        :"=r"(res)
>> > +                        :
>> > +                        :
>> > +                       );
>> > +  return res;
>> > +}
>> > +
>> > +static __inline__ void __attribute__((__always_inline__, __nodebug__))
>> > +__writeeflags(unsigned long long __f)
>> > +{
>> > +  __asm__ __volatile__ ("pushq %0\n\t"
>> > +                        "popf\n"
>> > +                        :
>> > +                        :"r"(__f)
>> > +                        :"flags"
>> > +                       );
>> > +}
>> > +
>> > +#else
>> > +static __inline__ unsigned int __attribute__((__always_inline__,
>> > __nodebug__))
>> > +__readeflags(void)
>> > +{
>> > +  unsigned int res = 0;
>> > +  __asm__ __volatile__ ("pushf\n\t"
>> > +                        "popl %0\n"
>> > +                        :"=r"(res)
>> > +                        :
>> > +                        :
>> > +                       );
>> > +  return res;
>> > +}
>> > +
>> > +static __inline__ void __attribute__((__always_inline__, __nodebug__))
>> > +__writeeflags(unsigned int __f)
>> > +{
>> > +  __asm__ __volatile__ ("pushl %0\n\t"
>> > +                        "popf\n"
>> > +                        :
>> > +                        :"r"(__f)
>> > +                        :"flags"
>> > +                       );
>> > +}
>> > +#endif
>> > +#else
>> > +
>> >  #ifdef __cplusplus
>> >  extern "C" {
>> >  #endif
>> > @@ -780,5 +828,5 @@
>> >  }
>> >  #endif
>> >
>> > -#endif /* __INTRIN_H */
>> >  #endif /* _MSC_VER */
>> > +#endif /* __INTRIN_H */
>
>



More information about the cfe-commits mailing list