Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-13 Thread Uros Bizjak via Gcc-patches
On Tue, Oct 13, 2020 at 10:30 AM Hongyu Wang  wrote:
>
> Hi:
>
> This patch is about to support User Interrupt (UINTR) instructions.
>
> This feature defines user interrupts as new events in the architecture.  They 
> are delivered to software operating in 64-bit mode with CPL = 3 without any 
> change to segmentation state.
>
> For more details, please refer to 
> https://software.intel.com/content/dam/develop/external/us/en/documents/architecture-instruction-set-extensions-programming-reference.pdf
>
> Bootstrap ok, regression test on i386/x86 backend is ok.
>
> OK for master?
>
> gcc/
> * common/config/i386/cpuinfo.h (get_available_features):
> Detect UINTR.
> * common/config/i386/i386-common.c (OPTION_MASK_ISA2_UINTR_SET
> OPTION_MASK_ISA2_UINTR_UNSET): New.
> (ix86_handle_option): Handle -muintr.
> * common/config/i386/i386-cpuinfo.h (enum processor_features):
> Add FEATURE_UINTR.
> * common/config/i386/i386-isas.h: Add ISA_NAMES_TABLE_ENTRY
> for uintr.
> * config.gcc: Add uintrintrin.h to extra_headers.
> * config/i386/uintrintrin.h: New.
> * config/i386/cpuid.h (bit_UINTR): New.
> * config/i386/driver-i386.c (host_detect_local_cpu): Detect UINTR.
> * config/i386/i386-builtin-types.def: Add new types.
> * config/i386/i386-builtin.def: Add new builtins.
> * config/i386/i386-builtins.c (ix86_init_mmx_sse_builtins): Add
> __builtin_ia32_testui.
> * config/i386/i386-builtins.h (ix86_builtins): Add
> IX86_BUILTIN_TESTUI.
> * config/i386/i386-c.c (ix86_target_macros_internal): Define
> __UINTR__.
> * config/i386/i386-expand.c (ix86_expand_special_args_builtin):
> Handle UINT8_FTYPE_VOID.
> (ix86_expand_builtin): Handle IX86_BUILTIN_TESTUI.
> * config/i386/i386-options.c (isa2_opts): Add -muintr.
> (ix86_valid_target_attribute_inner_p): Handle UINTR.
> (ix86_option_override_internal): Add TARGET_64BIT check for UINTR.
> * config/i386/i386.h (TARGET_UINTR, TARGET_UINTR_P, PTA_UINTR): New.
> (PTA_SAPPHIRRAPIDS): Add PTA_UINTR.
> * config/i386/i386.opt: Add -muintr.
> * config/i386/i386.md
> (define_int_iterator UINTR_UNSPECV): New.
> (define_int_attr uintr_unspecv): New.
> (uintr_, uintr_senduipi, testui):
> New define_insn patterns.
> * config/i386/x86gprintrin.h: Include uintrintrin.h
> * doc/invoke.texi: Document -muintr.
> * doc/extend.texi: Document uintr.
>
> gcc/testsuite/
>
> * gcc.target/i386/funcspec-56.inc: Add new target attribute.
> * gcc.target/i386/uintr-1.c: New test.
> * gcc.target/i386/uintr-2.c: Ditto.
> * gcc.target/i386/uintr-3.c: Ditto.
> * gcc.target/i386/uintr-4.c: Ditto.
> * gcc.target/i386/uintr-5.c: Ditto.

Please also add -muintr to g++.dg/other/i386-{2,3}.C and
gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
header.

OK with the above change.

Thanks,
Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongyu Wang via Gcc-patches
>
> Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> header.
>

Thanks for your review. We found that without adding -muintr, the
intrinsics header could also be tested. Make-check for these file all get
passed.

And there is no intrinsic/builtin with const int parameter. So we remove
-muintr from these files.


Uros Bizjak  于2020年10月14日周三 下午2:18写道:

> On Tue, Oct 13, 2020 at 10:30 AM Hongyu Wang 
> wrote:
> >
> > Hi:
> >
> > This patch is about to support User Interrupt (UINTR) instructions.
> >
> > This feature defines user interrupts as new events in the architecture.
> They are delivered to software operating in 64-bit mode with CPL = 3
> without any change to segmentation state.
> >
> > For more details, please refer to
> https://software.intel.com/content/dam/develop/external/us/en/documents/architecture-instruction-set-extensions-programming-reference.pdf
> >
> > Bootstrap ok, regression test on i386/x86 backend is ok.
> >
> > OK for master?
> >
> > gcc/
> > * common/config/i386/cpuinfo.h (get_available_features):
> > Detect UINTR.
> > * common/config/i386/i386-common.c (OPTION_MASK_ISA2_UINTR_SET
> > OPTION_MASK_ISA2_UINTR_UNSET): New.
> > (ix86_handle_option): Handle -muintr.
> > * common/config/i386/i386-cpuinfo.h (enum processor_features):
> > Add FEATURE_UINTR.
> > * common/config/i386/i386-isas.h: Add ISA_NAMES_TABLE_ENTRY
> > for uintr.
> > * config.gcc: Add uintrintrin.h to extra_headers.
> > * config/i386/uintrintrin.h: New.
> > * config/i386/cpuid.h (bit_UINTR): New.
> > * config/i386/driver-i386.c (host_detect_local_cpu): Detect UINTR.
> > * config/i386/i386-builtin-types.def: Add new types.
> > * config/i386/i386-builtin.def: Add new builtins.
> > * config/i386/i386-builtins.c (ix86_init_mmx_sse_builtins): Add
> > __builtin_ia32_testui.
> > * config/i386/i386-builtins.h (ix86_builtins): Add
> > IX86_BUILTIN_TESTUI.
> > * config/i386/i386-c.c (ix86_target_macros_internal): Define
> > __UINTR__.
> > * config/i386/i386-expand.c (ix86_expand_special_args_builtin):
> > Handle UINT8_FTYPE_VOID.
> > (ix86_expand_builtin): Handle IX86_BUILTIN_TESTUI.
> > * config/i386/i386-options.c (isa2_opts): Add -muintr.
> > (ix86_valid_target_attribute_inner_p): Handle UINTR.
> > (ix86_option_override_internal): Add TARGET_64BIT check for UINTR.
> > * config/i386/i386.h (TARGET_UINTR, TARGET_UINTR_P, PTA_UINTR): New.
> > (PTA_SAPPHIRRAPIDS): Add PTA_UINTR.
> > * config/i386/i386.opt: Add -muintr.
> > * config/i386/i386.md
> > (define_int_iterator UINTR_UNSPECV): New.
> > (define_int_attr uintr_unspecv): New.
> > (uintr_, uintr_senduipi, testui):
> > New define_insn patterns.
> > * config/i386/x86gprintrin.h: Include uintrintrin.h
> > * doc/invoke.texi: Document -muintr.
> > * doc/extend.texi: Document uintr.
> >
> > gcc/testsuite/
> >
> > * gcc.target/i386/funcspec-56.inc: Add new target attribute.
> > * gcc.target/i386/uintr-1.c: New test.
> > * gcc.target/i386/uintr-2.c: Ditto.
> > * gcc.target/i386/uintr-3.c: Ditto.
> > * gcc.target/i386/uintr-4.c: Ditto.
> > * gcc.target/i386/uintr-5.c: Ditto.
>
> Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> header.
>
> OK with the above change.
>
> Thanks,
> Uros.
>


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Uros Bizjak via Gcc-patches
On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang  wrote:
>
> >
> > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> > header.
> >
>
> Thanks for your review. We found that without adding -muintr, the intrinsics 
> header could also be tested. Make-check for these file all get passed.
>
> And there is no intrinsic/builtin with const int parameter. So we remove 
> -muintr from these files.

Can your double check that relevant instructions are indeed generated?
Without -muintr, relevant patterns in i386.md are effectively blocked,
and perhaps a call to __builtin_ia32_* is generated instead.

Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Uros Bizjak via Gcc-patches
On Wed, Oct 14, 2020 at 10:42 AM Uros Bizjak  wrote:
>
> On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang  wrote:
> >
> > >
> > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> > > header.
> > >
> >
> > Thanks for your review. We found that without adding -muintr, the 
> > intrinsics header could also be tested. Make-check for these file all get 
> > passed.
> >
> > And there is no intrinsic/builtin with const int parameter. So we remove 
> > -muintr from these files.
>
> Can your double check that relevant instructions are indeed generated?
> Without -muintr, relevant patterns in i386.md are effectively blocked,
> and perhaps a call to __builtin_ia32_* is generated instead.

Ah, I see the issue.

The new header should be tested via x86gprintrin-* test cases.

Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongyu Wang via Gcc-patches
Uros Bizjak  于2020年10月14日周三 下午4:42写道:

> On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang 
> wrote:
> >
> > >
> > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> > > header.
> > >
> >
> > Thanks for your review. We found that without adding -muintr, the
> intrinsics header could also be tested. Make-check for these file all get
> passed.
> >
> > And there is no intrinsic/builtin with const int parameter. So we remove
> -muintr from these files.
>
> Can your double check that relevant instructions are indeed generated?
> Without -muintr, relevant patterns in i386.md are effectively blocked,
> and perhaps a call to __builtin_ia32_* is generated instead.
>

Yes, in sse-14.s we have

_clui:
.LFB136:
.cfi_startproc
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq%rsp, %rbp
.cfi_def_cfa_register 6
clui
nop
popq%rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc


>
> Uros.
>


-- 
Regards,

Hongyu, Wang


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongyu Wang via Gcc-patches
Uros Bizjak  于2020年10月14日周三 下午4:53写道:
>
> On Wed, Oct 14, 2020 at 10:42 AM Uros Bizjak  wrote:
> >
> > On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang  wrote:
> > >
> > > >
> > > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> > > > header.
> > > >
> > >
> > > Thanks for your review. We found that without adding -muintr, the 
> > > intrinsics header could also be tested. Make-check for these file all get 
> > > passed.
> > >
> > > And there is no intrinsic/builtin with const int parameter. So we remove 
> > > -muintr from these files.
> >
> > Can your double check that relevant instructions are indeed generated?
> > Without -muintr, relevant patterns in i386.md are effectively blocked,
> > and perhaps a call to __builtin_ia32_* is generated instead.
>
> Ah, I see the issue.
>
> The new header should be tested via x86gprintrin-* test cases.
>
> Uros.

Also for x86gprintrin-3.s, without -muintr:

_clui:
.LFB128:
.cfi_startproc
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq%rsp, %rbp
.cfi_def_cfa_register 6
clui
nop
popq%rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc

-- 
Regards,

Hongyu, Wang


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Uros Bizjak via Gcc-patches
On Wed, Oct 14, 2020 at 11:04 AM Hongyu Wang  wrote:
>
>
>
> Uros Bizjak  于2020年10月14日周三 下午4:42写道:
>>
>> On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang  wrote:
>> >
>> > >
>> > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
>> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
>> > > header.
>> > >
>> >
>> > Thanks for your review. We found that without adding -muintr, the 
>> > intrinsics header could also be tested. Make-check for these file all get 
>> > passed.
>> >
>> > And there is no intrinsic/builtin with const int parameter. So we remove 
>> > -muintr from these files.
>>
>> Can your double check that relevant instructions are indeed generated?
>> Without -muintr, relevant patterns in i386.md are effectively blocked,
>> and perhaps a call to __builtin_ia32_* is generated instead.
>
>
> Yes, in sse-14.s we have
>
> _clui:
> .LFB136:
> .cfi_startproc
> pushq   %rbp
> .cfi_def_cfa_offset 16
> .cfi_offset 6, -16
> movq%rsp, %rbp
> .cfi_def_cfa_register 6
> clui
> nop
> popq%rbp
> .cfi_def_cfa 7, 8
> ret
> .cfi_endproc

Strange, without -muintr, it should not be generated, and some error
about failed inlining due to target specific option mismatch shoul be
emitted.

Can you please investigate this a bit more?

Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongtao Liu via Gcc-patches
On Wed, Oct 14, 2020 at 5:21 PM Uros Bizjak  wrote:
>
> On Wed, Oct 14, 2020 at 11:04 AM Hongyu Wang  wrote:
> >
> >
> >
> > Uros Bizjak  于2020年10月14日周三 下午4:42写道:
> >>
> >> On Wed, Oct 14, 2020 at 10:34 AM Hongyu Wang  
> >> wrote:
> >> >
> >> > >
> >> > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> >> > > header.
> >> > >
> >> >
> >> > Thanks for your review. We found that without adding -muintr, the 
> >> > intrinsics header could also be tested. Make-check for these file all 
> >> > get passed.
> >> >
> >> > And there is no intrinsic/builtin with const int parameter. So we remove 
> >> > -muintr from these files.
> >>
> >> Can your double check that relevant instructions are indeed generated?
> >> Without -muintr, relevant patterns in i386.md are effectively blocked,
> >> and perhaps a call to __builtin_ia32_* is generated instead.
> >
> >
> > Yes, in sse-14.s we have
> >
> > _clui:
> > .LFB136:
> > .cfi_startproc
> > pushq   %rbp
> > .cfi_def_cfa_offset 16
> > .cfi_offset 6, -16
> > movq%rsp, %rbp
> > .cfi_def_cfa_register 6
> > clui
> > nop
> > popq%rbp
> > .cfi_def_cfa 7, 8
> > ret
> > .cfi_endproc
>
> Strange, without -muintr, it should not be generated, and some error
> about failed inlining due to target specific option mismatch shoul be
> emitted.
>
> Can you please investigate this a bit more?
>

Because of function target attribute?

> Uros.



-- 
BR,
Hongtao


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Uros Bizjak via Gcc-patches
> > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new intrinsics
> > >> > > header.
> > >> > >
> > >> >
> > >> > Thanks for your review. We found that without adding -muintr, the 
> > >> > intrinsics header could also be tested. Make-check for these file all 
> > >> > get passed.
> > >> >
> > >> > And there is no intrinsic/builtin with const int parameter. So we 
> > >> > remove -muintr from these files.
> > >>
> > >> Can your double check that relevant instructions are indeed generated?
> > >> Without -muintr, relevant patterns in i386.md are effectively blocked,
> > >> and perhaps a call to __builtin_ia32_* is generated instead.
> > >
> > >
> > > Yes, in sse-14.s we have
> > >
> > > _clui:
> > > .LFB136:
> > > .cfi_startproc
> > > pushq   %rbp
> > > .cfi_def_cfa_offset 16
> > > .cfi_offset 6, -16
> > > movq%rsp, %rbp
> > > .cfi_def_cfa_register 6
> > > clui
> > > nop
> > > popq%rbp
> > > .cfi_def_cfa 7, 8
> > > ret
> > > .cfi_endproc
> >
> > Strange, without -muintr, it should not be generated, and some error
> > about failed inlining due to target specific option mismatch shoul be
> > emitted.
> >
> > Can you please investigate this a bit more?
> >
>
> Because of function target attribute?

I don't think so. Please consider this similar testcase:

--cut here--
#ifndef __SSE2__
#pragma GCC push_options
#pragma GCC target("sse2")
#define __DISABLE_SSE2__
#endif /* __SSE2__ */

typedef double __v2df __attribute__ ((__vector_size__ (16)));
typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));

extern __inline __m128d __attribute__((__gnu_inline__,
__always_inline__, __artificial__))
_mm_add_sd (__m128d __A, __m128d __B)
{
  return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
}

#ifdef __DISABLE_SSE2__
#undef __DISABLE_SSE2__
#pragma GCC pop_options
#endif /* __DISABLE_SSE2__ */


__v2df foo (__v2df a, __v2df b)
{
  return _mm_add_sd (a, b);
}
--cut here--

$ gcc -O2 -mno-sse2 -S -dp sse2.c
sse2.c: In function ‘foo’:
sse2.c:11:1: error: inlining failed in call to ‘always_inline’
‘_mm_add_sd’: target specific option mismatch
  11 | _mm_add_sd (__m128d __A, __m128d __B)
 | ^~
sse2.c:24:10: note: called from here
  24 |   return _mm_add_sd (a, b);
 |  ^

I'd expect some similar warning from missing -mumip.

Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongyu Wang via Gcc-patches
Uros Bizjak  于2020年10月14日周三 下午7:19写道:
>
> > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new
intrinsics
> > > >> > > header.
> > > >> > >
> > > >> >
> > > >> > Thanks for your review. We found that without adding -muintr,
the intrinsics header could also be tested. Make-check for these file all
get passed.
> > > >> >
> > > >> > And there is no intrinsic/builtin with const int parameter. So
we remove -muintr from these files.
> > > >>
> > > >> Can your double check that relevant instructions are indeed
generated?
> > > >> Without -muintr, relevant patterns in i386.md are effectively
blocked,
> > > >> and perhaps a call to __builtin_ia32_* is generated instead.
> > > >
> > > >
> > > > Yes, in sse-14.s we have
> > > >
> > > > _clui:
> > > > .LFB136:
> > > > .cfi_startproc
> > > > pushq   %rbp
> > > > .cfi_def_cfa_offset 16
> > > > .cfi_offset 6, -16
> > > > movq%rsp, %rbp
> > > > .cfi_def_cfa_register 6
> > > > clui
> > > > nop
> > > > popq%rbp
> > > > .cfi_def_cfa 7, 8
> > > > ret
> > > > .cfi_endproc
> > >
> > > Strange, without -muintr, it should not be generated, and some error
> > > about failed inlining due to target specific option mismatch shoul be
> > > emitted.
> > >
> > > Can you please investigate this a bit more?
> > >
> >
> > Because of function target attribute?
>
> I don't think so. Please consider this similar testcase:
>
> --cut here--
> #ifndef __SSE2__
> #pragma GCC push_options
> #pragma GCC target("sse2")
> #define __DISABLE_SSE2__
> #endif /* __SSE2__ */
>
> typedef double __v2df __attribute__ ((__vector_size__ (16)));
> typedef double __m128d __attribute__ ((__vector_size__ (16),
__may_alias__));
>
> extern __inline __m128d __attribute__((__gnu_inline__,
> __always_inline__, __artificial__))
> _mm_add_sd (__m128d __A, __m128d __B)
> {
>   return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
> }
>
> #ifdef __DISABLE_SSE2__
> #undef __DISABLE_SSE2__
> #pragma GCC pop_options
> #endif /* __DISABLE_SSE2__ */
>
>
> __v2df foo (__v2df a, __v2df b)
> {
>   return _mm_add_sd (a, b);
> }
> --cut here--
>
> $ gcc -O2 -mno-sse2 -S -dp sse2.c
> sse2.c: In function ‘foo’:
> sse2.c:11:1: error: inlining failed in call to ‘always_inline’
> ‘_mm_add_sd’: target specific option mismatch
>   11 | _mm_add_sd (__m128d __A, __m128d __B)
>  | ^~
> sse2.c:24:10: note: called from here
>   24 |   return _mm_add_sd (a, b);
>  |  ^
>
> I'd expect some similar warning from missing -mumip.
>

For this case, I can confirm uintr could generate similar warning without
-muintr. But
sse-{12,13,14,22,23}.c will not test intrinsic call for uintr, since it
doesn't have const
int parameter intrinsics.

sse-{13,14,22,23}.c has

#define extern
#define __inline

So intrinsic will be treated as common call to builtin, then

#pragma GCC push_options
#pragma GCC target("uintr")

ensures the builtin could be expanded correctly.

I think the intrinsic call test should be in uintr-1.c, so it is redundant
to add -muintr in sse-{12,13,14,22,23}.c
or x86gprintrin-*.c.

>
> Uros.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread H.J. Lu via Gcc-patches
On Wed, Oct 14, 2020 at 6:31 AM Hongyu Wang via Gcc-patches
 wrote:
>
> Uros Bizjak  于2020年10月14日周三 下午7:19写道:
> >
> > > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > > >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new
> intrinsics
> > > > >> > > header.
> > > > >> > >
> > > > >> >
> > > > >> > Thanks for your review. We found that without adding -muintr,
> the intrinsics header could also be tested. Make-check for these file all
> get passed.
> > > > >> >
> > > > >> > And there is no intrinsic/builtin with const int parameter. So
> we remove -muintr from these files.
> > > > >>
> > > > >> Can your double check that relevant instructions are indeed
> generated?
> > > > >> Without -muintr, relevant patterns in i386.md are effectively
> blocked,
> > > > >> and perhaps a call to __builtin_ia32_* is generated instead.
> > > > >
> > > > >
> > > > > Yes, in sse-14.s we have
> > > > >
> > > > > _clui:
> > > > > .LFB136:
> > > > > .cfi_startproc
> > > > > pushq   %rbp
> > > > > .cfi_def_cfa_offset 16
> > > > > .cfi_offset 6, -16
> > > > > movq%rsp, %rbp
> > > > > .cfi_def_cfa_register 6
> > > > > clui
> > > > > nop
> > > > > popq%rbp
> > > > > .cfi_def_cfa 7, 8
> > > > > ret
> > > > > .cfi_endproc
> > > >
> > > > Strange, without -muintr, it should not be generated, and some error
> > > > about failed inlining due to target specific option mismatch shoul be
> > > > emitted.
> > > >
> > > > Can you please investigate this a bit more?
> > > >
> > >
> > > Because of function target attribute?
> >
> > I don't think so. Please consider this similar testcase:
> >
> > --cut here--
> > #ifndef __SSE2__
> > #pragma GCC push_options
> > #pragma GCC target("sse2")
> > #define __DISABLE_SSE2__
> > #endif /* __SSE2__ */
> >
> > typedef double __v2df __attribute__ ((__vector_size__ (16)));
> > typedef double __m128d __attribute__ ((__vector_size__ (16),
> __may_alias__));
> >
> > extern __inline __m128d __attribute__((__gnu_inline__,
> > __always_inline__, __artificial__))
> > _mm_add_sd (__m128d __A, __m128d __B)
> > {
> >   return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
> > }
> >
> > #ifdef __DISABLE_SSE2__
> > #undef __DISABLE_SSE2__
> > #pragma GCC pop_options
> > #endif /* __DISABLE_SSE2__ */
> >
> >
> > __v2df foo (__v2df a, __v2df b)
> > {
> >   return _mm_add_sd (a, b);
> > }
> > --cut here--
> >
> > $ gcc -O2 -mno-sse2 -S -dp sse2.c
> > sse2.c: In function ‘foo’:
> > sse2.c:11:1: error: inlining failed in call to ‘always_inline’
> > ‘_mm_add_sd’: target specific option mismatch
> >   11 | _mm_add_sd (__m128d __A, __m128d __B)
> >  | ^~
> > sse2.c:24:10: note: called from here
> >   24 |   return _mm_add_sd (a, b);
> >  |  ^
> >
> > I'd expect some similar warning from missing -mumip.
> >
>
> For this case, I can confirm uintr could generate similar warning without
> -muintr. But
> sse-{12,13,14,22,23}.c will not test intrinsic call for uintr, since it
> doesn't have const
> int parameter intrinsics.
>
> sse-{13,14,22,23}.c has
>
> #define extern
> #define __inline
>
> So intrinsic will be treated as common call to builtin, then
>
> #pragma GCC push_options
> #pragma GCC target("uintr")
>
> ensures the builtin could be expanded correctly.
>
> I think the intrinsic call test should be in uintr-1.c, so it is redundant
> to add -muintr in sse-{12,13,14,22,23}.c
> or x86gprintrin-*.c.

Please add UINTR intrinsic tests to x86gprintrin-*.c to cover such
usages.

> >
> > Uros.



-- 
H.J.


Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Hongyu Wang via Gcc-patches
Hi Uros,

Sorry for my misunderstanding. The test is for the correctness check
of intrinsic header.
I have add -muintr to x86gprintrin-{1,2,3,4,5}.c.

UINTR is 64bit only, so I add them with dg-additional-option.

Updated patch. If you agree, we will check-in the attached patch.

Thanks for your help.

H.J. Lu  于2020年10月14日周三 下午9:35写道:
>
> On Wed, Oct 14, 2020 at 6:31 AM Hongyu Wang via Gcc-patches
>  wrote:
> >
> > Uros Bizjak  于2020年10月14日周三 下午7:19写道:
> > >
> > > > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > > > >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new
> > intrinsics
> > > > > >> > > header.
> > > > > >> > >
> > > > > >> >
> > > > > >> > Thanks for your review. We found that without adding -muintr,
> > the intrinsics header could also be tested. Make-check for these file all
> > get passed.
> > > > > >> >
> > > > > >> > And there is no intrinsic/builtin with const int parameter. So
> > we remove -muintr from these files.
> > > > > >>
> > > > > >> Can your double check that relevant instructions are indeed
> > generated?
> > > > > >> Without -muintr, relevant patterns in i386.md are effectively
> > blocked,
> > > > > >> and perhaps a call to __builtin_ia32_* is generated instead.
> > > > > >
> > > > > >
> > > > > > Yes, in sse-14.s we have
> > > > > >
> > > > > > _clui:
> > > > > > .LFB136:
> > > > > > .cfi_startproc
> > > > > > pushq   %rbp
> > > > > > .cfi_def_cfa_offset 16
> > > > > > .cfi_offset 6, -16
> > > > > > movq%rsp, %rbp
> > > > > > .cfi_def_cfa_register 6
> > > > > > clui
> > > > > > nop
> > > > > > popq%rbp
> > > > > > .cfi_def_cfa 7, 8
> > > > > > ret
> > > > > > .cfi_endproc
> > > > >
> > > > > Strange, without -muintr, it should not be generated, and some error
> > > > > about failed inlining due to target specific option mismatch shoul be
> > > > > emitted.
> > > > >
> > > > > Can you please investigate this a bit more?
> > > > >
> > > >
> > > > Because of function target attribute?
> > >
> > > I don't think so. Please consider this similar testcase:
> > >
> > > --cut here--
> > > #ifndef __SSE2__
> > > #pragma GCC push_options
> > > #pragma GCC target("sse2")
> > > #define __DISABLE_SSE2__
> > > #endif /* __SSE2__ */
> > >
> > > typedef double __v2df __attribute__ ((__vector_size__ (16)));
> > > typedef double __m128d __attribute__ ((__vector_size__ (16),
> > __may_alias__));
> > >
> > > extern __inline __m128d __attribute__((__gnu_inline__,
> > > __always_inline__, __artificial__))
> > > _mm_add_sd (__m128d __A, __m128d __B)
> > > {
> > >   return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
> > > }
> > >
> > > #ifdef __DISABLE_SSE2__
> > > #undef __DISABLE_SSE2__
> > > #pragma GCC pop_options
> > > #endif /* __DISABLE_SSE2__ */
> > >
> > >
> > > __v2df foo (__v2df a, __v2df b)
> > > {
> > >   return _mm_add_sd (a, b);
> > > }
> > > --cut here--
> > >
> > > $ gcc -O2 -mno-sse2 -S -dp sse2.c
> > > sse2.c: In function ‘foo’:
> > > sse2.c:11:1: error: inlining failed in call to ‘always_inline’
> > > ‘_mm_add_sd’: target specific option mismatch
> > >   11 | _mm_add_sd (__m128d __A, __m128d __B)
> > >  | ^~
> > > sse2.c:24:10: note: called from here
> > >   24 |   return _mm_add_sd (a, b);
> > >  |  ^
> > >
> > > I'd expect some similar warning from missing -mumip.
> > >
> >
> > For this case, I can confirm uintr could generate similar warning without
> > -muintr. But
> > sse-{12,13,14,22,23}.c will not test intrinsic call for uintr, since it
> > doesn't have const
> > int parameter intrinsics.
> >
> > sse-{13,14,22,23}.c has
> >
> > #define extern
> > #define __inline
> >
> > So intrinsic will be treated as common call to builtin, then
> >
> > #pragma GCC push_options
> > #pragma GCC target("uintr")
> >
> > ensures the builtin could be expanded correctly.
> >
> > I think the intrinsic call test should be in uintr-1.c, so it is redundant
> > to add -muintr in sse-{12,13,14,22,23}.c
> > or x86gprintrin-*.c.
>
> Please add UINTR intrinsic tests to x86gprintrin-*.c to cover such
> usages.
>
> > >
> > > Uros.
>
>
>
> --
> H.J.
From 7b5ba74517bf58b9f985bfe7591372c64a313ad7 Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Mon, 20 May 2019 17:56:41 +0800
Subject: [PATCH] Enable gcc support for UINTR

2020-05-20  Hongtao Liu  

gcc/
	* common/config/i386/cpuinfo.h (get_available_features):
	Detect UINTR.
	* common/config/i386/i386-common.c (OPTION_MASK_ISA2_UINTR_SET
	OPTION_MASK_ISA2_UINTR_UNSET): New.
	(ix86_handle_option): Handle -muintr.
	* common/config/i386/i386-cpuinfo.h (enum processor_features):
	Add FEATURE_UINTR.
	* common/config/i386/i386-isas.h: Add ISA_NAMES_TABLE_ENTRY
	for uintr.
	* config.gcc: Add uintrintrin.h to extra_headers.
	* config/i386/uintrintrin.h: New.
	* config/i386/cpuid.h (bit_UINTR): New.
	* config/i386/driver-i386.c (host_detect_local_cpu): Detect UINTR.
	* config/i38

Re: [Patch] x86: Enable support for Intel UINTR extension

2020-10-14 Thread Uros Bizjak via Gcc-patches
On Wed, Oct 14, 2020 at 5:06 PM Hongyu Wang  wrote:
>
> Hi Uros,
>
> Sorry for my misunderstanding. The test is for the correctness check
> of intrinsic header.
> I have add -muintr to x86gprintrin-{1,2,3,4,5}.c.
>
> UINTR is 64bit only, so I add them with dg-additional-option.
>
> Updated patch. If you agree, we will check-in the attached patch.

Yes, the patch is OK.

Thanks,
Uros.

> Thanks for your help.
>
> H.J. Lu  于2020年10月14日周三 下午9:35写道:
> >
> > On Wed, Oct 14, 2020 at 6:31 AM Hongyu Wang via Gcc-patches
> >  wrote:
> > >
> > > Uros Bizjak  于2020年10月14日周三 下午7:19写道:
> > > >
> > > > > > Please also add -muintr to g++.dg/other/i386-{2,3}.C and
> > > > > > >> > > gcc.target/i386-sse-{12,13,14,22,23}.c. This will test new
> > > intrinsics
> > > > > > >> > > header.
> > > > > > >> > >
> > > > > > >> >
> > > > > > >> > Thanks for your review. We found that without adding -muintr,
> > > the intrinsics header could also be tested. Make-check for these file all
> > > get passed.
> > > > > > >> >
> > > > > > >> > And there is no intrinsic/builtin with const int parameter. So
> > > we remove -muintr from these files.
> > > > > > >>
> > > > > > >> Can your double check that relevant instructions are indeed
> > > generated?
> > > > > > >> Without -muintr, relevant patterns in i386.md are effectively
> > > blocked,
> > > > > > >> and perhaps a call to __builtin_ia32_* is generated instead.
> > > > > > >
> > > > > > >
> > > > > > > Yes, in sse-14.s we have
> > > > > > >
> > > > > > > _clui:
> > > > > > > .LFB136:
> > > > > > > .cfi_startproc
> > > > > > > pushq   %rbp
> > > > > > > .cfi_def_cfa_offset 16
> > > > > > > .cfi_offset 6, -16
> > > > > > > movq%rsp, %rbp
> > > > > > > .cfi_def_cfa_register 6
> > > > > > > clui
> > > > > > > nop
> > > > > > > popq%rbp
> > > > > > > .cfi_def_cfa 7, 8
> > > > > > > ret
> > > > > > > .cfi_endproc
> > > > > >
> > > > > > Strange, without -muintr, it should not be generated, and some error
> > > > > > about failed inlining due to target specific option mismatch shoul 
> > > > > > be
> > > > > > emitted.
> > > > > >
> > > > > > Can you please investigate this a bit more?
> > > > > >
> > > > >
> > > > > Because of function target attribute?
> > > >
> > > > I don't think so. Please consider this similar testcase:
> > > >
> > > > --cut here--
> > > > #ifndef __SSE2__
> > > > #pragma GCC push_options
> > > > #pragma GCC target("sse2")
> > > > #define __DISABLE_SSE2__
> > > > #endif /* __SSE2__ */
> > > >
> > > > typedef double __v2df __attribute__ ((__vector_size__ (16)));
> > > > typedef double __m128d __attribute__ ((__vector_size__ (16),
> > > __may_alias__));
> > > >
> > > > extern __inline __m128d __attribute__((__gnu_inline__,
> > > > __always_inline__, __artificial__))
> > > > _mm_add_sd (__m128d __A, __m128d __B)
> > > > {
> > > >   return (__m128d)__builtin_ia32_addsd ((__v2df)__A, (__v2df)__B);
> > > > }
> > > >
> > > > #ifdef __DISABLE_SSE2__
> > > > #undef __DISABLE_SSE2__
> > > > #pragma GCC pop_options
> > > > #endif /* __DISABLE_SSE2__ */
> > > >
> > > >
> > > > __v2df foo (__v2df a, __v2df b)
> > > > {
> > > >   return _mm_add_sd (a, b);
> > > > }
> > > > --cut here--
> > > >
> > > > $ gcc -O2 -mno-sse2 -S -dp sse2.c
> > > > sse2.c: In function ‘foo’:
> > > > sse2.c:11:1: error: inlining failed in call to ‘always_inline’
> > > > ‘_mm_add_sd’: target specific option mismatch
> > > >   11 | _mm_add_sd (__m128d __A, __m128d __B)
> > > >  | ^~
> > > > sse2.c:24:10: note: called from here
> > > >   24 |   return _mm_add_sd (a, b);
> > > >  |  ^
> > > >
> > > > I'd expect some similar warning from missing -mumip.
> > > >
> > >
> > > For this case, I can confirm uintr could generate similar warning without
> > > -muintr. But
> > > sse-{12,13,14,22,23}.c will not test intrinsic call for uintr, since it
> > > doesn't have const
> > > int parameter intrinsics.
> > >
> > > sse-{13,14,22,23}.c has
> > >
> > > #define extern
> > > #define __inline
> > >
> > > So intrinsic will be treated as common call to builtin, then
> > >
> > > #pragma GCC push_options
> > > #pragma GCC target("uintr")
> > >
> > > ensures the builtin could be expanded correctly.
> > >
> > > I think the intrinsic call test should be in uintr-1.c, so it is redundant
> > > to add -muintr in sse-{12,13,14,22,23}.c
> > > or x86gprintrin-*.c.
> >
> > Please add UINTR intrinsic tests to x86gprintrin-*.c to cover such
> > usages.
> >
> > > >
> > > > Uros.
> >
> >
> >
> > --
> > H.J.