Commit 5b200ac2 by Feng Wang Committed by Paul Brook

f95-lang.c (gfc_init_builtin_functions): Use vold_list_node.

	* f95-lang.c (gfc_init_builtin_functions): Use vold_list_node.
	Create decls for __builtin_pow{,f}.
	* gfortran.h (PREFIX_LEN): Define.
	* trans-decl.c (gfor_fndecl_math_powi): Add.
	(gfor_fndecl_math_powf, gfor_fndecl_math_pow): Remove.
	(gfc_build_intrinsic_function_decls): Create decls for powi.
	* trans-expr.c (powi_table): Add.
	(gfc_conv_integer_power): Remove.
	(gfc_conv_powi): New function.
	(gfc_conv_cst_int_power): New function.
	(gfc_conv_power_op): Use new powi routines.
	* trans.h (struct gfc_powdecl_list): Add.
	(gfor_fndecl_math_powi): Add.
	(gfor_fndecl_math_powf, gfor_fndecl_math_pow): Remove.
testsuite/
	* gfortran.fortran-torture/execute/power.f90: Test constant integers.
libgfortran/
	* Makefile.am (i_pow_c): Set it. Add build rule.
	(gfor_built_src): Use it.
	(m4_files): add m4/pow.m4.
	* Makefile.in: Regenerate.
	* m4/pow.m4: New file.
	* generated/pow_*.c: Regenerate.

From-SVN: r82014
parent 933520b9
2004-05-18 Paul Brook <paul@codesourcery.com>
* f95-lang.c (gfc_init_builtin_functions): Use vold_list_node.
Create decls for __builtin_pow{,f}.
* gfortran.h (PREFIX_LEN): Define.
* trans-decl.c (gfor_fndecl_math_powi): Add.
(gfor_fndecl_math_powf, gfor_fndecl_math_pow): Remove.
(gfc_build_intrinsic_function_decls): Create decls for powi.
* trans-expr.c (powi_table): Add.
(gfc_conv_integer_power): Remove.
(gfc_conv_powi): New function.
(gfc_conv_cst_int_power): New function.
(gfc_conv_power_op): Use new powi routines.
* trans.h (struct gfc_powdecl_list): Add.
(gfor_fndecl_math_powi): Add.
(gfor_fndecl_math_powf, gfor_fndecl_math_pow): Remove.
2004-05-18 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
* trans.c, trans-decl.c: Fix comment typos.
......
......@@ -750,16 +750,13 @@ gfc_init_builtin_functions (void)
tree mfunc_double[2];
tree ftype;
tree tmp;
tree voidchain;
voidchain = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
tmp = tree_cons (NULL_TREE, float_type_node, voidchain);
tmp = tree_cons (NULL_TREE, float_type_node, void_list_node);
mfunc_float[0] = build_function_type (float_type_node, tmp);
tmp = tree_cons (NULL_TREE, float_type_node, tmp);
mfunc_float[1] = build_function_type (float_type_node, tmp);
tmp = tree_cons (NULL_TREE, double_type_node, voidchain);
tmp = tree_cons (NULL_TREE, double_type_node, void_list_node);
mfunc_double[0] = build_function_type (double_type_node, tmp);
tmp = tree_cons (NULL_TREE, double_type_node, tmp);
mfunc_double[1] = build_function_type (double_type_node, tmp);
......@@ -777,57 +774,63 @@ gfc_init_builtin_functions (void)
gfc_define_builtin ("__builtin_roundf", mfunc_float[0],
BUILT_IN_ROUNDF, "roundf", true);
/* These are used to implement the ** operator. */
gfc_define_builtin ("__builtin_pow", mfunc_double[0],
BUILT_IN_POW, "pow", true);
gfc_define_builtin ("__builtin_powf", mfunc_float[0],
BUILT_IN_POWF, "powf", true);
/* Other builtin functions we use. */
tmp = tree_cons (NULL_TREE, long_integer_type_node, voidchain);
tmp = tree_cons (NULL_TREE, long_integer_type_node, void_list_node);
tmp = tree_cons (NULL_TREE, long_integer_type_node, tmp);
ftype = build_function_type (long_integer_type_node, tmp);
gfc_define_builtin ("__builtin_expect", ftype, BUILT_IN_EXPECT,
"__builtin_expect", true);
tmp = tree_cons (NULL_TREE, size_type_node, voidchain);
tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
tmp = tree_cons (NULL_TREE, pvoid_type_node, tmp);
tmp = tree_cons (NULL_TREE, pvoid_type_node, tmp);
ftype = build_function_type (pvoid_type_node, tmp);
gfc_define_builtin ("__builtin_memcpy", ftype, BUILT_IN_MEMCPY,
"memcpy", false);
tmp = tree_cons (NULL_TREE, integer_type_node, voidchain);
tmp = tree_cons (NULL_TREE, integer_type_node, void_list_node);
ftype = build_function_type (integer_type_node, tmp);
gfc_define_builtin ("__builtin_clz", ftype, BUILT_IN_CLZ, "clz", true);
tmp = tree_cons (NULL_TREE, long_integer_type_node, voidchain);
tmp = tree_cons (NULL_TREE, long_integer_type_node, void_list_node);
ftype = build_function_type (integer_type_node, tmp);
gfc_define_builtin ("__builtin_clzl", ftype, BUILT_IN_CLZL, "clzl", true);
tmp = tree_cons (NULL_TREE, long_long_integer_type_node, voidchain);
tmp = tree_cons (NULL_TREE, long_long_integer_type_node, void_list_node);
ftype = build_function_type (integer_type_node, tmp);
gfc_define_builtin ("__builtin_clzll", ftype, BUILT_IN_CLZLL, "clzll", true);
tmp = tree_cons (NULL_TREE, pvoid_type_node, voidchain);
tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
tmp = tree_cons (NULL_TREE, pvoid_type_node, tmp);
tmp = tree_cons (NULL_TREE, pvoid_type_node, tmp);
ftype = build_function_type (void_type_node, tmp);
gfc_define_builtin ("__builtin_init_trampoline", ftype,
BUILT_IN_INIT_TRAMPOLINE, "init_trampoline", false);
tmp = tree_cons (NULL_TREE, pvoid_type_node, voidchain);
tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
ftype = build_function_type (pvoid_type_node, tmp);
gfc_define_builtin ("__builtin_adjust_trampoline", ftype,
BUILT_IN_ADJUST_TRAMPOLINE, "adjust_trampoline", true);
tmp = tree_cons (NULL_TREE, pvoid_type_node, voidchain);
tmp = tree_cons (NULL_TREE, size_type_node, voidchain);
tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
tmp = tree_cons (NULL_TREE, size_type_node, void_list_node);
ftype = build_function_type (pvoid_type_node, tmp);
gfc_define_builtin ("__builtin_stack_alloc", ftype, BUILT_IN_STACK_ALLOC,
"stack_alloc", false);
/* The stack_save and stack_restore builtins aren't used directly. They
are inserted during gimplification to implement stack_alloc calls. */
ftype = build_function_type (pvoid_type_node, voidchain);
ftype = build_function_type (pvoid_type_node, void_list_node);
gfc_define_builtin ("__builtin_stack_save", ftype, BUILT_IN_STACK_SAVE,
"stack_save", false);
tmp = tree_cons (NULL_TREE, pvoid_type_node, voidchain);
tmp = tree_cons (NULL_TREE, pvoid_type_node, void_list_node);
ftype = build_function_type (void_type_node, tmp);
gfc_define_builtin ("__builtin_stack_restore", ftype, BUILT_IN_STACK_RESTORE,
"stack_restore", false);
......
......@@ -82,6 +82,7 @@ char *alloca ();
ugly to look at and a pain to type when you add the prefix by hand,
so we hide it behind a macro. */
#define PREFIX(x) "_gfortran_" x
#define PREFIX_LEN 10
/* Macro to initialize an mstring structure. */
#define minit(s, t) { s, NULL, t }
......
......@@ -93,8 +93,7 @@ tree gfor_fndecl_associated;
/* Math functions. Many other math functions are handled in
trans-intrinsic.c. */
tree gfor_fndecl_math_powf;
tree gfor_fndecl_math_pow;
gfc_powdecl_list gfor_fndecl_math_powi[3][2];
tree gfor_fndecl_math_cpowf;
tree gfor_fndecl_math_cpow;
tree gfor_fndecl_math_cabsf;
......@@ -1398,14 +1397,40 @@ gfc_build_intrinsic_function_decls (void)
/* Power functions. */
gfor_fndecl_math_powf =
gfc_build_library_function_decl (get_identifier ("powf"),
gfc_real4_type_node,
1, gfc_real4_type_node);
gfor_fndecl_math_pow =
gfc_build_library_function_decl (get_identifier ("pow"),
gfc_real8_type_node,
1, gfc_real8_type_node);
{
tree type;
tree itype;
int kind;
int ikind;
static int kinds[2] = {4, 8};
char name[PREFIX_LEN + 10]; /* _gfortran_pow_?n_?n */
for (ikind=0; ikind < 2; ikind++)
{
itype = gfc_get_int_type (kinds[ikind]);
for (kind = 0; kind < 2; kind ++)
{
type = gfc_get_int_type (kinds[kind]);
sprintf(name, PREFIX("pow_i%d_i%d"), kinds[kind], kinds[ikind]);
gfor_fndecl_math_powi[kind][ikind].integer =
gfc_build_library_function_decl (get_identifier (name),
type, 2, type, itype);
type = gfc_get_real_type (kinds[kind]);
sprintf(name, PREFIX("pow_r%d_i%d"), kinds[kind], kinds[ikind]);
gfor_fndecl_math_powi[kind][ikind].real =
gfc_build_library_function_decl (get_identifier (name),
type, 2, type, itype);
type = gfc_get_complex_type (kinds[kind]);
sprintf(name, PREFIX("pow_c%d_i%d"), kinds[kind], kinds[ikind]);
gfor_fndecl_math_powi[kind][ikind].cmplx =
gfc_build_library_function_decl (get_identifier (name),
type, 2, type, itype);
}
}
}
gfor_fndecl_math_cpowf =
gfc_build_library_function_decl (get_identifier ("cpowf"),
gfc_complex4_type_node,
......
......@@ -428,8 +428,16 @@ extern GTY(()) tree gfor_fndecl_associated;
/* Math functions. Many other math functions are handled in
trans-intrinsic.c. */
extern GTY(()) tree gfor_fndecl_math_powf;
extern GTY(()) tree gfor_fndecl_math_pow;
typedef struct gfc_powdecl_list GTY(())
{
tree integer;
tree real;
tree cmplx;
}
gfc_powdecl_list;
extern GTY(()) gfc_powdecl_list gfor_fndecl_math_powi[3][2];
extern GTY(()) tree gfor_fndecl_math_cpowf;
extern GTY(()) tree gfor_fndecl_math_cpow;
extern GTY(()) tree gfor_fndecl_math_cabsf;
......
2004-05-18 Paul Brook <paul@codesourcery.com>
* gfortran.fortran-torture/execute/power.f90: Test constant integers.
2004-05-18 Andrew Pinski <pinskia@physics.uc.edu>
* gcc.dg/tree-ssa/20040518-1.c: New test.
......
......@@ -3,9 +3,41 @@ program testpow
implicit none
real(kind=4) r, s, two
real(kind=8) :: q
complex(kind=4) :: c
complex(kind=4) :: c, z
real, parameter :: del = 0.0001
integer i
integer i, j
i = 2
j = i ** 10
if (abs (j - 1024) .gt. del) call abort
j = i ** (-10)
if (abs (j - 0) .gt. del) call abort
j = i ** 0
if (abs (j - 1) .gt. del) call abort
i = 1
j = i ** 10
if (abs (j - 1) .gt. del) call abort
j = i ** (-10)
if (abs (j - 1) .gt. del) call abort
j = i ** 0
if (abs (j - 1) .gt. del) call abort
i = -1
j = i ** 10
if (abs (j - 1) .gt. del) call abort
j = i ** (-10)
if (abs (j - 1) .gt. del) call abort
j = i ** 0
if (abs (j - 1) .gt. del) call abort
j = i ** 11
if (abs (j - (-1)) .gt. del) call abort
j = i ** (-11)
if (abs (j - (-1)) .gt. del) call abort
c = (2.0, 3.0)
z = c ** 2
if (abs(z - (-5.0, 12.0)) .gt. del) call abort
z = c ** 7
if (abs(z - (6554.0, 4449.0)) .gt. del) call abort
two = 2.0
......
2004-05-18 Paul Brook <paul@codesourcery.com>
* Makefile.am (i_pow_c): Set it. Add build rule.
(gfor_built_src): Use it.
(m4_files): add m4/pow.m4.
* Makefile.in: Regenerate.
* m4/pow.m4: New file.
* generated/pow_*.c: Regenerate.
2004-05-18 Paul Brook <paul@codesourcery.com>
* Makefile.am: Remove references to types.m4.
* m4/iparm.m4: Merge with types.m4.
* m4/types.m4: Remove.
......
......@@ -222,6 +222,20 @@ i_set_exponent_c = \
generated/set_exponent_r4.c \
generated/set_exponent_r8.c
i_pow_c = \
generated/pow_i4_i4.c \
generated/pow_i8_i4.c \
generated/pow_r4_i4.c \
generated/pow_r8_i4.c \
generated/pow_c4_i4.c \
generated/pow_c8_i4.c \
generated/pow_i4_i8.c \
generated/pow_i8_i8.c \
generated/pow_r4_i8.c \
generated/pow_r8_i8.c \
generated/pow_c4_i8.c \
generated/pow_c8_i8.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 \
m4/minloc0.m4 m4/minloc1.m4 m4/minval.m4 m4/product.m4 m4/sum.m4 \
......@@ -229,14 +243,15 @@ m4_files= m4/iparm.m4 m4/ifunction.m4 m4/iforeach.m4 m4/all.m4 \
m4/ctrig.m4 m4/cexp.m4 m4/chyp.m4 m4/mtype.m4 \
m4/specific.m4 m4/specific2.m4 m4/head.m4 m4/shape.m4 m4/reshape.m4 \
m4/transpose.m4 m4/eoshift1.m4 m4/eoshift3.m4 m4/exponent.m4 \
m4/fraction.m4 m4/nearest.m4 m4/set_exponent.m4
m4/fraction.m4 m4/nearest.m4 m4/set_exponent.m4 m4/pow.m4
gfor_built_src= $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
$(i_maxloc1_c) $(i_maxval_c) $(i_minloc0_c) $(i_minloc1_c) $(i_minval_c) \
$(i_product_c) $(i_sum_c) $(i_dotprod_c) $(i_dotprodl_c) $(i_dotprodc_c) \
$(i_matmul_c) $(i_matmull_c) $(i_transpose_c) $(i_shape_c) $(i_eoshift1_c) \
$(i_eoshift3_c) $(i_cshift1_c) $(i_reshape_c) $(in_pack_c) $(in_unpack_c) \
$(i_exponent_c) $(i_fraction_c) $(i_nearest_c) $(i_set_exponent_c)
$(i_exponent_c) $(i_fraction_c) $(i_nearest_c) $(i_set_exponent_c) \
$(i_pow_c)
# We only use these if libm doesn't contain complex math functions.
......@@ -443,6 +458,9 @@ $(i_nearest_c): m4/nearest.m4 m4/mtype.m4
$(i_set_exponent_c): m4/set_exponent.m4 m4/mtype.m4
m4 -Dfile=$@ -I$(srcdir)/m4 set_exponent.m4 > $@
$(i_pow_c): m4/pow.m4 $(I_M4_DEPS)
m4 -Dfile=$@ -I$(srcdir)/m4 pow.m4 > $@
$(gfor_math_trig_c): m4/ctrig.m4 m4/mtype.m4
m4 -Dfile=$@ -I$(srcdir)/m4 ctrig.m4 > $@
......
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_COMPLEX_4
prefix(pow_c4_i4) (GFC_COMPLEX_4 a, GFC_INTEGER_4 b)
{
GFC_COMPLEX_4 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_COMPLEX_4
prefix(pow_c4_i8) (GFC_COMPLEX_4 a, GFC_INTEGER_8 b)
{
GFC_COMPLEX_4 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_COMPLEX_8
prefix(pow_c8_i4) (GFC_COMPLEX_8 a, GFC_INTEGER_4 b)
{
GFC_COMPLEX_8 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_COMPLEX_8
prefix(pow_c8_i8) (GFC_COMPLEX_8 a, GFC_INTEGER_8 b)
{
GFC_COMPLEX_8 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_INTEGER_4
prefix(pow_i4_i4) (GFC_INTEGER_4 a, GFC_INTEGER_4 b)
{
GFC_INTEGER_4 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
if (x == 1)
return 1;
if (x == -1)
return (n & 1) ? -1 : 1;
return (x == 0) ? 1 / x : 0;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_INTEGER_4
prefix(pow_i4_i8) (GFC_INTEGER_4 a, GFC_INTEGER_8 b)
{
GFC_INTEGER_4 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
if (x == 1)
return 1;
if (x == -1)
return (n & 1) ? -1 : 1;
return (x == 0) ? 1 / x : 0;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_INTEGER_8
prefix(pow_i8_i4) (GFC_INTEGER_8 a, GFC_INTEGER_4 b)
{
GFC_INTEGER_8 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
if (x == 1)
return 1;
if (x == -1)
return (n & 1) ? -1 : 1;
return (x == 0) ? 1 / x : 0;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_INTEGER_8
prefix(pow_i8_i8) (GFC_INTEGER_8 a, GFC_INTEGER_8 b)
{
GFC_INTEGER_8 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
if (x == 1)
return 1;
if (x == -1)
return (n & 1) ? -1 : 1;
return (x == 0) ? 1 / x : 0;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_REAL_4
prefix(pow_r4_i4) (GFC_REAL_4 a, GFC_INTEGER_4 b)
{
GFC_REAL_4 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_REAL_4
prefix(pow_r4_i8) (GFC_REAL_4 a, GFC_INTEGER_8 b)
{
GFC_REAL_4 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_REAL_8
prefix(pow_r8_i4) (GFC_REAL_8 a, GFC_INTEGER_4 b)
{
GFC_REAL_8 pow, x;
GFC_INTEGER_4 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
GFC_REAL_8
prefix(pow_r8_i8) (GFC_REAL_8 a, GFC_INTEGER_8 b)
{
GFC_REAL_8 pow, x;
GFC_INTEGER_8 n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
n = -n;
x = pow / x;
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
`/* Support routines for the intrinsic power (**) operator.
Copyright 2004 Free Software Foundation, Inc.
Contributed by Paul Brook
This file is part of the GNU Fortran 95 runtime library (libgfor).
Libgfor is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
Ligbfor 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with libgfor; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "libgfortran.h"'
include(iparm.m4)dnl
/* Uuse Binary Method to calculate the powi. This is not an optimal but
a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
of Computer Programming", 3rd Edition, 1998. */
rtype_name
`prefix(pow_'rtype_code`_'atype_code) (rtype_name a, atype_name b)
{
rtype_name pow, x;
atype_name n, u;
n = b;
x = a;
pow = 1;
if (n != 0)
{
if (n < 0)
{
ifelse(rtype_letter,i,`dnl
if (x == 1)
return 1;
if (x == -1)
return (n & 1) ? -1 : 1;
return (x == 0) ? 1 / x : 0;
',`
n = -n;
x = pow / x;
')dnl
}
u = n;
for (;;)
{
if (u & 1)
pow *= x;
u >>= 1;
if (u)
x *= x;
else
break;
}
}
return pow;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment