diff mbox

[wide-int] Add fast path for hosts with HWI widening multiplication

Message ID 87vbtg2kcq.fsf@talisman.default
State New
Headers show

Commit Message

Richard Sandiford May 8, 2014, 6:31 p.m. UTC
"Joseph S. Myers" <joseph@codesourcery.com> writes:
> On Thu, 8 May 2014, Ramana Radhakrishnan wrote:
>
>> <DATE>  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>> 
>>        * wide-int.cc (UTItype): Define.
>>        (UDWtype): Define for appropriate W_TYPE_SIZE.
>
> This breaks builds for 32-bit hosts, where TImode isn't supported.  You 
> can only use TImode on the host if it's 64-bit.
>
> wide-int.cc:37:56: error: unable to emulate 'TI'

The longlong.h interface seems to be designed to be as difficult to use
as possible :-(  So maybe we really do need to limit it to hosts that are
known to work and benefit from it.

How about the following?  I tested that it produces identical
wide-int.o .text for x86_64.

I think additions to or removals from the list should be treated as
pre-approved.

Thanks,
Richard


gcc/
	* wide-int.cc: Only include longlong.h for certain targets.

Comments

Kenneth Zadeck May 8, 2014, 6:36 p.m. UTC | #1
everyone who has a private port will hate you forever.   note that i 
have 2 of them.
On 05/08/2014 02:31 PM, Richard Sandiford wrote:
> "Joseph S. Myers" <joseph@codesourcery.com> writes:
>> On Thu, 8 May 2014, Ramana Radhakrishnan wrote:
>>
>>> <DATE>  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>>>
>>>         * wide-int.cc (UTItype): Define.
>>>         (UDWtype): Define for appropriate W_TYPE_SIZE.
>> This breaks builds for 32-bit hosts, where TImode isn't supported.  You
>> can only use TImode on the host if it's 64-bit.
>>
>> wide-int.cc:37:56: error: unable to emulate 'TI'
> The longlong.h interface seems to be designed to be as difficult to use
> as possible :-(  So maybe we really do need to limit it to hosts that are
> known to work and benefit from it.
>
> How about the following?  I tested that it produces identical
> wide-int.o .text for x86_64.
>
> I think additions to or removals from the list should be treated as
> pre-approved.
>
> Thanks,
> Richard
>
>
> gcc/
> 	* wide-int.cc: Only include longlong.h for certain targets.
>
> Index: gcc/wide-int.cc
> ===================================================================
> --- gcc/wide-int.cc	2014-05-08 19:13:15.782158808 +0100
> +++ gcc/wide-int.cc	2014-05-08 19:28:52.880742385 +0100
> @@ -27,19 +27,20 @@ along with GCC; see the file COPYING3.
>   #include "tree.h"
>   #include "dumpfile.h"
>   
> -#if GCC_VERSION >= 3000
> +#if (GCC_VERSION >= 3000 \
> +     && (defined __aarch64 \
> +         || defined __alpha \
> +         || defined __ia64 \
> +         || defined __powerpc64__ \
> +         || defined __sparcv9 \
> +         || defined __x86_64__))
>   #define W_TYPE_SIZE HOST_BITS_PER_WIDE_INT
> -typedef unsigned HOST_HALF_WIDE_INT UHWtype;
> -typedef unsigned HOST_WIDE_INT UWtype;
>   typedef unsigned int UQItype __attribute__ ((mode (QI)));
>   typedef unsigned int USItype __attribute__ ((mode (SI)));
>   typedef unsigned int UDItype __attribute__ ((mode (DI)));
> -typedef unsigned int UTItype __attribute__ ((mode (TI)));
> -#if W_TYPE_SIZE == 32
> -# define UDWtype       UDItype
> -#elif W_TYPE_SIZE == 64
> -# define UDWtype       UTItype
> -#endif
> +typedef unsigned HOST_HALF_WIDE_INT UHWtype;
> +typedef unsigned HOST_WIDE_INT UWtype;
> +typedef unsigned int UDWtype __attribute__ ((mode (TI)));
>   #include "longlong.h"
>   #endif
>
Richard Sandiford May 8, 2014, 7:18 p.m. UTC | #2
Kenneth Zadeck <zadeck@naturalbridge.com> writes:
> everyone who has a private port will hate you forever.   note that i 
> have 2 of them.

Got any other ideas though?  I suppose if we're prepared to break
compatibility with whatever the upstream of longlong.h is, we could
make more use of intN_t and uintN_t.

Having a whitelist of hosts seems like the best fix though.
I'm not sure the default umul_ppmm is going to be any better
than not defining it.

Thanks,
Richard

> On 05/08/2014 02:31 PM, Richard Sandiford wrote:
>> "Joseph S. Myers" <joseph@codesourcery.com> writes:
>>> On Thu, 8 May 2014, Ramana Radhakrishnan wrote:
>>>
>>>> <DATE>  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>>>>
>>>>         * wide-int.cc (UTItype): Define.
>>>>         (UDWtype): Define for appropriate W_TYPE_SIZE.
>>> This breaks builds for 32-bit hosts, where TImode isn't supported.  You
>>> can only use TImode on the host if it's 64-bit.
>>>
>>> wide-int.cc:37:56: error: unable to emulate 'TI'
>> The longlong.h interface seems to be designed to be as difficult to use
>> as possible :-(  So maybe we really do need to limit it to hosts that are
>> known to work and benefit from it.
>>
>> How about the following?  I tested that it produces identical
>> wide-int.o .text for x86_64.
>>
>> I think additions to or removals from the list should be treated as
>> pre-approved.
>>
>> Thanks,
>> Richard
>>
>>
>> gcc/
>> 	* wide-int.cc: Only include longlong.h for certain targets.
>>
>> Index: gcc/wide-int.cc
>> ===================================================================
>> --- gcc/wide-int.cc	2014-05-08 19:13:15.782158808 +0100
>> +++ gcc/wide-int.cc	2014-05-08 19:28:52.880742385 +0100
>> @@ -27,19 +27,20 @@ along with GCC; see the file COPYING3.
>>   #include "tree.h"
>>   #include "dumpfile.h"
>>   
>> -#if GCC_VERSION >= 3000
>> +#if (GCC_VERSION >= 3000 \
>> +     && (defined __aarch64 \
>> +         || defined __alpha \
>> +         || defined __ia64 \
>> +         || defined __powerpc64__ \
>> +         || defined __sparcv9 \
>> +         || defined __x86_64__))
>>   #define W_TYPE_SIZE HOST_BITS_PER_WIDE_INT
>> -typedef unsigned HOST_HALF_WIDE_INT UHWtype;
>> -typedef unsigned HOST_WIDE_INT UWtype;
>>   typedef unsigned int UQItype __attribute__ ((mode (QI)));
>>   typedef unsigned int USItype __attribute__ ((mode (SI)));
>>   typedef unsigned int UDItype __attribute__ ((mode (DI)));
>> -typedef unsigned int UTItype __attribute__ ((mode (TI)));
>> -#if W_TYPE_SIZE == 32
>> -# define UDWtype       UDItype
>> -#elif W_TYPE_SIZE == 64
>> -# define UDWtype       UTItype
>> -#endif
>> +typedef unsigned HOST_HALF_WIDE_INT UHWtype;
>> +typedef unsigned HOST_WIDE_INT UWtype;
>> +typedef unsigned int UDWtype __attribute__ ((mode (TI)));
>>   #include "longlong.h"
>>   #endif
>>
H.J. Lu May 8, 2014, 7:34 p.m. UTC | #3
On Thu, May 8, 2014 at 12:18 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> Kenneth Zadeck <zadeck@naturalbridge.com> writes:
>> everyone who has a private port will hate you forever.   note that i
>> have 2 of them.
>
> Got any other ideas though?  I suppose if we're prepared to break
> compatibility with whatever the upstream of longlong.h is, we could
> make more use of intN_t and uintN_t.
>
> Having a whitelist of hosts seems like the best fix though.
> I'm not sure the default umul_ppmm is going to be any better
> than not defining it.
>

Can you add a configure time check if

typedef unsigned int UTItype __attribute__ ((mode (TI)));

is supported?
Jakub Jelinek May 8, 2014, 7:42 p.m. UTC | #4
On Thu, May 08, 2014 at 12:34:28PM -0700, H.J. Lu wrote:
> On Thu, May 8, 2014 at 12:18 PM, Richard Sandiford
> <rdsandiford@googlemail.com> wrote:
> > Kenneth Zadeck <zadeck@naturalbridge.com> writes:
> >> everyone who has a private port will hate you forever.   note that i
> >> have 2 of them.
> >
> > Got any other ideas though?  I suppose if we're prepared to break
> > compatibility with whatever the upstream of longlong.h is, we could
> > make more use of intN_t and uintN_t.
> >
> > Having a whitelist of hosts seems like the best fix though.
> > I'm not sure the default umul_ppmm is going to be any better
> > than not defining it.
> >
> 
> Can you add a configure time check if
> 
> typedef unsigned int UTItype __attribute__ ((mode (TI)));
> 
> is supported?

Why?  Isn't that #ifdef __SIZEOF_INT128__ ?

	Jakub
H.J. Lu May 8, 2014, 7:48 p.m. UTC | #5
On Thu, May 8, 2014 at 12:42 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, May 08, 2014 at 12:34:28PM -0700, H.J. Lu wrote:
>> On Thu, May 8, 2014 at 12:18 PM, Richard Sandiford
>> <rdsandiford@googlemail.com> wrote:
>> > Kenneth Zadeck <zadeck@naturalbridge.com> writes:
>> >> everyone who has a private port will hate you forever.   note that i
>> >> have 2 of them.
>> >
>> > Got any other ideas though?  I suppose if we're prepared to break
>> > compatibility with whatever the upstream of longlong.h is, we could
>> > make more use of intN_t and uintN_t.
>> >
>> > Having a whitelist of hosts seems like the best fix though.
>> > I'm not sure the default umul_ppmm is going to be any better
>> > than not defining it.
>> >
>>
>> Can you add a configure time check if
>>
>> typedef unsigned int UTItype __attribute__ ((mode (TI)));
>>
>> is supported?
>
> Why?  Isn't that #ifdef __SIZEOF_INT128__ ?
>

Yes, we can use that.  Will it work?
Richard Earnshaw May 9, 2014, 9:01 a.m. UTC | #6
On 08/05/14 19:31, Richard Sandiford wrote:
> "Joseph S. Myers" <joseph@codesourcery.com> writes:
>> On Thu, 8 May 2014, Ramana Radhakrishnan wrote:
>>
>>> <DATE>  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
>>>
>>>        * wide-int.cc (UTItype): Define.
>>>        (UDWtype): Define for appropriate W_TYPE_SIZE.
>>
>> This breaks builds for 32-bit hosts, where TImode isn't supported.  You 
>> can only use TImode on the host if it's 64-bit.
>>
>> wide-int.cc:37:56: error: unable to emulate 'TI'
> 
> The longlong.h interface seems to be designed to be as difficult to use
> as possible :-(  So maybe we really do need to limit it to hosts that are
> known to work and benefit from it.
> 
> How about the following?  I tested that it produces identical
> wide-int.o .text for x86_64.
> 
> I think additions to or removals from the list should be treated as
> pre-approved.
> 
> Thanks,
> Richard
> 
> 
> gcc/
> 	* wide-int.cc: Only include longlong.h for certain targets.
> 
> Index: gcc/wide-int.cc
> ===================================================================
> --- gcc/wide-int.cc	2014-05-08 19:13:15.782158808 +0100
> +++ gcc/wide-int.cc	2014-05-08 19:28:52.880742385 +0100
> @@ -27,19 +27,20 @@ along with GCC; see the file COPYING3.
>  #include "tree.h"
>  #include "dumpfile.h"
>  
> -#if GCC_VERSION >= 3000
> +#if (GCC_VERSION >= 3000 \
> +     && (defined __aarch64 \

Needs tailing underscores: __aarch64__

R.

> +         || defined __alpha \
> +         || defined __ia64 \
> +         || defined __powerpc64__ \
> +         || defined __sparcv9 \
> +         || defined __x86_64__))
>  #define W_TYPE_SIZE HOST_BITS_PER_WIDE_INT
> -typedef unsigned HOST_HALF_WIDE_INT UHWtype;
> -typedef unsigned HOST_WIDE_INT UWtype;
>  typedef unsigned int UQItype __attribute__ ((mode (QI)));
>  typedef unsigned int USItype __attribute__ ((mode (SI)));
>  typedef unsigned int UDItype __attribute__ ((mode (DI)));
> -typedef unsigned int UTItype __attribute__ ((mode (TI)));
> -#if W_TYPE_SIZE == 32
> -# define UDWtype       UDItype
> -#elif W_TYPE_SIZE == 64
> -# define UDWtype       UTItype
> -#endif
> +typedef unsigned HOST_HALF_WIDE_INT UHWtype;
> +typedef unsigned HOST_WIDE_INT UWtype;
> +typedef unsigned int UDWtype __attribute__ ((mode (TI)));
>  #include "longlong.h"
>  #endif
>  
>
diff mbox

Patch

Index: gcc/wide-int.cc
===================================================================
--- gcc/wide-int.cc	2014-05-08 19:13:15.782158808 +0100
+++ gcc/wide-int.cc	2014-05-08 19:28:52.880742385 +0100
@@ -27,19 +27,20 @@  along with GCC; see the file COPYING3.
 #include "tree.h"
 #include "dumpfile.h"
 
-#if GCC_VERSION >= 3000
+#if (GCC_VERSION >= 3000 \
+     && (defined __aarch64 \
+         || defined __alpha \
+         || defined __ia64 \
+         || defined __powerpc64__ \
+         || defined __sparcv9 \
+         || defined __x86_64__))
 #define W_TYPE_SIZE HOST_BITS_PER_WIDE_INT
-typedef unsigned HOST_HALF_WIDE_INT UHWtype;
-typedef unsigned HOST_WIDE_INT UWtype;
 typedef unsigned int UQItype __attribute__ ((mode (QI)));
 typedef unsigned int USItype __attribute__ ((mode (SI)));
 typedef unsigned int UDItype __attribute__ ((mode (DI)));
-typedef unsigned int UTItype __attribute__ ((mode (TI)));
-#if W_TYPE_SIZE == 32
-# define UDWtype       UDItype
-#elif W_TYPE_SIZE == 64
-# define UDWtype       UTItype
-#endif
+typedef unsigned HOST_HALF_WIDE_INT UHWtype;
+typedef unsigned HOST_WIDE_INT UWtype;
+typedef unsigned int UDWtype __attribute__ ((mode (TI)));
 #include "longlong.h"
 #endif