public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* 128-bit long long?
@ 2004-03-21 17:34 Scott Robert Ladd
  2004-03-21 17:37 ` Andreas Jaeger
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Scott Robert Ladd @ 2004-03-21 17:34 UTC (permalink / raw)
  To: gcc

On a 64-bit AMD64 architecture, GCC defines long long as 64 bits, the 
same as a long.

Given that certain 64-bit instructions (multiply) produce 128-bit 
results, doesn't it seem logical the long long be defined as 128 bits?

I'm just wonder...

-- 
Scott Robert Ladd
Coyote Gulch Productions (http://www.coyotegulch.com)
Software Invention for High-Performance Computing

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 17:34 128-bit long long? Scott Robert Ladd
@ 2004-03-21 17:37 ` Andreas Jaeger
  2004-03-21 18:02   ` Paolo Carlini
  2004-03-21 20:27   ` Erik Trulsson
  2004-03-21 20:52 ` Zack Weinberg
  2004-03-30  2:10 ` Jim Wilson
  2 siblings, 2 replies; 11+ messages in thread
From: Andreas Jaeger @ 2004-03-21 17:37 UTC (permalink / raw)
  To: Scott Robert Ladd; +Cc: gcc

[-- Attachment #1: Type: text/plain, Size: 569 bytes --]

Scott Robert Ladd <coyote@coyotegulch.com> writes:

> On a 64-bit AMD64 architecture, GCC defines long long as 64 bits, the
> same as a long.
>
> Given that certain 64-bit instructions (multiply) produce 128-bit
> results, doesn't it seem logical the long long be defined as 128 bits?
>
> I'm just wonder...

That will break too many "portable" software ;-(.

Andreas
-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SuSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

[-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 17:37 ` Andreas Jaeger
@ 2004-03-21 18:02   ` Paolo Carlini
  2004-03-21 20:27   ` Erik Trulsson
  1 sibling, 0 replies; 11+ messages in thread
From: Paolo Carlini @ 2004-03-21 18:02 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: Scott Robert Ladd, gcc

Andreas Jaeger wrote:

>That will break too many "portable" software ;-(.
>  
>
Thanks. In this respect C99 seems much better than current C++.
However:

    http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2004/n1568.htm

:)

Paolo.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 17:37 ` Andreas Jaeger
  2004-03-21 18:02   ` Paolo Carlini
@ 2004-03-21 20:27   ` Erik Trulsson
  1 sibling, 0 replies; 11+ messages in thread
From: Erik Trulsson @ 2004-03-21 20:27 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: Scott Robert Ladd, gcc

On Sun, Mar 21, 2004 at 04:35:47PM +0100, Andreas Jaeger wrote:
> Scott Robert Ladd <coyote@coyotegulch.com> writes:
> 
> > On a 64-bit AMD64 architecture, GCC defines long long as 64 bits, the
> > same as a long.
> >
> > Given that certain 64-bit instructions (multiply) produce 128-bit
> > results, doesn't it seem logical the long long be defined as 128 bits?
> >
> > I'm just wonder...
> 
> That will break too many "portable" software ;-(.

And probably some software that actually is (or rather was) portable.
In C90 it was (implicitly) guaranteed that 'long' was the largest
integer type.  This is not guaranteed in C99, but there is almost
certainly code out there that relies on 'long' being the largest
integer type.
Having 'long long' and 'long' being the same size keeps the compiler
compatible with C90.
(I don't know if that is the reason the sizes where chosen as they
were, but it is certainly *a* good reason for doing it.)

Then there are of course loads of buggy software that make invalid
assumptions and break when faced with a 128-bit 'long long', but I
suspect that many of them will break when faced with a 64-bit 'long' as
well, so I don't know if they are much to worry about.


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 17:34 128-bit long long? Scott Robert Ladd
  2004-03-21 17:37 ` Andreas Jaeger
@ 2004-03-21 20:52 ` Zack Weinberg
  2004-03-21 21:11   ` Joseph S. Myers
  2004-03-21 21:20   ` Scott Robert Ladd
  2004-03-30  2:10 ` Jim Wilson
  2 siblings, 2 replies; 11+ messages in thread
From: Zack Weinberg @ 2004-03-21 20:52 UTC (permalink / raw)
  To: Scott Robert Ladd; +Cc: gcc

Scott Robert Ladd <coyote@coyotegulch.com> writes:

> On a 64-bit AMD64 architecture, GCC defines long long as 64 bits, the
> same as a long.
>
> Given that certain 64-bit instructions (multiply) produce 128-bit
> results, doesn't it seem logical the long long be defined as 128 bits?

No, for two reasons:

1) The choice of 64-bit 'long long' has been written into the ABI of
   most LP64-model operating systems; we can't unilaterally change it.

2) This is actually the correct choice, as it removes the aberration
   that makes 'long' not the widest basic integral type.  There is
   lots and lots of code in the wild written to the assumption that
   sizeof(long) >= sizeof(size_t) - this is at least potentially
   broken by ABIs where long long is wider than long.

   (This was an extremely contentious topic during the development of
   C99.  As best as I can tell from an outside perspective, 'long long' 
   was only standardized due to pressure from Microsoft who can't for
   some reason implement an LP64 model.  Everyone else hated the idea
   of making 'long' not necessarily the widest basic integral type.)

Best current practice appears to be to provide an "extended integral
type" __int128.  This doesn't have the problems of 'long long' because
it's not a *basic* integral type (in particular, it cannot be used for
size_t).

zw

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 20:52 ` Zack Weinberg
@ 2004-03-21 21:11   ` Joseph S. Myers
  2004-03-21 21:20   ` Scott Robert Ladd
  1 sibling, 0 replies; 11+ messages in thread
From: Joseph S. Myers @ 2004-03-21 21:11 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Scott Robert Ladd, gcc

On Sun, 21 Mar 2004, Zack Weinberg wrote:

> Best current practice appears to be to provide an "extended integral
> type" __int128.  This doesn't have the problems of 'long long' because
> it's not a *basic* integral type (in particular, it cannot be used for
> size_t).

Except it can't be an extended integer type within the meaning of C99
either, because the same ABIs also fix intmax_t to be 64 bits.

-- 
Joseph S. Myers
jsm@polyomino.org.uk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 20:52 ` Zack Weinberg
  2004-03-21 21:11   ` Joseph S. Myers
@ 2004-03-21 21:20   ` Scott Robert Ladd
  2004-03-22  0:12     ` Paolo Carlini
  1 sibling, 1 reply; 11+ messages in thread
From: Scott Robert Ladd @ 2004-03-21 21:20 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc

Zack Weinberg wrote:
> Best current practice appears to be to provide an "extended integral
> type" __int128.  This doesn't have the problems of 'long long' because
> it's not a *basic* integral type (in particular, it cannot be used for
> size_t).

I always wondered why C99 didn't define both int128_t and uint128_t in 
<stdint.h>.

..Scott

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 21:20   ` Scott Robert Ladd
@ 2004-03-22  0:12     ` Paolo Carlini
  2004-03-24  5:38       ` Richard B. Kreckel
  0 siblings, 1 reply; 11+ messages in thread
From: Paolo Carlini @ 2004-03-22  0:12 UTC (permalink / raw)
  To: Scott Robert Ladd; +Cc: Zack Weinberg, gcc

Scott Robert Ladd wrote:

> I always wondered why C99 didn't define both int128_t and uint128_t in 
> <stdint.h>.

However, according to 7.18.1.1, p3, intN_t and uintN_t are *all* optional.

I wonder if any 64 bit architecture actually provides 128bit integer types,
typedef-ed in stdint.h. Sparc64?!? s390x?!?

Paolo.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-22  0:12     ` Paolo Carlini
@ 2004-03-24  5:38       ` Richard B. Kreckel
  2004-03-24  5:57         ` Paolo Carlini
  0 siblings, 1 reply; 11+ messages in thread
From: Richard B. Kreckel @ 2004-03-24  5:38 UTC (permalink / raw)
  To: gcc; +Cc: Paolo Carlini, Scott Robert Ladd, Zack Weinberg

On Sun, 21 Mar 2004, Paolo Carlini wrote:

> Scott Robert Ladd wrote:
>
> > I always wondered why C99 didn't define both int128_t and uint128_t in
> > <stdint.h>.
>
> However, according to 7.18.1.1, p3, intN_t and uintN_t are *all* optional.

Hmmm, I've always believed that the next sentence ("However, if an
implementation provides integer types with widths of 8, 16, 32 or 64 bits,
it shall define the corresponding typedef names") is to be construed as a
*requirement* of these types on machines where they make sense.  In
particular this applies to x86 and x86_64, the two architectures this
thread was originally all about.

Regards
    -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-24  5:38       ` Richard B. Kreckel
@ 2004-03-24  5:57         ` Paolo Carlini
  0 siblings, 0 replies; 11+ messages in thread
From: Paolo Carlini @ 2004-03-24  5:57 UTC (permalink / raw)
  To: Richard.Kreckel; +Cc: gcc

Richard B. Kreckel wrote:

>Hmmm, I've always believed that the next sentence ("However, if an
>implementation provides integer types with widths of 8, 16, 32 or 64 bits,
>it shall define the corresponding typedef names") is to be construed as a
>*requirement* of these types on machines where they make sense.
>
I agree.

Paolo.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: 128-bit long long?
  2004-03-21 17:34 128-bit long long? Scott Robert Ladd
  2004-03-21 17:37 ` Andreas Jaeger
  2004-03-21 20:52 ` Zack Weinberg
@ 2004-03-30  2:10 ` Jim Wilson
  2 siblings, 0 replies; 11+ messages in thread
From: Jim Wilson @ 2004-03-30  2:10 UTC (permalink / raw)
  To: Scott Robert Ladd; +Cc: gcc

Scott Robert Ladd wrote:
> On a 64-bit AMD64 architecture, GCC defines long long as 64 bits, the 
> same as a long.
> Given that certain 64-bit instructions (multiply) produce 128-bit 
> results, doesn't it seem logical the long long be defined as 128 bits?

Part of the reason here is historical accident.  Early 64-bit targets 
had to be supported via cross compilation from 32-bit hosts.  Gcc 
internally represents tree and rtl values as 2 HOST_WIDE_INT values. 
This was before most compilers had long long support, so HOST_WIDE_INT 
had to be long.  Thus a 32-bit host could support at most a 64-bit 
integer type.  So all early 64-bit ports had to limit long long to 
64-bits.  This restriction was removed relatively recently, between 3.3 
and 3.4.  So it wasn't until 3.4 that we can have a 128-bit long long 
type and still support cross compilation from a 32-bit host.  However, 
by now, 64-bit long long assumptions have been written into so much 
software that changing it would be too painful.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-03-30  0:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-21 17:34 128-bit long long? Scott Robert Ladd
2004-03-21 17:37 ` Andreas Jaeger
2004-03-21 18:02   ` Paolo Carlini
2004-03-21 20:27   ` Erik Trulsson
2004-03-21 20:52 ` Zack Weinberg
2004-03-21 21:11   ` Joseph S. Myers
2004-03-21 21:20   ` Scott Robert Ladd
2004-03-22  0:12     ` Paolo Carlini
2004-03-24  5:38       ` Richard B. Kreckel
2004-03-24  5:57         ` Paolo Carlini
2004-03-30  2:10 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).