re PR libfortran/30533 ([4.1 only] minval, maxval missing for kind=1 and kind=2)

2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	PR libfortran/30765
	* Makefile.am: Add $(srcdir) too all files in generated/.
	(i_maxloc0_c): Add maxloc0_4_i1.c, maxloc0_8_i1.c,
	maxloc0_16_i1.c, maxloc0_4_i2.c, maxloc0_8_i2.c and
	maxloc0_16_i2.c.
	(i_maxloc1_c): Add maxloc1_4_i1.c, maxloc1_8_i1.c,
	maxloc1_16_i1.c, maxloc1_4_i2.c, maxloc1_8_i2.c and
	maxloc1_16_i2.c.
	(i_maxval_c): Add maxval_i1.c and maxval_i2.c.
	(i_minloc0_c):  Add minloc0_4_i1.c, minloc0_8_i1.c,
	minloc0_16_i1.c, minloc0_4_i2.c, minloc0_8_i2.c and
	minloc0_16_i2.c.
	(i_minloc_1.c): Add minloc1_4_i1.c, minloc1_8_i1.c,
	minloc1_16_i1.c, minloc1_4_i2.c, minloc1_8_i2.c and
	minloc1_16_i2.c.
	(i_minval_c):  Add minval_i1.c and minval_i2.c.
	(i_sum_c):  Add sum_i1.c and sum_i2.c.
	(i_product_c):  Add product_i1.c and product_i2.c.
	(i_matmul_c):  Add matmul_i1.c and matmul_i2.c.
	(gfor_built_specific_src):  Remove $(srcdir) from target.
	(gfor_bulit_specific2_src):  Likewise.
	Makefile.in:  Regenerated.
	libgfortran.h:  Add GFC_INTEGER_1_HUGE and GFC_INTEGER_2_HUGE.
	Add gfc_array_i1 and gfc_array_i2.
	* generated/matmul_i1.c: New file.
	* generated/matmul_i2.c: New file.
	* generated/maxloc0_16_i1.c: New file.
	* generated/maxloc0_16_i2.c: New file.
	* generated/maxloc0_4_i1.c: New file.
	* generated/maxloc0_4_i2.c: New file.
	* generated/maxloc0_8_i1.c: New file.
	* generated/maxloc0_8_i2.c: New file.
	* generated/maxloc1_16_i1.c: New file.
	* generated/maxloc1_16_i2.c: New file.
	* generated/maxloc1_4_i1.c: New file.
	* generated/maxloc1_4_i2.c: New file.
	* generated/maxloc1_8_i1.c: New file.
	* generated/maxloc1_8_i2.c: New file.
	* generated/maxval_i1.c: New file.
	* generated/maxval_i2.c: New file.
	* generated/minloc0_16_i1.c: New file.
	* generated/minloc0_16_i2.c: New file.
	* generated/minloc0_4_i1.c: New file.
	* generated/minloc0_4_i2.c: New file.
	* generated/minloc0_8_i1.c: New file.
	* generated/minloc0_8_i2.c: New file.
	* generated/minloc1_16_i1.c: New file.
	* generated/minloc1_16_i2.c: New file.
	* generated/minloc1_4_i1.c: New file.
	* generated/minloc1_4_i2.c: New file.
	* generated/minloc1_8_i1.c: New file.
	* generated/minloc1_8_i2.c: New file.
	* generated/minval_i1.c: New file.
	* generated/minval_i2.c: New file.
	* generated/product_i1.c: New file.
	* generated/product_i2.c: New file.
	* generated/sum_i1.c: New file.
	* generated/sum_i2.c: New file.

2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	* fortran/iresolve.c(gfc_resolve_maxloc):  Remove coercion of
	argument to default integer.
	(gfc_resolve_minloc):  Likewise.

2007-02-19  Thomas Koenig  <Thomas.Koenig@online.de>

	PR libfortran/30533
	* gfortran.dg/intrinsic_intkinds_1.f90:  New test.

From-SVN: r122137
This commit is contained in:
Thomas Koenig 2007-02-19 20:49:10 +00:00 committed by Thomas Koenig
parent c116cd05fb
commit 567c915b04
42 changed files with 15461 additions and 2121 deletions

View File

@ -1,3 +1,10 @@
2007-02-19 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/30533
* fortran/iresolve.c(gfc_resolve_maxloc): Remove coercion of
argument to default integer.
(gfc_resolve_minloc): Likewise.
2007-02-18 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/30681

View File

@ -1231,19 +1231,6 @@ gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
else
name = "maxloc";
/* If the rank of the function is nonzero, we are going to call
a library function. Coerce the argument to one of the
existing library functions for this case. */
if (f->rank != 0 && array->ts.type == BT_INTEGER
&& array->ts.kind < gfc_default_integer_kind)
{
gfc_typespec ts;
ts.type = BT_INTEGER;
ts.kind = gfc_default_integer_kind;
gfc_convert_type_warn (array, &ts, 2, 0);
}
f->value.function.name
= gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
gfc_type_letter (array->ts.type), array->ts.kind);
@ -1398,19 +1385,6 @@ gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
else
name = "minloc";
/* If the rank of the function is nonzero, we are going to call
a library function. Coerce the argument to one of the
existing library functions for this case. */
if (f->rank != 0 && array->ts.type == BT_INTEGER
&& array->ts.kind < gfc_default_integer_kind)
{
gfc_typespec ts;
ts.type = BT_INTEGER;
ts.kind = gfc_default_integer_kind;
gfc_convert_type_warn (array, &ts, 2, 0);
}
f->value.function.name
= gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
gfc_type_letter (array->ts.type), array->ts.kind);

View File

@ -1,3 +1,8 @@
2007-02-19 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/30533
* gfortran.dg/intrinsic_intkinds_1.f90: New test.
2007-02-19 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* gcc.dg/20031012-1.c: Replace -Walways-true with -Waddress.

View File

@ -0,0 +1,20 @@
! { dg-do run }
! Test assorted intrinsics for integer kinds 1 and 2
program main
integer(kind=1), dimension(2,2) :: a
integer(kind=2), dimension(2,2) :: b
integer(kind=1), dimension(2) :: r1
integer(kind=2), dimension(2) :: r2
logical, dimension(2,2) :: ma
ma = .false.
a = reshape((/ 1_1, 2_1, 3_1, 4_1/), shape(a))
b = reshape((/ 1_2, 2_2, 3_2, 4_2/), shape(b))
if (any(sum(a,dim=2) /= (/ 4, 6 /))) call abort
if (any(sum(b,dim=2) /= (/ 4, 6 /))) call abort
if (any(product(a,dim=2) /= (/ 3, 8 /))) call abort
if (any(product(b,dim=2) /= (/ 3, 8 /))) call abort
if (any(matmul(a,a) /= reshape ( (/ 7, 10, 15, 22 /), shape(a)))) call abort
if (any(matmul(b,b) /= reshape ( (/ 7, 10, 15, 22 /), shape(b)))) call abort
if (any(maxval(a,dim=2,mask=ma) /= -128)) call abort
if (any(maxval(b,dim=2,mask=ma) /= -32768)) call abort
end program main

View File

@ -1,3 +1,65 @@
2007-02-19 Thomas Koenig <Thomas.Koenig@online.de>
PR libfortran/30533
PR libfortran/30765
* Makefile.am: Add $(srcdir) too all files in generated/.
(i_maxloc0_c): Add maxloc0_4_i1.c, maxloc0_8_i1.c,
maxloc0_16_i1.c, maxloc0_4_i2.c, maxloc0_8_i2.c and
maxloc0_16_i2.c.
(i_maxloc1_c): Add maxloc1_4_i1.c, maxloc1_8_i1.c,
maxloc1_16_i1.c, maxloc1_4_i2.c, maxloc1_8_i2.c and
maxloc1_16_i2.c.
(i_maxval_c): Add maxval_i1.c and maxval_i2.c.
(i_minloc0_c): Add minloc0_4_i1.c, minloc0_8_i1.c,
minloc0_16_i1.c, minloc0_4_i2.c, minloc0_8_i2.c and
minloc0_16_i2.c.
(i_minloc_1.c): Add minloc1_4_i1.c, minloc1_8_i1.c,
minloc1_16_i1.c, minloc1_4_i2.c, minloc1_8_i2.c and
minloc1_16_i2.c.
(i_minval_c): Add minval_i1.c and minval_i2.c.
(i_sum_c): Add sum_i1.c and sum_i2.c.
(i_product_c): Add product_i1.c and product_i2.c.
(i_matmul_c): Add matmul_i1.c and matmul_i2.c.
(gfor_built_specific_src): Remove $(srcdir) from target.
(gfor_bulit_specific2_src): Likewise.
Makefile.in: Regenerated.
libgfortran.h: Add GFC_INTEGER_1_HUGE and GFC_INTEGER_2_HUGE.
Add gfc_array_i1 and gfc_array_i2.
* generated/matmul_i1.c: New file.
* generated/matmul_i2.c: New file.
* generated/maxloc0_16_i1.c: New file.
* generated/maxloc0_16_i2.c: New file.
* generated/maxloc0_4_i1.c: New file.
* generated/maxloc0_4_i2.c: New file.
* generated/maxloc0_8_i1.c: New file.
* generated/maxloc0_8_i2.c: New file.
* generated/maxloc1_16_i1.c: New file.
* generated/maxloc1_16_i2.c: New file.
* generated/maxloc1_4_i1.c: New file.
* generated/maxloc1_4_i2.c: New file.
* generated/maxloc1_8_i1.c: New file.
* generated/maxloc1_8_i2.c: New file.
* generated/maxval_i1.c: New file.
* generated/maxval_i2.c: New file.
* generated/minloc0_16_i1.c: New file.
* generated/minloc0_16_i2.c: New file.
* generated/minloc0_4_i1.c: New file.
* generated/minloc0_4_i2.c: New file.
* generated/minloc0_8_i1.c: New file.
* generated/minloc0_8_i2.c: New file.
* generated/minloc1_16_i1.c: New file.
* generated/minloc1_16_i2.c: New file.
* generated/minloc1_4_i1.c: New file.
* generated/minloc1_4_i2.c: New file.
* generated/minloc1_8_i1.c: New file.
* generated/minloc1_8_i2.c: New file.
* generated/minval_i1.c: New file.
* generated/minval_i2.c: New file.
* generated/product_i1.c: New file.
* generated/product_i2.c: New file.
* generated/sum_i1.c: New file.
* generated/sum_i2.c: New file.
2007-02-16 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* runtime/memory.c (deallocate): Correct comment.

View File

@ -109,314 +109,348 @@ runtime/string.c \
runtime/select.c
i_all_c= \
generated/all_l4.c \
generated/all_l8.c \
generated/all_l16.c
$(srcdir)/generated/all_l4.c \
$(srcdir)/generated/all_l8.c \
$(srcdir)/generated/all_l16.c
i_any_c= \
generated/any_l4.c \
generated/any_l8.c \
generated/any_l16.c
$(srcdir)/generated/any_l4.c \
$(srcdir)/generated/any_l8.c \
$(srcdir)/generated/any_l16.c
i_count_c= \
generated/count_4_l4.c \
generated/count_8_l4.c \
generated/count_16_l4.c \
generated/count_4_l8.c \
generated/count_8_l8.c \
generated/count_16_l8.c \
generated/count_4_l16.c \
generated/count_8_l16.c \
generated/count_16_l16.c
$(srcdir)/generated/count_4_l4.c \
$(srcdir)/generated/count_8_l4.c \
$(srcdir)/generated/count_16_l4.c \
$(srcdir)/generated/count_4_l8.c \
$(srcdir)/generated/count_8_l8.c \
$(srcdir)/generated/count_16_l8.c \
$(srcdir)/generated/count_4_l16.c \
$(srcdir)/generated/count_8_l16.c \
$(srcdir)/generated/count_16_l16.c
i_maxloc0_c= \
generated/maxloc0_4_i4.c \
generated/maxloc0_8_i4.c \
generated/maxloc0_16_i4.c \
generated/maxloc0_4_i8.c \
generated/maxloc0_8_i8.c \
generated/maxloc0_16_i8.c \
generated/maxloc0_4_i16.c \
generated/maxloc0_8_i16.c \
generated/maxloc0_16_i16.c \
generated/maxloc0_4_r4.c \
generated/maxloc0_8_r4.c \
generated/maxloc0_16_r4.c \
generated/maxloc0_4_r8.c \
generated/maxloc0_8_r8.c \
generated/maxloc0_16_r8.c \
generated/maxloc0_4_r10.c \
generated/maxloc0_8_r10.c \
generated/maxloc0_16_r10.c \
generated/maxloc0_4_r16.c \
generated/maxloc0_8_r16.c \
generated/maxloc0_16_r16.c
$(srcdir)/generated/maxloc0_4_i1.c \
$(srcdir)/generated/maxloc0_8_i1.c \
$(srcdir)/generated/maxloc0_16_i1.c \
$(srcdir)/generated/maxloc0_4_i2.c \
$(srcdir)/generated/maxloc0_8_i2.c \
$(srcdir)/generated/maxloc0_16_i2.c \
$(srcdir)/generated/maxloc0_4_i4.c \
$(srcdir)/generated/maxloc0_8_i4.c \
$(srcdir)/generated/maxloc0_16_i4.c \
$(srcdir)/generated/maxloc0_4_i8.c \
$(srcdir)/generated/maxloc0_8_i8.c \
$(srcdir)/generated/maxloc0_16_i8.c \
$(srcdir)/generated/maxloc0_4_i16.c \
$(srcdir)/generated/maxloc0_8_i16.c \
$(srcdir)/generated/maxloc0_16_i16.c \
$(srcdir)/generated/maxloc0_4_r4.c \
$(srcdir)/generated/maxloc0_8_r4.c \
$(srcdir)/generated/maxloc0_16_r4.c \
$(srcdir)/generated/maxloc0_4_r8.c \
$(srcdir)/generated/maxloc0_8_r8.c \
$(srcdir)/generated/maxloc0_16_r8.c \
$(srcdir)/generated/maxloc0_4_r10.c \
$(srcdir)/generated/maxloc0_8_r10.c \
$(srcdir)/generated/maxloc0_16_r10.c \
$(srcdir)/generated/maxloc0_4_r16.c \
$(srcdir)/generated/maxloc0_8_r16.c \
$(srcdir)/generated/maxloc0_16_r16.c
i_maxloc1_c= \
generated/maxloc1_4_i4.c \
generated/maxloc1_8_i4.c \
generated/maxloc1_16_i4.c \
generated/maxloc1_4_i8.c \
generated/maxloc1_8_i8.c \
generated/maxloc1_16_i8.c \
generated/maxloc1_4_i16.c \
generated/maxloc1_8_i16.c \
generated/maxloc1_16_i16.c \
generated/maxloc1_4_r4.c \
generated/maxloc1_8_r4.c \
generated/maxloc1_16_r4.c \
generated/maxloc1_4_r8.c \
generated/maxloc1_8_r8.c \
generated/maxloc1_16_r8.c \
generated/maxloc1_4_r10.c \
generated/maxloc1_8_r10.c \
generated/maxloc1_16_r10.c \
generated/maxloc1_4_r16.c \
generated/maxloc1_8_r16.c \
generated/maxloc1_16_r16.c
$(srcdir)/generated/maxloc1_4_i1.c \
$(srcdir)/generated/maxloc1_8_i1.c \
$(srcdir)/generated/maxloc1_16_i1.c \
$(srcdir)/generated/maxloc1_4_i2.c \
$(srcdir)/generated/maxloc1_8_i2.c \
$(srcdir)/generated/maxloc1_16_i2.c \
$(srcdir)/generated/maxloc1_4_i4.c \
$(srcdir)/generated/maxloc1_8_i4.c \
$(srcdir)/generated/maxloc1_16_i4.c \
$(srcdir)/generated/maxloc1_4_i8.c \
$(srcdir)/generated/maxloc1_8_i8.c \
$(srcdir)/generated/maxloc1_16_i8.c \
$(srcdir)/generated/maxloc1_4_i16.c \
$(srcdir)/generated/maxloc1_8_i16.c \
$(srcdir)/generated/maxloc1_16_i16.c \
$(srcdir)/generated/maxloc1_4_r4.c \
$(srcdir)/generated/maxloc1_8_r4.c \
$(srcdir)/generated/maxloc1_16_r4.c \
$(srcdir)/generated/maxloc1_4_r8.c \
$(srcdir)/generated/maxloc1_8_r8.c \
$(srcdir)/generated/maxloc1_16_r8.c \
$(srcdir)/generated/maxloc1_4_r10.c \
$(srcdir)/generated/maxloc1_8_r10.c \
$(srcdir)/generated/maxloc1_16_r10.c \
$(srcdir)/generated/maxloc1_4_r16.c \
$(srcdir)/generated/maxloc1_8_r16.c \
$(srcdir)/generated/maxloc1_16_r16.c
i_maxval_c= \
generated/maxval_i4.c \
generated/maxval_i8.c \
generated/maxval_i16.c \
generated/maxval_r4.c \
generated/maxval_r8.c \
generated/maxval_r10.c \
generated/maxval_r16.c
$(srcdir)/generated/maxval_i1.c \
$(srcdir)/generated/maxval_i2.c \
$(srcdir)/generated/maxval_i4.c \
$(srcdir)/generated/maxval_i8.c \
$(srcdir)/generated/maxval_i16.c \
$(srcdir)/generated/maxval_r4.c \
$(srcdir)/generated/maxval_r8.c \
$(srcdir)/generated/maxval_r10.c \
$(srcdir)/generated/maxval_r16.c
i_minloc0_c= \
generated/minloc0_4_i4.c \
generated/minloc0_8_i4.c \
generated/minloc0_16_i4.c \
generated/minloc0_4_i8.c \
generated/minloc0_8_i8.c \
generated/minloc0_16_i8.c \
generated/minloc0_4_i16.c \
generated/minloc0_8_i16.c \
generated/minloc0_16_i16.c \
generated/minloc0_4_r4.c \
generated/minloc0_8_r4.c \
generated/minloc0_16_r4.c \
generated/minloc0_4_r8.c \
generated/minloc0_8_r8.c \
generated/minloc0_16_r8.c \
generated/minloc0_4_r10.c \
generated/minloc0_8_r10.c \
generated/minloc0_16_r10.c \
generated/minloc0_4_r16.c \
generated/minloc0_8_r16.c \
generated/minloc0_16_r16.c
$(srcdir)/generated/minloc0_4_i1.c \
$(srcdir)/generated/minloc0_8_i1.c \
$(srcdir)/generated/minloc0_16_i1.c \
$(srcdir)/generated/minloc0_4_i2.c \
$(srcdir)/generated/minloc0_8_i2.c \
$(srcdir)/generated/minloc0_16_i2.c \
$(srcdir)/generated/minloc0_4_i4.c \
$(srcdir)/generated/minloc0_8_i4.c \
$(srcdir)/generated/minloc0_16_i4.c \
$(srcdir)/generated/minloc0_4_i8.c \
$(srcdir)/generated/minloc0_8_i8.c \
$(srcdir)/generated/minloc0_16_i8.c \
$(srcdir)/generated/minloc0_4_i16.c \
$(srcdir)/generated/minloc0_8_i16.c \
$(srcdir)/generated/minloc0_16_i16.c \
$(srcdir)/generated/minloc0_4_r4.c \
$(srcdir)/generated/minloc0_8_r4.c \
$(srcdir)/generated/minloc0_16_r4.c \
$(srcdir)/generated/minloc0_4_r8.c \
$(srcdir)/generated/minloc0_8_r8.c \
$(srcdir)/generated/minloc0_16_r8.c \
$(srcdir)/generated/minloc0_4_r10.c \
$(srcdir)/generated/minloc0_8_r10.c \
$(srcdir)/generated/minloc0_16_r10.c \
$(srcdir)/generated/minloc0_4_r16.c \
$(srcdir)/generated/minloc0_8_r16.c \
$(srcdir)/generated/minloc0_16_r16.c
i_minloc1_c= \
generated/minloc1_4_i4.c \
generated/minloc1_8_i4.c \
generated/minloc1_16_i4.c \
generated/minloc1_4_i8.c \
generated/minloc1_8_i8.c \
generated/minloc1_16_i8.c \
generated/minloc1_4_i16.c \
generated/minloc1_8_i16.c \
generated/minloc1_16_i16.c \
generated/minloc1_4_r4.c \
generated/minloc1_8_r4.c \
generated/minloc1_16_r4.c \
generated/minloc1_4_r8.c \
generated/minloc1_8_r8.c \
generated/minloc1_16_r8.c \
generated/minloc1_4_r10.c \
generated/minloc1_8_r10.c \
generated/minloc1_16_r10.c \
generated/minloc1_4_r16.c \
generated/minloc1_8_r16.c \
generated/minloc1_16_r16.c
$(srcdir)/generated/minloc1_4_i1.c \
$(srcdir)/generated/minloc1_8_i1.c \
$(srcdir)/generated/minloc1_16_i1.c \
$(srcdir)/generated/minloc1_4_i2.c \
$(srcdir)/generated/minloc1_8_i2.c \
$(srcdir)/generated/minloc1_16_i2.c \
$(srcdir)/generated/minloc1_4_i4.c \
$(srcdir)/generated/minloc1_8_i4.c \
$(srcdir)/generated/minloc1_16_i4.c \
$(srcdir)/generated/minloc1_4_i8.c \
$(srcdir)/generated/minloc1_8_i8.c \
$(srcdir)/generated/minloc1_16_i8.c \
$(srcdir)/generated/minloc1_4_i16.c \
$(srcdir)/generated/minloc1_8_i16.c \
$(srcdir)/generated/minloc1_16_i16.c \
$(srcdir)/generated/minloc1_4_r4.c \
$(srcdir)/generated/minloc1_8_r4.c \
$(srcdir)/generated/minloc1_16_r4.c \
$(srcdir)/generated/minloc1_4_r8.c \
$(srcdir)/generated/minloc1_8_r8.c \
$(srcdir)/generated/minloc1_16_r8.c \
$(srcdir)/generated/minloc1_4_r10.c \
$(srcdir)/generated/minloc1_8_r10.c \
$(srcdir)/generated/minloc1_16_r10.c \
$(srcdir)/generated/minloc1_4_r16.c \
$(srcdir)/generated/minloc1_8_r16.c \
$(srcdir)/generated/minloc1_16_r16.c
i_minval_c= \
generated/minval_i4.c \
generated/minval_i8.c \
generated/minval_i16.c \
generated/minval_r4.c \
generated/minval_r8.c \
generated/minval_r10.c \
generated/minval_r16.c
$(srcdir)/generated/minval_i1.c \
$(srcdir)/generated/minval_i2.c \
$(srcdir)/generated/minval_i4.c \
$(srcdir)/generated/minval_i8.c \
$(srcdir)/generated/minval_i16.c \
$(srcdir)/generated/minval_r4.c \
$(srcdir)/generated/minval_r8.c \
$(srcdir)/generated/minval_r10.c \
$(srcdir)/generated/minval_r16.c
i_sum_c= \
generated/sum_i4.c \
generated/sum_i8.c \
generated/sum_i16.c \
generated/sum_r4.c \
generated/sum_r8.c \
generated/sum_r10.c \
generated/sum_r16.c \
generated/sum_c4.c \
generated/sum_c8.c \
generated/sum_c10.c \
generated/sum_c16.c
$(srcdir)/generated/sum_i1.c \
$(srcdir)/generated/sum_i2.c \
$(srcdir)/generated/sum_i4.c \
$(srcdir)/generated/sum_i8.c \
$(srcdir)/generated/sum_i16.c \
$(srcdir)/generated/sum_r4.c \
$(srcdir)/generated/sum_r8.c \
$(srcdir)/generated/sum_r10.c \
$(srcdir)/generated/sum_r16.c \
$(srcdir)/generated/sum_c4.c \
$(srcdir)/generated/sum_c8.c \
$(srcdir)/generated/sum_c10.c \
$(srcdir)/generated/sum_c16.c
i_product_c= \
generated/product_i4.c \
generated/product_i8.c \
generated/product_i16.c \
generated/product_r4.c \
generated/product_r8.c \
generated/product_r10.c \
generated/product_r16.c \
generated/product_c4.c \
generated/product_c8.c \
generated/product_c10.c \
generated/product_c16.c
$(srcdir)/generated/product_i1.c \
$(srcdir)/generated/product_i2.c \
$(srcdir)/generated/product_i4.c \
$(srcdir)/generated/product_i8.c \
$(srcdir)/generated/product_i16.c \
$(srcdir)/generated/product_r4.c \
$(srcdir)/generated/product_r8.c \
$(srcdir)/generated/product_r10.c \
$(srcdir)/generated/product_r16.c \
$(srcdir)/generated/product_c4.c \
$(srcdir)/generated/product_c8.c \
$(srcdir)/generated/product_c10.c \
$(srcdir)/generated/product_c16.c
i_matmul_c= \
generated/matmul_i4.c \
generated/matmul_i8.c \
generated/matmul_i16.c \
generated/matmul_r4.c \
generated/matmul_r8.c \
generated/matmul_r10.c \
generated/matmul_r16.c \
generated/matmul_c4.c \
generated/matmul_c8.c \
generated/matmul_c10.c \
generated/matmul_c16.c
$(srcdir)/generated/matmul_i1.c \
$(srcdir)/generated/matmul_i2.c \
$(srcdir)/generated/matmul_i4.c \
$(srcdir)/generated/matmul_i8.c \
$(srcdir)/generated/matmul_i16.c \
$(srcdir)/generated/matmul_r4.c \
$(srcdir)/generated/matmul_r8.c \
$(srcdir)/generated/matmul_r10.c \
$(srcdir)/generated/matmul_r16.c \
$(srcdir)/generated/matmul_c4.c \
$(srcdir)/generated/matmul_c8.c \
$(srcdir)/generated/matmul_c10.c \
$(srcdir)/generated/matmul_c16.c
i_matmull_c= \
generated/matmul_l4.c \
generated/matmul_l8.c \
generated/matmul_l16.c
$(srcdir)/generated/matmul_l4.c \
$(srcdir)/generated/matmul_l8.c \
$(srcdir)/generated/matmul_l16.c
i_transpose_c= \
generated/transpose_i4.c \
generated/transpose_i8.c \
generated/transpose_i16.c \
generated/transpose_r4.c \
generated/transpose_r8.c \
generated/transpose_r10.c \
generated/transpose_r16.c \
generated/transpose_c4.c \
generated/transpose_c8.c \
generated/transpose_c10.c \
generated/transpose_c16.c
$(srcdir)/generated/transpose_i4.c \
$(srcdir)/generated/transpose_i8.c \
$(srcdir)/generated/transpose_i16.c \
$(srcdir)/generated/transpose_r4.c \
$(srcdir)/generated/transpose_r8.c \
$(srcdir)/generated/transpose_r10.c \
$(srcdir)/generated/transpose_r16.c \
$(srcdir)/generated/transpose_c4.c \
$(srcdir)/generated/transpose_c8.c \
$(srcdir)/generated/transpose_c10.c \
$(srcdir)/generated/transpose_c16.c
i_shape_c= \
generated/shape_i4.c \
generated/shape_i8.c \
generated/shape_i16.c
$(srcdir)/generated/shape_i4.c \
$(srcdir)/generated/shape_i8.c \
$(srcdir)/generated/shape_i16.c
i_reshape_c= \
generated/reshape_i4.c \
generated/reshape_i8.c \
generated/reshape_i16.c \
generated/reshape_r4.c \
generated/reshape_r8.c \
generated/reshape_r10.c \
generated/reshape_r16.c \
generated/reshape_c4.c \
generated/reshape_c8.c \
generated/reshape_c10.c \
generated/reshape_c16.c
$(srcdir)/generated/reshape_i4.c \
$(srcdir)/generated/reshape_i8.c \
$(srcdir)/generated/reshape_i16.c \
$(srcdir)/generated/reshape_r4.c \
$(srcdir)/generated/reshape_r8.c \
$(srcdir)/generated/reshape_r10.c \
$(srcdir)/generated/reshape_r16.c \
$(srcdir)/generated/reshape_c4.c \
$(srcdir)/generated/reshape_c8.c \
$(srcdir)/generated/reshape_c10.c \
$(srcdir)/generated/reshape_c16.c
i_eoshift1_c= \
generated/eoshift1_4.c \
generated/eoshift1_8.c \
generated/eoshift1_16.c
$(srcdir)/generated/eoshift1_4.c \
$(srcdir)/generated/eoshift1_8.c \
$(srcdir)/generated/eoshift1_16.c
i_eoshift3_c= \
generated/eoshift3_4.c \
generated/eoshift3_8.c \
generated/eoshift3_16.c
$(srcdir)/generated/eoshift3_4.c \
$(srcdir)/generated/eoshift3_8.c \
$(srcdir)/generated/eoshift3_16.c
i_cshift1_c= \
generated/cshift1_4.c \
generated/cshift1_8.c \
generated/cshift1_16.c
$(srcdir)/generated/cshift1_4.c \
$(srcdir)/generated/cshift1_8.c \
$(srcdir)/generated/cshift1_16.c
in_pack_c = \
generated/in_pack_i4.c \
generated/in_pack_i8.c \
generated/in_pack_i16.c \
generated/in_pack_c4.c \
generated/in_pack_c8.c \
generated/in_pack_c10.c \
generated/in_pack_c16.c
$(srcdir)/generated/in_pack_i4.c \
$(srcdir)/generated/in_pack_i8.c \
$(srcdir)/generated/in_pack_i16.c \
$(srcdir)/generated/in_pack_c4.c \
$(srcdir)/generated/in_pack_c8.c \
$(srcdir)/generated/in_pack_c10.c \
$(srcdir)/generated/in_pack_c16.c
in_unpack_c = \
generated/in_unpack_i4.c \
generated/in_unpack_i8.c \
generated/in_unpack_i16.c \
generated/in_unpack_c4.c \
generated/in_unpack_c8.c \
generated/in_unpack_c10.c \
generated/in_unpack_c16.c
$(srcdir)/generated/in_unpack_i4.c \
$(srcdir)/generated/in_unpack_i8.c \
$(srcdir)/generated/in_unpack_i16.c \
$(srcdir)/generated/in_unpack_c4.c \
$(srcdir)/generated/in_unpack_c8.c \
$(srcdir)/generated/in_unpack_c10.c \
$(srcdir)/generated/in_unpack_c16.c
i_exponent_c = \
generated/exponent_r4.c \
generated/exponent_r8.c \
generated/exponent_r10.c \
generated/exponent_r16.c
$(srcdir)/generated/exponent_r4.c \
$(srcdir)/generated/exponent_r8.c \
$(srcdir)/generated/exponent_r10.c \
$(srcdir)/generated/exponent_r16.c
i_spacing_c = \
generated/spacing_r4.c \
generated/spacing_r8.c \
generated/spacing_r10.c \
generated/spacing_r16.c
$(srcdir)/generated/spacing_r4.c \
$(srcdir)/generated/spacing_r8.c \
$(srcdir)/generated/spacing_r10.c \
$(srcdir)/generated/spacing_r16.c
i_rrspacing_c = \
generated/rrspacing_r4.c \
generated/rrspacing_r8.c \
generated/rrspacing_r10.c \
generated/rrspacing_r16.c
$(srcdir)/generated/rrspacing_r4.c \
$(srcdir)/generated/rrspacing_r8.c \
$(srcdir)/generated/rrspacing_r10.c \
$(srcdir)/generated/rrspacing_r16.c
i_fraction_c = \
generated/fraction_r4.c \
generated/fraction_r8.c \
generated/fraction_r10.c \
generated/fraction_r16.c
$(srcdir)/generated/fraction_r4.c \
$(srcdir)/generated/fraction_r8.c \
$(srcdir)/generated/fraction_r10.c \
$(srcdir)/generated/fraction_r16.c
i_nearest_c = \
generated/nearest_r4.c \
generated/nearest_r8.c \
generated/nearest_r10.c \
generated/nearest_r16.c
$(srcdir)/generated/nearest_r4.c \
$(srcdir)/generated/nearest_r8.c \
$(srcdir)/generated/nearest_r10.c \
$(srcdir)/generated/nearest_r16.c
i_set_exponent_c = \
generated/set_exponent_r4.c \
generated/set_exponent_r8.c \
generated/set_exponent_r10.c \
generated/set_exponent_r16.c
$(srcdir)/generated/set_exponent_r4.c \
$(srcdir)/generated/set_exponent_r8.c \
$(srcdir)/generated/set_exponent_r10.c \
$(srcdir)/generated/set_exponent_r16.c
i_pow_c = \
generated/pow_i4_i4.c \
generated/pow_i8_i4.c \
generated/pow_i16_i4.c \
generated/pow_r4_i4.c \
generated/pow_r8_i4.c \
generated/pow_r10_i4.c \
generated/pow_r16_i4.c \
generated/pow_c4_i4.c \
generated/pow_c8_i4.c \
generated/pow_c10_i4.c \
generated/pow_c16_i4.c \
generated/pow_i4_i8.c \
generated/pow_i8_i8.c \
generated/pow_i16_i8.c \
generated/pow_r4_i8.c \
generated/pow_r8_i8.c \
generated/pow_r10_i8.c \
generated/pow_r16_i8.c \
generated/pow_c4_i8.c \
generated/pow_c8_i8.c \
generated/pow_c10_i8.c \
generated/pow_c16_i8.c \
generated/pow_i4_i16.c \
generated/pow_i8_i16.c \
generated/pow_i16_i16.c \
generated/pow_r4_i16.c \
generated/pow_r8_i16.c \
generated/pow_r10_i16.c \
generated/pow_r16_i16.c \
generated/pow_c4_i16.c \
generated/pow_c8_i16.c \
generated/pow_c10_i16.c \
generated/pow_c16_i16.c
$(srcdir)/generated/pow_i4_i4.c \
$(srcdir)/generated/pow_i8_i4.c \
$(srcdir)/generated/pow_i16_i4.c \
$(srcdir)/generated/pow_r4_i4.c \
$(srcdir)/generated/pow_r8_i4.c \
$(srcdir)/generated/pow_r10_i4.c \
$(srcdir)/generated/pow_r16_i4.c \
$(srcdir)/generated/pow_c4_i4.c \
$(srcdir)/generated/pow_c8_i4.c \
$(srcdir)/generated/pow_c10_i4.c \
$(srcdir)/generated/pow_c16_i4.c \
$(srcdir)/generated/pow_i4_i8.c \
$(srcdir)/generated/pow_i8_i8.c \
$(srcdir)/generated/pow_i16_i8.c \
$(srcdir)/generated/pow_r4_i8.c \
$(srcdir)/generated/pow_r8_i8.c \
$(srcdir)/generated/pow_r10_i8.c \
$(srcdir)/generated/pow_r16_i8.c \
$(srcdir)/generated/pow_c4_i8.c \
$(srcdir)/generated/pow_c8_i8.c \
$(srcdir)/generated/pow_c10_i8.c \
$(srcdir)/generated/pow_c16_i8.c \
$(srcdir)/generated/pow_i4_i16.c \
$(srcdir)/generated/pow_i8_i16.c \
$(srcdir)/generated/pow_i16_i16.c \
$(srcdir)/generated/pow_r4_i16.c \
$(srcdir)/generated/pow_r8_i16.c \
$(srcdir)/generated/pow_r10_i16.c \
$(srcdir)/generated/pow_r16_i16.c \
$(srcdir)/generated/pow_c4_i16.c \
$(srcdir)/generated/pow_c8_i16.c \
$(srcdir)/generated/pow_c10_i16.c \
$(srcdir)/generated/pow_c16_i16.c
m4_files= m4/iparm.m4 m4/ifunction.m4 m4/iforeach.m4 m4/all.m4 \
m4/any.m4 m4/count.m4 m4/maxloc0.m4 m4/maxloc1.m4 m4/maxval.m4 \
@ -440,146 +474,146 @@ gfor_built_src= $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
# Machine generated specifics
gfor_built_specific_src= \
generated/_abs_c4.F90 \
generated/_abs_c8.F90 \
generated/_abs_c10.F90 \
generated/_abs_c16.F90 \
generated/_abs_i4.F90 \
generated/_abs_i8.F90 \
generated/_abs_i16.F90 \
generated/_abs_r4.F90 \
generated/_abs_r8.F90 \
generated/_abs_r10.F90 \
generated/_abs_r16.F90 \
generated/_aimag_c4.F90 \
generated/_aimag_c8.F90 \
generated/_aimag_c10.F90 \
generated/_aimag_c16.F90 \
generated/_exp_r4.F90 \
generated/_exp_r8.F90 \
generated/_exp_r10.F90 \
generated/_exp_r16.F90 \
generated/_exp_c4.F90 \
generated/_exp_c8.F90 \
generated/_exp_c10.F90 \
generated/_exp_c16.F90 \
generated/_log_r4.F90 \
generated/_log_r8.F90 \
generated/_log_r10.F90 \
generated/_log_r16.F90 \
generated/_log_c4.F90 \
generated/_log_c8.F90 \
generated/_log_c10.F90 \
generated/_log_c16.F90 \
generated/_log10_r4.F90 \
generated/_log10_r8.F90 \
generated/_log10_r10.F90 \
generated/_log10_r16.F90 \
generated/_sqrt_r4.F90 \
generated/_sqrt_r8.F90 \
generated/_sqrt_r10.F90 \
generated/_sqrt_r16.F90 \
generated/_sqrt_c4.F90 \
generated/_sqrt_c8.F90 \
generated/_sqrt_c10.F90 \
generated/_sqrt_c16.F90 \
generated/_asin_r4.F90 \
generated/_asin_r8.F90 \
generated/_asin_r10.F90 \
generated/_asin_r16.F90 \
generated/_asinh_r4.F90 \
generated/_asinh_r8.F90 \
generated/_asinh_r10.F90 \
generated/_asinh_r16.F90 \
generated/_acos_r4.F90 \
generated/_acos_r8.F90 \
generated/_acos_r10.F90 \
generated/_acos_r16.F90 \
generated/_acosh_r4.F90 \
generated/_acosh_r8.F90 \
generated/_acosh_r10.F90 \
generated/_acosh_r16.F90 \
generated/_atan_r4.F90 \
generated/_atan_r8.F90 \
generated/_atan_r10.F90 \
generated/_atan_r16.F90 \
generated/_atanh_r4.F90 \
generated/_atanh_r8.F90 \
generated/_atanh_r10.F90 \
generated/_atanh_r16.F90 \
generated/_sin_r4.F90 \
generated/_sin_r8.F90 \
generated/_sin_r10.F90 \
generated/_sin_r16.F90 \
generated/_sin_c4.F90 \
generated/_sin_c8.F90 \
generated/_sin_c10.F90 \
generated/_sin_c16.F90 \
generated/_cos_r4.F90 \
generated/_cos_r8.F90 \
generated/_cos_r10.F90 \
generated/_cos_r16.F90 \
generated/_cos_c4.F90 \
generated/_cos_c8.F90 \
generated/_cos_c10.F90 \
generated/_cos_c16.F90 \
generated/_tan_r4.F90 \
generated/_tan_r8.F90 \
generated/_tan_r10.F90 \
generated/_tan_r16.F90 \
generated/_sinh_r4.F90 \
generated/_sinh_r8.F90 \
generated/_sinh_r10.F90 \
generated/_sinh_r16.F90 \
generated/_cosh_r4.F90 \
generated/_cosh_r8.F90 \
generated/_cosh_r10.F90 \
generated/_cosh_r16.F90 \
generated/_tanh_r4.F90 \
generated/_tanh_r8.F90 \
generated/_tanh_r10.F90 \
generated/_tanh_r16.F90 \
generated/_conjg_c4.F90 \
generated/_conjg_c8.F90 \
generated/_conjg_c10.F90 \
generated/_conjg_c16.F90 \
generated/_aint_r4.F90 \
generated/_aint_r8.F90 \
generated/_aint_r10.F90 \
generated/_aint_r16.F90 \
generated/_anint_r4.F90 \
generated/_anint_r8.F90 \
generated/_anint_r10.F90 \
generated/_anint_r16.F90
$(srcdir)/generated/_abs_c4.F90 \
$(srcdir)/generated/_abs_c8.F90 \
$(srcdir)/generated/_abs_c10.F90 \
$(srcdir)/generated/_abs_c16.F90 \
$(srcdir)/generated/_abs_i4.F90 \
$(srcdir)/generated/_abs_i8.F90 \
$(srcdir)/generated/_abs_i16.F90 \
$(srcdir)/generated/_abs_r4.F90 \
$(srcdir)/generated/_abs_r8.F90 \
$(srcdir)/generated/_abs_r10.F90 \
$(srcdir)/generated/_abs_r16.F90 \
$(srcdir)/generated/_aimag_c4.F90 \
$(srcdir)/generated/_aimag_c8.F90 \
$(srcdir)/generated/_aimag_c10.F90 \
$(srcdir)/generated/_aimag_c16.F90 \
$(srcdir)/generated/_exp_r4.F90 \
$(srcdir)/generated/_exp_r8.F90 \
$(srcdir)/generated/_exp_r10.F90 \
$(srcdir)/generated/_exp_r16.F90 \
$(srcdir)/generated/_exp_c4.F90 \
$(srcdir)/generated/_exp_c8.F90 \
$(srcdir)/generated/_exp_c10.F90 \
$(srcdir)/generated/_exp_c16.F90 \
$(srcdir)/generated/_log_r4.F90 \
$(srcdir)/generated/_log_r8.F90 \
$(srcdir)/generated/_log_r10.F90 \
$(srcdir)/generated/_log_r16.F90 \
$(srcdir)/generated/_log_c4.F90 \
$(srcdir)/generated/_log_c8.F90 \
$(srcdir)/generated/_log_c10.F90 \
$(srcdir)/generated/_log_c16.F90 \
$(srcdir)/generated/_log10_r4.F90 \
$(srcdir)/generated/_log10_r8.F90 \
$(srcdir)/generated/_log10_r10.F90 \
$(srcdir)/generated/_log10_r16.F90 \
$(srcdir)/generated/_sqrt_r4.F90 \
$(srcdir)/generated/_sqrt_r8.F90 \
$(srcdir)/generated/_sqrt_r10.F90 \
$(srcdir)/generated/_sqrt_r16.F90 \
$(srcdir)/generated/_sqrt_c4.F90 \
$(srcdir)/generated/_sqrt_c8.F90 \
$(srcdir)/generated/_sqrt_c10.F90 \
$(srcdir)/generated/_sqrt_c16.F90 \
$(srcdir)/generated/_asin_r4.F90 \
$(srcdir)/generated/_asin_r8.F90 \
$(srcdir)/generated/_asin_r10.F90 \
$(srcdir)/generated/_asin_r16.F90 \
$(srcdir)/generated/_asinh_r4.F90 \
$(srcdir)/generated/_asinh_r8.F90 \
$(srcdir)/generated/_asinh_r10.F90 \
$(srcdir)/generated/_asinh_r16.F90 \
$(srcdir)/generated/_acos_r4.F90 \
$(srcdir)/generated/_acos_r8.F90 \
$(srcdir)/generated/_acos_r10.F90 \
$(srcdir)/generated/_acos_r16.F90 \
$(srcdir)/generated/_acosh_r4.F90 \
$(srcdir)/generated/_acosh_r8.F90 \
$(srcdir)/generated/_acosh_r10.F90 \
$(srcdir)/generated/_acosh_r16.F90 \
$(srcdir)/generated/_atan_r4.F90 \
$(srcdir)/generated/_atan_r8.F90 \
$(srcdir)/generated/_atan_r10.F90 \
$(srcdir)/generated/_atan_r16.F90 \
$(srcdir)/generated/_atanh_r4.F90 \
$(srcdir)/generated/_atanh_r8.F90 \
$(srcdir)/generated/_atanh_r10.F90 \
$(srcdir)/generated/_atanh_r16.F90 \
$(srcdir)/generated/_sin_r4.F90 \
$(srcdir)/generated/_sin_r8.F90 \
$(srcdir)/generated/_sin_r10.F90 \
$(srcdir)/generated/_sin_r16.F90 \
$(srcdir)/generated/_sin_c4.F90 \
$(srcdir)/generated/_sin_c8.F90 \
$(srcdir)/generated/_sin_c10.F90 \
$(srcdir)/generated/_sin_c16.F90 \
$(srcdir)/generated/_cos_r4.F90 \
$(srcdir)/generated/_cos_r8.F90 \
$(srcdir)/generated/_cos_r10.F90 \
$(srcdir)/generated/_cos_r16.F90 \
$(srcdir)/generated/_cos_c4.F90 \
$(srcdir)/generated/_cos_c8.F90 \
$(srcdir)/generated/_cos_c10.F90 \
$(srcdir)/generated/_cos_c16.F90 \
$(srcdir)/generated/_tan_r4.F90 \
$(srcdir)/generated/_tan_r8.F90 \
$(srcdir)/generated/_tan_r10.F90 \
$(srcdir)/generated/_tan_r16.F90 \
$(srcdir)/generated/_sinh_r4.F90 \
$(srcdir)/generated/_sinh_r8.F90 \
$(srcdir)/generated/_sinh_r10.F90 \
$(srcdir)/generated/_sinh_r16.F90 \
$(srcdir)/generated/_cosh_r4.F90 \
$(srcdir)/generated/_cosh_r8.F90 \
$(srcdir)/generated/_cosh_r10.F90 \
$(srcdir)/generated/_cosh_r16.F90 \
$(srcdir)/generated/_tanh_r4.F90 \
$(srcdir)/generated/_tanh_r8.F90 \
$(srcdir)/generated/_tanh_r10.F90 \
$(srcdir)/generated/_tanh_r16.F90 \
$(srcdir)/generated/_conjg_c4.F90 \
$(srcdir)/generated/_conjg_c8.F90 \
$(srcdir)/generated/_conjg_c10.F90 \
$(srcdir)/generated/_conjg_c16.F90 \
$(srcdir)/generated/_aint_r4.F90 \
$(srcdir)/generated/_aint_r8.F90 \
$(srcdir)/generated/_aint_r10.F90 \
$(srcdir)/generated/_aint_r16.F90 \
$(srcdir)/generated/_anint_r4.F90 \
$(srcdir)/generated/_anint_r8.F90 \
$(srcdir)/generated/_anint_r10.F90 \
$(srcdir)/generated/_anint_r16.F90
gfor_built_specific2_src= \
generated/_sign_i4.F90 \
generated/_sign_i8.F90 \
generated/_sign_i16.F90 \
generated/_sign_r4.F90 \
generated/_sign_r8.F90 \
generated/_sign_r10.F90 \
generated/_sign_r16.F90 \
generated/_dim_i4.F90 \
generated/_dim_i8.F90 \
generated/_dim_i16.F90 \
generated/_dim_r4.F90 \
generated/_dim_r8.F90 \
generated/_dim_r10.F90 \
generated/_dim_r16.F90 \
generated/_atan2_r4.F90 \
generated/_atan2_r8.F90 \
generated/_atan2_r10.F90 \
generated/_atan2_r16.F90 \
generated/_mod_i4.F90 \
generated/_mod_i8.F90 \
generated/_mod_i16.F90 \
generated/_mod_r4.F90 \
generated/_mod_r8.F90 \
generated/_mod_r10.F90 \
generated/_mod_r16.F90
$(srcdir)/generated/_sign_i4.F90 \
$(srcdir)/generated/_sign_i8.F90 \
$(srcdir)/generated/_sign_i16.F90 \
$(srcdir)/generated/_sign_r4.F90 \
$(srcdir)/generated/_sign_r8.F90 \
$(srcdir)/generated/_sign_r10.F90 \
$(srcdir)/generated/_sign_r16.F90 \
$(srcdir)/generated/_dim_i4.F90 \
$(srcdir)/generated/_dim_i8.F90 \
$(srcdir)/generated/_dim_i16.F90 \
$(srcdir)/generated/_dim_r4.F90 \
$(srcdir)/generated/_dim_r8.F90 \
$(srcdir)/generated/_dim_r10.F90 \
$(srcdir)/generated/_dim_r16.F90 \
$(srcdir)/generated/_atan2_r4.F90 \
$(srcdir)/generated/_atan2_r8.F90 \
$(srcdir)/generated/_atan2_r10.F90 \
$(srcdir)/generated/_atan2_r16.F90 \
$(srcdir)/generated/_mod_i4.F90 \
$(srcdir)/generated/_mod_i8.F90 \
$(srcdir)/generated/_mod_i16.F90 \
$(srcdir)/generated/_mod_r4.F90 \
$(srcdir)/generated/_mod_r8.F90 \
$(srcdir)/generated/_mod_r10.F90 \
$(srcdir)/generated/_mod_r16.F90
gfor_misc_specifics = generated/misc_specifics.F90
gfor_misc_specifics = $(srcdir)/generated/misc_specifics.F90
gfor_specific_src= \
$(gfor_built_specific_src) \
@ -717,13 +751,13 @@ $(i_pow_c): m4/pow.m4 $(I_M4_DEPS)
$(M4) -Dfile=$@ -I$(srcdir)/m4 pow.m4 > $@
$(gfor_built_specific_src): m4/specific.m4 m4/head.m4
$(M4) -Dfile=$@ -I$(srcdir)/m4 specific.m4 > $(srcdir)/$@
$(M4) -Dfile=$@ -I$(srcdir)/m4 specific.m4 > $@
$(gfor_built_specific2_src): m4/specific2.m4 m4/head.m4
$(M4) -Dfile=$@ -I$(srcdir)/m4 specific2.m4 > $(srcdir)/$@
$(M4) -Dfile=$@ -I$(srcdir)/m4 specific2.m4 > $@
$(gfor_misc_specifics): m4/misc_specifics.m4 m4/head.m4
$(M4) -Dfile=$@ -I$(srcdir)/m4 misc_specifics.m4 > $(srcdir)/$@
$(M4) -Dfile=$@ -I$(srcdir)/m4 misc_specifics.m4 > $@
## end of maintainer mode only rules
endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,339 @@
/* Implementation of the MATMUL intrinsic
Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1)
/* Prototype for the BLAS ?gemm subroutine, a pointer to which can be
passed to us by the front-end, in which case we'll call it for large
matrices. */
typedef void (*blas_call)(const char *, const char *, const int *, const int *,
const int *, const GFC_INTEGER_1 *, const GFC_INTEGER_1 *,
const int *, const GFC_INTEGER_1 *, const int *,
const GFC_INTEGER_1 *, GFC_INTEGER_1 *, const int *,
int, int);
/* The order of loops is different in the case of plain matrix
multiplication C=MATMUL(A,B), and in the frequent special case where
the argument A is the temporary result of a TRANSPOSE intrinsic:
C=MATMUL(TRANSPOSE(A),B). Transposed temporaries are detected by
looking at their strides.
The equivalent Fortran pseudo-code is:
DIMENSION A(M,COUNT), B(COUNT,N), C(M,N)
IF (.NOT.IS_TRANSPOSED(A)) THEN
C = 0
DO J=1,N
DO K=1,COUNT
DO I=1,M
C(I,J) = C(I,J)+A(I,K)*B(K,J)
ELSE
DO J=1,N
DO I=1,M
S = 0
DO K=1,COUNT
S = S+A(I,K)*B(K,J)
C(I,J) = S
ENDIF
*/
/* If try_blas is set to a nonzero value, then the matmul function will
see if there is a way to perform the matrix multiplication by a call
to the BLAS gemm function. */
extern void matmul_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict a, gfc_array_i1 * const restrict b, int try_blas,
int blas_limit, blas_call gemm);
export_proto(matmul_i1);
void
matmul_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict a, gfc_array_i1 * const restrict b, int try_blas,
int blas_limit, blas_call gemm)
{
const GFC_INTEGER_1 * restrict abase;
const GFC_INTEGER_1 * restrict bbase;
GFC_INTEGER_1 * restrict dest;
index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
index_type x, y, n, count, xcount, ycount;
assert (GFC_DESCRIPTOR_RANK (a) == 2
|| GFC_DESCRIPTOR_RANK (b) == 2);
/* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
Either A or B (but not both) can be rank 1:
o One-dimensional argument A is implicitly treated as a row matrix
dimensioned [1,count], so xcount=1.
o One-dimensional argument B is implicitly treated as a column matrix
dimensioned [count, 1], so ycount=1.
*/
if (retarray->data == NULL)
{
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
retarray->dim[0].stride = 1;
}
else if (GFC_DESCRIPTOR_RANK (b) == 1)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
retarray->dim[0].stride = 1;
}
else
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
retarray->dim[0].stride = 1;
retarray->dim[1].lbound = 0;
retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
retarray->dim[1].stride = retarray->dim[0].ubound+1;
}
retarray->data
= internal_malloc_size (sizeof (GFC_INTEGER_1) * size0 ((array_t *) retarray));
retarray->offset = 0;
}
if (GFC_DESCRIPTOR_RANK (retarray) == 1)
{
/* One-dimensional result may be addressed in the code below
either as a row or a column matrix. We want both cases to
work. */
rxstride = rystride = retarray->dim[0].stride;
}
else
{
rxstride = retarray->dim[0].stride;
rystride = retarray->dim[1].stride;
}
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
/* Treat it as a a row matrix A[1,count]. */
axstride = a->dim[0].stride;
aystride = 1;
xcount = 1;
count = a->dim[0].ubound + 1 - a->dim[0].lbound;
}
else
{
axstride = a->dim[0].stride;
aystride = a->dim[1].stride;
count = a->dim[1].ubound + 1 - a->dim[1].lbound;
xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
}
assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
if (GFC_DESCRIPTOR_RANK (b) == 1)
{
/* Treat it as a column matrix B[count,1] */
bxstride = b->dim[0].stride;
/* bystride should never be used for 1-dimensional b.
in case it is we want it to cause a segfault, rather than
an incorrect result. */
bystride = 0xDEADBEEF;
ycount = 1;
}
else
{
bxstride = b->dim[0].stride;
bystride = b->dim[1].stride;
ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
}
abase = a->data;
bbase = b->data;
dest = retarray->data;
/* Now that everything is set up, we're performing the multiplication
itself. */
#define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
&& (bxstride == 1 || bystride == 1)
&& (((float) xcount) * ((float) ycount) * ((float) count)
> POW3(blas_limit)))
{
const int m = xcount, n = ycount, k = count, ldc = rystride;
const GFC_INTEGER_1 one = 1, zero = 0;
const int lda = (axstride == 1) ? aystride : axstride,
ldb = (bxstride == 1) ? bystride : bxstride;
if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
{
assert (gemm != NULL);
gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m, &n, &k,
&one, abase, &lda, bbase, &ldb, &zero, dest, &ldc, 1, 1);
return;
}
}
if (rxstride == 1 && axstride == 1 && bxstride == 1)
{
const GFC_INTEGER_1 * restrict bbase_y;
GFC_INTEGER_1 * restrict dest_y;
const GFC_INTEGER_1 * restrict abase_n;
GFC_INTEGER_1 bbase_yn;
if (rystride == xcount)
memset (dest, 0, (sizeof (GFC_INTEGER_1) * xcount * ycount));
else
{
for (y = 0; y < ycount; y++)
for (x = 0; x < xcount; x++)
dest[x + y*rystride] = (GFC_INTEGER_1)0;
}
for (y = 0; y < ycount; y++)
{
bbase_y = bbase + y*bystride;
dest_y = dest + y*rystride;
for (n = 0; n < count; n++)
{
abase_n = abase + n*aystride;
bbase_yn = bbase_y[n];
for (x = 0; x < xcount; x++)
{
dest_y[x] += abase_n[x] * bbase_yn;
}
}
}
}
else if (rxstride == 1 && aystride == 1 && bxstride == 1)
{
if (GFC_DESCRIPTOR_RANK (a) != 1)
{
const GFC_INTEGER_1 *restrict abase_x;
const GFC_INTEGER_1 *restrict bbase_y;
GFC_INTEGER_1 *restrict dest_y;
GFC_INTEGER_1 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
dest_y = &dest[y*rystride];
for (x = 0; x < xcount; x++)
{
abase_x = &abase[x*axstride];
s = (GFC_INTEGER_1) 0;
for (n = 0; n < count; n++)
s += abase_x[n] * bbase_y[n];
dest_y[x] = s;
}
}
}
else
{
const GFC_INTEGER_1 *restrict bbase_y;
GFC_INTEGER_1 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
s = (GFC_INTEGER_1) 0;
for (n = 0; n < count; n++)
s += abase[n*axstride] * bbase_y[n];
dest[y*rystride] = s;
}
}
}
else if (axstride < aystride)
{
for (y = 0; y < ycount; y++)
for (x = 0; x < xcount; x++)
dest[x*rxstride + y*rystride] = (GFC_INTEGER_1)0;
for (y = 0; y < ycount; y++)
for (n = 0; n < count; n++)
for (x = 0; x < xcount; x++)
/* dest[x,y] += a[x,n] * b[n,y] */
dest[x*rxstride + y*rystride] += abase[x*axstride + n*aystride] * bbase[n*bxstride + y*bystride];
}
else if (GFC_DESCRIPTOR_RANK (a) == 1)
{
const GFC_INTEGER_1 *restrict bbase_y;
GFC_INTEGER_1 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
s = (GFC_INTEGER_1) 0;
for (n = 0; n < count; n++)
s += abase[n*axstride] * bbase_y[n*bxstride];
dest[y*rxstride] = s;
}
}
else
{
const GFC_INTEGER_1 *restrict abase_x;
const GFC_INTEGER_1 *restrict bbase_y;
GFC_INTEGER_1 *restrict dest_y;
GFC_INTEGER_1 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
dest_y = &dest[y*rystride];
for (x = 0; x < xcount; x++)
{
abase_x = &abase[x*axstride];
s = (GFC_INTEGER_1) 0;
for (n = 0; n < count; n++)
s += abase_x[n*aystride] * bbase_y[n*bxstride];
dest_y[x*rxstride] = s;
}
}
}
}
#endif

View File

@ -0,0 +1,339 @@
/* Implementation of the MATMUL intrinsic
Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2)
/* Prototype for the BLAS ?gemm subroutine, a pointer to which can be
passed to us by the front-end, in which case we'll call it for large
matrices. */
typedef void (*blas_call)(const char *, const char *, const int *, const int *,
const int *, const GFC_INTEGER_2 *, const GFC_INTEGER_2 *,
const int *, const GFC_INTEGER_2 *, const int *,
const GFC_INTEGER_2 *, GFC_INTEGER_2 *, const int *,
int, int);
/* The order of loops is different in the case of plain matrix
multiplication C=MATMUL(A,B), and in the frequent special case where
the argument A is the temporary result of a TRANSPOSE intrinsic:
C=MATMUL(TRANSPOSE(A),B). Transposed temporaries are detected by
looking at their strides.
The equivalent Fortran pseudo-code is:
DIMENSION A(M,COUNT), B(COUNT,N), C(M,N)
IF (.NOT.IS_TRANSPOSED(A)) THEN
C = 0
DO J=1,N
DO K=1,COUNT
DO I=1,M
C(I,J) = C(I,J)+A(I,K)*B(K,J)
ELSE
DO J=1,N
DO I=1,M
S = 0
DO K=1,COUNT
S = S+A(I,K)*B(K,J)
C(I,J) = S
ENDIF
*/
/* If try_blas is set to a nonzero value, then the matmul function will
see if there is a way to perform the matrix multiplication by a call
to the BLAS gemm function. */
extern void matmul_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict a, gfc_array_i2 * const restrict b, int try_blas,
int blas_limit, blas_call gemm);
export_proto(matmul_i2);
void
matmul_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict a, gfc_array_i2 * const restrict b, int try_blas,
int blas_limit, blas_call gemm)
{
const GFC_INTEGER_2 * restrict abase;
const GFC_INTEGER_2 * restrict bbase;
GFC_INTEGER_2 * restrict dest;
index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
index_type x, y, n, count, xcount, ycount;
assert (GFC_DESCRIPTOR_RANK (a) == 2
|| GFC_DESCRIPTOR_RANK (b) == 2);
/* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
Either A or B (but not both) can be rank 1:
o One-dimensional argument A is implicitly treated as a row matrix
dimensioned [1,count], so xcount=1.
o One-dimensional argument B is implicitly treated as a column matrix
dimensioned [count, 1], so ycount=1.
*/
if (retarray->data == NULL)
{
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = b->dim[1].ubound - b->dim[1].lbound;
retarray->dim[0].stride = 1;
}
else if (GFC_DESCRIPTOR_RANK (b) == 1)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
retarray->dim[0].stride = 1;
}
else
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = a->dim[0].ubound - a->dim[0].lbound;
retarray->dim[0].stride = 1;
retarray->dim[1].lbound = 0;
retarray->dim[1].ubound = b->dim[1].ubound - b->dim[1].lbound;
retarray->dim[1].stride = retarray->dim[0].ubound+1;
}
retarray->data
= internal_malloc_size (sizeof (GFC_INTEGER_2) * size0 ((array_t *) retarray));
retarray->offset = 0;
}
if (GFC_DESCRIPTOR_RANK (retarray) == 1)
{
/* One-dimensional result may be addressed in the code below
either as a row or a column matrix. We want both cases to
work. */
rxstride = rystride = retarray->dim[0].stride;
}
else
{
rxstride = retarray->dim[0].stride;
rystride = retarray->dim[1].stride;
}
if (GFC_DESCRIPTOR_RANK (a) == 1)
{
/* Treat it as a a row matrix A[1,count]. */
axstride = a->dim[0].stride;
aystride = 1;
xcount = 1;
count = a->dim[0].ubound + 1 - a->dim[0].lbound;
}
else
{
axstride = a->dim[0].stride;
aystride = a->dim[1].stride;
count = a->dim[1].ubound + 1 - a->dim[1].lbound;
xcount = a->dim[0].ubound + 1 - a->dim[0].lbound;
}
assert(count == b->dim[0].ubound + 1 - b->dim[0].lbound);
if (GFC_DESCRIPTOR_RANK (b) == 1)
{
/* Treat it as a column matrix B[count,1] */
bxstride = b->dim[0].stride;
/* bystride should never be used for 1-dimensional b.
in case it is we want it to cause a segfault, rather than
an incorrect result. */
bystride = 0xDEADBEEF;
ycount = 1;
}
else
{
bxstride = b->dim[0].stride;
bystride = b->dim[1].stride;
ycount = b->dim[1].ubound + 1 - b->dim[1].lbound;
}
abase = a->data;
bbase = b->data;
dest = retarray->data;
/* Now that everything is set up, we're performing the multiplication
itself. */
#define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
&& (bxstride == 1 || bystride == 1)
&& (((float) xcount) * ((float) ycount) * ((float) count)
> POW3(blas_limit)))
{
const int m = xcount, n = ycount, k = count, ldc = rystride;
const GFC_INTEGER_2 one = 1, zero = 0;
const int lda = (axstride == 1) ? aystride : axstride,
ldb = (bxstride == 1) ? bystride : bxstride;
if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
{
assert (gemm != NULL);
gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m, &n, &k,
&one, abase, &lda, bbase, &ldb, &zero, dest, &ldc, 1, 1);
return;
}
}
if (rxstride == 1 && axstride == 1 && bxstride == 1)
{
const GFC_INTEGER_2 * restrict bbase_y;
GFC_INTEGER_2 * restrict dest_y;
const GFC_INTEGER_2 * restrict abase_n;
GFC_INTEGER_2 bbase_yn;
if (rystride == xcount)
memset (dest, 0, (sizeof (GFC_INTEGER_2) * xcount * ycount));
else
{
for (y = 0; y < ycount; y++)
for (x = 0; x < xcount; x++)
dest[x + y*rystride] = (GFC_INTEGER_2)0;
}
for (y = 0; y < ycount; y++)
{
bbase_y = bbase + y*bystride;
dest_y = dest + y*rystride;
for (n = 0; n < count; n++)
{
abase_n = abase + n*aystride;
bbase_yn = bbase_y[n];
for (x = 0; x < xcount; x++)
{
dest_y[x] += abase_n[x] * bbase_yn;
}
}
}
}
else if (rxstride == 1 && aystride == 1 && bxstride == 1)
{
if (GFC_DESCRIPTOR_RANK (a) != 1)
{
const GFC_INTEGER_2 *restrict abase_x;
const GFC_INTEGER_2 *restrict bbase_y;
GFC_INTEGER_2 *restrict dest_y;
GFC_INTEGER_2 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
dest_y = &dest[y*rystride];
for (x = 0; x < xcount; x++)
{
abase_x = &abase[x*axstride];
s = (GFC_INTEGER_2) 0;
for (n = 0; n < count; n++)
s += abase_x[n] * bbase_y[n];
dest_y[x] = s;
}
}
}
else
{
const GFC_INTEGER_2 *restrict bbase_y;
GFC_INTEGER_2 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
s = (GFC_INTEGER_2) 0;
for (n = 0; n < count; n++)
s += abase[n*axstride] * bbase_y[n];
dest[y*rystride] = s;
}
}
}
else if (axstride < aystride)
{
for (y = 0; y < ycount; y++)
for (x = 0; x < xcount; x++)
dest[x*rxstride + y*rystride] = (GFC_INTEGER_2)0;
for (y = 0; y < ycount; y++)
for (n = 0; n < count; n++)
for (x = 0; x < xcount; x++)
/* dest[x,y] += a[x,n] * b[n,y] */
dest[x*rxstride + y*rystride] += abase[x*axstride + n*aystride] * bbase[n*bxstride + y*bystride];
}
else if (GFC_DESCRIPTOR_RANK (a) == 1)
{
const GFC_INTEGER_2 *restrict bbase_y;
GFC_INTEGER_2 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
s = (GFC_INTEGER_2) 0;
for (n = 0; n < count; n++)
s += abase[n*axstride] * bbase_y[n*bxstride];
dest[y*rxstride] = s;
}
}
else
{
const GFC_INTEGER_2 *restrict abase_x;
const GFC_INTEGER_2 *restrict bbase_y;
GFC_INTEGER_2 *restrict dest_y;
GFC_INTEGER_2 s;
for (y = 0; y < ycount; y++)
{
bbase_y = &bbase[y*bystride];
dest_y = &dest[y*rystride];
for (x = 0; x < xcount; x++)
{
abase_x = &abase[x*axstride];
s = (GFC_INTEGER_2) 0;
for (n = 0; n < count; n++)
s += abase_x[n*aystride] * bbase_y[n*bxstride];
dest_y[x*rxstride] = s;
}
}
}
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
extern void maxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(maxloc0_16_i1);
void
maxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_16 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_16_i1);
void
mmaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_16 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_16_i1);
void
smaxloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_16 *dest;
if (*mask)
{
maxloc0_16_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
extern void maxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(maxloc0_16_i2);
void
maxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_16 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_16_i2);
void
mmaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_16 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_16_i2);
void
smaxloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_16 *dest;
if (*mask)
{
maxloc0_16_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
extern void maxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(maxloc0_4_i1);
void
maxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_4 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_4_i1);
void
mmaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_4 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_4_i1);
void
smaxloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_4 *dest;
if (*mask)
{
maxloc0_4_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
extern void maxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(maxloc0_4_i2);
void
maxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_4 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_4_i2);
void
mmaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_4 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_4_i2);
void
smaxloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_4 *dest;
if (*mask)
{
maxloc0_4_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
extern void maxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(maxloc0_8_i1);
void
maxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_8 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_8_i1);
void
mmaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_8 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_8_i1);
void
smaxloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_8 *dest;
if (*mask)
{
maxloc0_8_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
extern void maxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(maxloc0_8_i2);
void
maxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_8 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*base > maxval || !dest[0])
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mmaxloc0_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mmaxloc0_8_i2);
void
mmaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_8 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base > maxval || !dest[0]))
{
maxval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void smaxloc0_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(smaxloc0_8_i2);
void
smaxloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_8 *dest;
if (*mask)
{
maxloc0_8_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
extern void maxloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(maxloc1_16_i1);
void
maxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_16 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_16 result;
src = base;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_16_i1);
void
mmaxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_16 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_16 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_16_i1);
void
smaxloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_16 *dest;
if (*mask)
{
maxloc1_16_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
extern void maxloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(maxloc1_16_i2);
void
maxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_16 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_16 result;
src = base;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_16_i2);
void
mmaxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_16 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_16 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_16_i2);
void
smaxloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_16 *dest;
if (*mask)
{
maxloc1_16_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
extern void maxloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(maxloc1_4_i1);
void
maxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_4 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_4 result;
src = base;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_4_i1);
void
mmaxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_4 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_4 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_4_i1);
void
smaxloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_4 *dest;
if (*mask)
{
maxloc1_4_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
extern void maxloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(maxloc1_4_i2);
void
maxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_4 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_4 result;
src = base;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_4_i2);
void
mmaxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_4 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_4 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_4_i2);
void
smaxloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_4 *dest;
if (*mask)
{
maxloc1_4_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
extern void maxloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(maxloc1_8_i1);
void
maxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_8 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_8 result;
src = base;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_8_i1);
void
mmaxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_8 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_8 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 maxval;
maxval = (-GFC_INTEGER_1_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_8_i1);
void
smaxloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_8 *dest;
if (*mask)
{
maxloc1_8_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MAXLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
extern void maxloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(maxloc1_8_i2);
void
maxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_8 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_8 result;
src = base;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > maxval || !result)
{
maxval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxloc1_8_i2);
void
mmaxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_8 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_8 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 maxval;
maxval = (-GFC_INTEGER_2_HUGE-1);
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src > maxval || !result))
{
maxval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxloc1_8_i2);
void
smaxloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_8 *dest;
if (*mask)
{
maxloc1_8_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,410 @@
/* Implementation of the MAXVAL intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
extern void maxval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(maxval_i1);
void
maxval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_1 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_1 result;
src = base;
{
result = (-GFC_INTEGER_1_HUGE-1);
if (len <= 0)
*dest = (-GFC_INTEGER_1_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxval_i1);
void
mmaxval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_1 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_1 result;
src = base;
msrc = mbase;
{
result = (-GFC_INTEGER_1_HUGE-1);
if (len <= 0)
*dest = (-GFC_INTEGER_1_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && *src > result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxval_i1);
void
smaxval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_1 *dest;
if (*mask)
{
maxval_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = (-GFC_INTEGER_1_HUGE-1) ;
}
#endif

View File

@ -0,0 +1,410 @@
/* Implementation of the MAXVAL intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
extern void maxval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(maxval_i2);
void
maxval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_2 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_2 result;
src = base;
{
result = (-GFC_INTEGER_2_HUGE-1);
if (len <= 0)
*dest = (-GFC_INTEGER_2_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src > result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mmaxval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mmaxval_i2);
void
mmaxval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_2 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_2 result;
src = base;
msrc = mbase;
{
result = (-GFC_INTEGER_2_HUGE-1);
if (len <= 0)
*dest = (-GFC_INTEGER_2_HUGE-1);
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && *src > result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void smaxval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(smaxval_i2);
void
smaxval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_2 *dest;
if (*mask)
{
maxval_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = (-GFC_INTEGER_2_HUGE-1) ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
extern void minloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(minloc0_16_i1);
void
minloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_16 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_16_i1);
void
mminloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_16 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_16_i1);
void
sminloc0_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_16 *dest;
if (*mask)
{
minloc0_16_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
extern void minloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(minloc0_16_i2);
void
minloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_16 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_16_i2);
void
mminloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_16 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_16_i2);
void
sminloc0_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_16 *dest;
if (*mask)
{
minloc0_16_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
extern void minloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(minloc0_4_i1);
void
minloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_4 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_4_i1);
void
mminloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_4 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_4_i1);
void
sminloc0_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_4 *dest;
if (*mask)
{
minloc0_4_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
extern void minloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(minloc0_4_i2);
void
minloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_4 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_4_i2);
void
mminloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_4 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_4_i2);
void
sminloc0_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_4 *dest;
if (*mask)
{
minloc0_4_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
extern void minloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array);
export_proto(minloc0_8_i1);
void
minloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_1 *base;
GFC_INTEGER_8 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_8_i1);
void
mminloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_8 *dest;
const GFC_INTEGER_1 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_8_i1);
void
sminloc0_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_8 *dest;
if (*mask)
{
minloc0_8_i1 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,326 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
extern void minloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array);
export_proto(minloc0_8_i2);
void
minloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride;
const GFC_INTEGER_2 *base;
GFC_INTEGER_8 *dest;
index_type rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*base < minval || !dest[0])
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
}
}
}
}
}
extern void mminloc0_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, gfc_array_l4 * const restrict);
export_proto(mminloc0_8_i2);
void
mminloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
index_type dstride;
GFC_INTEGER_8 *dest;
const GFC_INTEGER_2 *base;
GFC_LOGICAL_4 *mbase;
int rank;
index_type n;
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
count[n] = 0;
if (extent[n] <= 0)
{
/* Set the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
return;
}
}
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
/* Initialize the return value. */
for (n = 0; n < rank; n++)
dest[n * dstride] = 0;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
while (base)
{
{
/* Implementation start. */
if (*mbase && (*base < minval || !dest[0]))
{
minval = *base;
for (n = 0; n < rank; n++)
dest[n * dstride] = count[n] + 1;
}
/* Implementation end. */
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the loop. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
}
}
}
}
}
extern void sminloc0_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, GFC_LOGICAL_4 *);
export_proto(sminloc0_8_i2);
void
sminloc0_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type dstride;
index_type n;
GFC_INTEGER_8 *dest;
if (*mask)
{
minloc0_8_i2 (retarray, array);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n<rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_16)
extern void minloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(minloc1_16_i1);
void
minloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_16 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_16 result;
src = base;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_16_i1);
void
mminloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_16 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_16 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_16_i1 (gfc_array_i16 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_16_i1);
void
sminloc1_16_i1 (gfc_array_i16 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_16 *dest;
if (*mask)
{
minloc1_16_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_16)
extern void minloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(minloc1_16_i2);
void
minloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_16 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_16 result;
src = base;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_16_i2);
void
mminloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_16 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_16) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_16 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_16)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_16_i2 (gfc_array_i16 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_16_i2);
void
sminloc1_16_i2 (gfc_array_i16 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_16 *dest;
if (*mask)
{
minloc1_16_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_16) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_4)
extern void minloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(minloc1_4_i1);
void
minloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_4 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_4 result;
src = base;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_4_i1);
void
mminloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_4 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_4 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_4_i1 (gfc_array_i4 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_4_i1);
void
sminloc1_4_i1 (gfc_array_i4 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_4 *dest;
if (*mask)
{
minloc1_4_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_4)
extern void minloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(minloc1_4_i2);
void
minloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_4 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_4 result;
src = base;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_4_i2);
void
mminloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_4 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_4) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_4 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_4)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_4_i2 (gfc_array_i4 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_4_i2);
void
sminloc1_4_i2 (gfc_array_i4 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_4 *dest;
if (*mask)
{
minloc1_4_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_4) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_8)
extern void minloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(minloc1_8_i1);
void
minloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_8 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_8 result;
src = base;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_8_i1);
void
mminloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_8 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_8 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_1 minval;
minval = GFC_INTEGER_1_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_8_i1 (gfc_array_i8 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_8_i1);
void
sminloc1_8_i1 (gfc_array_i8 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_8 *dest;
if (*mask)
{
minloc1_8_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,421 @@
/* Implementation of the MINLOC intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include <limits.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_8)
extern void minloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(minloc1_8_i2);
void
minloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_8 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_8 result;
src = base;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < minval || !result)
{
minval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminloc1_8_i2);
void
mminloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_8 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_8) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_8 result;
src = base;
msrc = mbase;
{
GFC_INTEGER_2 minval;
minval = GFC_INTEGER_2_HUGE;
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && (*src < minval || !result))
{
minval = *src;
result = (GFC_INTEGER_8)n + 1;
}
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminloc1_8_i2 (gfc_array_i8 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminloc1_8_i2);
void
sminloc1_8_i2 (gfc_array_i8 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_8 *dest;
if (*mask)
{
minloc1_8_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_8) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,410 @@
/* Implementation of the MINVAL intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
extern void minval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(minval_i1);
void
minval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_1 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_1 result;
src = base;
{
result = GFC_INTEGER_1_HUGE;
if (len <= 0)
*dest = GFC_INTEGER_1_HUGE;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminval_i1);
void
mminval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_1 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_1 result;
src = base;
msrc = mbase;
{
result = GFC_INTEGER_1_HUGE;
if (len <= 0)
*dest = GFC_INTEGER_1_HUGE;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && *src < result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminval_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminval_i1);
void
sminval_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_1 *dest;
if (*mask)
{
minval_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = GFC_INTEGER_1_HUGE ;
}
#endif

View File

@ -0,0 +1,410 @@
/* Implementation of the MINVAL intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include <float.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
extern void minval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(minval_i2);
void
minval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_2 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_2 result;
src = base;
{
result = GFC_INTEGER_2_HUGE;
if (len <= 0)
*dest = GFC_INTEGER_2_HUGE;
else
{
for (n = 0; n < len; n++, src += delta)
{
if (*src < result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mminval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mminval_i2);
void
mminval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_2 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_2 result;
src = base;
msrc = mbase;
{
result = GFC_INTEGER_2_HUGE;
if (len <= 0)
*dest = GFC_INTEGER_2_HUGE;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc && *src < result)
result = *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sminval_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sminval_i2);
void
sminval_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_2 *dest;
if (*mask)
{
minval_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = GFC_INTEGER_2_HUGE ;
}
#endif

View File

@ -0,0 +1,408 @@
/* Implementation of the PRODUCT intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
extern void product_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(product_i1);
void
product_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_1 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_1 result;
src = base;
{
result = 1;
if (len <= 0)
*dest = 1;
else
{
for (n = 0; n < len; n++, src += delta)
{
result *= *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mproduct_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mproduct_i1);
void
mproduct_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_1 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_1 result;
src = base;
msrc = mbase;
{
result = 1;
if (len <= 0)
*dest = 1;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc)
result *= *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sproduct_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sproduct_i1);
void
sproduct_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_1 *dest;
if (*mask)
{
product_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 1 ;
}
#endif

View File

@ -0,0 +1,408 @@
/* Implementation of the PRODUCT intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
extern void product_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(product_i2);
void
product_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_2 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_2 result;
src = base;
{
result = 1;
if (len <= 0)
*dest = 1;
else
{
for (n = 0; n < len; n++, src += delta)
{
result *= *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void mproduct_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(mproduct_i2);
void
mproduct_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_2 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_2 result;
src = base;
msrc = mbase;
{
result = 1;
if (len <= 0)
*dest = 1;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc)
result *= *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void sproduct_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(sproduct_i2);
void
sproduct_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_2 *dest;
if (*mask)
{
product_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 1 ;
}
#endif

View File

@ -0,0 +1,408 @@
/* Implementation of the SUM intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_1) && defined (HAVE_GFC_INTEGER_1)
extern void sum_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict);
export_proto(sum_i1);
void
sum_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_1 * restrict base;
GFC_INTEGER_1 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_1 * restrict src;
GFC_INTEGER_1 result;
src = base;
{
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
result += *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void msum_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(msum_i1);
void
msum_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_1 * restrict dest;
const GFC_INTEGER_1 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_1) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_1 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_1 result;
src = base;
msrc = mbase;
{
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc)
result += *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void ssum_i1 (gfc_array_i1 * const restrict,
gfc_array_i1 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(ssum_i1);
void
ssum_i1 (gfc_array_i1 * const restrict retarray,
gfc_array_i1 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_1 *dest;
if (*mask)
{
sum_i1 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_1) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -0,0 +1,408 @@
/* Implementation of the SUM intrinsic
Copyright 2002 Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran 95 runtime library (libgfortran).
Libgfortran is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
In addition to the permissions in the GNU General Public License, the
Free Software Foundation gives you unlimited permission to link the
compiled version of this file into combinations with other programs,
and to distribute those combinations without any restriction coming
from the use of this file. (The General Public License restrictions
do apply in other respects; for example, they cover modification of
the file, and distribution when not linked into a combine
executable.)
Libgfortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with libgfortran; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
#include "config.h"
#include <stdlib.h>
#include <assert.h>
#include "libgfortran.h"
#if defined (HAVE_GFC_INTEGER_2) && defined (HAVE_GFC_INTEGER_2)
extern void sum_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict);
export_proto(sum_i2);
void
sum_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
const GFC_INTEGER_2 * restrict base;
GFC_INTEGER_2 * restrict dest;
index_type rank;
index_type n;
index_type len;
index_type delta;
index_type dim;
/* Make dim zero based to avoid confusion. */
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
delta = array->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
len = 0;
}
base = array->data;
dest = retarray->data;
while (base)
{
const GFC_INTEGER_2 * restrict src;
GFC_INTEGER_2 result;
src = base;
{
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta)
{
result += *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
dest += dstride[n];
}
}
}
}
extern void msum_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
gfc_array_l4 * const restrict);
export_proto(msum_i2);
void
msum_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
gfc_array_l4 * const restrict mask)
{
index_type count[GFC_MAX_DIMENSIONS];
index_type extent[GFC_MAX_DIMENSIONS];
index_type sstride[GFC_MAX_DIMENSIONS];
index_type dstride[GFC_MAX_DIMENSIONS];
index_type mstride[GFC_MAX_DIMENSIONS];
GFC_INTEGER_2 * restrict dest;
const GFC_INTEGER_2 * restrict base;
const GFC_LOGICAL_4 * restrict mbase;
int rank;
int dim;
index_type n;
index_type len;
index_type delta;
index_type mdelta;
dim = (*pdim) - 1;
rank = GFC_DESCRIPTOR_RANK (array) - 1;
len = array->dim[dim].ubound + 1 - array->dim[dim].lbound;
if (len <= 0)
return;
delta = array->dim[dim].stride;
mdelta = mask->dim[dim].stride;
for (n = 0; n < dim; n++)
{
sstride[n] = array->dim[n].stride;
mstride[n] = mask->dim[n].stride;
extent[n] = array->dim[n].ubound + 1 - array->dim[n].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
for (n = dim; n < rank; n++)
{
sstride[n] = array->dim[n + 1].stride;
mstride[n] = mask->dim[n + 1].stride;
extent[n] =
array->dim[n + 1].ubound + 1 - array->dim[n + 1].lbound;
if (extent[n] < 0)
extent[n] = 0;
}
if (retarray->data == NULL)
{
size_t alloc_size;
for (n = 0; n < rank; n++)
{
retarray->dim[n].lbound = 0;
retarray->dim[n].ubound = extent[n]-1;
if (n == 0)
retarray->dim[n].stride = 1;
else
retarray->dim[n].stride = retarray->dim[n-1].stride * extent[n-1];
}
alloc_size = sizeof (GFC_INTEGER_2) * retarray->dim[rank-1].stride
* extent[rank-1];
retarray->offset = 0;
retarray->dtype = (array->dtype & ~GFC_DTYPE_RANK_MASK) | rank;
if (alloc_size == 0)
{
/* Make sure we have a zero-sized array. */
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = -1;
return;
}
else
retarray->data = internal_malloc_size (alloc_size);
}
else
{
if (rank != GFC_DESCRIPTOR_RANK (retarray))
runtime_error ("rank of return array incorrect");
}
for (n = 0; n < rank; n++)
{
count[n] = 0;
dstride[n] = retarray->dim[n].stride;
if (extent[n] <= 0)
return;
}
dest = retarray->data;
base = array->data;
mbase = mask->data;
if (GFC_DESCRIPTOR_SIZE (mask) != 4)
{
/* This allows the same loop to be used for all logical types. */
assert (GFC_DESCRIPTOR_SIZE (mask) == 8);
for (n = 0; n < rank; n++)
mstride[n] <<= 1;
mdelta <<= 1;
mbase = (GFOR_POINTER_L8_TO_L4 (mbase));
}
while (base)
{
const GFC_INTEGER_2 * restrict src;
const GFC_LOGICAL_4 * restrict msrc;
GFC_INTEGER_2 result;
src = base;
msrc = mbase;
{
result = 0;
if (len <= 0)
*dest = 0;
else
{
for (n = 0; n < len; n++, src += delta, msrc += mdelta)
{
if (*msrc)
result += *src;
}
*dest = result;
}
}
/* Advance to the next element. */
count[0]++;
base += sstride[0];
mbase += mstride[0];
dest += dstride[0];
n = 0;
while (count[n] == extent[n])
{
/* When we get to the end of a dimension, reset it and increment
the next dimension. */
count[n] = 0;
/* We could precalculate these products, but this is a less
frequently used path so probably not worth it. */
base -= sstride[n] * extent[n];
mbase -= mstride[n] * extent[n];
dest -= dstride[n] * extent[n];
n++;
if (n == rank)
{
/* Break out of the look. */
base = NULL;
break;
}
else
{
count[n]++;
base += sstride[n];
mbase += mstride[n];
dest += dstride[n];
}
}
}
}
extern void ssum_i2 (gfc_array_i2 * const restrict,
gfc_array_i2 * const restrict, const index_type * const restrict,
GFC_LOGICAL_4 *);
export_proto(ssum_i2);
void
ssum_i2 (gfc_array_i2 * const restrict retarray,
gfc_array_i2 * const restrict array,
const index_type * const restrict pdim,
GFC_LOGICAL_4 * mask)
{
index_type rank;
index_type n;
index_type dstride;
GFC_INTEGER_2 *dest;
if (*mask)
{
sum_i2 (retarray, array, pdim);
return;
}
rank = GFC_DESCRIPTOR_RANK (array);
if (rank <= 0)
runtime_error ("Rank of array needs to be > 0");
if (retarray->data == NULL)
{
retarray->dim[0].lbound = 0;
retarray->dim[0].ubound = rank-1;
retarray->dim[0].stride = 1;
retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1;
retarray->offset = 0;
retarray->data = internal_malloc_size (sizeof (GFC_INTEGER_2) * rank);
}
else
{
if (GFC_DESCRIPTOR_RANK (retarray) != 1)
runtime_error ("rank of return array does not equal 1");
if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank)
runtime_error ("dimension of return array incorrect");
}
dstride = retarray->dim[0].stride;
dest = retarray->data;
for (n = 0; n < rank; n++)
dest[n * dstride] = 0 ;
}
#endif

View File

@ -224,6 +224,10 @@ internal_proto(l8_to_l4_offset);
#define GFOR_POINTER_L8_TO_L4(p8) \
(l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
#define GFC_INTEGER_1_HUGE \
(GFC_INTEGER_1)((((GFC_UINTEGER_1)1) << 7) - 1)
#define GFC_INTEGER_2_HUGE \
(GFC_INTEGER_2)((((GFC_UINTEGER_2)1) << 15) - 1)
#define GFC_INTEGER_4_HUGE \
(GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
#define GFC_INTEGER_8_HUGE \
@ -283,6 +287,8 @@ struct {\
/* Commonly used array descriptor types. */
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_1) gfc_array_i1;
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_2) gfc_array_i2;
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
#ifdef HAVE_GFC_INTEGER_16