[libgfortran] I/O of 128 bits integers
FX Coudert
fxcoudert@gmail.com
Wed May 25 21:24:00 GMT 2005
Hi all,
Attached patch is an attempt at handling I/O of 128bits integers, and
any other types of integer in the future.
The libgfortran code relied on int64_t being the largest integer kind:
many parameters were passed as int64_t before being cast into their
final type. This is obviously wrong on some platforms, such as x86_64.
So, I propose we #define GFC_INTEGER_LARGEST to the largest integer kind
available, and use this instead of int64_t.
The question is: how do we know, when compiling the library, which is
the largest available integer kind for the target?
To do some testing, I defined GFC_INTEGER_LARGEST to be __int128_t on
x86_64 and int64_t everywhere else. With that, the patch bootstraps and
is regtested on i686-linux and x86_64-linux. On the latter, I can now do:
$ uname -mo
x86_64 GNU/Linux
$ cat a.f90
character(len=60) c
integer(kind=16) i, j
print *, bit_size(0_16)
print *, huge(0_16)
j = 2**(bit_size(0_16)-1) - 2**7
write (c,*) j
read (c,*) i
if (i /= j) call abort
write (c,'(I60)') j
read (c,'(I60)') i
if (i /= j) call abort
end
$ gfc a.f90 && ./a.out
128
170141183460469231731687303715884105727
$
I am waiting for comments on the general idea, the coding-style and
choice of name for GFC_INTEGER_LARGEST, as well as idea for a general
way to determine this type at compile-time. When everything is settled,
I will submit a proper patch (with ChangeLog entries and all).
Thanks,
FX
More information about the Fortran
mailing list