3D-ICE 3.0.0
ic_element.c
1/******************************************************************************
2 * This file is part of 3D-ICE, version 3.1.0 . *
3 * *
4 * 3D-ICE is free software: you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free *
6 * Software Foundation, either version 3 of the License, or any later *
7 * version. *
8 * *
9 * 3D-ICE is distributed in the hope that it will be useful, but WITHOUT *
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
12 * more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along *
15 * with 3D-ICE. If not, see <http://www.gnu.org/licenses/>. *
16 * *
17 * Copyright (C) 2021 *
18 * Embedded Systems Laboratory - Ecole Polytechnique Federale de Lausanne *
19 * All Rights Reserved. *
20 * *
21 * Authors: Arvind Sridhar Alessandro Vincenzi *
22 * Giseong Bak Martino Ruggiero *
23 * Thomas Brunschwiler Eder Zulian *
24 * Federico Terraneo Darong Huang *
25 * Luis Costero Marina Zapater *
26 * David Atienza *
27 * *
28 * For any comment, suggestion or request about 3D-ICE, please register and *
29 * write to the mailing list (see http://listes.epfl.ch/doc.cgi?liste=3d-ice) *
30 * Any usage of 3D-ICE for research, commercial or other purposes must be *
31 * properly acknowledged in the resulting products or publications. *
32 * *
33 * EPFL-STI-IEL-ESL Mail : 3d-ice@listes.epfl.ch *
34 * Batiment ELG, ELG 130 (SUBSCRIPTION IS NECESSARY) *
35 * Station 11 *
36 * 1015 Lausanne, Switzerland Url : http://esl.epfl.ch/3d-ice *
37 ******************************************************************************/
38
39#include <stdlib.h> // For the memory functions malloc/free
40
41#include "ic_element.h"
42#include "macros.h"
43
44/******************************************************************************/
45
47{
48 icel->SW_X = (ChipDimension_t) 0.0 ;
49 icel->SW_Y = (ChipDimension_t) 0.0 ;
50 icel->Length = (ChipDimension_t) 0.0 ;
51 icel->Width = (ChipDimension_t) 0.0 ;
52 icel->Discr_X = (ChipDimension_t) 0.0 ;
53 icel->Discr_Y = (ChipDimension_t) 0.0 ;
54 icel->SW_Row = (CellIndex_t) 0u ;
55 icel->SW_Column = (CellIndex_t) 0u ;
56 icel->NE_Row = (CellIndex_t) 0u ;
57 icel->NE_Column = (CellIndex_t) 0u ;
58 icel->Index_start = (CellIndex_t) 0u ;
59 icel->Index_end = (CellIndex_t) 0u ;
60}
61
62/******************************************************************************/
63
65{
66 ic_element_destroy (dst) ;
67
68 dst->SW_X = src->SW_X ;
69 dst->SW_Y = src->SW_Y ;
70 dst->Length = src->Length ;
71 dst->Width = src->Width ;
72 dst->Discr_X = src->Discr_X ;
73 dst->Discr_Y = src->Discr_Y ;
74 dst->SW_Row = src->SW_Row ;
75 dst->SW_Column = src->SW_Column ;
76 dst->NE_Row = src->NE_Row ;
77 dst->NE_Column = src->NE_Column ;
78 dst->Index_start = src->Index_start ;
79 dst->Index_end = src->Index_end ;
80}
81
82/******************************************************************************/
83
85{
86 // Nothing to do ...
87
88 ic_element_init (icel) ;
89}
90
91/******************************************************************************/
92
94{
95 ICElement_t *icel = (ICElement_t *) malloc (sizeof(ICElement_t));
96
97 if (icel != NULL)
98
99 ic_element_init (icel) ;
100
101 return icel ;
102}
103
104/*****************************************************************************/
105
107{
108 if (icel == NULL)
109
110 return NULL ;
111
112 ICElement_t *newi = ic_element_calloc ( ) ;
113
114 if (newi != NULL)
115
116 ic_element_copy (newi, icel) ;
117
118 return newi ;
119}
120
121/*****************************************************************************/
122
124{
125 if (icel == NULL)
126
127 return ;
128
129 ic_element_destroy (icel) ;
130
131 free (icel) ;
132}
133
134/******************************************************************************/
135
137{
138 return icel->SW_X == other->SW_X
139 && icel->SW_Y == other->SW_Y
140 && icel->Length == other->Length
141 && icel->Width == other->Width ;
142}
143
144/******************************************************************************/
145
147(
148 ICElement_t *icel,
149 FILE *stream,
150 String_t prefix
151)
152{
153 fprintf (stream,
154 "%s rectangle (%.1f, %.1f, %.1f, %.1f ) ;\n",
155 prefix, icel->SW_X, icel->SW_Y,
156 icel->Length, icel->Width) ;
157}
158
159/******************************************************************************/
160
162(
163 ICElement_t *icelement,
164 CellDimension_t cellx,
165 CellDimension_t celly
166)
167{
168 return ( cellx >= icelement->SW_X
169 && celly >= icelement->SW_Y
170 && cellx < icelement->SW_X + icelement->Length
171 && celly < icelement->SW_Y + icelement->Width) ;
172}
173
174/******************************************************************************/
175
177(
178 ICElement_t *icelement_a,
179 ICElement_t *icelement_b
180)
181{
182 if (icelement_a == icelement_b)
183
184 return false ;
185
186 if ( (icelement_a->SW_X + icelement_a->Length)
187 <= icelement_b->SW_X
188 || icelement_a->SW_X
189 >= (icelement_b->SW_X + icelement_b->Length))
190
191 return false ;
192
193 if ( (icelement_a->SW_Y + icelement_a->Width)
194 <= icelement_b->SW_Y
195 || icelement_a->SW_Y
196 >= (icelement_b->SW_Y + icelement_b->Width))
197
198 return false ;
199
200 return true ;
201}
202
203/******************************************************************************/
204
205bool check_location (ICElement_t *icel, Dimensions_t *dimensions)
206{
207 return ( (icel->SW_X < 0.0)
208
209 || (icel->SW_X + icel->Length > get_chip_length (dimensions))
210
211 || (icel->SW_Y < 0.0)
212
213 || (icel->SW_Y + icel->Width > get_chip_width (dimensions)) ) ;
214}
215
216/******************************************************************************/
217
218void align_to_grid (ICElement_t *icel, Dimensions_t *dimensions)
219{
220 /* We "search" for these values instead of computing them directly
221 since the lengths of the cells along the length of the ic might not
222 be uniform
223 */
224
225 /* West side */
226
227 CellIndex_t column_index = first_column (dimensions) ;
228
229 while (get_cell_location_x (dimensions, column_index + 1) <= icel->SW_X)
230
231 column_index++ ;
232
233 icel->SW_Column = column_index-- ;
234
235 /* East side */
236
237 while (get_cell_location_x (dimensions, column_index + 1) < icel->SW_X + icel->Length)
238
239 column_index++ ;
240
241 icel->NE_Column = column_index ;
242
243 /* South side */
244
245 CellIndex_t row_index = first_row (dimensions) ;
246
247 while (get_cell_location_y (dimensions, row_index + 1) <= icel->SW_Y)
248
249 row_index++ ;
250
251 icel->SW_Row = row_index-- ;
252
253 /* North side */
254
255 while (get_cell_location_y (dimensions, row_index + 1) < icel->SW_Y + icel->Width)
256
257 row_index++ ;
258
259 icel->NE_Row = row_index ;
260}
261
262/******************************************************************************/
263
265(
266 ICElement_t *icel,
267 Dimensions_t *dimensions,
268 Temperature_t *temperatures
269)
270{
271 CellIndex_t row = icel->SW_Row ;
272 CellIndex_t column = icel->SW_Column ;
273 Temperature_t max_temperature;
274
275 if (dimensions->NonUniform == 1)
276 {
277 max_temperature = *(temperatures + icel->Index_start) ;
278 for (CellIndex_t i = icel->Index_start; i<= icel->Index_end; i++)
279 {
280 max_temperature = MAX
281 (
282 max_temperature,
283 *(temperatures + i)
284 ) ;
285 }
286 }
287 else
288 {
289 max_temperature =
290
291 *(temperatures + get_cell_offset_in_layer(dimensions, row, column)) ;
292
293 for (row = icel->SW_Row ; row <= icel->NE_Row ; row++)
294 {
295 for (column = icel->SW_Column ; column <= icel->NE_Column ; column++)
296 {
297 max_temperature = MAX
298 (
299 max_temperature,
300 *(temperatures + get_cell_offset_in_layer (dimensions, row, column))
301 ) ;
302
303 } // FOR_EVERY_IC_ELEMENT_COLUMN
304 } // FOR_EVERY_IC_ELEMENT_ROW
305 }
306
307 return max_temperature ;
308}
309
310/******************************************************************************/
311
313(
314 ICElement_t *icel,
315 Dimensions_t *dimensions,
316 Temperature_t *temperatures
317)
318{
319 CellIndex_t row = icel->SW_Row ;
320 CellIndex_t column = icel->SW_Column ;
321 Temperature_t min_temperature;
322
323 if (dimensions->NonUniform == 1)
324 {
325 min_temperature =
326
327 *(temperatures + icel->Index_start) ;
328 for (CellIndex_t i = icel->Index_start; i<= icel->Index_end; i++)
329 {
330 min_temperature = MIN
331 (
332 min_temperature,
333 *(temperatures + i)
334 ) ;
335 }
336 }
337 else
338 {
339 min_temperature =
340
341 *(temperatures + get_cell_offset_in_layer(dimensions, row, column)) ;
342
343 for (row = icel->SW_Row ; row <= icel->NE_Row ; row++)
344 {
345 for (column = icel->SW_Column ; column <= icel->NE_Column ; column++)
346 {
347 min_temperature = MIN
348 (
349 min_temperature,
350 *(temperatures + get_cell_offset_in_layer (dimensions, row, column))
351 ) ;
352
353 } // FOR_EVERY_IC_ELEMENT_COLUMN
354 } // FOR_EVERY_IC_ELEMENT_ROW
355 }
356
357
358
359 return min_temperature ;
360}
361
362/******************************************************************************/
363
365(
366 ICElement_t *icel,
367 Dimensions_t *dimensions,
368 Temperature_t *temperatures
369)
370{
371 CellIndex_t row ;
372 CellIndex_t column ;
373 CellIndex_t counter = 0u ;
374
375 Temperature_t avg_temperature = 0.0 ;
376
377 if (dimensions->NonUniform == 1)
378 {
379 for (CellIndex_t i = icel->Index_start; i<= icel->Index_end; i++)
380 {
381 avg_temperature += *(temperatures + i) ;
382 counter++ ;
383 }
384 }
385 else
386 {
387 for (row = icel->SW_Row ; row <= icel->NE_Row ; row++)
388 {
389 for (column = icel->SW_Column ; column <= icel->NE_Column ; column++)
390 {
391 avg_temperature +=
392
393 *(temperatures + get_cell_offset_in_layer (dimensions, row, column)) ;
394
395 counter++ ;
396
397 } // FOR_EVERY_IC_ELEMENT_COLUMN
398 } // FOR_EVERY_IC_ELEMENT_ROW
399 }
400 return avg_temperature / (Temperature_t) counter ;
401}
402
403/******************************************************************************/
ChipDimension_t get_chip_length(Dimensions_t *dimensions)
Definition: dimensions.c:699
ChipDimension_t get_cell_location_y(Dimensions_t *dimensions, CellIndex_t row_index)
Definition: dimensions.c:621
ChipDimension_t get_chip_width(Dimensions_t *dimensions)
Definition: dimensions.c:706
ChipDimension_t get_cell_location_x(Dimensions_t *dimensions, CellIndex_t column_index)
Definition: dimensions.c:602
CellIndex_t get_cell_offset_in_layer(Dimensions_t *dimensions, CellIndex_t row_index, CellIndex_t column_index)
Definition: dimensions.c:674
CellIndex_t first_column(Dimensions_t *dimensions)
CellIndex_t first_row(Dimensions_t *dimensions)
bool check_intersection(ICElement_t *icelement_a, ICElement_t *icelement_b)
Definition: ic_element.c:177
Temperature_t get_avg_temperature_ic_element(ICElement_t *icel, Dimensions_t *dimensions, Temperature_t *temperatures)
Definition: ic_element.c:365
void ic_element_print(ICElement_t *icel, FILE *stream, String_t prefix)
Definition: ic_element.c:147
bool ic_element_equal(ICElement_t *icel, ICElement_t *other)
Definition: ic_element.c:136
Temperature_t get_min_temperature_ic_element(ICElement_t *icel, Dimensions_t *dimensions, Temperature_t *temperatures)
Definition: ic_element.c:313
Temperature_t get_max_temperature_ic_element(ICElement_t *icel, Dimensions_t *dimensions, Temperature_t *temperatures)
Definition: ic_element.c:265
void ic_element_copy(ICElement_t *dst, ICElement_t *src)
Definition: ic_element.c:64
ICElement_t * ic_element_clone(ICElement_t *icel)
Definition: ic_element.c:106
ICElement_t * ic_element_calloc(void)
Definition: ic_element.c:93
void ic_element_destroy(ICElement_t *icel)
Definition: ic_element.c:84
void ic_element_free(ICElement_t *icel)
Definition: ic_element.c:123
bool check_location(ICElement_t *icel, Dimensions_t *dimensions)
Definition: ic_element.c:205
void align_to_grid(ICElement_t *icel, Dimensions_t *dimensions)
Definition: ic_element.c:218
void ic_element_init(ICElement_t *icel)
Definition: ic_element.c:46
bool ic_element_has_center(ICElement_t *icelement, CellDimension_t cellx, CellDimension_t celly)
Definition: ic_element.c:162
#define MIN(a, b)
Definition: macros.h:78
#define MAX(a, b)
Definition: macros.h:69
char * String_t
Definition: string_t.h:55
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
uint8_t NonUniform
Definition: dimensions.h:326
ChipDimension_t Discr_X
Definition: ic_element.h:85
CellIndex_t Index_start
Definition: ic_element.h:113
ChipDimension_t SW_Y
Definition: ic_element.h:73
ChipDimension_t SW_X
Definition: ic_element.h:69
CellIndex_t NE_Column
Definition: ic_element.h:109
CellIndex_t Index_end
Definition: ic_element.h:117
ChipDimension_t Width
Definition: ic_element.h:81
ChipDimension_t Length
Definition: ic_element.h:77
CellIndex_t SW_Row
Definition: ic_element.h:94
CellIndex_t NE_Row
Definition: ic_element.h:104
ChipDimension_t Discr_Y
Definition: ic_element.h:89
CellIndex_t SW_Column
Definition: ic_element.h:99
double ChipDimension_t
Definition: types.h:187
double Temperature_t
Definition: types.h:71
double CellDimension_t
Definition: types.h:177
uint32_t CellIndex_t
Definition: types.h:213