[Patch,Fortran] PR 33197 Add NORM2 and PARITY

Tobias Burnus burnus@net-b.de
Thu Aug 26 13:40:00 GMT 2010


  This patch adds NORM2 (= sqrt(sum(array**2))) and 
PARITY(logical_array) - and thus the last F2008 math intrinsics, which 
means that PR 33197 can be closed afterwards. (Though, there are still 
lots of bits-related intrinsics missing.)

All algorithms are implemented three times: (a) in simplify, (b) in 
trans-intrinsics (for scalar results, i.e. rank-1 arrays or if no dim= 
has been given), and (c) in libgfortran.

Please check when reading/testing the patch that it works correctly for 
zero-sized arrays, size-1 arrays and (for NORM2) arrays with values > 
sqrt(huge(a)).

For norm2 (L2 norm), one essentially does:
   tmp = max(array)  ! = L_infinity norm
   norm2 = tmp * sqrt( (array/tmp)**2)
to avoid an overflow. However, it is implemented using a single pass. 
For NORM2, an algorithm based on the one in BLAS is used though I have 
realized that I start with SCALE == 1, RESULT = 0 while BLAS uses the 
opposite starting values. Both seem to lead to the same result, thus, I 
do not know which one is better. Quickly thinking about it, mine seems 
to be better (faster + more accurate) for small values (<= 1.0), but I 
might be wrong. Cf. http://www.netlib.org/blas/snrm2.f

For simplify, NORM2 does not divide by max(array) as seemingly no 
overflow (truncation) occurs until the norm2 calculation has been 
completed. Thus, lazy as I was, I did not change that part to the more 
complicated algorithm.

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: norm2_parity-changes.txt
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20100826/0773ba52/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: norm2_parity.diff
Type: text/x-patch
Size: 44523 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20100826/0773ba52/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: norm2_parity-gen.diff
Type: text/x-patch
Size: 164951 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20100826/0773ba52/attachment-0001.bin>


More information about the Fortran mailing list