Skip to content

Commit dbb3dee

Browse files
committed
stt: cleanup flute code
- Move variables to local scope rather than C style at the top of the func. - Naming style - Eliminate macros - Use vector over malloc - Drop all but LUT_SOURCE=LUT_VAR Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent a0ec515 commit dbb3dee

File tree

2 files changed

+727
-1175
lines changed

2 files changed

+727
-1175
lines changed

src/stt/include/stt/flute.h

Lines changed: 55 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -9,173 +9,86 @@
99

1010
#pragma once
1111

12-
namespace stt {
12+
namespace stt::flt {
1313

14-
namespace flt {
15-
16-
using stt::Branch;
1714
using stt::Tree;
1815

19-
/*****************************/
20-
/* User-Defined Parameters */
21-
/*****************************/
22-
#define FLUTE_ROUTING 1 // 1 to construct routing, 0 to estimate WL only
23-
#define FLUTE_LOCAL_REFINEMENT 1 // Suggestion: Set to 1 if ACCURACY >= 5
24-
#define FLUTE_REMOVE_DUPLICATE_PIN \
25-
0 // Remove dup. pin for flute_wl() & flute()
26-
27-
#define FLUTE_POWVFILE "POWV9.dat" // LUT for POWV (Wirelength Vector)
28-
#define FLUTE_POSTFILE "POST9.dat" // LUT for POST (Steiner Tree)
29-
#define FLUTE_D 9 // LUT is used for d <= FLUTE_D, FLUTE_D <= 9
30-
3116
class Flute
3217
{
33-
public:
34-
struct csoln;
35-
36-
private:
37-
using LUT_TYPE = boost::multi_array<std::shared_ptr<struct csoln[]>, 2>*;
38-
using NUMSOLN_TYPE = int**;
39-
4018
public:
4119
Flute() = default;
4220
~Flute() { deleteLUT(); }
4321

44-
// User-Callable Functions
45-
// Delete LUT tables for exit so they are not leaked.
46-
4722
Tree flute(const std::vector<int>& x, const std::vector<int>& y, int acc);
48-
int wirelength(Tree t);
49-
void plottree(Tree t);
23+
int wirelength(const Tree& t);
24+
void plottree(const Tree& t);
5025
Tree flutes(const std::vector<int>& xs,
5126
const std::vector<int>& ys,
5227
const std::vector<int>& s,
53-
int acc)
54-
{
55-
int d = xs.size();
56-
if (FLUTE_REMOVE_DUPLICATE_PIN == 1) {
57-
return flutes_RDP(d, xs, ys, s, acc);
58-
}
59-
return flutes_ALLD(d, xs, ys, s, acc);
60-
}
28+
int acc);
29+
int flute_wl(int d,
30+
const std::vector<int>& x,
31+
const std::vector<int>& y,
32+
int acc);
6133

6234
private:
35+
struct Csoln;
36+
37+
using LutType = boost::multi_array<std::shared_ptr<Csoln[]>, 2>*;
38+
using NumSoln = int**;
39+
6340
void readLUT();
64-
void makeLUT(LUT_TYPE& LUT, NUMSOLN_TYPE& numsoln);
65-
void initLUT(int to_d, LUT_TYPE LUT, NUMSOLN_TYPE numsoln);
41+
void makeLUT(LutType& lut, NumSoln& numsoln);
42+
void initLUT(int to_d, LutType lut, NumSoln numsoln);
6643
void ensureLUT(int d);
6744
void deleteLUT();
68-
void deleteLUT(LUT_TYPE& LUT, NUMSOLN_TYPE& numsoln);
45+
void deleteLUT(LutType& lut, NumSoln& numsoln);
6946

70-
int flute_wl(int d,
71-
const std::vector<int>& x,
72-
const std::vector<int>& y,
73-
int acc);
74-
75-
Tree dmergetree(Tree t1, Tree t2);
76-
Tree hmergetree(Tree t1, Tree t2, const std::vector<int>& s);
77-
Tree vmergetree(Tree t1, Tree t2);
47+
Tree d_merge_tree(const Tree& t1, const Tree& t2) const;
48+
Tree h_merge_tree(const Tree& t1, const Tree& t2, const std::vector<int>& s);
49+
Tree v_merge_tree(const Tree& t1, const Tree& t2) const;
7850
void local_refinement(int deg, Tree* tp, int p);
7951

80-
// Other useful functions
81-
int flutes_wl_LD(int d,
82-
const std::vector<int>& xs,
83-
const std::vector<int>& ys,
84-
const std::vector<int>& s);
85-
int flutes_wl_MD(int d,
86-
const std::vector<int>& xs,
87-
const std::vector<int>& ys,
88-
const std::vector<int>& s,
89-
int acc);
90-
int flutes_wl_RDP(int d,
91-
std::vector<int> xs,
92-
std::vector<int> ys,
93-
std::vector<int> s,
94-
int acc);
95-
Tree flutes_LD(int d,
96-
const std::vector<int>& xs,
97-
const std::vector<int>& ys,
98-
const std::vector<int>& s);
99-
Tree flutes_MD(int d,
100-
const std::vector<int>& xs,
101-
const std::vector<int>& ys,
102-
const std::vector<int>& s,
103-
int acc);
104-
Tree flutes_RDP(int d,
105-
std::vector<int> xs,
106-
std::vector<int> ys,
107-
std::vector<int> s,
108-
int acc);
109-
110-
int flutes_wl_LMD(int d,
111-
const std::vector<int>& xs,
112-
const std::vector<int>& ys,
113-
const std::vector<int>& s,
114-
int acc)
115-
{
116-
if (d <= FLUTE_D) {
117-
return flutes_wl_LD(d, xs, ys, s);
118-
}
119-
return flutes_wl_MD(d, xs, ys, s, acc);
120-
}
121-
122-
int flutes_wl_ALLD(int d,
123-
const std::vector<int>& xs,
124-
const std::vector<int>& ys,
125-
const std::vector<int>& s,
126-
int acc)
127-
{
128-
return flutes_wl_LMD(d, xs, ys, s, acc);
129-
}
130-
131-
int flutes_wl(int d,
132-
const std::vector<int>& xs,
133-
const std::vector<int>& ys,
134-
const std::vector<int>& s,
135-
int acc)
136-
{
137-
if (FLUTE_REMOVE_DUPLICATE_PIN == 1) {
138-
return flutes_wl_RDP(d, xs, ys, s, acc);
139-
}
140-
return flutes_wl_ALLD(d, xs, ys, s, acc);
141-
}
142-
143-
Tree flutes_ALLD(int d,
144-
const std::vector<int>& xs,
145-
const std::vector<int>& ys,
146-
const std::vector<int>& s,
147-
int acc)
148-
{
149-
if (d <= FLUTE_D) {
150-
return flutes_LD(d, xs, ys, s);
151-
}
152-
return flutes_MD(d, xs, ys, s, acc);
153-
}
154-
155-
Tree flutes_LMD(int d,
156-
const std::vector<int>& xs,
157-
const std::vector<int>& ys,
158-
const std::vector<int>& s,
159-
int acc)
160-
{
161-
if (d <= FLUTE_D) {
162-
return flutes_LD(d, xs, ys, s);
163-
}
164-
return flutes_MD(d, xs, ys, s, acc);
165-
}
52+
int flutes_wl_low_degree(int d,
53+
const std::vector<int>& xs,
54+
const std::vector<int>& ys,
55+
const std::vector<int>& s);
56+
int flutes_wl_medium_degree(int d,
57+
const std::vector<int>& xs,
58+
const std::vector<int>& ys,
59+
const std::vector<int>& s,
60+
int acc);
61+
Tree flutes_low_degree(int d,
62+
const std::vector<int>& xs,
63+
const std::vector<int>& ys,
64+
const std::vector<int>& s);
65+
Tree flutes_medium_degree(int d,
66+
const std::vector<int>& xs,
67+
const std::vector<int>& ys,
68+
const std::vector<int>& s,
69+
int acc);
70+
71+
int flutes_wl_all_degree(int d,
72+
const std::vector<int>& xs,
73+
const std::vector<int>& ys,
74+
const std::vector<int>& s,
75+
int acc);
76+
77+
Tree flutes_all_degree(int d,
78+
const std::vector<int>& xs,
79+
const std::vector<int>& ys,
80+
const std::vector<int>& s,
81+
int acc);
16682

167-
private:
16883
// Dynamically allocate LUTs.
169-
LUT_TYPE LUT_ = nullptr;
170-
NUMSOLN_TYPE numsoln_ = nullptr;
171-
// LUTs are initialized to this order at startup.
172-
static constexpr int lut_initial_d = 8;
84+
LutType lut_ = nullptr;
85+
NumSoln numsoln_ = nullptr;
17386
int lut_valid_d_ = 0;
17487

175-
static constexpr int numgrp[10]
88+
// LUTs are initialized to this order at startup.
89+
static constexpr int kLutInitialDegree = 8;
90+
static constexpr int kNumGroup[10]
17691
= {0, 0, 0, 0, 6, 30, 180, 1260, 10080, 90720};
17792
};
17893

179-
} // namespace flt
180-
181-
} // namespace stt
94+
} // namespace stt::flt

0 commit comments

Comments
 (0)