128 bit signed and unsigned integer types

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Dec 28 18:34:55 PST 2008

Yigal Chripun wrote:
> Andrei Alexandrescu wrote:
>> dsimcha wrote:
>>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>>> article
>>>> Walter Bright wrote:
>>>>> John Reimer wrote:
>>>>>> Hello Walter,
>>>>>>> You know, the unimplemented 128 bit integer types.
>>>>>>> Does anyone have a use for these?
>>>>>> Was that "cent" and "ucent"?
>>>>> yes.
>>>>>> Would any of these map well to SSE Instructions on Intel CPU's?
>>>>> Not a chance :-(
>>>> Then it looks like we better leave large fixed-size integers to a
>>>> library.
>>>> Andrei
>>> Something that I still don't think has been made very clear in this
>>> discussion
>>> that I'm very curious about: How efficient would these large
>>> fixed-size ints be
>>> (on 32-bit hardware)? Would they be almost as fast as 64-bit, almost
>>> as slow as
>>> bigints, or somewhere roughly in the middle? Obviously on 64-bit
>>> hardware they
>>> can be made fast, but if that's the only place they can be made fast,
>>> then I think
>>> it's more important that DMD support 64-bit hardware first.
>> Assume we define a FixedInt(uint bits) structure. That would contain the
>> value in-situ so there is no dynamic allocation, no indirection, and
>> full-blown copying. For built-in sizes, FixedInt will alias itself away,
>> for example:
>> template FixedInt(uint n) if (n == 8) { alias byte FixedInt; }
>> template FixedInt(uint n) if (n == 16) { alias short FixedInt; }
>> template FixedInt(uint n) if (n == 32) { alias int FixedInt; }
>> template FixedInt(uint n) if (n == 64) { alias long FixedInt; }
>> That's nice because it allows you to use FixedInt with a parameterized
>> size throughout, yet still take advantage of builtin optimizations
>> whenever applicable.
>> For the larger sizes and operations my guess would be that FixedInt will
>> be close to what can be achieved via built-ins.
>> Andrei
> is it possible to make int/long/short/etc internal to the compiler and 
> use the above FixedInt in the language? there shouldn't be any 
> performance differences between an old-style int and the above 
> FixedInt!(32), for instance.
> this way all the different types are reduced to one built-in type that 
> looks like a template. similar to the way C++ uses the template syntax 
> for casts like static_cast<type>(var) even though it's usually 
> implemented inside the compiler.

Well it's possible but probably too verbose for many. I mean, if I had 
only FixedInt, I'd first define int, short et al as aliases :o).


More information about the Digitalmars-d mailing list