LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2012, 08:12 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
double size ints in C


On 32 bit architectures, GCC provided 64 bit integer types, with compiled code generally calling some function to do the work, though I do remember seeing this compiled in-line somewhere at one time (maybe a different version or a different compiler or a different architecture ... I have worked with ARM, MIPS, and PPC as well as x86).

Conclusion: it is not that hard to do the steps to implement double sized int arithmetic by a compiler.

So what about doing 128 bit integers on a 64 bit architecture with similar code? That doesn't seem to be implemented in GCC, or if it is, requires some special setting or header to make it (or the types) available. Anyone know how to do this? I'm wanting to avoid using a GMP or similar library for the 128 bit case, and let me just code it like normal arithmetic in C.
 
Old 03-05-2012, 01:48 PM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Code:
aconole@aconole-azilap:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) 
aconole@aconole-azilap:~$ cat double_int.c
#include <stdio.h>

int main(int argc, char *argv[])
{
    __int128 a = 0;

    a += 1590;
    
    printf("sizeof(__int128) = %lu\n", sizeof(a));

    return 0;
}
aconole@aconole-azilap:~$ gcc -o double_int double_int.c
aconole@aconole-azilap:~$ ./double_int 
sizeof(__int128) = 16
aconole@aconole-azilap:~$
Does this help?
 
1 members found this post helpful.
Old 03-05-2012, 04:06 PM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by orgcandman View Post
Code:
aconole@aconole-azilap:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) 
aconole@aconole-azilap:~$ cat double_int.c
#include <stdio.h>

int main(int argc, char *argv[])
{
    __int128 a = 0;

    a += 1590;
    
    printf("sizeof(__int128) = %lu\n", sizeof(a));

    return 0;
}
aconole@aconole-azilap:~$ gcc -o double_int double_int.c
aconole@aconole-azilap:~$ ./double_int 
sizeof(__int128) = 16
aconole@aconole-azilap:~$
Does this help?
Sort of. Looks like gcc 4.4.5 in my Ubuntu 10.10 doesn't have this.

Code:
lorentz/phil /home/phil 70> cat biggerint.c
#include <stdio.h>

int main(int argc, char *argv[])
{
    __int128 a = 0;

    a += 1590;
    
    printf("sizeof(__int128) = %lu\n", sizeof(a));

    return 0;
}
lorentz/phil /home/phil 71> gcc -o biggerint biggerint.c
biggerint.c: In function 'main':
biggerint.c:5: error: '__int128' undeclared (first use in this function)
biggerint.c:5: error: (Each undeclared identifier is reported only once
biggerint.c:5: error: for each function it appears in.)
biggerint.c:5: error: expected ';' before 'a'
biggerint.c:7: error: 'a' undeclared (first use in this function)
lorentz/phil /home/phil 72> find /usr/include -type f -exec fgrep -l __int128 '{}' ';'
lorentz/phil /home/phil 73>
Well, at least I now know WHAT to check for in a future version of gcc if I can get a usable desktop set up on a newer Ubuntu or convert everything I have over to another distro. Any idea just which version of gcc this started working?
 
Old 03-06-2012, 08:48 AM   #4
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
I'm not exactly sure when it was "blessed" by the gcc community, but it seems that a preliminary patch was delivered in Jan 2010.

All my reading seems to indicate it is in GCC 4.6+
 
Old 03-06-2012, 12:24 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by orgcandman View Post
I'm not exactly sure when it was "blessed" by the gcc community, but it seems that a preliminary patch was delivered in Jan 2010.

All my reading seems to indicate it is in GCC 4.6+
Thanks for the info. Ubuntu Oneiric (11.10) seems to be where 4.6 begins to be available. Slackware does not have 4.6, yet (maybe whatever follows 13.37 will have it).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
double desktop size edgjerp Linux - Hardware 1 05-26-2010 11:55 AM
XMMS Double size problem impeteperry Ubuntu 0 11-15-2006 02:38 PM
Swap double size of the RAM zillah Fedora 3 12-24-2005 07:13 AM
Swap double size of the RAM zillah Solaris / OpenSolaris 3 11-22-2005 11:30 AM
How do I double the size of my taksbar. zwyrbla Linux - Newbie 1 08-24-2004 12:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration