顯示具有 計算機組織 標籤的文章。 顯示所有文章
顯示具有 計算機組織 標籤的文章。 顯示所有文章

2009年10月8日 星期四

Bandwidth vs. Throughput


Bandwidth跟Throughput的定義解釋影片

2008年8月27日 星期三

2-bit Left Shift

32位元左移2位元
// 32-bit Shift left by 2
module leftShift2 (in,out);
input [31:0] in;
output [31:0] out;
reg [31:0] out;
out = { in[29:0], 1'b0, 1'b0 };
endmodule // leftShift2

module leftShift2 (in,out);
input [31:0] in;
output [31:0] out;
reg [31:0] out;
out = in << 2;
endmodule

參考來源:
http://inst.eecs.berkeley.edu/~cs61c/fa04/lectures/L26-dg-singlecpu.pdf

16-bits Sign Extender to 32-bits

這個Sign Extender主要是希望把16bits的有號數變成32bits的有號數
verilog範例程式如下:
// Sign extender from 16- to 32-bits.
module signExtend (in,out);
input [15:0] in;
output [31:0] out;
reg [31:0] out;
out = { in[15], in[15], in[15], in[15],
in[15], in[15], in[15], in[15],
in[15], in[15], in[15], in[15],
in[15], in[15], in[15], in[15],
in[15:0] };
endmodule // signExtend

另一個比較好的寫法
// Sign Extender
module SignExtend(In, Out);
input [15:0] In;
output [31:0] Out;
assign Out = {{16{In[15]}},In[15:0]};
endmodule

Joint(Concatenation) Operation - Joint different operands as one by { and }
Example 1:
// A = 1'b1, B = 2'b00, C = 2'b10, D = 3'b110
Y = { B, C} // Y is 4'b0010
Y = { A, B, C, D, 3'b001} // Y is 11'b10010110001
Y = { A, B[0], C[1]} // Y is 3'b101
Example 2:
wire [1:0] a, b; wire [2:0] x; wire [3;0] y, Z;
assign x = {1’b0, a}; // x[2]=0, x[1]=a[1], x[0]=a[0]
assign y = {a, b}; /* y[3]=a[1], y[2]=a[0], y[1]=b[1],
y[0]=b[0] */
assign {cout, y} = x + Z; // Concatenation of a result

Replication Operation - Repetition operand several times
Example 1:
A = 1'b1; B = 2'b00; C = 2'b10; D = 3'b110;
Y = { 4{A} } // Y is 4'b1111
Y = { 4{A}, 2{B}, C} //Y is 8'b1111000010

Example 2:
wire [1:0] a, b; wire [4:0] x;
assign x = {2{1’b0}, a}; // Equivalent to x = {0,0,a }
assign y = {2{a}, 3{b}}; //Equivalent to y = {a,a,b,b,b}

有parameter的寫法
<code>module SIGN_EXTEND(in, out);
parameter INSIZE = 16, OUTSIZE = 32;

input [INSIZE-1:0] in;
output [OUTSIZE-1:0] out;
assign out = {{ OUTSIZE-INSIZE {in[INSIZE-1]}}, in};
endmodule // SIGN_EXTEND</code>

資料來源:
berkeley Single Cycle CPU Datapath with Verilog
Multicycle Processor Design in Verilog

2008年8月26日 星期二

Register File in Verilog

在CPU裏面最重要的結構就是暫存器檔案(Register File)。Reading the Register FileWriting into the Register File底下列出簡單的Register File的Verilog範例程式碼

I/O Input
(1)Clock Signal(時脈訊號):clk
(2)Write Enable Signal(寫入暫存器訊號):en_write
(3)Address Bus(指定暫存器編號,需要3個5位元):ra1、ra2、wa
(4)Input Data Bus(寫入的資料,需要1個32位元):wd

I/O Output
(1)Output Data Bus(輸出的資料,需要2個32位元):rd1,rd2
module regfile
(
input [4:0] ra1,output [31:0] rd1,
input [4:0] ra2,output [31:0] rd2,
input clk,
input en_write,
input [4:0] wa,input [31:0] wd
);

reg [31:0] registers[31:0];
// 暫存器0永遠輸出0
assign rd1 = (ra1 == 5'b00000) ? 32'h00000000 : registers[ra1];
assign rd2 = (ra2 == 5'b00000) ? 32'h00000000 : registers[ra2];
// 當en_write=1時,執行將wd寫入暫存器的動作
always @(posedge clk)
begin
if ( en_write )
registers[wa] <= wd;
end

endmodule

2008年8月1日 星期五

Single Cycle,Multi Cycle vs Pipeline



  1. Single cycle:Basicly one instruction one Cycle, and critical path more long.

  2. Multi cycle:one instruction many Cycle, buf critical path shorter then Single cycle.Using FSM to implement one instruction.


    1. Break instruction execution into multiple cycles

    2. One clock cycle for each major task


      1. Instruction Fetch

      2. Instruction Decode and Register Fetch

      3. Execution, memory address computation, or branch computation

      4. Memory access / R-type instruction completion

      5. Memory read completion

    3. Share hardware to simplify datapath。

  3. pipeline:Instruction to go through a several clock. A clock to complete an Instruction, but exception of some special exceptions Instruction.


  • Single Cycle

  • 假設有一台全功能洗衣機,4項功能可以全自動做完
    (1)洗衣服(20分鐘)
    (2)脫水(20分鐘)
    (3)烘乾(30分鐘)
    (4)燙衣服(20分鐘)

    但是在Single Cycle缺點是,每一個功能所花的時間必需一樣,所以需取最大值30分鐘,
    而且這個"洗衣服的工作"必需從頭做到尾才行。
    所以要收衣服,就是一定要30+30+30+30=120分鐘後,去收衣服才行。

  • Multiple Cycle

  • 也是同樣的一台全功能洗衣機,也是一樣4個步驟。
    但它會變成不是全自動的,而是你必需每隔30分鐘去看一次,
    洗衣服的工作是否要進入下一個步驟
    洗衣服->脫水->烘乾->燙衣服
    這樣子的好處是如果有衣服不能烘或不能燙,那就可以跳過該步驟以節省時間。
    但還是一樣有浪費掉的時間,因為每個步驟所花的時間也是必需一樣的。

  • Multiple Cycle with Pipeline

  • 把原本的一台全功能洗衣機,變4台專職的機器
    (1)專門洗衣服的機器
    (2)專門脫水的機器
    (3)專門烘乾的機器
    (4)專門燙衣服的機器
    這樣子一來,當第一批衣服一洗完拿去脫水後,第二批衣服就可以開始洗了,可以加速洗衣服的速度。


    總結一下
    Single Cycle主要目的是希望所有的指令皆在一個Cycle執行完畢,所以呢,最快的指令必需等待最慢的指令。
    Multi Cycle就是為了解決Single Cycle效率不夠好的情況,讓最快的指令不必去等待最慢的指令。
    Pipeline主要的目的是希望在同一個時間內能執行多道指令,增加效能。

    Enhancing Performance with Pipelining
    Lab2

    底下這個網頁不錯唷,有用Java做成的Single Cycle Datapath及Pipeline Datapath
    Computer Architecture Pipelined CPU Tutorial

    2008年7月24日 星期四

    One CPU and HyperThreading and DuelCore介紹

    [轉貼]One CPU and HyperThreading and DuelCore

    Hyper-Threading 的中文翻譯成『超執行緒』, 同樣簡稱為『H.T.』。
    用比較淺顯的概念來說, Hyper-Threading 就是把1 個實體的CPU『模擬』成2 顆CPU、增加處理器運作效率, 藉以有效地善用資源、減少系統資源的浪費:
    既然Hyper-Threading 是『模擬』2 顆CPU 的效果, 故其效能是無法等同 2 顆真正的CPU, 或1 顆雙核心的CPU;但比起原先單一架構的處理器, 確實可提高不少的執行效率。

    雙核心
    目前CPU 已經發展到了多核心的架構, 而雙核心的CPU 已經逐漸變成主流。雙核心相當於將兩個CPU (核心)包裝在單一個CPU 晶片上。
    不同於剛剛提過的Hyper-Threading 技術, 是將單一核心的CPU 模擬成兩個核心, 而是真正雙實體核心的CPU, 其效能是遠超過使用Hyper-Threading 技術的單核心CPU 。

    以簡單的概念來解釋, 若將CPU 比喻為廚房, 那麼單核心就像只有一位廚師, 一次只能做一道菜, 必須做完一道菜之後才能再做下一道。
    若加上Hyper-Threading 技術, 那麼這個廚師就有能力一次做兩道菜, 只不過這個廚師必須分心輪流做這兩道菜。
    而雙核心就像是兩個廚師, 可以同時專心做兩道菜, 當然速度要比一個廚師快得多了。若是再加上Hyper-Threading 技術, 那麼這兩位廚師就可以同時做四道菜了!

    Intel 的介紹雙核心與Hyper-Threading(圖文語音並茂)

    資料來源:
    第二章 中央處理單元

    一個小故事讓我們明白資金流通的意義

    “又是炎熱小鎮慵懶的一天。太陽高掛,街道無人,每個人都債台高築,靠信用度日。這時,從外地來了一位有錢的旅客,他進了一家旅館,拿出一張1000 元鈔票放在櫃檯,說想先看看房間,挑一間合適的過夜,就在此人上樓的時候---- 店主抓了這張1000 元鈔,跑到隔壁屠戶那裡支付了他欠的肉錢...