This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [g77 testsuite]
- To: "Billinghurst, David (CRTS)" <David dot Billinghurst at riotinto dot com>
- Subject: Re: [g77 testsuite]
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Wed, 18 Jul 2001 22:23:22 +0200
- CC: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <8D00C32549556B4E977F81DBC24E985D1B1B73@crtsmail1.technol_exch.corp.riotinto.org>
"Billinghurst, David (CRTS)" wrote:
> This tests compliance with Fortran 90 bit manipulation functions. The test
> for BIT_SIZE could be strengthened if we could be sure of the size of
> INTEGER*1, INTEGER*2 and INTEGER.
I think while we can't be sure, we *can* perform a consistency test
[quoting the Fortran 95 Standard's October '97 draft because that's what
I have at hand]:
<QUOTE MODE=FORTRAN-STANDARDESE>
13.5.7 Bit manipulation and inquiry procedures
...
For the purposes of these procedures, a bit is defined to be a binary
digit w located at position k of a nonnegative integer scalar object
*based on a model nonnegative integer* [emphasis mine] defined by
z-1 k
j = SUM w x 2
k=0 k
and for which w may have the value 0 or 1.
k
...
An inquiry function BIT_SIZE is available to determine the parameter z
of the model.
...
13.14.50 ISHFT(I, SHIFT)
...
Result Value. The result has the value obtained by shifting the bits of
I by SHIFT positions. If SHIFT is positive, the shift is to the left;
if SHIFT is negative, the shift is to the right; and if SHIFT is zero,
no shift is performed. Bits shifted out from the left of from the
right, as appropriate, are lost. Zeros are shifted in from the opposite
end. The model for the interpretation of an integer value as a sequence
of bits is in 13.5.7.
...
13.14.78 NOT(I)
...
Result Value. The result has the value obtained by complementing I
bit-by-bit to the following truth table:
I NOT(I)
--------------
1 0
0 1
The model for the interpretation of an integer value as a sequence of
bits is in 13.5.7.
...
</QUOTE MODE=PHEW>
So I think
INTEGER I
I = 1
IF (ISHFT(I, BIT_SIZE(I)) .NE. 0) CALL ABORT
I = 0
IF (ISHFT(NOT(I), -BIT_SIZE(I)) .NE. 0) CALL ABORT
END
would test for this consistency (and mutatis mutandis for
INTEGER*{1|2|8}).
The nice thing is - this actually fails for i686-pc-linux-gnu (and
probably a lot of other targets).
;-)
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)