OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgfortran/] [m4/] [pow.m4] - Blame information for rev 830

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 733 jeremybenn
`/* Support routines for the intrinsic power (**) operator.
2
   Copyright 2004, 2007, 2009 Free Software Foundation, Inc.
3
   Contributed by Paul Brook
4
 
5
This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
 
7
Libgfortran is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public
9
License as published by the Free Software Foundation; either
10
version 3 of the License, or (at your option) any later version.
11
 
12
Libgfortran is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
Under Section 7 of GPL version 3, you are granted additional
18
permissions described in the GCC Runtime Library Exception, version
19
3.1, as published by the Free Software Foundation.
20
 
21
You should have received a copy of the GNU General Public License and
22
a copy of the GCC Runtime Library Exception along with this program;
23
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
<http://www.gnu.org/licenses/>.  */
25
 
26
#include "libgfortran.h"'
27
 
28
include(iparm.m4)dnl
29
 
30
/* Use Binary Method to calculate the powi. This is not an optimal but
31
   a simple and reasonable arithmetic. See section 4.6.3, "Evaluation of
32
   Powers" of Donald E. Knuth, "Seminumerical Algorithms", Vol. 2, "The Art
33
   of Computer Programming", 3rd Edition, 1998.  */
34
 
35
`#if defined (HAVE_'rtype_name`) && defined (HAVE_'atype_name`)'
36
 
37
rtype_name `pow_'rtype_code`_'atype_code` ('rtype_name` a, 'atype_name` b);
38
export_proto(pow_'rtype_code`_'atype_code`);
39
 
40
'rtype_name`
41
pow_'rtype_code`_'atype_code` ('rtype_name` a, 'atype_name` b)
42
{
43
  'rtype_name` pow, x;
44
  'atype_name` n;
45
  GFC_UINTEGER_'atype_kind` u;
46
 
47
  n = b;
48
  x = a;
49
  pow = 1;
50
  if (n != 0)
51
    {
52
      if (n < 0)
53
        {
54
'ifelse(rtype_letter,i,`dnl
55
          if (x == 1)
56
            return 1;
57
          if (x == -1)
58
            return (n & 1) ? -1 : 1;
59
          return (x == 0) ? 1 / x : 0;
60
',`
61
          u = -n;
62
          x = pow / x;
63
')dnl
64
`       }
65
      else
66
        {
67
           u = n;
68
        }
69
      for (;;)
70
        {
71
          if (u & 1)
72
            pow *= x;
73
          u >>= 1;
74
          if (u)
75
            x *= x;
76
          else
77
            break;
78
        }
79
    }
80
  return pow;
81
}
82
 
83
#endif'

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.