scfx_pow10.cc revision 12854
112854Sgabeblack@google.com/***************************************************************************** 212854Sgabeblack@google.com 312854Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412854Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512854Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612854Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712854Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812854Sgabeblack@google.com License. You may obtain a copy of the License at 912854Sgabeblack@google.com 1012854Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112854Sgabeblack@google.com 1212854Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312854Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412854Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512854Sgabeblack@google.com implied. See the License for the specific language governing 1612854Sgabeblack@google.com permissions and limitations under the License. 1712854Sgabeblack@google.com 1812854Sgabeblack@google.com *****************************************************************************/ 1912854Sgabeblack@google.com 2012854Sgabeblack@google.com/***************************************************************************** 2112854Sgabeblack@google.com 2212854Sgabeblack@google.com scfx_pow10.cpp - 2312854Sgabeblack@google.com 2412854Sgabeblack@google.com Original Author: Robert Graulich, Synopsys, Inc. 2512854Sgabeblack@google.com Martin Janssen, Synopsys, Inc. 2612854Sgabeblack@google.com 2712854Sgabeblack@google.com *****************************************************************************/ 2812854Sgabeblack@google.com 2912854Sgabeblack@google.com/***************************************************************************** 3012854Sgabeblack@google.com 3112854Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3212854Sgabeblack@google.com changes you are making here. 3312854Sgabeblack@google.com 3412854Sgabeblack@google.com Name, Affiliation, Date: 3512854Sgabeblack@google.com Description of Modification: 3612854Sgabeblack@google.com 3712854Sgabeblack@google.com *****************************************************************************/ 3812854Sgabeblack@google.com 3912854Sgabeblack@google.com 4012854Sgabeblack@google.com// $Log: scfx_pow10.cpp,v $ 4112854Sgabeblack@google.com// Revision 1.1.1.1 2006/12/15 20:20:04 acg 4212854Sgabeblack@google.com// SystemC 2.3 4312854Sgabeblack@google.com// 4412854Sgabeblack@google.com// Revision 1.3 2006/01/13 18:53:58 acg 4512854Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in 4612854Sgabeblack@google.com// the source. 4712854Sgabeblack@google.com// 4812854Sgabeblack@google.com 4912854Sgabeblack@google.com#include "systemc/ext/dt/fx/scfx_pow10.hh" 5012854Sgabeblack@google.com 5112854Sgabeblack@google.comnamespace sc_dt 5212854Sgabeblack@google.com{ 5312854Sgabeblack@google.com 5412854Sgabeblack@google.com// ---------------------------------------------------------------------------- 5512854Sgabeblack@google.com// CLASS : scfx_pow10 5612854Sgabeblack@google.com// 5712854Sgabeblack@google.com// Class to compute (and cache) powers of 10 in arbitrary precision. 5812854Sgabeblack@google.com// ---------------------------------------------------------------------------- 5912854Sgabeblack@google.com 6012854Sgabeblack@google.comscfx_pow10::scfx_pow10() 6112854Sgabeblack@google.com{ 6212854Sgabeblack@google.com m_pos[0] = scfx_rep(10.0); 6312854Sgabeblack@google.com m_neg[0] = scfx_rep(0.1); 6412854Sgabeblack@google.com 6512854Sgabeblack@google.com for (int i = 1; i < SCFX_POW10_TABLE_SIZE; i++) { 6612854Sgabeblack@google.com m_pos[i].set_nan(); 6712854Sgabeblack@google.com m_neg[i].set_nan(); 6812854Sgabeblack@google.com } 6912854Sgabeblack@google.com} 7012854Sgabeblack@google.com 7112854Sgabeblack@google.comscfx_pow10::~scfx_pow10() {} 7212854Sgabeblack@google.com 7312854Sgabeblack@google.comconst scfx_rep 7412854Sgabeblack@google.comscfx_pow10::operator() (int i) 7512854Sgabeblack@google.com{ 7612854Sgabeblack@google.com if (i == 0) { 7712854Sgabeblack@google.com return scfx_rep(1.0); 7812854Sgabeblack@google.com } 7912854Sgabeblack@google.com 8012854Sgabeblack@google.com if (i > 0) { 8112854Sgabeblack@google.com int bit = scfx_find_msb(i); 8212854Sgabeblack@google.com scfx_rep result = *pos(bit); 8312854Sgabeblack@google.com if (bit) { 8412854Sgabeblack@google.com while (--bit >= 0) { 8512854Sgabeblack@google.com if ((1 << bit) & i) { 8612854Sgabeblack@google.com scfx_rep *tmp = mult_scfx_rep(result, *pos(bit)); 8712854Sgabeblack@google.com result = *tmp; 8812854Sgabeblack@google.com delete tmp; 8912854Sgabeblack@google.com } 9012854Sgabeblack@google.com } 9112854Sgabeblack@google.com } 9212854Sgabeblack@google.com return result; 9312854Sgabeblack@google.com } else { 9412854Sgabeblack@google.com i = -i; 9512854Sgabeblack@google.com int bit = scfx_find_msb(i); 9612854Sgabeblack@google.com scfx_rep result = *neg(bit); 9712854Sgabeblack@google.com if (bit) { 9812854Sgabeblack@google.com while (--bit >= 0) { 9912854Sgabeblack@google.com if ((1 << bit) & i) { 10012854Sgabeblack@google.com scfx_rep *tmp = mult_scfx_rep(result, *neg(bit)); 10112854Sgabeblack@google.com result = *tmp; 10212854Sgabeblack@google.com delete tmp; 10312854Sgabeblack@google.com } 10412854Sgabeblack@google.com } 10512854Sgabeblack@google.com } 10612854Sgabeblack@google.com return result; 10712854Sgabeblack@google.com } 10812854Sgabeblack@google.com} 10912854Sgabeblack@google.com 11012854Sgabeblack@google.com 11112854Sgabeblack@google.comscfx_rep * 11212854Sgabeblack@google.comscfx_pow10::pos(int i) 11312854Sgabeblack@google.com{ 11412854Sgabeblack@google.com if (!m_pos[i].is_normal()) { 11512854Sgabeblack@google.com multiply(m_pos[i], *pos(i - 1), *pos(i - 1)); 11612854Sgabeblack@google.com } 11712854Sgabeblack@google.com return &m_pos[i]; 11812854Sgabeblack@google.com} 11912854Sgabeblack@google.com 12012854Sgabeblack@google.comscfx_rep * 12112854Sgabeblack@google.comscfx_pow10::neg(int i) 12212854Sgabeblack@google.com{ 12312854Sgabeblack@google.com if (!m_neg[i].is_normal()) { 12412854Sgabeblack@google.com multiply(m_neg[i], *neg(i - 1), *neg(i - 1)); 12512854Sgabeblack@google.com } 12612854Sgabeblack@google.com return &m_neg[i]; 12712854Sgabeblack@google.com} 12812854Sgabeblack@google.com 12912854Sgabeblack@google.com} // namespace sc_dt 130