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 #pragma once
33 #include <cstdint>
34 #include <cmath>
35 #include "hurricane/Commons.h"
36 
37 
38 namespace Hurricane {
39 
40  class DataBase;
41 
42 
43  class DbU {
44  friend class DataBase;
45  public:
46  enum FunctionFlags { NoFlags = 0
47  , NoTechnoUpdate = (1<<0)
48  };
49  enum UnitPower { Pico = 1
50  , Nano
51  , Micro
52  , Milli
53  , Unity
54  , Kilo
55  };
56  enum StringMode { Db = (1<<0)
57  , Grid = (1<<1)
58  , Symbolic = (1<<2)
59  , Physical = (1<<3)
60  , SmartTruncate = (1<<4)
61  };
62  enum SnapMode { Inferior = 1
63  , Superior = 2
64  , Nearest = 4
65  };
66  public:
67  typedef std::int64_t Unit;
68 
69  public:
70  static void checkGridBound ( double value );
71  static void checkLambdaBound ( double value );
72  static void checkPhysicalBound ( double value, UnitPower p );
73  // User to DB Converters.
74  static inline Unit fromDb ( Unit value );
75  static inline Unit fromGrid ( double value );
76  static inline Unit fromLambda ( double value );
77  static inline Unit fromPhysical ( double value, UnitPower p );
78  static inline Unit fromMicrons ( double value );
79  static inline Unit fromNanos ( double value );
80  // Old naming scheme (was not very clear).
81  static inline Unit db ( Unit value );
82  static inline Unit grid ( double value );
83  static inline Unit lambda ( double value );
84  static inline Unit physicalToDbu ( double value, UnitPower p );
85  // Precision & Resolution Managment.
86  static unsigned int getPrecision ();
87  static unsigned int getMaximalPrecision ();
88  static double getResolution ();
89  static void setPrecision ( unsigned int precision, unsigned int flags=NoFlags );
90  // Foundry Grid Managment.
91  static double getUnitPower ( UnitPower p );
92  static void setPhysicalsPerGrid ( double gridsPerLambda, UnitPower p );
93  static double getPhysicalsPerGrid ();
94  static double physicalToGrid ( double physical, UnitPower p );
95  // Huge Polygon Step Managment.
96  static inline DbU::Unit getPolygonStep ();
97  static inline void setPolygonStep ( DbU::Unit );
98  // Lamba Managment.
99  static void setGridsPerLambda ( double gridsPerLambda, unsigned int flags=NoFlags );
100  static double getGridsPerLambda ();
101  // Snap Grid Managment.
104  static inline void setRealSnapGridStep ( DbU::Unit step );
107  static inline void setSymbolicSnapGridStep ( DbU::Unit step );
109  static inline DbU::Unit getOnPhysicalGrid ( DbU::Unit u, SnapMode mode=Superior );
110  static inline DbU::Unit toCeil ( DbU::Unit u, DbU::Unit step );
111  static inline DbU::Unit toFloor ( DbU::Unit u, DbU::Unit step );
112  // Conversions.
113  static inline Unit toDb ( Unit u );
114  static inline double toGrid ( Unit u );
115  static inline double toGrid ( double u );
116  static inline double toLambda ( Unit u );
117  static inline double toLambda ( double u );
118  static inline double toPhysical ( Unit u, UnitPower p );
119  static inline double toPhysical ( double u, UnitPower p );
120  static inline double toMicrons ( Unit u );
121  static inline double toNanos ( Unit u );
122  // Old naming scheme (not very clear).
123  static inline Unit getDb ( Unit u );
124  static inline double getGrid ( Unit u );
125  static inline double getGrid ( double u );
126  static inline double getLambda ( Unit u );
127  static inline double getLambda ( double u );
128  static inline double getPhysical ( Unit u, UnitPower p );
129  static inline double getPhysical ( double u, UnitPower p );
130  static string getValueString ( Unit u, int mode=SmartTruncate );
131  static string getValueString ( double u, int mode=SmartTruncate );
132  static Record* getValueRecord ( const Unit* u );
133  static Slot* getValueSlot ( const string& name, const Unit* u );
134  static void setStringMode ( unsigned int mode, UnitPower p=Nano );
135  static void getStringMode ( unsigned int& mode, UnitPower& p );
136  private:
137  static void _updateBounds ();
138 
139  public:
140  // Static Attributes: constants.
141  static const Unit Min;
142  static const Unit Max;
143  private:
144  // Internal: Static Attributes.
145  static const unsigned int _maximalPrecision;
146  static unsigned int _precision;
147  static double _resolution;
148  static double _gridsPerLambda;
149  static double _physicalsPerGrid;
150  static unsigned int _stringMode;
151  static DbU::UnitPower _stringModeUnitPower;
152  static DbU::Unit _realSnapGridStep;
153  static DbU::Unit _symbolicSnapGridStep;
154  static DbU::Unit _polygonStep;
155  static double _gridMax;
156  static double _lambdaMax;
157  static double _physicalMax;
158  };
159 
160 
161 // Inline Functions.
162 // New converter naming scheme.
163  inline DbU::Unit DbU::fromDb ( DbU::Unit value ) { return value; }
164  inline DbU::Unit DbU::fromGrid ( double value ) { checkGridBound (value); return (Unit)rint( value/_resolution ); }
165  inline DbU::Unit DbU::fromLambda ( double value ) { checkLambdaBound (value); return fromGrid(value*_gridsPerLambda); }
166  inline DbU::Unit DbU::fromPhysical ( double value, UnitPower p ) { checkPhysicalBound(value,p); return fromGrid((value*getUnitPower(p))/_physicalsPerGrid); }
167  inline DbU::Unit DbU::fromMicrons ( double value ) { return fromPhysical(value,UnitPower::Micro); }
168  inline DbU::Unit DbU::fromNanos ( double value ) { return fromPhysical(value,UnitPower::Nano); }
169  inline DbU::Unit DbU::toDb ( DbU::Unit u ) { return u; }
170  inline double DbU::toGrid ( DbU::Unit u ) { return _resolution*(double)u; }
171  inline double DbU::toGrid ( double u ) { return _resolution*u; }
172  inline double DbU::toLambda ( DbU::Unit u ) { return toGrid(u)/_gridsPerLambda; }
173  inline double DbU::toLambda ( double u ) { return toGrid(u)/_gridsPerLambda; }
174  inline double DbU::toPhysical ( DbU::Unit u, UnitPower p ) { return (_physicalsPerGrid*_resolution*(double)u)/getUnitPower(p); }
175  inline double DbU::toPhysical ( double u, UnitPower p ) { return (_physicalsPerGrid*_resolution*u)/getUnitPower(p); }
176  inline double DbU::toMicrons ( Unit u ) { return toPhysical(u,UnitPower::Micro); }
177  inline double DbU::toNanos ( Unit u ) { return toPhysical(u,UnitPower::Nano); }
178  inline DbU::Unit DbU::getPolygonStep () { return _polygonStep; }
179 
180 // Old converter naming scheme.
181  inline DbU::Unit DbU::db ( DbU::Unit value ) { return fromDb(value); }
182  inline DbU::Unit DbU::grid ( double value ) { return fromGrid(value); }
183  inline DbU::Unit DbU::lambda ( double value ) { return fromLambda(value); }
184  inline DbU::Unit DbU::physicalToDbu ( double value, UnitPower p ) { return fromPhysical(value,p); }
185  inline DbU::Unit DbU::getDb ( DbU::Unit u ) { return toDb(u); }
186  inline double DbU::getGrid ( DbU::Unit u ) { return toGrid(u); }
187  inline double DbU::getGrid ( double u ) { return toGrid(u); }
188  inline double DbU::getLambda ( DbU::Unit u ) { return toLambda(u); }
189  inline double DbU::getLambda ( double u ) { return toLambda(u); }
190  inline double DbU::getPhysical ( DbU::Unit u, UnitPower p ) { return toPhysical(u,p); }
191  inline double DbU::getPhysical ( double u, UnitPower p ) { return toPhysical(u,p); }
192 
193  inline void DbU::setRealSnapGridStep ( DbU::Unit step ) { _realSnapGridStep = step; }
194  inline void DbU::setSymbolicSnapGridStep ( DbU::Unit step ) { _symbolicSnapGridStep = step; }
195  inline void DbU::setPolygonStep ( DbU::Unit step ) { _polygonStep = step; }
196  inline DbU::Unit DbU::getOnPhysicalGrid ( DbU::Unit u, SnapMode mode ) { return getOnCustomGrid(u, grid(1), mode); }
197 
198  inline DbU::Unit DbU::toCeil ( DbU::Unit u, DbU::Unit step )
199  { DbU::Unit modulo = u % step; return (modulo) ? (u + step - modulo) : u; }
200 
201  inline DbU::Unit DbU::toFloor ( DbU::Unit u, DbU::Unit step )
202  { DbU::Unit modulo = u % step; return (modulo) ? (u - modulo) : u; }
203 
204 
205 } // End of Hurricane namespace.
206 
207 
208 // inline void jsonWriteDbU ( JsonWriter* w, const std::string& key, long* value )
209 // { w->key( key ); w->write( value ); }
210 
211 
212 template<>
213 inline std::string getString ( const std::pair<Hurricane::DbU::Unit,Hurricane::DbU::Unit>& p )
214 {
215  return "const std::pair<DbU::Unit,DbU::Unit>";
216 }
217 
218 
219 template<>
220 inline Hurricane::Record* getRecord ( const std::pair<Hurricane::DbU::Unit,Hurricane::DbU::Unit>& p )
221 {
222  Hurricane::Record* record = NULL;
223  record = new Hurricane::Record ( "const std::pair<DbU::Unit,DbU::Unit>" );
224  record->add( Hurricane::DbU::getValueSlot("first" , &p.first ) );
225  record->add( Hurricane::DbU::getValueSlot("second", &p.second) );
226  return record;
227 }
228 
229 
230 template<>
231 inline std::string getString ( const std::array<Hurricane::DbU::Unit*,3>& a )
232 {
233  return "const array<DbU::Unit*,3>";
234 }
235 
236 
237 template<>
238 inline Hurricane::Record* getRecord ( const std::array<Hurricane::DbU::Unit*,3>& a )
239 {
240  Hurricane::Record* record = NULL;
241  record = new Hurricane::Record ( "const array<DbU::Unit*,3>" );
242 
243  for ( size_t i=0 ; i<a.size() ; ++i ) {
244  std::string label = "[" + getString(i) + "] ";
245  record->add( Hurricane::DbU::getValueSlot(label, a[i]) );
246  }
247  return record;
248 }
249 
250 
251 template<>
252 inline std::string getString ( const std::vector<Hurricane::DbU::Unit>* v )
253 {
254  std::string name = "const std::vector<DbU::Unit>:";
255  return name + getString<size_t>(v->size());
256 }
257 
258 
259 template<>
260 inline Hurricane::Record* getRecord ( const std::vector<Hurricane::DbU::Unit>* v )
261 {
262  Hurricane::Record* record = NULL;
263  record = new Hurricane::Record ( "const vector<DbU::Unit>" );
264 
265  for ( size_t i=0 ; i<v->size() ; ++i ) {
266  std::string label = "[" + getString(i) + "] ";
267  record->add( Hurricane::DbU::getValueSlot(label, &(*v)[i]) );
268  }
269  return record;
270 }
The whole DataBase (API).
Definition: DataBase.h:40
DataBase Unit managment (API).
Definition: DbU.h:43
static DbU::Unit getRealSnapGridStep()
SnapMode
Definition: DbU.h:62
@ Nearest
Definition: DbU.h:64
@ Inferior
Definition: DbU.h:62
@ Superior
Definition: DbU.h:63
static Unit fromPhysical(double value, UnitPower p)
Definition: DbU.h:166
static double getResolution()
static Unit grid(double value)
Definition: DbU.h:182
static void setRealSnapGridStep(DbU::Unit step)
Definition: DbU.h:193
static double toGrid(Unit u)
Definition: DbU.h:170
static Unit fromGrid(double value)
Definition: DbU.h:164
static Unit getDb(Unit u)
Definition: DbU.h:185
static double toLambda(Unit u)
Definition: DbU.h:172
static Unit fromLambda(double value)
Definition: DbU.h:165
std::int64_t Unit
Definition: DbU.h:67
UnitPower
Definition: DbU.h:49
@ Nano
Definition: DbU.h:50
@ Pico
Definition: DbU.h:49
@ Kilo
Definition: DbU.h:54
@ Micro
Definition: DbU.h:51
@ Milli
Definition: DbU.h:52
@ Unity
Definition: DbU.h:53
static unsigned int getPrecision()
static DbU::Unit getSymbolicSnapGridStep()
StringMode
Definition: DbU.h:56
@ Symbolic
Definition: DbU.h:58
@ Db
Definition: DbU.h:56
@ Grid
Definition: DbU.h:57
static DbU::Unit getOnCustomGrid(DbU::Unit u, DbU::Unit step, SnapMode mode=Nearest)
static DbU::Unit getOnRealSnapGrid(DbU::Unit u, SnapMode mode=Nearest)
static unsigned int getMaximalPrecision()
static void setStringMode(unsigned int mode, UnitPower p=Nano)
static DbU::Unit getOnPhysicalGrid(DbU::Unit u, SnapMode mode=Superior)
Definition: DbU.h:196
static double getGridsPerLambda()
static void setSymbolicSnapGridStep(DbU::Unit step)
Definition: DbU.h:194
static Unit lambda(double value)
Definition: DbU.h:183
static double toPhysical(Unit u, UnitPower p)
Definition: DbU.h:174
static void setGridsPerLambda(double gridsPerLambda, unsigned int flags=NoFlags)
static Unit db(Unit value)
Definition: DbU.h:181
static void setPrecision(unsigned int precision, unsigned int flags=NoFlags)
static DbU::Unit getOnSymbolicSnapGrid(DbU::Unit u, SnapMode mode=Nearest)
static double getGrid(Unit u)
Definition: DbU.h:186
static string getValueString(Unit u, int mode=SmartTruncate)
static double getLambda(Unit u)
Definition: DbU.h:188
static Unit toDb(Unit u)
Definition: DbU.h:169
static Unit fromDb(Unit value)
Definition: DbU.h:163
The namespace dedicated to Hurricane.
Definition: Generalities.dox:5


Generated by doxygen 1.9.1 on Thu Aug 11 2022 Return to top of page
Hurricane VLSI Database Copyright © 2000-2020 Bull S.A. All rights reserved