# Hurricane VLSI Database

DbU.h
1 // -*- C++ -*-
2 //
3 // Copyright (c) BULL S.A. 2000-2018, All Rights Reserved
4 //
5 // This file is part of Hurricane.
6 //
7 // Hurricane is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
11 //
12 // Hurricane is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
14 // TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the Lesser GNU General Public
18 // License along with Hurricane. If not, see
19 // <http://www.gnu.org/licenses/>.
20 //
21 // +-----------------------------------------------------------------+
22 // | H U R R I C A N E |
23 // | V L S I B a c k e n d D a t a - B a s e |
24 // | |
25 // | Author : Remy Escassut |
26 // | E-mail : Jean-Paul.Chaput@lip6.fr |
27 // | =============================================================== |
28 // | C++ Header : "./hurricane/DbU.h" |
29 // +-----------------------------------------------------------------+
30
31
32 #ifndef HURRICANE_DBU_H
33 #define HURRICANE_DBU_H
34
35
36 #include <cstdint>
37 #include <cmath>
38 #include "hurricane/Commons.h"
39
40
41 namespace Hurricane {
42
43 class DataBase;
44
45
46 class DbU {
47 friend class DataBase;
48 public:
49 enum FunctionFlags { NoFlags = 0
50 , NoTechnoUpdate = (1<<0)
51 };
52 enum UnitPower { Pico = 1
53 , Nano
54 , Micro
55 , Milli
56 , Unity
57 , Kilo
58 };
59 enum StringMode { Db = (1<<0)
60 , Grid = (1<<1)
61 , Symbolic = (1<<2)
62 , Physical = (1<<3)
63 , SmartTruncate = (1<<4)
64 };
65 enum SnapMode { Inferior = 1
66 , Superior = 2
67 , Nearest = 4
68 };
69 public:
70 typedef std::int64_t Unit;
71
72 public:
73 static void checkGridBound ( double value );
74 static void checkLambdaBound ( double value );
75 static void checkPhysicalBound ( double value, UnitPower p );
76 // User to DB Converters.
77 static inline Unit fromDb ( Unit value );
78 static inline Unit fromGrid ( double value );
79 static inline Unit fromLambda ( double value );
80 static inline Unit fromPhysical ( double value, UnitPower p );
81 // Old naming scheme (was not very clear).
82 static inline Unit db ( Unit value );
83 static inline Unit grid ( double value );
84 static inline Unit lambda ( double value );
85 static inline Unit physicalToDbu ( double value, UnitPower p );
86 // Precision & Resolution Managment.
87 static unsigned int getPrecision ();
88 static unsigned int getMaximalPrecision ();
89 static double getResolution ();
90 static void setPrecision ( unsigned int precision, unsigned int flags=NoFlags );
91 // Foundry Grid Managment.
92 static double getUnitPower ( UnitPower p );
93 static void setPhysicalsPerGrid ( double gridsPerLambda, UnitPower p );
94 static double getPhysicalsPerGrid ();
95 static double physicalToGrid ( double physical, UnitPower p );
96 // Huge Polygon Step Managment.
97 static inline DbU::Unit getPolygonStep ();
98 static inline void setPolygonStep ( DbU::Unit );
99 // Lamba Managment.
100 static void setGridsPerLambda ( double gridsPerLambda, unsigned int flags=NoFlags );
101 static double getGridsPerLambda ();
102 // Snap Grid Managment.
103 static DbU::Unit getRealSnapGridStep ();
104 static DbU::Unit getOnRealSnapGrid ( DbU::Unit u, SnapMode mode=Nearest );
105 static inline void setRealSnapGridStep ( DbU::Unit step );
106 static DbU::Unit getSymbolicSnapGridStep ();
107 static DbU::Unit getOnSymbolicSnapGrid ( DbU::Unit u, SnapMode mode=Nearest );
108 static inline void setSymbolicSnapGridStep ( DbU::Unit step );
109 static DbU::Unit getOnCustomGrid ( DbU::Unit u, DbU::Unit step, SnapMode mode=Nearest );
110 static inline DbU::Unit getOnPhysicalGrid ( DbU::Unit u, SnapMode mode=Superior );
111 // Conversions.
112 static inline Unit toDb ( Unit u );
113 static inline double toGrid ( Unit u );
114 static inline double toGrid ( double u );
115 static inline double toLambda ( Unit u );
116 static inline double toLambda ( double u );
117 static inline double toPhysical ( Unit u, UnitPower p );
118 static inline double toPhysical ( double u, UnitPower p );
119 // Old naming scheme (not very clear).
120 static inline Unit getDb ( Unit u );
121 static inline double getGrid ( Unit u );
122 static inline double getGrid ( double u );
123 static inline double getLambda ( Unit u );
124 static inline double getLambda ( double u );
125 static inline double getPhysical ( Unit u, UnitPower p );
126 static inline double getPhysical ( double u, UnitPower p );
127 static string getValueString ( Unit u, int mode=SmartTruncate );
128 static string getValueString ( double u, int mode=SmartTruncate );
129 static Record* getValueRecord ( const Unit* u );
130 static Slot* getValueSlot ( const string& name, const Unit* u );
131 static void setStringMode ( unsigned int mode, UnitPower p=Nano );
132 static void getStringMode ( unsigned int& mode, UnitPower& p );
133 private:
134 static void _updateBounds ();
135
136 public:
137 // Static Attributes: constants.
138 static const Unit Min;
139 static const Unit Max;
140 private:
141 // Internal: Static Attributes.
142 static const unsigned int _maximalPrecision;
143 static unsigned int _precision;
144 static double _resolution;
145 static double _gridsPerLambda;
146 static double _physicalsPerGrid;
147 static unsigned int _stringMode;
148 static DbU::UnitPower _stringModeUnitPower;
149 static DbU::Unit _realSnapGridStep;
150 static DbU::Unit _symbolicSnapGridStep;
151 static DbU::Unit _polygonStep;
152 static double _gridMax;
153 static double _lambdaMax;
154 static double _physicalMax;
155 };
156
157
158 // Inline Functions.
159 // New converter naming scheme.
160 inline DbU::Unit DbU::fromDb ( DbU::Unit value ) { return value; }
161 inline DbU::Unit DbU::fromGrid ( double value ) { checkGridBound (value); return (Unit)rint( value/_resolution ); }
162 inline DbU::Unit DbU::fromLambda ( double value ) { checkLambdaBound (value); return fromGrid(value*_gridsPerLambda); }
163 inline DbU::Unit DbU::fromPhysical ( double value, UnitPower p ) { checkPhysicalBound(value,p); return fromGrid((value*getUnitPower(p))/_physicalsPerGrid); }
164 inline DbU::Unit DbU::toDb ( DbU::Unit u ) { return u; }
165 inline double DbU::toGrid ( DbU::Unit u ) { return _resolution*(double)u; }
166 inline double DbU::toGrid ( double u ) { return _resolution*u; }
167 inline double DbU::toLambda ( DbU::Unit u ) { return toGrid(u)/_gridsPerLambda; }
168 inline double DbU::toLambda ( double u ) { return toGrid(u)/_gridsPerLambda; }
169 inline double DbU::toPhysical ( DbU::Unit u, UnitPower p ) { return (_physicalsPerGrid*_resolution*(double)u)/getUnitPower(p); }
170 inline double DbU::toPhysical ( double u, UnitPower p ) { return (_physicalsPerGrid*_resolution*u)/getUnitPower(p); }
171 inline DbU::Unit DbU::getPolygonStep () { return _polygonStep; }
172
173 // Old converter naming scheme.
174 inline DbU::Unit DbU::db ( DbU::Unit value ) { return fromDb(value); }
175 inline DbU::Unit DbU::grid ( double value ) { return fromGrid(value); }
176 inline DbU::Unit DbU::lambda ( double value ) { return fromLambda(value); }
177 inline DbU::Unit DbU::physicalToDbu ( double value, UnitPower p ) { return fromPhysical(value,p); }
178 inline DbU::Unit DbU::getDb ( DbU::Unit u ) { return toDb(u); }
179 inline double DbU::getGrid ( DbU::Unit u ) { return toGrid(u); }
180 inline double DbU::getGrid ( double u ) { return toGrid(u); }
181 inline double DbU::getLambda ( DbU::Unit u ) { return toLambda(u); }
182 inline double DbU::getLambda ( double u ) { return toLambda(u); }
183 inline double DbU::getPhysical ( DbU::Unit u, UnitPower p ) { return toPhysical(u,p); }
184 inline double DbU::getPhysical ( double u, UnitPower p ) { return toPhysical(u,p); }
185
186 inline void DbU::setRealSnapGridStep ( DbU::Unit step ) { _realSnapGridStep = step; }
187 inline void DbU::setSymbolicSnapGridStep ( DbU::Unit step ) { _symbolicSnapGridStep = step; }
188 inline void DbU::setPolygonStep ( DbU::Unit step ) { _polygonStep = step; }
189 inline DbU::Unit DbU::getOnPhysicalGrid ( DbU::Unit u, SnapMode mode ) { return getOnCustomGrid(u, grid(1), mode); }
190
191
192 } // End of Hurricane namespace.
193
194
195 // inline void jsonWriteDbU ( JsonWriter* w, const std::string& key, long* value )
196 // { w->key( key ); w->write( value ); }
197
198
199 template<>
200 inline std::string getString ( const std::pair<Hurricane::DbU::Unit,Hurricane::DbU::Unit>& p )
201 {
202 return "const std::pair<DbU::Unit,DbU::Unit>";
203 }
204
205
206 template<>
207 inline Hurricane::Record* getRecord ( const std::pair<Hurricane::DbU::Unit,Hurricane::DbU::Unit>& p )
208 {
209 Hurricane::Record* record = NULL;
210 record = new Hurricane::Record ( "const std::pair<DbU::Unit,DbU::Unit>" );
211 record->add( Hurricane::DbU::getValueSlot("first" , &p.first ) );
212 record->add( Hurricane::DbU::getValueSlot("second", &p.second) );
213 return record;
214 }
215
216
217 template<>
218 inline std::string getString ( const std::array<Hurricane::DbU::Unit*,3>& a )
219 {
220 return "const array<DbU::Unit*,3>";
221 }
222
223
224 template<>
225 inline Hurricane::Record* getRecord ( const std::array<Hurricane::DbU::Unit*,3>& a )
226 {
227 Hurricane::Record* record = NULL;
228 record = new Hurricane::Record ( "const array<DbU::Unit*,3>" );
229
230 for ( size_t i=0 ; i<a.size() ; ++i ) {
231 std::string label = "[" + getString(i) + "] ";
232 record->add( Hurricane::DbU::getValueSlot(label, a[i]) );
233 }
234 return record;
235 }
236
237
238 template<>
239 inline std::string getString ( const std::vector<Hurricane::DbU::Unit>* v )
240 {
241 std::string name = "const std::vector<DbU::Unit>:";
242 return name + getString<size_t>(v->size());
243 }
244
245
246 template<>
247 inline Hurricane::Record* getRecord ( const std::vector<Hurricane::DbU::Unit>* v )
248 {
249 Hurricane::Record* record = NULL;
250 record = new Hurricane::Record ( "const vector<DbU::Unit>" );
251
252 for ( size_t i=0 ; i<v->size() ; ++i ) {
253 std::string label = "[" + getString(i) + "] ";
254 record->add( Hurricane::DbU::getValueSlot(label, &(*v)[i]) );
255 }
256 return record;
257 }
258
259
260 #endif // HURRICANE_DBU_H
Hurricane::DbU::toDb
static Unit toDb(Unit u)
Definition: DbU.h:164
Hurricane::DbU::getOnCustomGrid
static DbU::Unit getOnCustomGrid(DbU::Unit u, DbU::Unit step, SnapMode mode=Nearest)
Hurricane::DbU::getPrecision
static unsigned int getPrecision()
Hurricane::DbU::setStringMode
static void setStringMode(unsigned int mode, UnitPower p=Nano)
Hurricane::DbU::getResolution
static double getResolution()
Hurricane::DbU::Superior
Definition: DbU.h:66
Hurricane::DbU::fromPhysical
static Unit fromPhysical(double value, UnitPower p)
Definition: DbU.h:163
Hurricane::DbU::lambda
static Unit lambda(double value)
Definition: DbU.h:176
Hurricane::DbU::getOnSymbolicSnapGrid
static DbU::Unit getOnSymbolicSnapGrid(DbU::Unit u, SnapMode mode=Nearest)
Hurricane::DbU::Db
Definition: DbU.h:59
Hurricane::DbU::getDb
static Unit getDb(Unit u)
Definition: DbU.h:178
Hurricane::DbU::Nearest
Definition: DbU.h:67
Hurricane::DbU::Inferior
Definition: DbU.h:65
Hurricane::DbU::getOnPhysicalGrid
static DbU::Unit getOnPhysicalGrid(DbU::Unit u, SnapMode mode=Superior)
Definition: DbU.h:189
Hurricane::DbU::setSymbolicSnapGridStep
static void setSymbolicSnapGridStep(DbU::Unit step)
Definition: DbU.h:187
Hurricane::DbU::fromLambda
static Unit fromLambda(double value)
Definition: DbU.h:162
Hurricane::DbU::Unit
std::int64_t Unit
Definition: DbU.h:70
Hurricane::DbU::StringMode
StringMode
Definition: DbU.h:59
Hurricane::DbU::setGridsPerLambda
static void setGridsPerLambda(double gridsPerLambda, unsigned int flags=NoFlags)
Hurricane::DbU::Kilo
Definition: DbU.h:57
Hurricane::DbU::getOnRealSnapGrid
static DbU::Unit getOnRealSnapGrid(DbU::Unit u, SnapMode mode=Nearest)
Hurricane::DbU::Grid
Definition: DbU.h:60
Hurricane::DbU::getRealSnapGridStep
static DbU::Unit getRealSnapGridStep()
Hurricane::DbU::getValueString
static string getValueString(Unit u, int mode=SmartTruncate)
Hurricane::DbU::fromDb
static Unit fromDb(Unit value)
Definition: DbU.h:160
Hurricane::DbU::setPrecision
static void setPrecision(unsigned int precision, unsigned int flags=NoFlags)
Hurricane::DbU::Pico
Definition: DbU.h:52
Hurricane::DataBase
The whole DataBase (API).
Definition: DataBase.h:40
Hurricane::DbU::db
static Unit db(Unit value)
Definition: DbU.h:174
Hurricane::DbU::Micro
Definition: DbU.h:54
Hurricane::DbU
DataBase Unit managment (API).
Definition: DbU.h:46
Hurricane::DbU::toPhysical
static double toPhysical(Unit u, UnitPower p)
Definition: DbU.h:169
Hurricane::DbU::getGridsPerLambda
static double getGridsPerLambda()
Hurricane::DbU::setRealSnapGridStep
static void setRealSnapGridStep(DbU::Unit step)
Definition: DbU.h:186
Hurricane::DbU::UnitPower
UnitPower
Definition: DbU.h:52
Hurricane::DbU::grid
static Unit grid(double value)
Definition: DbU.h:175
Hurricane::DbU::Unity
Definition: DbU.h:56
Hurricane::DbU::toGrid
static double toGrid(Unit u)
Definition: DbU.h:165
Hurricane::DbU::Nano
Definition: DbU.h:53
Hurricane::DbU::Symbolic
Definition: DbU.h:61
Hurricane
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5
Hurricane::DbU::getMaximalPrecision
static unsigned int getMaximalPrecision()
Hurricane::DbU::SnapMode
SnapMode
Definition: DbU.h:65
Hurricane::DbU::getSymbolicSnapGridStep
static DbU::Unit getSymbolicSnapGridStep()
Hurricane::DbU::fromGrid
static Unit fromGrid(double value)
Definition: DbU.h:161
Hurricane::DbU::getLambda
static double getLambda(Unit u)
Definition: DbU.h:181
Hurricane::DbU::getGrid
static double getGrid(Unit u)
Definition: DbU.h:179
Hurricane::DbU::toLambda
static double toLambda(Unit u)
Definition: DbU.h:167
Hurricane::DbU::Milli
Definition: DbU.h:55

Generated by doxygen 1.8.14 on Tue Jul 21 2020 | Return to top of page

Hurricane VLSI Database | Copyright © 2000-2016 Bull S.A. All rights reserved