88################################################################################
99
1010
11+ import math
12+
13+
14+ def pick_column_mux_factor (rows , bits ):
15+ """Fold a tall array into a square one.
16+
17+ The array is rows/factor cells tall and bits*factor cells wide, so
18+ the factor that squares it is sqrt(rows/bits). Rounded to a power of
19+ two because a column mux selects one of 2^n bit lines, and clamped
20+ at 1 so a wide, shallow memory is left alone.
21+
22+ Area does not change: this moves cells between the two dimensions
23+ rather than adding or removing any.
24+ """
25+ if rows <= 0 or bits <= 0 :
26+ return 1
27+ ideal = math .sqrt (float (rows ) / float (bits ))
28+ if ideal <= 1.0 :
29+ return 1
30+ lo = 2 ** math .floor (math .log2 (ideal ))
31+ hi = lo * 2
32+ # Nearest in log space, which is what "closest to square" means when
33+ # the candidates are powers of two.
34+ return lo if (ideal / lo ) <= (hi / ideal ) else hi
35+
36+
1137class Process :
1238 def __init__ (self , json_data ):
1339 """Initialize from json_data imported from config file"""
@@ -23,9 +49,14 @@ def __init__(self, json_data):
2349 self .contacted_poly_pitch_nm = json_data .get ("contacted_poly_pitch_nm" , None )
2450 self .fin_pitch_nm = json_data .get ("fin_pitch_nm" , None )
2551 self .manufacturing_grid_nm = int (json_data ["manufacturing_grid_nm" ])
26- self .column_mux_factor = int (json_data ["column_mux_factor" ])
2752
2853 # Optional keys
54+ # Absent means get_macro_dimensions picks one per memory
55+ self .column_mux_factor = (
56+ int (json_data ["column_mux_factor" ])
57+ if "column_mux_factor" in json_data
58+ else None
59+ )
2960 self .snap_width_nm = (
3061 int (json_data ["snap_width_nm" ]) if "snap_width_nm" in json_data else 1
3162 )
@@ -99,7 +130,6 @@ def get_macro_dimensions(self, width_in_bits, depth, num_banks, additional_heigh
99130 and process parameters
100131 """
101132
102- column_mux_factor = self .column_mux_factor
103133 bitcell_width , bitcell_height = self .get_bitcell_dimensions ()
104134
105135 all_bitcell_height = bitcell_height * depth
@@ -111,6 +141,11 @@ def get_macro_dimensions(self, width_in_bits, depth, num_banks, additional_heigh
111141 elif num_banks != 1 :
112142 raise Exception ("Unsupported number of banks: {}" .format (num_banks ))
113143
144+ column_mux_factor = self .column_mux_factor
145+ if column_mux_factor is None :
146+ column_mux_factor = pick_column_mux_factor (
147+ depth / num_banks , width_in_bits * num_banks
148+ )
114149 all_bitcell_height = all_bitcell_height / column_mux_factor
115150 all_bitcell_width = all_bitcell_width * column_mux_factor
116151
@@ -202,7 +237,7 @@ def get_y_step(self):
202237 return self .y_step
203238
204239 def get_column_mux_factor (self ):
205- """Returns the column mux factor"""
240+ """Returns the column mux factor, None if picked per memory """
206241 return self .column_mux_factor
207242
208243 def set_calc_dimensions (self , val ):
0 commit comments