range_fx.cpp revision 12855:588919e0e4aa
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 range_fx.cpp -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38// This may look like C code, but it is really -*- C++ -*- 39// 40// range_fx.cxx -- 41// Copyright Synopsys 1998 42// Author : Ric Hilderink 43// Created On : Mon Jan 11 13:03:27 1999 44// Status : none 45// 46 47 48#include <limits.h> 49#define SC_INCLUDE_FX 50#define SC_FXVAL_IMPLICIT_FXVAL 51#include "systemc.h" 52 53#define T_FX_FLOAT sc_fxval 54#define T_FX_UFIX sc_ufix 55#define T_FX_FIX sc_fix 56#define T_FX_FIXED sc_fixed<222,111> 57#define T_FX_UFIXED sc_ufixed<222,111> 58 59#define RANGE_TO_MIN(FX_TTT) \ 60{ \ 61 FX_TTT x(1); \ 62 FX_TTT d(1); \ 63 \ 64 int i; \ 65 for (i = 0; i < 300; ++i) \ 66 { \ 67 d = d / 2; \ 68 x += d; \ 69 out << i << " " << d.to_double() << " " << x.to_double() << " " << x.to_string(SC_BIN, SC_E) << "\n"; \ 70 } \ 71} 72 73 74#define RANGE_MIN_MAX(FX_TTT) \ 75{ \ 76 FX_TTT x(1); \ 77 FX_TTT d(4); \ 78 FX_TTT e(0.125); \ 79 int i; \ 80 for (i = 0; i < 300; ++i) \ 81 { \ 82 d = d * 2; \ 83 e = e / 2; \ 84 x += d + e; \ 85 out << i << " " << d.to_double() << " " << x.to_double() << " " << x.to_string(SC_BIN, SC_E) << "\n"; \ 86 } \ 87 for (i = 0; i < 300; ++i) \ 88 { \ 89 x -= (d + e); \ 90 out << i << " " << d.to_double() << " " << x.to_double() << " " << x.to_string(SC_BIN, SC_E) << "\n"; \ 91 d = d / 2; \ 92 e = e * 2; \ 93 } \ 94} 95 96#define RANGE_TO_MAX(FX_TTT) \ 97{ \ 98 FX_TTT x(1); \ 99 FX_TTT d(1); \ 100 int i; \ 101 for (i = 0; i < 300; ++i) \ 102 { \ 103 d = d * 2; \ 104 x += d; \ 105 out << i << " " << d.to_double() << " " << x.to_double() << " " << x.to_string(SC_BIN, SC_E) << "\n"; \ 106 } \ 107 for (i = 0; i < 300; ++i) \ 108 { \ 109 x -= d; \ 110 out << i << " " << d.to_double() << " " << x.to_double() << " " << x.to_string(SC_BIN, SC_E) << "\n"; \ 111 d = d / 2; \ 112 } \ 113} 114 115 116static void range_to_min(ostream& out) 117{ 118 RANGE_TO_MIN(T_FX_FLOAT); 119 RANGE_TO_MIN(T_FX_UFIX); 120 RANGE_TO_MIN(T_FX_FIX); 121 RANGE_TO_MIN(T_FX_FIXED); 122 RANGE_TO_MIN(T_FX_UFIXED); 123} 124 125static void range_to_max(ostream& out) 126{ 127 RANGE_TO_MAX(T_FX_FLOAT); 128 RANGE_TO_MAX(T_FX_UFIX); 129 RANGE_TO_MAX(T_FX_FIX); 130 RANGE_TO_MAX(T_FX_FIXED); 131 RANGE_TO_MAX(T_FX_UFIXED); 132} 133 134static void range_min_max(ostream& out) 135{ 136 RANGE_MIN_MAX(T_FX_FLOAT); 137 RANGE_MIN_MAX(T_FX_UFIX); 138 RANGE_MIN_MAX(T_FX_FIX); 139 RANGE_MIN_MAX(T_FX_FIXED); 140 RANGE_MIN_MAX(T_FX_UFIXED); 141} 142 143 144void range_fx(ostream& out) 145{ 146 sc_fxtype_params fooCast(222, 111, SC_RND, SC_SAT); 147 out << "************** range_FX_TTT\n"; 148 range_to_min(out); 149 range_to_max(out); 150 range_min_max(out); 151} 152 153