Skip to content

Commit 782b315

Browse files
committed
odb: Move AthArray, AthPool, array1.h to rcx
Signed-off-by: Matt Liberty <[email protected]>
1 parent cdea98d commit 782b315

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+642
-687
lines changed

src/odb/include/odb/util.h

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <string>
1111
#include <vector>
1212

13-
#include "odb/array1.h"
14-
1513
namespace utl {
1614
class Logger;
1715
}
@@ -25,178 +23,6 @@ class dbTechLayer;
2523
class Rect;
2624
class Polygon;
2725

28-
// A class that implements an array that can grow efficiently
29-
template <class T>
30-
class AthArray
31-
{
32-
public:
33-
AthArray(int alloc_size = 128)
34-
{
35-
if (alloc_size < 2) {
36-
alloc_size = 2;
37-
}
38-
m_alloc_size_ = alloc_size;
39-
m_num_mallocated_first_level_ = alloc_size;
40-
m_ptr_ = (T**) malloc(sizeof(T*) * m_num_mallocated_first_level_);
41-
for (int i = 0; i < m_num_mallocated_first_level_; i++) {
42-
m_ptr_[i] = nullptr;
43-
}
44-
m_num_allocated_elem_ = 0;
45-
m_num_mallocated_elem_ = 0;
46-
}
47-
48-
~AthArray()
49-
{
50-
for (int i = 0; i < m_num_mallocated_first_level_; i++) {
51-
if (m_ptr_[i]) {
52-
free(m_ptr_[i]);
53-
}
54-
}
55-
free(m_ptr_);
56-
}
57-
58-
void add()
59-
{
60-
int first_level_idx, second_level_idx;
61-
allocNext(&first_level_idx, &second_level_idx);
62-
m_num_allocated_elem_++;
63-
}
64-
65-
int add(T elem)
66-
{
67-
int first_level_idx, second_level_idx;
68-
allocNext(&first_level_idx, &second_level_idx);
69-
70-
m_ptr_[first_level_idx][second_level_idx] = elem;
71-
int n = m_num_allocated_elem_++;
72-
return n;
73-
}
74-
75-
T& operator[](const int idx)
76-
{
77-
assert(idx < m_num_allocated_elem_);
78-
int first_level_idx, second_level_idx;
79-
find_indexes(idx, first_level_idx, second_level_idx);
80-
return m_ptr_[first_level_idx][second_level_idx];
81-
}
82-
83-
T get(const int idx)
84-
{
85-
assert(idx < m_num_allocated_elem_);
86-
int first_level_idx, second_level_idx;
87-
find_indexes(idx, first_level_idx, second_level_idx);
88-
return m_ptr_[first_level_idx][second_level_idx];
89-
}
90-
int getLast() { return m_num_allocated_elem_; }
91-
92-
private:
93-
void allocNext(int* ii, int* jj)
94-
{
95-
int first_level_idx, second_level_idx;
96-
find_indexes(m_num_allocated_elem_, first_level_idx, second_level_idx);
97-
// reallocate first level if it is too small
98-
if (m_num_mallocated_first_level_ * m_alloc_size_
99-
<= m_num_allocated_elem_) {
100-
int orig_first_level_size = m_num_mallocated_first_level_;
101-
m_num_mallocated_first_level_++;
102-
m_ptr_
103-
= (T**) realloc(m_ptr_, sizeof(T*) * m_num_mallocated_first_level_);
104-
assert(m_ptr_);
105-
for (int i = orig_first_level_size; i < m_num_mallocated_first_level_;
106-
i++) {
107-
m_ptr_[i] = nullptr;
108-
}
109-
}
110-
// Allocate more elements if needed
111-
if (m_ptr_[first_level_idx] == nullptr) {
112-
size_t size = sizeof(T);
113-
m_ptr_[first_level_idx] = (T*) malloc(size * m_alloc_size_);
114-
m_num_mallocated_elem_ = m_num_mallocated_first_level_ * m_alloc_size_;
115-
}
116-
*ii = first_level_idx;
117-
*jj = second_level_idx;
118-
}
119-
120-
void find_indexes(int num, int& first_level, int& second_level)
121-
{
122-
first_level = num / m_alloc_size_;
123-
second_level = num % m_alloc_size_;
124-
}
125-
126-
int m_alloc_size_;
127-
T** m_ptr_;
128-
int m_num_allocated_elem_;
129-
int m_num_mallocated_elem_;
130-
int m_num_mallocated_first_level_;
131-
};
132-
133-
// A simple pool allocation function
134-
//
135-
// Note: T must be default-constructible, as `new` is used to construct T when
136-
// memory debugging is enabled.
137-
template <class T>
138-
class AthPool
139-
{
140-
public:
141-
AthPool(const int freeAllocSize)
142-
{
143-
m_heap_ = new AthArray<T>(4096);
144-
free_table_ = new Ath__array1D<T*>(freeAllocSize);
145-
}
146-
147-
~AthPool()
148-
{
149-
delete m_heap_;
150-
delete free_table_;
151-
}
152-
153-
T* alloc(int* freeTableFlag = nullptr, int* id = nullptr)
154-
{
155-
T* a = nullptr;
156-
157-
if (free_table_->notEmpty()) {
158-
a = free_table_->pop();
159-
160-
if (freeTableFlag != nullptr) {
161-
*freeTableFlag = 1;
162-
}
163-
} else {
164-
m_heap_->add();
165-
int n = m_heap_->getLast() - 1;
166-
a = &(*m_heap_)[n];
167-
168-
if (id != nullptr) {
169-
*id = n;
170-
}
171-
172-
if (freeTableFlag != nullptr) {
173-
*freeTableFlag = 0;
174-
}
175-
}
176-
return a;
177-
}
178-
179-
void free(T* a)
180-
{
181-
assert(a); // should not free nullptr
182-
if (free_table_ != nullptr) {
183-
free_table_->add(a);
184-
}
185-
}
186-
187-
T* get(const int ii)
188-
{
189-
T* a = &(*m_heap_)[ii];
190-
return a;
191-
}
192-
193-
int getCnt() { return m_heap_->getLast(); }
194-
195-
private:
196-
AthArray<T>* m_heap_;
197-
Ath__array1D<T*>* free_table_;
198-
};
199-
20026
int makeSiteLoc(int x, double site_width, bool at_left_from_macro, int offset);
20127

20228
bool hasOneSiteMaster(dbDatabase* db);

src/rcx/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ cc_library(
6565
"src/process_ext.cpp",
6666
],
6767
hdrs = [
68+
"include/rcx/array1.h",
6869
"include/rcx/box.h",
6970
"include/rcx/dbUtil.h",
7071
"include/rcx/ext.h",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <cstdio>
88
#include <cstdlib>
99

10-
namespace odb {
10+
namespace rcx {
1111

1212
template <class T>
1313
class Ath__array1D
@@ -159,4 +159,4 @@ class Ath__array1D
159159
int iter_cnt_;
160160
};
161161

162-
} // namespace odb
162+
} // namespace rcx

0 commit comments

Comments
 (0)