112853Sgabeblack@google.com/*****************************************************************************
212853Sgabeblack@google.com
312853Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412853Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512853Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612853Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712853Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812853Sgabeblack@google.com  License.  You may obtain a copy of the License at
912853Sgabeblack@google.com
1012853Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112853Sgabeblack@google.com
1212853Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312853Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412853Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512853Sgabeblack@google.com  implied.  See the License for the specific language governing
1612853Sgabeblack@google.com  permissions and limitations under the License.
1712853Sgabeblack@google.com
1812853Sgabeblack@google.com *****************************************************************************/
1912853Sgabeblack@google.com
2012853Sgabeblack@google.com/*****************************************************************************
2112853Sgabeblack@google.com
2212853Sgabeblack@google.com  scfx_utils.h -
2312853Sgabeblack@google.com
2412853Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc.
2512853Sgabeblack@google.com
2612853Sgabeblack@google.com *****************************************************************************/
2712853Sgabeblack@google.com
2812853Sgabeblack@google.com/*****************************************************************************
2912853Sgabeblack@google.com
3012853Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112853Sgabeblack@google.com  changes you are making here.
3212853Sgabeblack@google.com
3312853Sgabeblack@google.com      Name, Affiliation, Date:
3412853Sgabeblack@google.com  Description of Modification:
3512853Sgabeblack@google.com
3612853Sgabeblack@google.com *****************************************************************************/
3712853Sgabeblack@google.com
3812853Sgabeblack@google.com// $Log: scfx_utils.h,v $
3912853Sgabeblack@google.com// Revision 1.2  2009/02/28 00:26:20  acg
4012853Sgabeblack@google.com//  Andy Goodrich: bug fixes.
4112853Sgabeblack@google.com//
4212853Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:31:36  acg
4312853Sgabeblack@google.com// SystemC 2.2
4412853Sgabeblack@google.com//
4512853Sgabeblack@google.com// Revision 1.3  2006/01/13 18:53:58  acg
4612853Sgabeblack@google.com// Andy Goodrich: added $Log command so that CVS comments are reproduced in
4712853Sgabeblack@google.com// the source.
4812853Sgabeblack@google.com//
4912853Sgabeblack@google.com
5012853Sgabeblack@google.com#ifndef __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__
5112853Sgabeblack@google.com#define __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__
5212853Sgabeblack@google.com
5312853Sgabeblack@google.com#include "sc_fxdefs.hh"
5412853Sgabeblack@google.com#include "scfx_params.hh"
5512853Sgabeblack@google.com#include "scfx_string.hh"
5612853Sgabeblack@google.com
5712853Sgabeblack@google.comnamespace sc_dt
5812853Sgabeblack@google.com{
5912853Sgabeblack@google.com
6012853Sgabeblack@google.com// ----------------------------------------------------------------------------
6112853Sgabeblack@google.com//  Find the most and least significant non-zero bits in a unsigned long
6212853Sgabeblack@google.com// ----------------------------------------------------------------------------
6312853Sgabeblack@google.com
6412853Sgabeblack@google.com#define MSB_STATEMENT(n) if (x >> n) { x >>= n; i += n; }
6512853Sgabeblack@google.com
6612853Sgabeblack@google.cominline int
6712853Sgabeblack@google.comscfx_find_msb(unsigned long x)
6812853Sgabeblack@google.com{
6912853Sgabeblack@google.com    int i = 0;
7013197Sgabeblack@google.com#   if SC_LONG_64
7112853Sgabeblack@google.com        MSB_STATEMENT(32);
7213197Sgabeblack@google.com#   endif // SC_LONG_64
7312853Sgabeblack@google.com    MSB_STATEMENT(16);
7412853Sgabeblack@google.com    MSB_STATEMENT(8);
7512853Sgabeblack@google.com    MSB_STATEMENT(4);
7612853Sgabeblack@google.com    MSB_STATEMENT(2);
7712853Sgabeblack@google.com    MSB_STATEMENT(1);
7812853Sgabeblack@google.com    return i;
7912853Sgabeblack@google.com}
8012853Sgabeblack@google.com
8112853Sgabeblack@google.com#undef MSB_STATEMENT
8212853Sgabeblack@google.com
8312853Sgabeblack@google.com#define LSB_STATEMENT(n) if (x << n) { x <<= n; i -= n; }
8412853Sgabeblack@google.com
8512853Sgabeblack@google.cominline int
8612853Sgabeblack@google.comscfx_find_lsb(unsigned long x)
8712853Sgabeblack@google.com{
8812853Sgabeblack@google.com    int i;
8913197Sgabeblack@google.com#   if SC_LONG_64
9012853Sgabeblack@google.com        i = 63;
9112853Sgabeblack@google.com        LSB_STATEMENT(32);
9212853Sgabeblack@google.com#   else
9312853Sgabeblack@google.com        i = 31;
9413197Sgabeblack@google.com#   endif // SC_LONG_64
9512853Sgabeblack@google.com    LSB_STATEMENT(16);
9612853Sgabeblack@google.com    LSB_STATEMENT(8);
9712853Sgabeblack@google.com    LSB_STATEMENT(4);
9812853Sgabeblack@google.com    LSB_STATEMENT(2);
9912853Sgabeblack@google.com    LSB_STATEMENT(1);
10012853Sgabeblack@google.com    return i;
10112853Sgabeblack@google.com}
10212853Sgabeblack@google.com
10312853Sgabeblack@google.com#undef LSB_STATEMENT
10412853Sgabeblack@google.com
10512853Sgabeblack@google.com
10612853Sgabeblack@google.com// ----------------------------------------------------------------------------
10712853Sgabeblack@google.com//  Utilities for parsing a character string number
10812853Sgabeblack@google.com// ----------------------------------------------------------------------------
10912853Sgabeblack@google.com
11012853Sgabeblack@google.cominline int
11112853Sgabeblack@google.comscfx_parse_sign(const char *&s, bool &sign_char)
11212853Sgabeblack@google.com{
11312853Sgabeblack@google.com    int sign = 1;
11412853Sgabeblack@google.com
11512853Sgabeblack@google.com    if (*s == '+') {
11612853Sgabeblack@google.com        ++s;
11712853Sgabeblack@google.com        sign_char = true;
11812853Sgabeblack@google.com    } else if (*s == '-' ) {
11912853Sgabeblack@google.com        sign = -1;
12012853Sgabeblack@google.com        ++s;
12112853Sgabeblack@google.com        sign_char = true;
12212853Sgabeblack@google.com    } else {
12312853Sgabeblack@google.com        sign_char = false;
12412853Sgabeblack@google.com    }
12512853Sgabeblack@google.com
12612853Sgabeblack@google.com    return sign;
12712853Sgabeblack@google.com}
12812853Sgabeblack@google.com
12912853Sgabeblack@google.cominline sc_numrep
13012853Sgabeblack@google.comscfx_parse_prefix(const char *&s)
13112853Sgabeblack@google.com{
13212853Sgabeblack@google.com    if (s[0] == '0') {
13312853Sgabeblack@google.com        switch (s[1]) {
13412853Sgabeblack@google.com          case 'b':
13512853Sgabeblack@google.com          case 'B':
13612853Sgabeblack@google.com            {
13712853Sgabeblack@google.com                if ((s[2] == 'u' || s[2] == 'U') &&
13812853Sgabeblack@google.com                    (s[3] == 's' || s[3] == 'S')) {
13912853Sgabeblack@google.com                    s += 4;
14012853Sgabeblack@google.com                    return SC_BIN_US;
14112853Sgabeblack@google.com                }
14212853Sgabeblack@google.com                if ((s[2] == 's' || s[2] == 'S') &&
14312853Sgabeblack@google.com                    (s[3] == 'm' || s[3] == 'M')) {
14412853Sgabeblack@google.com                    s += 4;
14512853Sgabeblack@google.com                    return SC_BIN_SM;
14612853Sgabeblack@google.com                }
14712853Sgabeblack@google.com                s += 2;
14812853Sgabeblack@google.com                return SC_BIN;
14912853Sgabeblack@google.com            }
15012853Sgabeblack@google.com          case 'o':
15112853Sgabeblack@google.com          case 'O':
15212853Sgabeblack@google.com            {
15312853Sgabeblack@google.com                if ((s[2] == 'u' || s[2] == 'U') &&
15412853Sgabeblack@google.com                    (s[3] == 's' || s[3] == 'S')) {
15512853Sgabeblack@google.com                    s += 4;
15612853Sgabeblack@google.com                    return SC_OCT_US;
15712853Sgabeblack@google.com                }
15812853Sgabeblack@google.com                if ((s[2] == 's' || s[2] == 'S') &&
15912853Sgabeblack@google.com                    (s[3] == 'm' || s[3] == 'M')) {
16012853Sgabeblack@google.com                    s += 4;
16112853Sgabeblack@google.com                    return SC_OCT_SM;
16212853Sgabeblack@google.com                }
16312853Sgabeblack@google.com                s += 2;
16412853Sgabeblack@google.com                return SC_OCT;
16512853Sgabeblack@google.com            }
16612853Sgabeblack@google.com          case 'x':
16712853Sgabeblack@google.com          case 'X':
16812853Sgabeblack@google.com            {
16912853Sgabeblack@google.com                if ((s[2] == 'u' || s[2] == 'U') &&
17012853Sgabeblack@google.com                    (s[3] == 's' || s[3] == 'S')) {
17112853Sgabeblack@google.com                    s += 4;
17212853Sgabeblack@google.com                    return SC_HEX_US;
17312853Sgabeblack@google.com                }
17412853Sgabeblack@google.com                if ((s[2] == 's' || s[2] == 'S') &&
17512853Sgabeblack@google.com                    (s[3] == 'm' || s[3] == 'M')) {
17612853Sgabeblack@google.com                    s += 4;
17712853Sgabeblack@google.com                    return SC_HEX_SM;
17812853Sgabeblack@google.com                }
17912853Sgabeblack@google.com                s += 2;
18012853Sgabeblack@google.com                return SC_HEX;
18112853Sgabeblack@google.com            }
18212853Sgabeblack@google.com          case 'd':
18312853Sgabeblack@google.com          case 'D':
18412853Sgabeblack@google.com            {
18512853Sgabeblack@google.com                s += 2;
18612853Sgabeblack@google.com                return SC_DEC;
18712853Sgabeblack@google.com            }
18812853Sgabeblack@google.com          case 'c':
18912853Sgabeblack@google.com          case 'C':
19012853Sgabeblack@google.com            {
19112853Sgabeblack@google.com                if ((s[2] == 's' || s[2] == 'S') &&
19212853Sgabeblack@google.com                    (s[3] == 'd' || s[3] == 'D')) {
19312853Sgabeblack@google.com                    s += 4;
19412853Sgabeblack@google.com                    return SC_CSD;
19512853Sgabeblack@google.com                }
19612853Sgabeblack@google.com                break;
19712853Sgabeblack@google.com            }
19812853Sgabeblack@google.com          default:
19912853Sgabeblack@google.com            break;
20012853Sgabeblack@google.com        }
20112853Sgabeblack@google.com    }
20212853Sgabeblack@google.com
20312853Sgabeblack@google.com    return SC_DEC;
20412853Sgabeblack@google.com}
20512853Sgabeblack@google.com
20612853Sgabeblack@google.cominline int
20712853Sgabeblack@google.comscfx_parse_base(const char *&s)
20812853Sgabeblack@google.com{
20912853Sgabeblack@google.com    const char *s1 = s + 1;
21012853Sgabeblack@google.com
21112853Sgabeblack@google.com    int base = 10;
21212853Sgabeblack@google.com
21312853Sgabeblack@google.com    if (*s == '0') {
21412853Sgabeblack@google.com        switch (*s1) {
21512853Sgabeblack@google.com          case 'b':
21612853Sgabeblack@google.com          case 'B': base =  2; s += 2; break;
21712853Sgabeblack@google.com          case 'o':
21812853Sgabeblack@google.com          case 'O': base =  8; s += 2; break;
21912853Sgabeblack@google.com          case 'd':
22012853Sgabeblack@google.com          case 'D': base = 10; s += 2; break;
22112853Sgabeblack@google.com          case 'x':
22212853Sgabeblack@google.com          case 'X': base = 16; s += 2; break;
22312853Sgabeblack@google.com        }
22412853Sgabeblack@google.com    }
22512853Sgabeblack@google.com
22612853Sgabeblack@google.com    return base;
22712853Sgabeblack@google.com}
22812853Sgabeblack@google.com
22912853Sgabeblack@google.cominline bool
23012853Sgabeblack@google.comscfx_is_equal(const char *a, const char *b)
23112853Sgabeblack@google.com{
23212853Sgabeblack@google.com    while (*a != 0 && *b != 0 && *a == *b) {
23312853Sgabeblack@google.com        ++ a;
23412853Sgabeblack@google.com        ++ b;
23512853Sgabeblack@google.com    }
23612853Sgabeblack@google.com    return (*a == 0 && *b == 0);
23712853Sgabeblack@google.com}
23812853Sgabeblack@google.com
23912853Sgabeblack@google.cominline bool
24012853Sgabeblack@google.comscfx_is_nan(const char *s)
24112853Sgabeblack@google.com{
24212853Sgabeblack@google.com    return scfx_is_equal(s, "NaN");
24312853Sgabeblack@google.com}
24412853Sgabeblack@google.com
24512853Sgabeblack@google.cominline bool
24612853Sgabeblack@google.comscfx_is_inf(const char *s)
24712853Sgabeblack@google.com{
24812853Sgabeblack@google.com    return (scfx_is_equal(s, "Inf") || scfx_is_equal(s, "Infinity"));
24912853Sgabeblack@google.com}
25012853Sgabeblack@google.com
25112853Sgabeblack@google.cominline bool
25212853Sgabeblack@google.comscfx_exp_start(const char *s)
25312853Sgabeblack@google.com{
25412853Sgabeblack@google.com    if (*s == 'e' || *s == 'E') {
25512853Sgabeblack@google.com        ++s;
25612853Sgabeblack@google.com        if (*s == '+' || *s == '-')
25712853Sgabeblack@google.com            return true;
25812853Sgabeblack@google.com    }
25912853Sgabeblack@google.com    return false;
26012853Sgabeblack@google.com}
26112853Sgabeblack@google.com
26212853Sgabeblack@google.cominline bool
26312853Sgabeblack@google.comscfx_is_digit(char c, sc_numrep numrep)
26412853Sgabeblack@google.com{
26512853Sgabeblack@google.com    bool is_digit;
26612853Sgabeblack@google.com
26712853Sgabeblack@google.com    switch(numrep) {
26812853Sgabeblack@google.com      case SC_DEC:
26912853Sgabeblack@google.com        {
27012853Sgabeblack@google.com            switch(c) {
27112853Sgabeblack@google.com              case '0': case '1': case '2': case '3': case '4':
27212853Sgabeblack@google.com              case '5': case '6': case '7': case '8': case '9':
27312853Sgabeblack@google.com                {
27412853Sgabeblack@google.com                    is_digit = true;
27512853Sgabeblack@google.com                    break;
27612853Sgabeblack@google.com                }
27712853Sgabeblack@google.com              default:
27812853Sgabeblack@google.com                    is_digit = false;
27912853Sgabeblack@google.com            }
28012853Sgabeblack@google.com            break;
28112853Sgabeblack@google.com        }
28212853Sgabeblack@google.com      case SC_BIN:
28312853Sgabeblack@google.com      case SC_BIN_US:
28412853Sgabeblack@google.com      case SC_BIN_SM:
28512853Sgabeblack@google.com        {
28612853Sgabeblack@google.com            switch(c) {
28712853Sgabeblack@google.com              case '0': case '1':
28812853Sgabeblack@google.com                {
28912853Sgabeblack@google.com                    is_digit = true;
29012853Sgabeblack@google.com                    break;
29112853Sgabeblack@google.com                }
29212853Sgabeblack@google.com              default:
29312853Sgabeblack@google.com                is_digit = false;
29412853Sgabeblack@google.com            }
29512853Sgabeblack@google.com            break;
29612853Sgabeblack@google.com        }
29712853Sgabeblack@google.com      case SC_OCT:
29812853Sgabeblack@google.com      case SC_OCT_US:
29912853Sgabeblack@google.com      case SC_OCT_SM:
30012853Sgabeblack@google.com        {
30112853Sgabeblack@google.com            switch(c) {
30212853Sgabeblack@google.com              case '0': case '1': case '2': case '3':
30312853Sgabeblack@google.com              case '4': case '5': case '6': case '7':
30412853Sgabeblack@google.com                {
30512853Sgabeblack@google.com                    is_digit = true;
30612853Sgabeblack@google.com                    break;
30712853Sgabeblack@google.com                }
30812853Sgabeblack@google.com              default:
30912853Sgabeblack@google.com                is_digit = false;
31012853Sgabeblack@google.com            }
31112853Sgabeblack@google.com            break;
31212853Sgabeblack@google.com        }
31312853Sgabeblack@google.com      case SC_HEX:
31412853Sgabeblack@google.com      case SC_HEX_US:
31512853Sgabeblack@google.com      case SC_HEX_SM:
31612853Sgabeblack@google.com        {
31712853Sgabeblack@google.com            switch (c) {
31812853Sgabeblack@google.com              case '0': case '1': case '2': case '3': case '4':
31912853Sgabeblack@google.com              case '5': case '6': case '7': case '8': case '9':
32012853Sgabeblack@google.com              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
32112853Sgabeblack@google.com              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
32212853Sgabeblack@google.com                {
32312853Sgabeblack@google.com                    is_digit = true;
32412853Sgabeblack@google.com                    break;
32512853Sgabeblack@google.com                }
32612853Sgabeblack@google.com              default:
32712853Sgabeblack@google.com                is_digit = false;
32812853Sgabeblack@google.com            }
32912853Sgabeblack@google.com            break;
33012853Sgabeblack@google.com        }
33112853Sgabeblack@google.com      case SC_CSD:
33212853Sgabeblack@google.com        {
33312853Sgabeblack@google.com            switch (c) {
33412853Sgabeblack@google.com              case '0': case '1': case '-':
33512853Sgabeblack@google.com                {
33612853Sgabeblack@google.com                    is_digit = true;
33712853Sgabeblack@google.com                    break;
33812853Sgabeblack@google.com                }
33912853Sgabeblack@google.com              default:
34012853Sgabeblack@google.com                is_digit = false;
34112853Sgabeblack@google.com            }
34212853Sgabeblack@google.com            break;
34312853Sgabeblack@google.com        }
34412853Sgabeblack@google.com      default:
34512853Sgabeblack@google.com        is_digit = false;
34612853Sgabeblack@google.com    }
34712853Sgabeblack@google.com
34812853Sgabeblack@google.com    return is_digit;
34912853Sgabeblack@google.com}
35012853Sgabeblack@google.com
35112853Sgabeblack@google.cominline int
35212853Sgabeblack@google.comscfx_to_digit(char c, sc_numrep numrep)
35312853Sgabeblack@google.com{
35412853Sgabeblack@google.com    int to_digit;
35512853Sgabeblack@google.com
35612853Sgabeblack@google.com    switch (numrep) {
35712853Sgabeblack@google.com      case SC_DEC:
35812853Sgabeblack@google.com      case SC_BIN:
35912853Sgabeblack@google.com      case SC_BIN_US:
36012853Sgabeblack@google.com      case SC_BIN_SM:
36112853Sgabeblack@google.com      case SC_OCT:
36212853Sgabeblack@google.com      case SC_OCT_US:
36312853Sgabeblack@google.com      case SC_OCT_SM:
36412853Sgabeblack@google.com        {
36512853Sgabeblack@google.com            to_digit = c - '0';
36612853Sgabeblack@google.com            break;
36712853Sgabeblack@google.com        }
36812853Sgabeblack@google.com      case SC_HEX:
36912853Sgabeblack@google.com      case SC_HEX_US:
37012853Sgabeblack@google.com      case SC_HEX_SM:
37112853Sgabeblack@google.com        {
37212853Sgabeblack@google.com            switch (c) {
37312853Sgabeblack@google.com              case '0': case '1': case '2': case '3': case '4':
37412853Sgabeblack@google.com              case '5': case '6': case '7': case '8': case '9':
37512853Sgabeblack@google.com                to_digit = c - '0';
37612853Sgabeblack@google.com                break;
37712853Sgabeblack@google.com              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
37812853Sgabeblack@google.com                to_digit = c - 'a' + 10;
37912853Sgabeblack@google.com                break;
38012853Sgabeblack@google.com              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
38112853Sgabeblack@google.com                to_digit = c - 'A' + 10;
38212853Sgabeblack@google.com                break;
38312853Sgabeblack@google.com              default:
38412853Sgabeblack@google.com                to_digit = -2;
38512853Sgabeblack@google.com            }
38612853Sgabeblack@google.com            break;
38712853Sgabeblack@google.com        }
38812853Sgabeblack@google.com      case SC_CSD:
38912853Sgabeblack@google.com        {
39012853Sgabeblack@google.com            if (c == '-')
39112853Sgabeblack@google.com                to_digit = -1;
39212853Sgabeblack@google.com            else
39312853Sgabeblack@google.com                to_digit = c - '0';
39412853Sgabeblack@google.com            break;
39512853Sgabeblack@google.com        }
39612853Sgabeblack@google.com      default:
39712853Sgabeblack@google.com        to_digit = -2;
39812853Sgabeblack@google.com    }
39912853Sgabeblack@google.com
40012853Sgabeblack@google.com    return to_digit;
40112853Sgabeblack@google.com}
40212853Sgabeblack@google.com
40312853Sgabeblack@google.com
40412853Sgabeblack@google.com// ----------------------------------------------------------------------------
40512853Sgabeblack@google.com//  Utilities for printing a character string number
40612853Sgabeblack@google.com// ----------------------------------------------------------------------------
40712853Sgabeblack@google.com
40812853Sgabeblack@google.cominline void scfx_print_nan(scfx_string &s) { s += "NaN"; }
40912853Sgabeblack@google.cominline void
41012853Sgabeblack@google.comscfx_print_inf(scfx_string &s, bool negative)
41112853Sgabeblack@google.com{
41212853Sgabeblack@google.com    if (negative)
41312853Sgabeblack@google.com        s += "-Inf";
41412853Sgabeblack@google.com    else
41512853Sgabeblack@google.com        s += "Inf";
41612853Sgabeblack@google.com}
41712853Sgabeblack@google.com
41812853Sgabeblack@google.cominline void
41912853Sgabeblack@google.comscfx_print_prefix(scfx_string &s, sc_numrep numrep)
42012853Sgabeblack@google.com{
42112853Sgabeblack@google.com    switch (numrep) {
42212853Sgabeblack@google.com      case SC_DEC:
42312853Sgabeblack@google.com        s += "0d";
42412853Sgabeblack@google.com        break;
42512853Sgabeblack@google.com      case SC_BIN:
42612853Sgabeblack@google.com        s += "0b";
42712853Sgabeblack@google.com        break;
42812853Sgabeblack@google.com      case SC_BIN_US:
42912853Sgabeblack@google.com        s += "0bus";
43012853Sgabeblack@google.com        break;
43112853Sgabeblack@google.com      case SC_BIN_SM:
43212853Sgabeblack@google.com        s += "0bsm";
43312853Sgabeblack@google.com        break;
43412853Sgabeblack@google.com      case SC_OCT:
43512853Sgabeblack@google.com        s += "0o";
43612853Sgabeblack@google.com        break;
43712853Sgabeblack@google.com      case SC_OCT_US:
43812853Sgabeblack@google.com        s += "0ous";
43912853Sgabeblack@google.com        break;
44012853Sgabeblack@google.com      case SC_OCT_SM:
44112853Sgabeblack@google.com        s += "0osm";
44212853Sgabeblack@google.com        break;
44312853Sgabeblack@google.com      case SC_HEX:
44412853Sgabeblack@google.com        s += "0x";
44512853Sgabeblack@google.com        break;
44612853Sgabeblack@google.com      case SC_HEX_US:
44712853Sgabeblack@google.com        s += "0xus";
44812853Sgabeblack@google.com        break;
44912853Sgabeblack@google.com      case SC_HEX_SM:
45012853Sgabeblack@google.com        s += "0xsm";
45112853Sgabeblack@google.com        break;
45212853Sgabeblack@google.com      case SC_CSD:
45312853Sgabeblack@google.com        s += "0csd";
45412853Sgabeblack@google.com        break;
45512853Sgabeblack@google.com      default:
45612853Sgabeblack@google.com        s += "unknown";
45712853Sgabeblack@google.com    }
45812853Sgabeblack@google.com}
45912853Sgabeblack@google.com
46012853Sgabeblack@google.cominline void
46112853Sgabeblack@google.comscfx_print_exp(scfx_string &s, int exp)
46212853Sgabeblack@google.com{
46312853Sgabeblack@google.com    if (exp != 0) {
46412853Sgabeblack@google.com        s += 'e';
46512853Sgabeblack@google.com
46612853Sgabeblack@google.com        if (exp < 0) {
46712853Sgabeblack@google.com            exp = - exp;
46812853Sgabeblack@google.com            s += '-';
46912853Sgabeblack@google.com        } else {
47012853Sgabeblack@google.com            s += '+';
47112853Sgabeblack@google.com        }
47212853Sgabeblack@google.com
47312853Sgabeblack@google.com        bool first = true;
47412853Sgabeblack@google.com        int scale = 1000000000;
47512853Sgabeblack@google.com        do {
47612853Sgabeblack@google.com            int digit = exp / scale;
47712853Sgabeblack@google.com            exp = exp % scale;
47812853Sgabeblack@google.com            if (digit != 0 || !first) {
47912853Sgabeblack@google.com                s += static_cast<char>(digit + '0');
48012853Sgabeblack@google.com                first = false;
48112853Sgabeblack@google.com            }
48212853Sgabeblack@google.com            scale /= 10;
48312853Sgabeblack@google.com        }
48412853Sgabeblack@google.com        while (scale > 0);
48512853Sgabeblack@google.com    }
48612853Sgabeblack@google.com}
48712853Sgabeblack@google.com
48812853Sgabeblack@google.comvoid scfx_tc2csd(scfx_string &, int);
48912853Sgabeblack@google.comvoid scfx_csd2tc(scfx_string &);
49012853Sgabeblack@google.com
49112853Sgabeblack@google.com} // namespace sc_dt
49212853Sgabeblack@google.com
49312853Sgabeblack@google.com#endif // __SYSTEMC_EXT_DT_FX_SCFX_UTILS_HH__
494