Patchwork Intrinsics for ADCX, ADOX, RDSEED and PREFETCHW

login
register
mail settings
Submitter Uros Bizjak
Date July 19, 2012, 12:13 p.m.
Message ID <CAFULd4bv6NrFoi3GSJXJaad+x4GDymqyvaT5KOUCkfdKA=5zVg@mail.gmail.com>
Download mbox | patch
Permalink /patch/171945/
State New
Headers show

Comments

Uros Bizjak - July 19, 2012, 12:13 p.m.
On Thu, Jul 19, 2012 at 11:51 AM, Jakub Jelinek <jakub@redhat.com> wrote:

> I think it is fine to change existing mm3dnow.h header, but not in the way
> it has been changed in the patch.  The thing is that unlike the newly added
> intrinsics headers, mm3dnow.h is still publicly includable header, and just
> including that header should work properly, so mm3dnow.h has to include
> prftchwintrin.h, which should be allowed to be included from x86intrin.h
> as well as mm3dnow.h, and that header should have guards, so that if both
> x86intrin.h is included and mm3dnow.h too (the latter first),
> prftchwintrin.h isn't included in twice.

Probably something like attached patch, with following changes to the
original patch:

+#if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
+# error "Never use <adxintrin.h> directly; include <x86intrin.h> instead."
+#endif

No need to check for _IMMINTRIN_H_INCLUDED (in all new headers).

In config/i386/prfchwintrin.h, change this part to:

+#if !defined _X86INTRIN_H_INCLUDED && !defined _MM3DNOW_H_INCLUDED
+# error "Never use <prfchwintrin.h> directly; include <x86intrin.h>
or <mm3dnow.h> instead."
+#endif

Uros.
Kirill Yukhin - July 24, 2012, 12:09 p.m.
Hi guys,
Uros, Jakub, thanks fr the inputs!

I've refactored the patch appliying (hopefully) all of your inputs.

It is attached.

Changelog is:
2012-07-24  Kirill Yukhin  <kirill.yukhin@intel.com>
	    Michael Zolotukhin  <michael.v.zolotukhin@intel.com>

        * common/config/i386/i386-common.c (OPTION_MASK_ISA_RDSEED_SET): New.
        (OPTION_MASK_ISA_ADX_SET): Likewise.
        (OPTION_MASK_ISA_PRFCHW_SET): Likewise.
        (OPTION_MASK_ISA_RDSEED_UNSET): Likewise.
        (OPTION_MASK_ISA_ADX_UNSET): Likewise.
        (OPTION_MASK_ISA_PRFCHW_UNSET): Likewise.
        (ix86_handle_option): Handle mrdseed, madx and mprfchw options.
        * config.gcc (i[34567]86-*-*): Add rdseedintrin.h, adxintrin.h and
        prfchwintrin.h.
        (x86_64-*-*): Likewise.
        * config/i386/adxintrin.h: New header.
        * config/i386/prfchwintrin.h: Likewise.
        * config/i386/rdseedintrin.h: Likewise.
        * config/i386/cpuid.h (bit_RDSEED): New.
        (bit_ADX): Likewise.
        (bit_PRFCHW): Likewise.
        (bit_BMI): Formatting fix.
        (bit_HLE): Likewise.
        (bit_RTM): Likewise.
        * config/i386/driver-i386.c (host_detect_local_cpu): Detect ADCX/ADOX,
        RDSEED and PREFETCHW support.
        * config/i386/i386-builtin-types.def
        (UCHAR_FTYPE_UCHAR_UINT_UINT_PINT): New function type.
        (UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PINT): Likewise.
        * config/i386/i386-c.c: Define __RDSEED__, __ADX__, and __PRFCHW__ if
        needed.
        * config/i386/i386.c (ix86_target_string): Define -mrdseed, -madx,
        -mprfchw options. Formatting fixes.
        (PTA_HLE): Formatting fix.
        (PTA_RDSEED): New.
        (PTA_ADX): Likewise.
        (PTA_PRFCHW): Likewise.
        (ix86_option_override_internal): Handle new options.
        (ix86_valid_target_attribute_inner_p): Add OPT_mrdseed, OPT_madx, and
        OPT_mprfchw.
        (ix86_builtins): Add IX86_BUILTIN_ADDXCARRY32,
        IX86_BUILTIN_ADDXCARRY64, IX86_BUILTIN_RDSEED16,
        IX86_BUILTIN_RDSEED32, IX86_BUILTIN_RDSEED64.
        (ix86_init_mmx_sse_builtins): Define corresponding built-ins.
        (ix86_expand_builtin): Handle these built-ins.
        (ix86_expand_args_builtin): Handle new function types.
        * config/i386/i386.h (TARGET_RDSEED): New.
        (TARGET_ADX): Likewise.
        (TARGET_PRFCHW): Likewise.
        * config/i386/i386.md: (adcx<mode>): New define_expand.
        (adcx<mode>_carry): New define_insn.
        (rdseed<mode>): Likewise.
        (prefetch): Enable for TARGET_PRFCHW.
        (prefetchw_<mode>): New define_insn for write-prefetch.
        (prefetch_3dnow_<mode>): Keep only read-prefetch here.
        * config/i386/i386.opt (mrdseed): New.
        (madx): Likewise.
        (mprfchw): Likewise.
        * config/i386/mm3dnow.h: Move _m_prefetchw from here to
        prfchwintrin.h.
        * config/i386/x86intrin.h: Include prfchwintrin.h, rdseedintrin.h,
        adxintrin.h.

testsuite/Changelog is:
2012-07-24  Kirill Yukhin  <kirill.yukhin@intel.com>
	    Michael Zolotukhin  <michael.v.zolotukhin@intel.com>

        * gcc.target/i386/adx-addxcarry32-1.c: New.
        * gcc.target/i386/adx-addxcarry32-2.c: New.
        * gcc.target/i386/adx-addxcarry64-1.c: New.
        * gcc.target/i386/adx-addxcarry64-2.c: New.
        * gcc.target/i386/adx-check.h: New.
        * gcc.target/i386/i386.exp: New.
        * gcc.target/i386/prefetchw-1.c: New.
        * gcc.target/i386/rdseed16-1.c: New.
        * gcc.target/i386/rdseed32-1.c: New.
        * gcc.target/i386/rdseed64-1.c: New.
	* gcc.target/i386/sse-12.c: Add -mrdseed, -madx, -mprfchw.
	* gcc.target/i386/sse-13.c: Ditto.
	* gcc.target/i386/sse-14.c: Ditto.
	* g++.dg/other/i386-2.C: Ditto.
	* g++.dg/other/i386-3.C: Ditto.


Bootstrap is passing. New tests are passing (under simulator),
extended tests are passing.

is it OK for trunk?

Thanks, K
Uros Bizjak - July 24, 2012, 12:49 p.m.
On Tue, Jul 24, 2012 at 2:09 PM, Kirill Yukhin <kirill.yukhin@gmail.com> wrote:

> Uros, Jakub, thanks fr the inputs!
>
> I've refactored the patch appliying (hopefully) all of your inputs.
>
> It is attached.

Can you please split the patch to three independent parts, prefetchw
handling, rdseed and adxx. I got lost in the patch the second time.

I propose we start with prefetch. You are still changing prefetch
patterns, while it should be enough to only change prefetch expander.

Thanks,
Uros.
Kirill Yukhin - July 24, 2012, 2:06 p.m.
> Can you please split the patch to three independent parts, prefetchw
> handling, rdseed and adxx. I got lost in the patch the second time.
Sure!

> I propose we start with prefetch. You are still changing prefetch
> patterns, while it should be enough to only change prefetch expander.
Actually, they're splitted since 3dnow has both prefetch and prefetchw
under single CPUID bit,
while under Intel's PRFTCH CPUID bit we have only prefetchw. So, old
pattern "*prefetch_3dnow_<mode>"
was set to be `prefetch` only for 3dnow, while new one is `prefetchw' only,
working both for PRFTCH and 3DNOW bits.

Changelog entry:
2012-07-24  Kirill Yukhin  <kirill.yukhin@intel.com>
	    Michael Zolotukhin  <michael.v.zolotukhin@intel.com>

        * common/config/i386/i386-common.c (OPTION_MASK_ISA_PRFCHW_SET): New.
        (OPTION_MASK_ISA_PRFCHW_UNSET): Likewise.
        (ix86_handle_option): Handle mprfchw option.
        * config.gcc (i[34567]86-*-*): Add prfchwintrin.h.
        (x86_64-*-*): Likewise.
        * config/i386/prfchwintrin.h: New header.
        * config/i386/cpuid.h (bit_PRFCHW): New.
        (bit_BMI): Formatting fix.
        (bit_HLE): Likewise.
        (bit_RTM): Likewise.
        * config/i386/driver-i386.c (host_detect_local_cpu): Detect
        PREFETCHW support.
        * config/i386/i386-c.c: Define __PRFCHW__ if needed.
        * config/i386/i386.c (ix86_target_string): Define
        -mprfchw option. Formatting fixes.
        (PTA_HLE): Formatting fix.
        (PTA_PRFCHW): New.
        (ix86_option_override_internal): Handle new option.
        (ix86_valid_target_attribute_inner_p): Add OPT_mprfchw.
        * config/i386/i386.h (TARGET_PRFCHW): New.
        * config/i386/i386.md (prefetch): Enable for TARGET_PRFCHW.
        (prefetchw_<mode>): New define_insn for write-prefetch.
        (prefetch_3dnow_<mode>): Keep only read-prefetch here.
        * config/i386/i386.opt (mprfchw): New.
        * config/i386/mm3dnow.h: Move _m_prefetchw from here to
        prfchwintrin.h.
        * config/i386/x86intrin.h: Include prfchwintrin.h.

testsuite/Changelog entry:
2012-07-24  Kirill Yukhin  <kirill.yukhin@intel.com>
	    Michael Zolotukhin  <michael.v.zolotukhin@intel.com>

        * gcc.target/i386/prefetchw-1.c: New.
	* gcc.target/i386/sse-12.c: Add -mprfchw.
	* gcc.target/i386/sse-13.c: Ditto.
	* gcc.target/i386/sse-14.c: Ditto.
	* g++.dg/other/i386-2.C: Ditto.
	* g++.dg/other/i386-3.C: Ditto.

patch is bootstrapping at the moment.

Any objections?

Thanks, K

Patch

Index: mm3dnow.h
===================================================================
--- mm3dnow.h	(revision 189643)
+++ mm3dnow.h	(working copy)
@@ -30,6 +30,7 @@ 
 #ifdef __3dNOW__
 
 #include <mmintrin.h>
+#include <prfchwintrin.h>
 
 extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _m_femms (void)
@@ -157,12 +158,6 @@ 
   __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
 }
 
-extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_m_prefetchw (void *__P)
-{
-  __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */);
-}
-
 extern __inline __m64 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _m_from_float (float __A)
 {
Index: x86intrin.h
===================================================================
--- x86intrin.h	(revision 189643)
+++ x86intrin.h	(working copy)
@@ -97,4 +97,8 @@ 
 #include <popcntintrin.h>
 #endif
 
+#ifdef __PRFCHW__
+#include <prfchwintrin.h>
+#endif
+
 #endif /* _X86INTRIN_H_INCLUDED */