Skip to content

Commit 84946a9

Browse files
committed
[rcx] ext2dBox translation unit: encapsulate/test.
Signed-off-by: Christopher D. Leary <[email protected]>
1 parent 81706ae commit 84946a9

File tree

9 files changed

+291
-106
lines changed

9 files changed

+291
-106
lines changed

src/odb/include/odb/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ class AthArray
229229
};
230230

231231
// A simple pool allocation function
232+
//
233+
// Note: T must be default-constructible, as `new` is used to construct T when
234+
// memory debugging is enabled.
232235
template <class T>
233236
class AthPool
234237
{

src/odb/test/diffs.rpt

Whitespace-only changes.

src/rcx/include/rcx/ext2dBox.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// BSD 3-Clause License
3+
//
4+
// Copyright (c) 2023, Nefelus Inc
5+
// All rights reserved.
6+
//
7+
// Redistribution and use in source and binary forms, with or without
8+
// modification, are permitted provided that the following conditions are met:
9+
//
10+
// * Redistributions of source code must retain the above copyright notice, this
11+
// list of conditions and the following disclaimer.
12+
//
13+
// * Redistributions in binary form must reproduce the above copyright notice,
14+
// this list of conditions and the following disclaimer in the documentation
15+
// and/or other materials provided with the distribution.
16+
//
17+
// * Neither the name of the copyright holder nor the names of its
18+
// contributors may be used to endorse or promote products derived from
19+
// this software without specific prior written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
// POSSIBILITY OF SUCH DAMAGE.
32+
33+
#pragma once
34+
35+
#include <array>
36+
#include <cstdio>
37+
38+
namespace rcx {
39+
40+
class ext2dBox // assume cross-section on the z-direction
41+
{
42+
public:
43+
// Implementation note: a default constructor is necessary because these are
44+
// AthPool allocated, and it requires the type to be default constructible.
45+
// We use placement new (with the full constructor below) for initialization
46+
// after pool allocation.
47+
ext2dBox() = default;
48+
49+
ext2dBox(std::array<int, 2> ll,
50+
std::array<int, 2> ur,
51+
unsigned int met,
52+
unsigned int id,
53+
unsigned int map,
54+
bool dir);
55+
56+
void rotate();
57+
bool matchCoords(int* ll, int* ur) const;
58+
void printGeoms3D(FILE* fp,
59+
double h,
60+
double t,
61+
const std::array<int, 2>& orig) const;
62+
unsigned int length() const;
63+
unsigned int width() const;
64+
int loX() const;
65+
int loY() const;
66+
unsigned int id() const;
67+
68+
unsigned int met() const { return _met; }
69+
unsigned int map() const { return _map; }
70+
bool dir() const { return _dir; }
71+
72+
int ur0() const { return _ur[0]; }
73+
int ur1() const { return _ur[1]; }
74+
int ll0() const { return _ll[0]; }
75+
int ll1() const { return _ll[1]; }
76+
77+
private:
78+
std::array<int, 2> _ll;
79+
std::array<int, 2> _ur;
80+
unsigned int _met;
81+
unsigned int _id;
82+
unsigned int _map;
83+
bool _dir;
84+
};
85+
86+
} // namespace rcx

src/rcx/include/rcx/extRCap.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include "ZObject.h"
4545
#include "db.h"
46+
#include "ext2dBox.h"
4647
#include "extprocess.h"
4748
#include "gseq.h"
4849
#include "odb.h"
@@ -63,27 +64,6 @@ using odb::Darr;
6364
using odb::uint;
6465
using utl::Logger;
6566

66-
class ext2dBox // assume cross-section on the z-direction
67-
{
68-
int _ll[2];
69-
int _ur[2];
70-
uint _met;
71-
uint _dir;
72-
uint _id;
73-
uint _map;
74-
75-
void rotate();
76-
bool matchCoords(int* ll, int* ur);
77-
void printGeoms3D(FILE* fp, double h, double t, int* orig);
78-
uint length();
79-
uint width();
80-
int loX();
81-
int loY();
82-
uint id();
83-
84-
friend class extMeasure;
85-
friend class extRCModel;
86-
};
8767
class extGeoVarTable
8868
{
8969
int _x;

src/rcx/src/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ target_sources(rcx
5959
extstats.cpp
6060
extprocess.cpp
6161
exttree.cpp
62+
ext2dBox.cpp
6263
hierSpef.cpp
6364
netRC.cpp
6465
powerConn.cpp
@@ -84,6 +85,41 @@ messages(
8485
OUTPUT_DIR ..
8586
)
8687

88+
############################################################
89+
# Unit testing
90+
############################################################
91+
enable_testing()
92+
93+
add_executable(rcxUnitTest
94+
${PROJECT_SOURCE_DIR}/test/ext2dBoxTest.cpp
95+
)
96+
97+
target_include_directories(rcxUnitTest
98+
PRIVATE
99+
${PROJECT_SOURCE_DIR}/src
100+
${OPENROAD_HOME}/include
101+
)
102+
103+
target_link_libraries(rcxUnitTest
104+
rcx
105+
)
106+
107+
# Use the shared library if found. We need to pass this info to
108+
# the code to select the corresponding include. Using the shared
109+
# library speeds up compilation.
110+
if (Boost_unit_test_framework_FOUND)
111+
message(STATUS "Boost unit_test_framework library found")
112+
target_link_libraries(trTest
113+
Boost::unit_test_framework
114+
)
115+
target_compile_definitions(trTest
116+
PRIVATE
117+
HAS_BOOST_UNIT_TEST_LIBRARY
118+
)
119+
endif()
120+
121+
add_test(NAME trTest COMMAND trTest)
122+
87123
if (Python3_FOUND AND BUILD_PYTHON)
88124
swig_lib(NAME rcx_py
89125
NAMESPACE rcx

src/rcx/src/ext2dBox.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "rcx/ext2dBox.h"
2+
3+
#include <utility>
4+
5+
namespace rcx {
6+
7+
ext2dBox::ext2dBox(std::array<int, 2> ll,
8+
std::array<int, 2> ur,
9+
unsigned int met,
10+
unsigned int id,
11+
unsigned int map,
12+
bool dir)
13+
: _ll(ll), _ur(ur), _met(met), _id(id), _map(map), _dir(dir)
14+
{
15+
}
16+
bool ext2dBox::matchCoords(int* ll, int* ur) const
17+
{
18+
if ((ur[0] < _ll[0]) || (ll[0] > _ur[0]) || (ur[1] < _ll[1])
19+
|| (ll[1] > _ur[1]))
20+
return false;
21+
22+
return true;
23+
}
24+
25+
void ext2dBox::rotate()
26+
{
27+
std::swap(_ur[0], _ur[1]);
28+
std::swap(_ll[0], _ll[1]);
29+
_dir = !_dir;
30+
}
31+
unsigned int ext2dBox::length() const
32+
{
33+
return _ur[_dir] - _ll[_dir];
34+
}
35+
unsigned int ext2dBox::width() const
36+
{
37+
return _ur[!_dir] - _ll[!_dir];
38+
}
39+
int ext2dBox::loX() const
40+
{
41+
return _ll[0];
42+
}
43+
int ext2dBox::loY() const
44+
{
45+
return _ll[1];
46+
}
47+
unsigned int ext2dBox::id() const
48+
{
49+
return _id;
50+
}
51+
void ext2dBox::printGeoms3D(FILE* fp,
52+
double h,
53+
double t,
54+
const std::array<int, 2>& orig) const
55+
{
56+
fprintf(fp,
57+
"%3d %8d -- M%d D%d %g %g %g %g L= %g W= %g H= %g TH= %g ORIG "
58+
"%g %g\n",
59+
_id,
60+
_map,
61+
_met,
62+
_dir,
63+
0.001 * _ll[0],
64+
0.001 * _ll[1],
65+
0.001 * _ur[0],
66+
0.001 * _ur[1],
67+
0.001 * length(),
68+
0.001 * width(),
69+
h,
70+
t,
71+
0.001 * (_ll[0] - orig[0]),
72+
0.001 * (_ll[1] - orig[1]));
73+
}
74+
75+
} // namespace rcx

src/rcx/src/extBench.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,14 @@ uint extRCModel::writePatternGeoms(extMeasure* m,
587587
0.001 * m->_ur[0],
588588
0.001 * m->_ur[1]);
589589

590+
const std::array<int, 2> orig = {m->_ll[0], m->_ll[1]};
590591
for (uint ii = 0; ii < boxArray->getCnt(); ii++) {
591592
ext2dBox* bb = boxArray->get(ii);
592-
uint met = bb->_met;
593+
uint met = bb->met();
593594

594595
double h = _process->getConductor(met)->_height;
595596
double t = _process->getConductor(met)->_thickness;
596-
bb->printGeoms3D(fp, h, t, m->_ll);
597+
bb->printGeoms3D(fp, h, t, orig);
597598
}
598599
fclose(fp);
599600
return boxArray->getCnt();
@@ -621,7 +622,7 @@ bool extRCModel::makePatternNet3D(extMeasure* measure,
621622
double th = _process->getConductor(measure->_met)->_thickness;
622623

623624
ext2dBox* bb1 = boxArray->get(0);
624-
uint mainDir = bb1->_dir;
625+
uint mainDir = bb1->dir();
625626
if (mainDir == 0) {
626627
int x = measure->_ll[0];
627628
measure->_ll[0] = measure->_ll[1];
@@ -643,7 +644,7 @@ bool extRCModel::makePatternNet3D(extMeasure* measure,
643644
if (mainDir == 0) {
644645
bb->rotate();
645646
}
646-
uint met = bb->_met;
647+
uint met = bb->met();
647648

648649
double h = _process->getConductor(met)->_height;
649650
double t = _process->getConductor(met)->_thickness;
@@ -683,14 +684,6 @@ uint extMeasure::getRSeg(dbNet* net, uint shapeId)
683684
else
684685
return 0;
685686
}
686-
bool ext2dBox::matchCoords(int* ll, int* ur)
687-
{
688-
if ((ur[0] < _ll[0]) || (ll[0] > _ur[0]) || (ur[1] < _ll[1])
689-
|| (ll[1] > _ur[1]))
690-
return false;
691-
692-
return true;
693-
}
694687

695688
uint extRCModel::runWiresSolver(uint netId, int shapeId)
696689
{

0 commit comments

Comments
 (0)