2023年4月11日 星期二

Vim設定檔

 "In ~/.vimrc
set bg=dark
set number
set backspace=2
set hlsearch
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set mouse=a
set breakindent
set linebreak
set showbreak=>>
set belloff=all
set clipboard=unnamedplus
"set clipboard=unnamed
syntax on
filetype on
filetype plugin on
filetype indent on
colorscheme default
nnoremap <C-g> 1<C-g>

2023年3月29日 星期三

Linux新增使用者指令

在Linux系統中新增使用者:

 useradd 使用者名稱

useradd -g 主要群組 使用者名稱

useradd -g 主要群組 -G 次要群組1,次要群組2 使用者名稱

創建完成後會自動在/home目錄下建立一個使用者的家目錄


更改使用者所屬的群組

usermod -g 主要群組 使用者名稱

usermod -a -G 次要群組 使用者名稱


2023年3月7日 星期二

一些 Python 中好用的功能

 查詢一個 Object 中有哪些可用的 Method:

    dir(object_name)

查詢一個 Method 的使用方式:

    help(object_name.method_name)

    寫在一個檔案 (module)、函式 (function) 和類別 (class) 最開頭的多行註解會自動轉為 module、function、class 的 __doc__ 變數的內容,會被當成 help message 印出。

2022年12月16日 星期五

自動修復 Hold Time Violation 的程式

以下程式會自動讀取 timing report 中的 hold time violation,跟據 clock pin name 找到 flip-flop,並且在 flip-flop output pin 的 net 上自動加入 delay cell。反覆執行以上動作直到所有的 hold time violation 都被修復為止。

In Tcl File:

proc fix_hold_time_violations {} {
    report_timing -delay_type min > top_hold.rpt
    set target_pin [exec python get_hold_time_violation.py top_hold.rpt]
    while {$target_pin != {}} {
        set target_net [get_nets -of_objects $target_pin]
        insert_buffer [get_nets $target_net] DELAY_CELL_NAME
        legalize_placement -cells [get_cells -hierarchical {eco_cell*}]
        route_zrt_eco -reroute modified_nets_only
        report_timing -delay_type min > top_hold.rpt
        set target_pin [exec python get_hold_time_violation.py top_hold.rpt]
    }
    derive_pg_connection -power_net VDD -ground_net VSS -power_pin VDD -ground_pin VSS
}

In Python File:

import sys
clock_pin_name1 = "CP"
clock_pin_name2 = "CLK"
if len(sys.argv) == 2:
    fname = sys.argv[1]
    with open(fname, "r") as f:
        lines = f.readlines()
        need_fix = 0
        for i in range(len(lines)):
            line = lines[i]
            if "slack" in line:
                if "VIOLATED" in line:
                    need_fix = 1
                break
        if need_fix:
            start = 0
            for i in range(len(lines)):
                line = lines[i]
                if "clock network delay" in line:
                    start = i
                    break
            if start:
                target_cell = ""
                for i in range(start, len(lines)):
                    line = lines[i]
                    if "/" + clock_pin_name1 in line or "/" + clock_pin_name2 in line:
                        start = i + 1
                        target_cell = line.split()[1][1:-1]
                        break
                if target_cell != "":
                    for i in range(start, len(lines)):
                        line = lines[i]
                        if target_cell in line:
                            start = i + 1
                            target_pin = line.split()[0]
                            print(target_pin)
                            break

2022年12月14日 星期三

自動修復 Short Error 的程式

以下程式利用 IC Compiler 的 verify_lvs 指令回報發生 short error 的 nets,用 python 將 short nets 擷取出來,將其刪除並重新繞線。反覆執行此流程直到所有 short errors 都被修復為止。

In Tcl File:

proc fix_short_nets {} {
    verify_lvs > lvs_result.txt
    set short_nets [exec python get_short_nets.py lvs_result.txt]
    while {$short_nets != {}} {
        remove_net_routing $short_nets
        route_zrt_eco -nets $short_nets -reroute modified_nets_only
        verify_lvs > lvs_result.txt
        set short_nets [exec python3 get_short_nets.py lvs_result.txt]
    }
}

In Python File:

import sys
short_net_list = []
if len(sys.argv) == 2:
    fname = sys.argv[1]
    with open(fname, "r") as f:
        lines = f.readlines()
        record = 0
        for line in lines:
            if "ERROR :" in line and "nets short together." in line:
                record = 1
            elif line == "\n":
                record = 0
            if record and not "ERROR :" in line:
                net = line.split()[0]
                if net != "VDD" and net != "VSS":
                    short_net_list.append(net)
for net in short_net_list:
    print(net, end = ' ')

2022年11月30日 星期三

Clock Gating 是什麼?怎麼做?

 

在同步數位邏輯電路中,所有 flip-flop 都是由一個 clock 訊號來觸發。由於 clock 是不斷地進行振盪的訊號,即使 flip-flop 的資料沒有改變,只要 clock 訊號變化,都會造成 flip-flop 上的能源消耗。為了降低晶片的功耗,clock gating 是一樣很重要的技術。

其概念是在 flip-flop 不需要運作的時候,將其 clock 訊號停住。在 standard cell library 中有提供 Clock Gating Cell,如下圖所示。

其中 E 是一個 enable 訊號,當 E = 1 時,代表 flip-flop 需要被觸發。當 E = 0 時,代表 flip-flop 不需要運作。GCLK 是 gated clock,是由一個 AND gate 產生,只有當 Q = 1 時,GCLK 才會等於 CLK,否則 GCLK 都是 0。

從波形中可以看出,當 E 改變時,Q 並不會馬上跟著改變,而要等到 CLK = 0 的時候,Q 才會變成 E。這樣做的用意是為了避免 GCLK 上產生毛刺 (glitch)。由於 clock 的 rising/falling edge 會觸發運算,在 clock 上的 glitch 是不允許的。

各位可以試著畫圖看看,假如直接讓 E 來控制 AND gate,當 E 從 1 變成 0 時,會使 GCLK 產生一個 glitch。(請記得 E 訊號是由 clock rising edge 觸發的,因此它總是會稍晚於 clock rising edge。)

大家應該也有注意到,除了 E 以外,還有一個 TE 訊號,這是 test enable 訊號。當我們要進行測試時,必須透過 scan chain 來進行,此時必須讓 clock 能夠送到所有的 flip-flop 上,因此當 TE = 1 時,GCLK 會一直等於 CLK。

要如何加入 clock gating 呢?目前的 Design Compiler 都有支援,可以自動根據 RTL code 來判斷哪些 flip-flop 要執行 clock gating 來降低 power consumption。由於 Clock Gating Cell 本身會占用面積,也是會耗電,假如每個 flip-flop 都進行 clock gating,並非最好的做法。這部份 Design Compiler 也會協助判斷。

只要在進行合成的時候,在 compile 指令後面加上一個 -gate_clock 的選項即可,如下:

compile_ultra -gate_clock


2022年8月12日 星期五

如何對 black box macro 進行時序約束

 進行 place and route 時,可能有些 macro 是 full-custom design,沒有針對此 macro 建立 timing library,對 IC compiler 來說,就是一個黑盒子,對於這種 black box macro,可透過以下指令進行時序約束。

Black Box Macro 的 Clock

set_clock_tree_exceptions -stop_pins [get_pins macro/CLK]

Black Box Macro 的輸入訊號

set_output_delay -max $MACRO_IN_DELAY -clock clk -reference_pin [get_pins macro/CLK] [get_pins macro/IN]

set_output_delay -min $MACRO_HOLD -clock clk -reference_pin [get_pins macro/CLK] [get_pins macro/IN]

$MACRO_IN_DELAY 是 macro 輸入訊號抵達內部 flip-flop 的延遲時間。$MACRO_HOLD 是內部 flip-flop 所需的 hold time 的負值 ($MACRO_HOLD 是負數)。

Black Box Macro 的輸出訊號

set_input_delay -max $MACRO_CLK_Q -clock clk -reference_pin [get_pins macro/CLK] [get_pins macro/OUT]

set_input_delay -min 0.0 -clock clk -reference_pin [get_pins macro/CLK] [get_pins macro/OUT]

$MACRO_CLK_Q 是 macro 內部flip-flop 的 clock to output 時間。

-max 和 -min 的設定都是必要的,假如只設定了 max delay,min delay 的延遲時間就會與 max delay 一樣。

參考資料

Static Timing Analysis for Nanometer Designs: A Practical Approach (2009)
by Rakesh Chadha & J. Bhasker