Skip to content

Commit f39c3c1

Browse files
authored
Merge pull request #2744 from cdleary/small-rcx-cleanups
[rcx] ext2dBox translation unit: encapsulate/test
2 parents 945dcaf + e680252 commit f39c3c1

File tree

12 files changed

+387
-135
lines changed

12 files changed

+387
-135
lines changed

src/drt/test/gc_test.tcl

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
11
source "helpers.tcl"
22

3-
set test_dir [pwd]
4-
set openroad_dir [file dirname [file dirname [file dirname $test_dir]]]
5-
set test_path [file join $openroad_dir "build" "src" "drt" "trTest"]
6-
7-
set test_status [catch { exec sh -c "BASE_DIR=$test_dir $test_path" } output option]
8-
9-
puts $test_status
10-
puts $output
11-
if { $test_status != 0 } {
12-
set test_err_info [lassign [dict get $option -errorcode] err_type]
13-
switch -exact -- $err_type {
14-
NONE {
15-
#passed
16-
}
17-
CHILDSTATUS {
18-
# non-zero exit status
19-
set exit_status [lindex $test_err_info 1]
20-
puts "ERROR: test returned exit code $exit_status"
21-
exit 1
22-
23-
}
24-
default {
25-
puts "ERROR: $option"
26-
exit 1
27-
}
28-
}
29-
}
30-
puts "pass"
31-
exit 0
3+
run_unit_test_and_exit [list "build" "src" "drt" "trTest"]

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/rcx/include/rcx/ext2dBox.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// BSD 3-Clause License
3+
//
4+
// Copyright (c) 2019-2023, Nefelus Inc, Google LLC
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+
void printGeoms3D(FILE* fp,
58+
double h,
59+
double t,
60+
const std::array<int, 2>& orig) const;
61+
unsigned int length() const;
62+
unsigned int width() const;
63+
int loX() const;
64+
int loY() const;
65+
unsigned int id() const;
66+
67+
unsigned int met() const { return _met; }
68+
unsigned int map() const { return _map; }
69+
bool dir() const { return _dir; }
70+
71+
int ur0() const { return _ur[0]; }
72+
int ur1() const { return _ur[1]; }
73+
int ll0() const { return _ll[0]; }
74+
int ll1() const { return _ll[1]; }
75+
76+
private:
77+
std::array<int, 2> _ll;
78+
std::array<int, 2> _ur;
79+
unsigned int _met;
80+
unsigned int _id;
81+
unsigned int _map;
82+
bool _dir;
83+
};
84+
85+
} // 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: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// BSD 3-Clause License
3+
//
4+
// Copyright (c) 2019-2023, Nefelus Inc, Google LLC
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+
#include "rcx/ext2dBox.h"
34+
35+
#include <utility>
36+
37+
namespace rcx {
38+
39+
ext2dBox::ext2dBox(std::array<int, 2> ll,
40+
std::array<int, 2> ur,
41+
unsigned int met,
42+
unsigned int id,
43+
unsigned int map,
44+
bool dir)
45+
: _ll(ll), _ur(ur), _met(met), _id(id), _map(map), _dir(dir)
46+
{
47+
}
48+
49+
void ext2dBox::rotate()
50+
{
51+
std::swap(_ur[0], _ur[1]);
52+
std::swap(_ll[0], _ll[1]);
53+
_dir = !_dir;
54+
}
55+
unsigned int ext2dBox::length() const
56+
{
57+
return _ur[_dir] - _ll[_dir];
58+
}
59+
unsigned int ext2dBox::width() const
60+
{
61+
return _ur[!_dir] - _ll[!_dir];
62+
}
63+
int ext2dBox::loX() const
64+
{
65+
return _ll[0];
66+
}
67+
int ext2dBox::loY() const
68+
{
69+
return _ll[1];
70+
}
71+
unsigned int ext2dBox::id() const
72+
{
73+
return _id;
74+
}
75+
void ext2dBox::printGeoms3D(FILE* fp,
76+
double h,
77+
double t,
78+
const std::array<int, 2>& orig) const
79+
{
80+
fprintf(fp,
81+
"%3d %8d -- M%d D%d %g %g %g %g L= %g W= %g H= %g TH= %g ORIG "
82+
"%g %g\n",
83+
_id,
84+
_map,
85+
_met,
86+
_dir,
87+
0.001 * _ll[0],
88+
0.001 * _ll[1],
89+
0.001 * _ur[0],
90+
0.001 * _ur[1],
91+
0.001 * length(),
92+
0.001 * width(),
93+
h,
94+
t,
95+
0.001 * (_ll[0] - orig[0]),
96+
0.001 * (_ll[1] - orig[1]));
97+
}
98+
99+
} // 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)