gem5
v20.1.0.0
systemc
dt
fx
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
49
#include "
systemc/ext/dt/fx/scfx_pow10.hh
"
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
60
scfx_pow10::scfx_pow10
()
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
71
scfx_pow10::~scfx_pow10
() {}
72
73
const
scfx_rep
74
scfx_pow10::operator()
(
int
i
)
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 *
112
scfx_pow10::pos
(
int
i
)
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 *
121
scfx_pow10::neg
(
int
i
)
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
sc_dt::scfx_rep
Definition:
scfx_rep.hh:169
sc_dt
Definition:
sc_bit.cc:67
ArmISA::i
Bitfield< 7 > i
Definition:
miscregs_types.hh:63
sc_dt::scfx_pow10::~scfx_pow10
~scfx_pow10()
Definition:
scfx_pow10.cc:103
sc_dt::scfx_rep::set_nan
void set_nan()
Definition:
scfx_rep.hh:330
sc_dt::SCFX_POW10_TABLE_SIZE
const int SCFX_POW10_TABLE_SIZE
Definition:
scfx_pow10.hh:98
sc_dt::scfx_pow10::operator()
const scfx_rep operator()(int)
Definition:
scfx_pow10.cc:106
sc_dt::scfx_pow10::m_neg
scfx_rep m_neg[SCFX_POW10_TABLE_SIZE]
Definition:
scfx_pow10.hh:113
sc_dt::scfx_pow10::pos
scfx_rep * pos(int)
Definition:
scfx_pow10.cc:144
sc_dt::scfx_find_msb
int scfx_find_msb(unsigned long x)
Definition:
scfx_utils.hh:98
sc_dt::mult_scfx_rep
scfx_rep * mult_scfx_rep(const scfx_rep &, const scfx_rep &, int max_wl=SC_DEFAULT_MAX_WL_)
Definition:
scfx_rep.hh:379
sc_dt::multiply
void multiply(scfx_rep &result, const scfx_rep &lhs, const scfx_rep &rhs, int max_wl)
Definition:
scfx_rep.cc:1452
sc_dt::scfx_pow10::scfx_pow10
scfx_pow10()
Definition:
scfx_pow10.cc:92
scfx_pow10.hh
sc_dt::scfx_pow10::neg
scfx_rep * neg(int)
Definition:
scfx_pow10.cc:153
sc_dt::scfx_pow10::m_pos
scfx_rep m_pos[SCFX_POW10_TABLE_SIZE]
Definition:
scfx_pow10.hh:112
Generated on Wed Sep 30 2020 14:02:14 for gem5 by
doxygen
1.8.17