gem5  v22.1.0.0
scfx_pow10.cc
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  scfx_pow10.cpp -
23 
24  Original Author: Robert Graulich, Synopsys, Inc.
25  Martin Janssen, Synopsys, Inc.
26 
27  *****************************************************************************/
28 
29 /*****************************************************************************
30 
31  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
32  changes you are making here.
33 
34  Name, Affiliation, Date:
35  Description of Modification:
36 
37  *****************************************************************************/
38 
39 
40 // $Log: scfx_pow10.cpp,v $
41 // Revision 1.1.1.1 2006/12/15 20:20:04 acg
42 // SystemC 2.3
43 //
44 // Revision 1.3 2006/01/13 18:53:58 acg
45 // Andy Goodrich: added $Log command so that CVS comments are reproduced in
46 // the source.
47 //
48 
50 
51 namespace sc_dt
52 {
53 
54 // ----------------------------------------------------------------------------
55 // CLASS : scfx_pow10
56 //
57 // Class to compute (and cache) powers of 10 in arbitrary precision.
58 // ----------------------------------------------------------------------------
59 
61 {
62  m_pos[0] = scfx_rep(10.0);
63  m_neg[0] = scfx_rep(0.1);
64 
65  for (int i = 1; i < SCFX_POW10_TABLE_SIZE; i++) {
66  m_pos[i].set_nan();
67  m_neg[i].set_nan();
68  }
69 }
70 
72 
73 const scfx_rep
75 {
76  if (i == 0) {
77  return scfx_rep(1.0);
78  }
79 
80  if (i > 0) {
81  int bit = scfx_find_msb(i);
82  scfx_rep result = *pos(bit);
83  if (bit) {
84  while (--bit >= 0) {
85  if ((1 << bit) & i) {
86  scfx_rep *tmp = mult_scfx_rep(result, *pos(bit));
87  result = *tmp;
88  delete tmp;
89  }
90  }
91  }
92  return result;
93  } else {
94  i = -i;
95  int bit = scfx_find_msb(i);
96  scfx_rep result = *neg(bit);
97  if (bit) {
98  while (--bit >= 0) {
99  if ((1 << bit) & i) {
100  scfx_rep *tmp = mult_scfx_rep(result, *neg(bit));
101  result = *tmp;
102  delete tmp;
103  }
104  }
105  }
106  return result;
107  }
108 }
109 
110 
111 scfx_rep *
113 {
114  if (!m_pos[i].is_normal()) {
115  multiply(m_pos[i], *pos(i - 1), *pos(i - 1));
116  }
117  return &m_pos[i];
118 }
119 
120 scfx_rep *
122 {
123  if (!m_neg[i].is_normal()) {
124  multiply(m_neg[i], *neg(i - 1), *neg(i - 1));
125  }
126  return &m_neg[i];
127 }
128 
129 } // namespace sc_dt
scfx_rep m_neg[SCFX_POW10_TABLE_SIZE]
Definition: scfx_pow10.hh:81
scfx_rep m_pos[SCFX_POW10_TABLE_SIZE]
Definition: scfx_pow10.hh:80
scfx_rep * pos(int)
Definition: scfx_pow10.cc:112
const scfx_rep operator()(int)
Definition: scfx_pow10.cc:74
scfx_rep * neg(int)
Definition: scfx_pow10.cc:121
void set_nan()
Definition: scfx_rep.hh:298
Bitfield< 7 > i
Definition: misc_types.hh:67
Definition: sc_bit.cc:68
scfx_rep * mult_scfx_rep(const scfx_rep &, const scfx_rep &, int max_wl=SC_DEFAULT_MAX_WL_)
Definition: scfx_rep.hh:347
int scfx_find_msb(unsigned long x)
Definition: scfx_utils.hh:67
const int SCFX_POW10_TABLE_SIZE
Definition: scfx_pow10.hh:66
void multiply(scfx_rep &result, const scfx_rep &lhs, const scfx_rep &rhs, int max_wl)
Definition: scfx_rep.cc:1420

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1