2016-11-08 18:57:35 +01:00
|
|
|
import sys
|
2018-07-10 23:17:09 +02:00
|
|
|
import datetime
|
|
|
|
|
import getpass
|
2016-11-08 18:57:35 +01:00
|
|
|
import debug
|
|
|
|
|
import design
|
2018-07-10 23:17:09 +02:00
|
|
|
from sram_1bank import sram_1bank
|
|
|
|
|
from sram_2bank import sram_2bank
|
|
|
|
|
from sram_4bank import sram_4bank
|
2016-11-08 18:57:35 +01:00
|
|
|
from math import log,sqrt,ceil
|
|
|
|
|
from vector import vector
|
2018-02-08 21:47:19 +01:00
|
|
|
from globals import OPTS, print_time
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-11-14 22:24:14 +01:00
|
|
|
|
2018-07-10 23:17:09 +02:00
|
|
|
class sram(sram_1bank,sram_2bank,sram_4bank):
|
2016-11-08 18:57:35 +01:00
|
|
|
"""
|
|
|
|
|
Dynamically generated SRAM by connecting banks to control logic. The
|
|
|
|
|
number of banks should be 1 , 2 or 4
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, word_size, num_words, num_banks, name):
|
2017-08-24 00:02:15 +02:00
|
|
|
|
2018-05-12 01:32:00 +02:00
|
|
|
from importlib import reload
|
2018-01-20 01:38:19 +01:00
|
|
|
c = reload(__import__(OPTS.control_logic))
|
|
|
|
|
self.mod_control_logic = getattr(c, OPTS.control_logic)
|
2018-03-19 23:11:42 +01:00
|
|
|
|
2018-01-20 01:38:19 +01:00
|
|
|
c = reload(__import__(OPTS.bitcell))
|
|
|
|
|
self.mod_bitcell = getattr(c, OPTS.bitcell)
|
2017-08-24 00:02:15 +02:00
|
|
|
self.bitcell = self.mod_bitcell()
|
2017-09-30 01:22:13 +02:00
|
|
|
|
2018-01-20 01:38:19 +01:00
|
|
|
c = reload(__import__(OPTS.ms_flop))
|
|
|
|
|
self.mod_ms_flop = getattr(c, OPTS.ms_flop)
|
2017-09-30 01:22:13 +02:00
|
|
|
self.ms_flop = self.mod_ms_flop()
|
2017-08-24 00:02:15 +02:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-06-02 20:11:57 +02:00
|
|
|
# reset the static duplicate name checker for unit tests
|
|
|
|
|
# in case we create more than one SRAM
|
2018-07-10 23:17:09 +02:00
|
|
|
from design import design
|
|
|
|
|
design.name_map=[]
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
self.word_size = word_size
|
|
|
|
|
self.num_words = num_words
|
|
|
|
|
self.num_banks = num_banks
|
|
|
|
|
|
|
|
|
|
debug.info(2, "create sram of size {0} with {1} num of words".format(self.word_size,
|
|
|
|
|
self.num_words))
|
2018-02-08 22:11:18 +01:00
|
|
|
start_time = datetime.datetime.now()
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2018-07-10 23:17:09 +02:00
|
|
|
self.compute_sizes()
|
|
|
|
|
|
|
|
|
|
if self.num_banks == 1:
|
|
|
|
|
sram_1bank.__init__(self,name)
|
|
|
|
|
elif self.num_banks == 2:
|
|
|
|
|
sram_2bank.__init__(self,name)
|
|
|
|
|
elif self.num_banks == 4:
|
|
|
|
|
sram_4bank.__init__(self,name)
|
|
|
|
|
else:
|
|
|
|
|
debug.error("Invalid number of banks.",-1)
|
2017-09-14 00:46:41 +02:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
self.control_size = 6
|
2017-12-12 23:53:19 +01:00
|
|
|
self.bank_to_bus_distance = 5*self.m3_width
|
2018-07-10 23:17:09 +02:00
|
|
|
|
2018-03-15 01:30:41 +01:00
|
|
|
self.create_modules()
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_pins()
|
|
|
|
|
self.create_layout()
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
# Can remove the following, but it helps for debug!
|
|
|
|
|
self.add_lvs_correspondence_points()
|
|
|
|
|
|
2018-03-05 23:22:24 +01:00
|
|
|
self.offset_all_coordinates()
|
2017-12-19 18:01:24 +01:00
|
|
|
sizes = self.find_highest_coords()
|
|
|
|
|
self.width = sizes[0]
|
|
|
|
|
self.height = sizes[1]
|
|
|
|
|
|
2018-02-05 23:52:51 +01:00
|
|
|
self.DRC_LVS(final_verification=True)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2018-02-08 23:58:55 +01:00
|
|
|
if not OPTS.is_unit_test:
|
|
|
|
|
print_time("SRAM creation", datetime.datetime.now(), start_time)
|
2018-02-08 22:11:18 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def compute_sizes(self):
|
2017-08-24 00:02:15 +02:00
|
|
|
""" Computes the organization of the memory using bitcell size by trying to make it square."""
|
2017-09-14 00:46:41 +02:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
debug.check(self.num_banks in [1,2,4], "Valid number of banks are 1 , 2 and 4.")
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
self.num_words_per_bank = self.num_words/self.num_banks
|
|
|
|
|
self.num_bits_per_bank = self.word_size*self.num_words_per_bank
|
|
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
# Compute the area of the bitcells and estimate a square bank (excluding auxiliary circuitry)
|
|
|
|
|
self.bank_area = self.bitcell.width*self.bitcell.height*self.num_bits_per_bank
|
2017-11-14 22:24:14 +01:00
|
|
|
self.bank_side_length = sqrt(self.bank_area)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
# Estimate the words per row given the height of the bitcell and the square side length
|
|
|
|
|
self.tentative_num_cols = int(self.bank_side_length/self.bitcell.width)
|
|
|
|
|
self.words_per_row = self.estimate_words_per_row(self.tentative_num_cols, self.word_size)
|
|
|
|
|
|
|
|
|
|
# Estimate the number of rows given the tentative words per row
|
|
|
|
|
self.tentative_num_rows = self.num_bits_per_bank / (self.words_per_row*self.word_size)
|
|
|
|
|
self.words_per_row = self.amend_words_per_row(self.tentative_num_rows, self.words_per_row)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
# Fix the number of columns and rows
|
2018-05-12 01:32:00 +02:00
|
|
|
self.num_cols = int(self.words_per_row*self.word_size)
|
|
|
|
|
self.num_rows = int(self.num_words_per_bank/self.words_per_row)
|
2017-08-24 00:02:15 +02:00
|
|
|
|
|
|
|
|
# Compute the address and bank sizes
|
2016-11-08 18:57:35 +01:00
|
|
|
self.row_addr_size = int(log(self.num_rows, 2))
|
|
|
|
|
self.col_addr_size = int(log(self.words_per_row, 2))
|
2017-08-24 00:02:15 +02:00
|
|
|
self.bank_addr_size = self.col_addr_size + self.row_addr_size
|
2017-11-14 22:24:14 +01:00
|
|
|
self.addr_size = self.bank_addr_size + int(log(self.num_banks, 2))
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-12-12 23:53:19 +01:00
|
|
|
debug.info(1,"Words per row: {}".format(self.words_per_row))
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
def estimate_words_per_row(self,tentative_num_cols, word_size):
|
2018-07-10 19:06:59 +02:00
|
|
|
"""
|
|
|
|
|
This provides a heuristic rounded estimate for the number of words
|
|
|
|
|
per row.
|
|
|
|
|
"""
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-08-24 00:02:15 +02:00
|
|
|
if tentative_num_cols < 1.5*word_size:
|
|
|
|
|
return 1
|
|
|
|
|
elif tentative_num_cols > 3*word_size:
|
|
|
|
|
return 4
|
2016-11-08 18:57:35 +01:00
|
|
|
else:
|
2017-08-24 00:02:15 +02:00
|
|
|
return 2
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def amend_words_per_row(self,tentative_num_rows, words_per_row):
|
2018-07-10 19:06:59 +02:00
|
|
|
"""
|
|
|
|
|
This picks the number of words per row more accurately by limiting
|
2017-08-24 00:02:15 +02:00
|
|
|
it to a minimum and maximum.
|
|
|
|
|
"""
|
|
|
|
|
# Recompute the words per row given a hard max
|
2016-11-08 18:57:35 +01:00
|
|
|
if(tentative_num_rows > 512):
|
2017-08-24 00:02:15 +02:00
|
|
|
debug.check(tentative_num_rows*words_per_row <= 2048, "Number of words exceeds 2048")
|
2018-05-12 01:32:00 +02:00
|
|
|
return int(words_per_row*tentative_num_rows/512)
|
2017-08-24 00:02:15 +02:00
|
|
|
# Recompute the words per row given a hard min
|
2016-11-08 18:57:35 +01:00
|
|
|
if(tentative_num_rows < 16):
|
2017-08-24 00:02:15 +02:00
|
|
|
debug.check(tentative_num_rows*words_per_row >= 16, "Minimum number of rows is 16, but given {0}".format(tentative_num_rows))
|
2018-05-12 01:32:00 +02:00
|
|
|
return int(words_per_row*tentative_num_rows/16)
|
2017-08-24 00:02:15 +02:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
return words_per_row
|
|
|
|
|
|
|
|
|
|
def add_pins(self):
|
2017-09-14 00:46:41 +02:00
|
|
|
""" Add pins for entire SRAM. """
|
|
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
for i in range(self.word_size):
|
2018-07-10 19:34:54 +02:00
|
|
|
self.add_pin("DIN[{0}]".format(i),"INPUT")
|
2016-11-08 18:57:35 +01:00
|
|
|
for i in range(self.addr_size):
|
2017-12-19 18:01:24 +01:00
|
|
|
self.add_pin("ADDR[{0}]".format(i),"INPUT")
|
2017-09-30 01:22:13 +02:00
|
|
|
|
2017-12-19 18:01:24 +01:00
|
|
|
# These are used to create the physical pins too
|
2018-03-15 01:30:41 +01:00
|
|
|
self.control_logic_inputs=self.control_logic.get_inputs()
|
|
|
|
|
self.control_logic_outputs=self.control_logic.get_outputs()
|
2017-09-30 01:22:13 +02:00
|
|
|
|
2018-03-17 01:46:29 +01:00
|
|
|
self.add_pin_list(self.control_logic_inputs,"INPUT")
|
2018-07-10 19:34:54 +02:00
|
|
|
|
|
|
|
|
for i in range(self.word_size):
|
|
|
|
|
self.add_pin("DOUT[{0}]".format(i),"OUTPUT")
|
|
|
|
|
|
2017-12-19 18:01:24 +01:00
|
|
|
self.add_pin("vdd","POWER")
|
|
|
|
|
self.add_pin("gnd","GROUND")
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-10-05 03:05:45 +02:00
|
|
|
|
2018-07-10 23:17:09 +02:00
|
|
|
def create_layout(self):
|
|
|
|
|
""" Layout creation """
|
|
|
|
|
self.add_modules()
|
|
|
|
|
self.route()
|
2017-10-05 03:05:45 +02:00
|
|
|
|
|
|
|
|
def compute_bus_sizes(self):
|
|
|
|
|
""" Compute the independent bus widths shared between two and four bank SRAMs """
|
|
|
|
|
|
|
|
|
|
# address size + control signals + one-hot bank select signals
|
|
|
|
|
self.num_vertical_line = self.addr_size + self.control_size + log(self.num_banks,2) + 1
|
|
|
|
|
# data bus size
|
2017-09-30 01:22:13 +02:00
|
|
|
self.num_horizontal_line = self.word_size
|
2017-09-14 00:46:41 +02:00
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
self.vertical_bus_width = self.m2_pitch*self.num_vertical_line
|
2017-10-05 03:05:45 +02:00
|
|
|
# vertical bus height depends on 2 or 4 banks
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
self.data_bus_height = self.m3_pitch*self.num_horizontal_line
|
2017-10-05 03:05:45 +02:00
|
|
|
self.data_bus_width = 2*(self.bank.width + self.bank_to_bus_distance) + self.vertical_bus_width
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
self.control_bus_height = self.m1_pitch*(self.control_size+2)
|
2017-10-05 03:05:45 +02:00
|
|
|
self.control_bus_width = self.bank.width + self.bank_to_bus_distance + self.vertical_bus_width
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
self.supply_bus_height = self.m1_pitch*2 # 2 for vdd/gnd placed with control bus
|
2017-10-05 03:05:45 +02:00
|
|
|
self.supply_bus_width = self.data_bus_width
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
# Sanity check to ensure we can fit the control logic above a single bank (0.9 is a hack really)
|
2018-07-10 19:06:59 +02:00
|
|
|
debug.check(self.bank.width + self.vertical_bus_width > 0.9*self.control_logic.width,
|
|
|
|
|
"Bank is too small compared to control logic.")
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-05 03:05:45 +02:00
|
|
|
def add_busses(self):
|
|
|
|
|
""" Add the horizontal and vertical busses """
|
2017-09-30 01:22:13 +02:00
|
|
|
# Vertical bus
|
|
|
|
|
# The order of the control signals on the control bus:
|
2018-03-15 01:30:41 +01:00
|
|
|
self.control_bus_names = ["clk_buf", "tri_en_bar", "tri_en", "clk_buf_bar", "w_en", "s_en"]
|
2018-07-10 19:06:59 +02:00
|
|
|
self.vert_control_bus_positions = self.create_vertical_bus(layer="metal2",
|
|
|
|
|
pitch=self.m2_pitch,
|
|
|
|
|
offset=self.vertical_bus_offset,
|
|
|
|
|
names=self.control_bus_names,
|
2018-07-10 19:34:54 +02:00
|
|
|
length=self.vertical_bus_height)
|
2017-10-05 03:05:45 +02:00
|
|
|
|
2018-03-12 21:14:53 +01:00
|
|
|
self.addr_bus_names=["A[{}]".format(i) for i in range(self.addr_size)]
|
2018-07-10 19:06:59 +02:00
|
|
|
self.vert_control_bus_positions.update(self.create_vertical_pin_bus(layer="metal2",
|
|
|
|
|
pitch=self.m2_pitch,
|
|
|
|
|
offset=self.addr_bus_offset,
|
|
|
|
|
names=self.addr_bus_names,
|
|
|
|
|
length=self.addr_bus_height))
|
2017-10-05 03:05:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
self.bank_sel_bus_names = ["bank_sel[{}]".format(i) for i in range(self.num_banks)]
|
2018-07-10 19:06:59 +02:00
|
|
|
self.vert_control_bus_positions.update(self.create_vertical_pin_bus(layer="metal2",
|
|
|
|
|
pitch=self.m2_pitch,
|
|
|
|
|
offset=self.bank_sel_bus_offset,
|
|
|
|
|
names=self.bank_sel_bus_names,
|
|
|
|
|
length=self.vertical_bus_height))
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Horizontal data bus
|
2017-10-05 03:05:45 +02:00
|
|
|
self.data_bus_names = ["DATA[{}]".format(i) for i in range(self.word_size)]
|
2018-07-10 19:06:59 +02:00
|
|
|
self.data_bus_positions = self.create_horizontal_pin_bus(layer="metal3",
|
|
|
|
|
pitch=self.m3_pitch,
|
|
|
|
|
offset=self.data_bus_offset,
|
|
|
|
|
names=self.data_bus_names,
|
|
|
|
|
length=self.data_bus_width)
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
# Horizontal control logic bus
|
|
|
|
|
# vdd/gnd in bus go along whole SRAM
|
|
|
|
|
# FIXME: Fatten these wires?
|
2018-07-10 19:06:59 +02:00
|
|
|
self.horz_control_bus_positions = self.create_horizontal_bus(layer="metal1",
|
|
|
|
|
pitch=self.m1_pitch,
|
|
|
|
|
offset=self.supply_bus_offset,
|
|
|
|
|
names=["vdd"],
|
|
|
|
|
length=self.supply_bus_width)
|
2017-10-05 03:05:45 +02:00
|
|
|
# The gnd rail must not be the entire width since we protrude the right-most vdd rail up for
|
|
|
|
|
# the decoder in 4-bank SRAMs
|
2018-07-10 19:06:59 +02:00
|
|
|
self.horz_control_bus_positions.update(self.create_horizontal_bus(layer="metal1",
|
|
|
|
|
pitch=self.m1_pitch,
|
|
|
|
|
offset=self.supply_bus_offset+vector(0,self.m1_pitch),
|
|
|
|
|
names=["gnd"],
|
|
|
|
|
length=self.supply_bus_width))
|
|
|
|
|
self.horz_control_bus_positions.update(self.create_horizontal_bus(layer="metal1",
|
|
|
|
|
pitch=self.m1_pitch,
|
|
|
|
|
offset=self.control_bus_offset,
|
|
|
|
|
names=self.control_bus_names,
|
|
|
|
|
length=self.control_bus_width))
|
|
|
|
|
|
2017-10-05 03:05:45 +02:00
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 18:15:29 +02:00
|
|
|
def route_vdd_gnd(self):
|
|
|
|
|
""" Propagate all vdd/gnd pins up to this level for all modules """
|
|
|
|
|
|
|
|
|
|
# These are the instances that every bank has
|
|
|
|
|
top_instances = [self.bitcell_array_inst,
|
|
|
|
|
self.precharge_array_inst,
|
|
|
|
|
self.sense_amp_array_inst,
|
|
|
|
|
self.write_driver_array_inst,
|
|
|
|
|
self.tri_gate_array_inst,
|
|
|
|
|
self.row_decoder_inst,
|
|
|
|
|
self.wordline_driver_inst]
|
|
|
|
|
# Add these if we use the part...
|
|
|
|
|
if self.col_addr_size > 0:
|
|
|
|
|
top_instances.append(self.col_decoder_inst)
|
|
|
|
|
top_instances.append(self.col_mux_array_inst)
|
|
|
|
|
|
|
|
|
|
if self.num_banks > 1:
|
|
|
|
|
top_instances.append(self.bank_select_inst)
|
2017-10-05 03:05:45 +02:00
|
|
|
|
2018-05-11 18:15:29 +02:00
|
|
|
|
|
|
|
|
for inst in top_instances:
|
|
|
|
|
# Column mux has no vdd
|
|
|
|
|
if self.col_addr_size==0 or (self.col_addr_size>0 and inst != self.col_mux_array_inst):
|
|
|
|
|
self.copy_layout_pin(inst, "vdd")
|
|
|
|
|
# Precharge has no gnd
|
|
|
|
|
if inst != self.precharge_array_inst:
|
|
|
|
|
self.copy_layout_pin(inst, "gnd")
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_multi_bank_modules(self):
|
|
|
|
|
""" Create the multibank address flops and bank decoder """
|
2018-07-10 23:17:09 +02:00
|
|
|
from dff_buf_array import dff_buf_array
|
2018-03-21 21:20:48 +01:00
|
|
|
self.msb_address = dff_buf_array(name="msb_address",
|
|
|
|
|
rows=1,
|
|
|
|
|
columns=self.num_banks/2)
|
2017-09-30 01:22:13 +02:00
|
|
|
self.add_mod(self.msb_address)
|
|
|
|
|
|
|
|
|
|
if self.num_banks>2:
|
|
|
|
|
self.msb_decoder = self.bank.decoder.pre2_4
|
|
|
|
|
self.add_mod(self.msb_decoder)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def create_modules(self):
|
|
|
|
|
""" Create all the modules that will be used """
|
|
|
|
|
|
2018-07-10 23:17:09 +02:00
|
|
|
from control_logic import control_logic
|
2016-11-08 18:57:35 +01:00
|
|
|
# Create the control logic module
|
2017-09-30 01:22:13 +02:00
|
|
|
self.control_logic = self.mod_control_logic(num_rows=self.num_rows)
|
|
|
|
|
self.add_mod(self.control_logic)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2018-03-15 01:30:41 +01:00
|
|
|
# Create the address and control flops (but not the clk)
|
2018-03-19 23:11:42 +01:00
|
|
|
dff_size = self.addr_size
|
2018-07-10 23:17:09 +02:00
|
|
|
from dff_array import dff_array
|
2018-03-21 23:23:32 +01:00
|
|
|
self.addr_dff = dff_array(name="dff_array", rows=dff_size, columns=1)
|
2018-03-19 23:11:42 +01:00
|
|
|
self.add_mod(self.addr_dff)
|
2018-03-12 21:14:53 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
# Create the bank module (up to four are instantiated)
|
2018-07-10 23:17:09 +02:00
|
|
|
from bank import bank
|
2016-11-08 18:57:35 +01:00
|
|
|
self.bank = bank(word_size=self.word_size,
|
|
|
|
|
num_words=self.num_words_per_bank,
|
|
|
|
|
words_per_row=self.words_per_row,
|
|
|
|
|
num_banks=self.num_banks,
|
2017-06-02 20:11:57 +02:00
|
|
|
name="bank")
|
2016-11-08 18:57:35 +01:00
|
|
|
self.add_mod(self.bank)
|
|
|
|
|
|
2018-03-12 21:14:53 +01:00
|
|
|
# Create bank decoder
|
2016-11-08 18:57:35 +01:00
|
|
|
if(self.num_banks > 1):
|
2017-09-30 01:22:13 +02:00
|
|
|
self.create_multi_bank_modules()
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
self.bank_count = 0
|
|
|
|
|
|
2018-03-05 22:49:22 +01:00
|
|
|
self.supply_rail_width = self.bank.supply_rail_width
|
|
|
|
|
self.supply_rail_pitch = self.bank.supply_rail_pitch
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
def add_bank(self, bank_num, position, x_flip, y_flip):
|
2017-09-14 00:46:41 +02:00
|
|
|
""" Place a bank at the given position with orientations """
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
# x_flip == 1 --> no flip in x_axis
|
|
|
|
|
# x_flip == -1 --> flip in x_axis
|
|
|
|
|
# y_flip == 1 --> no flip in y_axis
|
|
|
|
|
# y_flip == -1 --> flip in y_axis
|
|
|
|
|
|
|
|
|
|
# x_flip and y_flip are used for position translation
|
|
|
|
|
|
2017-09-14 00:46:41 +02:00
|
|
|
if x_flip == -1 and y_flip == -1:
|
|
|
|
|
bank_rotation = 180
|
|
|
|
|
else:
|
|
|
|
|
bank_rotation = 0
|
2016-11-08 18:57:35 +01:00
|
|
|
|
2017-09-14 00:46:41 +02:00
|
|
|
if x_flip == y_flip:
|
2016-11-08 18:57:35 +01:00
|
|
|
bank_mirror = "R0"
|
2017-09-14 00:46:41 +02:00
|
|
|
elif x_flip == -1:
|
2016-11-08 18:57:35 +01:00
|
|
|
bank_mirror = "MX"
|
2017-09-14 00:46:41 +02:00
|
|
|
elif y_flip == -1:
|
2016-11-08 18:57:35 +01:00
|
|
|
bank_mirror = "MY"
|
2017-09-14 00:46:41 +02:00
|
|
|
else:
|
|
|
|
|
bank_mirror = "R0"
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
bank_inst=self.add_inst(name="bank{0}".format(bank_num),
|
2017-09-14 00:46:41 +02:00
|
|
|
mod=self.bank,
|
|
|
|
|
offset=position,
|
|
|
|
|
mirror=bank_mirror,
|
|
|
|
|
rotate=bank_rotation)
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
temp = []
|
|
|
|
|
for i in range(self.word_size):
|
2018-05-11 18:15:29 +02:00
|
|
|
temp.append("DOUT[{0}]".format(i))
|
|
|
|
|
for i in range(self.word_size):
|
|
|
|
|
temp.append("DIN[{0}]".format(i))
|
2016-11-08 18:57:35 +01:00
|
|
|
for i in range(self.bank_addr_size):
|
2018-03-17 01:46:29 +01:00
|
|
|
temp.append("A[{0}]".format(i))
|
2016-11-08 18:57:35 +01:00
|
|
|
if(self.num_banks > 1):
|
2017-09-30 01:22:13 +02:00
|
|
|
temp.append("bank_sel[{0}]".format(bank_num))
|
2017-08-24 00:02:15 +02:00
|
|
|
temp.extend(["s_en", "w_en", "tri_en_bar", "tri_en",
|
2018-03-15 01:30:41 +01:00
|
|
|
"clk_buf_bar","clk_buf" , "vdd", "gnd"])
|
2016-11-08 18:57:35 +01:00
|
|
|
self.connect_inst(temp)
|
|
|
|
|
|
2017-09-14 00:46:41 +02:00
|
|
|
return bank_inst
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-20 00:23:13 +01:00
|
|
|
def add_addr_dff(self, position):
|
2018-03-12 21:14:53 +01:00
|
|
|
""" Add and place address and control flops """
|
2018-03-19 23:11:42 +01:00
|
|
|
self.addr_dff_inst = self.add_inst(name="address",
|
|
|
|
|
mod=self.addr_dff,
|
|
|
|
|
offset=position)
|
2018-03-12 21:14:53 +01:00
|
|
|
# inputs, outputs/output/bar
|
|
|
|
|
inputs = []
|
|
|
|
|
outputs = []
|
|
|
|
|
for i in range(self.addr_size):
|
|
|
|
|
inputs.append("ADDR[{}]".format(i))
|
|
|
|
|
outputs.append("A[{}]".format(i))
|
|
|
|
|
|
2018-03-20 00:23:13 +01:00
|
|
|
self.connect_inst(inputs + outputs + ["clk_buf", "vdd", "gnd"])
|
2018-03-12 21:14:53 +01:00
|
|
|
|
2018-03-15 01:30:41 +01:00
|
|
|
def add_control_logic(self, position):
|
2016-11-08 18:57:35 +01:00
|
|
|
""" Add and place control logic """
|
2018-03-17 01:46:29 +01:00
|
|
|
inputs = []
|
|
|
|
|
for i in self.control_logic_inputs:
|
|
|
|
|
if i != "clk":
|
|
|
|
|
inputs.append(i+"_s")
|
|
|
|
|
else:
|
|
|
|
|
inputs.append(i)
|
|
|
|
|
|
2017-09-14 00:46:41 +02:00
|
|
|
self.control_logic_inst=self.add_inst(name="control",
|
2017-09-30 01:22:13 +02:00
|
|
|
mod=self.control_logic,
|
2018-03-15 01:30:41 +01:00
|
|
|
offset=position)
|
2018-03-17 01:46:29 +01:00
|
|
|
self.connect_inst(inputs + self.control_logic_outputs + ["vdd", "gnd"])
|
2017-09-30 01:22:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_lvs_correspondence_points(self):
|
2017-12-12 23:53:19 +01:00
|
|
|
""" This adds some points for easier debugging if LVS goes wrong.
|
|
|
|
|
These should probably be turned off by default though, since extraction
|
|
|
|
|
will show these as ports in the extracted netlist.
|
|
|
|
|
"""
|
2017-09-30 01:44:24 +02:00
|
|
|
if self.num_banks==1: return
|
|
|
|
|
|
2017-09-30 01:22:13 +02:00
|
|
|
for n in self.control_bus_names:
|
|
|
|
|
self.add_label(text=n,
|
|
|
|
|
layer="metal2",
|
|
|
|
|
offset=self.vert_control_bus_positions[n])
|
|
|
|
|
for n in self.bank_sel_bus_names:
|
|
|
|
|
self.add_label(text=n,
|
|
|
|
|
layer="metal2",
|
|
|
|
|
offset=self.vert_control_bus_positions[n])
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-05 03:05:45 +02:00
|
|
|
|
|
|
|
|
|
2017-09-14 00:46:41 +02:00
|
|
|
def connect_rail_from_left_m2m3(self, src_pin, dest_pin):
|
|
|
|
|
""" Helper routine to connect an unrotated/mirrored oriented instance to the rails """
|
|
|
|
|
in_pos = src_pin.rc()
|
|
|
|
|
out_pos = vector(dest_pin.cx(), in_pos.y)
|
|
|
|
|
self.add_wire(("metal3","via2","metal2"),[in_pos, out_pos, out_pos - vector(0,self.m2_pitch)])
|
2018-03-17 01:46:29 +01:00
|
|
|
self.add_via_center(layers=("metal2","via2","metal3"),
|
|
|
|
|
offset=src_pin.rc(),
|
|
|
|
|
rotate=90)
|
2017-09-14 00:46:41 +02:00
|
|
|
|
|
|
|
|
def connect_rail_from_left_m2m1(self, src_pin, dest_pin):
|
|
|
|
|
""" Helper routine to connect an unrotated/mirrored oriented instance to the rails """
|
|
|
|
|
in_pos = src_pin.rc()
|
|
|
|
|
out_pos = vector(dest_pin.cx(), in_pos.y)
|
|
|
|
|
self.add_wire(("metal2","via1","metal1"),[in_pos, out_pos, out_pos - vector(0,self.m2_pitch)])
|
|
|
|
|
|
2018-03-17 01:46:29 +01:00
|
|
|
|
2016-11-08 18:57:35 +01:00
|
|
|
|
|
|
|
|
def sp_write(self, sp_name):
|
|
|
|
|
# Write the entire spice of the object to the file
|
|
|
|
|
############################################################
|
|
|
|
|
# Spice circuit
|
|
|
|
|
############################################################
|
|
|
|
|
sp = open(sp_name, 'w')
|
|
|
|
|
|
2018-02-03 04:33:07 +01:00
|
|
|
sp.write("**************************************************\n")
|
2016-11-08 18:57:35 +01:00
|
|
|
sp.write("* OpenRAM generated memory.\n")
|
2018-02-03 04:33:07 +01:00
|
|
|
sp.write("* Words: {}\n".format(self.num_words))
|
|
|
|
|
sp.write("* Data bits: {}\n".format(self.word_size))
|
|
|
|
|
sp.write("* Banks: {}\n".format(self.num_banks))
|
|
|
|
|
sp.write("* Column mux: {}:1\n".format(self.words_per_row))
|
|
|
|
|
sp.write("**************************************************\n")
|
2016-11-08 18:57:35 +01:00
|
|
|
# This causes unit test mismatch
|
2017-10-05 03:05:45 +02:00
|
|
|
# sp.write("* Created: {0}\n".format(datetime.datetime.now()))
|
|
|
|
|
# sp.write("* User: {0}\n".format(getpass.getuser()))
|
|
|
|
|
# sp.write(".global {0} {1}\n".format(spice["vdd_name"],
|
|
|
|
|
# spice["gnd_name"]))
|
2016-11-08 18:57:35 +01:00
|
|
|
usedMODS = list()
|
|
|
|
|
self.sp_write_file(sp, usedMODS)
|
|
|
|
|
del usedMODS
|
|
|
|
|
sp.close()
|
2017-05-30 21:50:07 +02:00
|
|
|
|
2017-11-09 20:13:44 +01:00
|
|
|
def analytical_delay(self,slew,load):
|
|
|
|
|
""" LH and HL are the same in analytical model. """
|
|
|
|
|
return self.bank.analytical_delay(slew,load)
|
2018-02-08 21:47:19 +01:00
|
|
|
|
2018-02-08 22:11:18 +01:00
|
|
|
def save_output(self):
|
2018-02-08 21:47:19 +01:00
|
|
|
""" Save all the output files while reporting time to do it as well. """
|
2018-02-08 22:11:18 +01:00
|
|
|
|
|
|
|
|
# Save the spice file
|
|
|
|
|
start_time = datetime.datetime.now()
|
2018-02-08 21:47:19 +01:00
|
|
|
spname = OPTS.output_path + self.name + ".sp"
|
|
|
|
|
print("SP: Writing to {0}".format(spname))
|
|
|
|
|
self.sp_write(spname)
|
2018-02-08 22:11:18 +01:00
|
|
|
print_time("Spice writing", datetime.datetime.now(), start_time)
|
|
|
|
|
|
|
|
|
|
# Save the extracted spice file
|
2018-02-08 21:47:19 +01:00
|
|
|
if OPTS.use_pex:
|
2018-02-08 22:11:18 +01:00
|
|
|
start_time = datetime.datetime.now()
|
|
|
|
|
# Output the extracted design if requested
|
|
|
|
|
sp_file = OPTS.output_path + "temp_pex.sp"
|
|
|
|
|
verify.run_pex(self.name, gdsname, spname, output=sp_file)
|
|
|
|
|
print_time("Extraction", datetime.datetime.now(), start_time)
|
|
|
|
|
else:
|
|
|
|
|
# Use generated spice file for characterization
|
|
|
|
|
sp_file = spname
|
2018-05-12 01:32:00 +02:00
|
|
|
print(sys.path)
|
2018-02-08 21:47:19 +01:00
|
|
|
# Characterize the design
|
2018-05-12 01:32:00 +02:00
|
|
|
start_time = datetime.datetime.now()
|
2018-02-08 21:47:19 +01:00
|
|
|
from characterizer import lib
|
2018-02-10 00:33:03 +01:00
|
|
|
print("LIB: Characterizing... ")
|
2018-02-08 21:47:19 +01:00
|
|
|
if OPTS.analytical_delay:
|
|
|
|
|
print("Using analytical delay models (no characterization)")
|
|
|
|
|
else:
|
|
|
|
|
if OPTS.spice_name!="":
|
|
|
|
|
print("Performing simulation-based characterization with {}".format(OPTS.spice_name))
|
|
|
|
|
if OPTS.trim_netlist:
|
|
|
|
|
print("Trimming netlist to speed up characterization.")
|
2018-05-12 01:32:00 +02:00
|
|
|
lib(out_dir=OPTS.output_path, sram=self, sp_file=sp_file)
|
2018-02-08 22:11:18 +01:00
|
|
|
print_time("Characterization", datetime.datetime.now(), start_time)
|
2018-02-08 21:47:19 +01:00
|
|
|
|
|
|
|
|
# Write the layout
|
2018-02-08 22:11:18 +01:00
|
|
|
start_time = datetime.datetime.now()
|
2018-02-08 21:47:19 +01:00
|
|
|
gdsname = OPTS.output_path + self.name + ".gds"
|
|
|
|
|
print("GDS: Writing to {0}".format(gdsname))
|
|
|
|
|
self.gds_write(gdsname)
|
2018-02-08 22:11:18 +01:00
|
|
|
print_time("GDS", datetime.datetime.now(), start_time)
|
2018-02-08 21:47:19 +01:00
|
|
|
|
|
|
|
|
# Create a LEF physical model
|
2018-02-08 22:11:18 +01:00
|
|
|
start_time = datetime.datetime.now()
|
2018-02-08 21:47:19 +01:00
|
|
|
lefname = OPTS.output_path + self.name + ".lef"
|
|
|
|
|
print("LEF: Writing to {0}".format(lefname))
|
|
|
|
|
self.lef_write(lefname)
|
2018-02-08 22:11:18 +01:00
|
|
|
print_time("LEF", datetime.datetime.now(), start_time)
|
2018-02-08 21:47:19 +01:00
|
|
|
|
|
|
|
|
# Write a verilog model
|
2018-02-08 22:11:18 +01:00
|
|
|
start_time = datetime.datetime.now()
|
2018-02-08 21:47:19 +01:00
|
|
|
vname = OPTS.output_path + self.name + ".v"
|
|
|
|
|
print("Verilog: Writing to {0}".format(vname))
|
|
|
|
|
self.verilog_write(vname)
|
2018-02-08 22:11:18 +01:00
|
|
|
print_time("Verilog", datetime.datetime.now(), start_time)
|