본문 바로가기
CS/3-1 컴구

[컴퓨터구조] #10. Single-Cycle MIPS(1)

by 이지이즤 2022. 4. 13.

 

Lec 10. Single-Cycle MIPS_1 (The Processor)

 

- Introduction

  Architecture : CPU 구조
                    -> instructions
                    -> registers
  Micro-architecture : CPU 구조를 이해하고 거기에 맞게 동작하는 hardware structure

                    -> datapaths (데이터 흐름, 경로. 데이터 처리에 사용되는 모든 로직들)
                        : operate on or hold data
                        ex) ALU, register file, MUX, memory
                    -> controllers (data path 제어/지시)
                        : receives the current instructions from memory and
                          tells the datapath how to execute instructions
                        ex) memory write signals, mux select, register enable, ALU control

             
- Multiple microarchitectures for an ISA
  Single-cycle : Each instruction is executed in a single cycle
                   -> 명령어 balance 안맞으면(너무 오래걸리는거랑 빠른거 공존하면)
                       가장 느린거 기준으로 맞춰지므로 전체적으로 느려짐. clock frequency가 제한됨.
  Pipeline : Execution is broken up into a series of steps
                   -> multiple instructions 들이 중첩 실행됨. -> throughput 증가.

Revisiting Performance

  Microarchitecture (Hardware implementation) affect CPI ans T (f)
  -> cost⬇ power⬇ performance⬆ 하는 것이 목표임.

 

 


 

 

- Digital Logic Design Basics

  Combinational logic 조합 회로
  : Output is directly determined by current input. 결과가 즉시 결정됨.


  Sequential logic 순차 회로 (state를 갖고있음)
  : Output is determined not only by current input, but also internal state (i.e., previous inputs)
   -> needs *state elements to store information
   -> flip-flops(edge triggered) and latches(level sensitive) are used to store the state information

 

* State Element (동기화 / 데이터 기억하는 역할)
  - (flip-flops로 구현된) Registers store data in a curcuit
    : Clock signal determines when to update the stored value.
      -> Rising-edge triggered : update when clock changes from 0 to 1
      -> Data input determines what (0 or 1) to update to the output


  - Register with write control (or enable)
    : Only updates on clock edge when write control (enable) input is 1

 

- Clock Methodology
  : all digital systems are syncronous to the clock. 클럭에 동기화 하기위해 플립플랍 사용함.
    Combinational logic(원하는대로 신호를 바꾸거나 제어하는 역할) sits between state elements(flip-flops)

 

 


 

 

- Our MIPS Model

실제 PC system과 Simplified한 그림

원래는 위의 그림 오른쪽 그림처럼 Address Bus 와 Data Bus가 1쌍만 있는데
우리는 아래 그림처럼 2쌍 있다고 가정하고 디자인 할거임.

우리가 공부하는 것!

- Verilog-HDL로 기술할 때 두가지 modeling을 사용할 거임
  -> Behavioral modeling
      : lowest modules. ex) ALU, register files
  -> Structure modeling
      : top module. ex) mips.v

- Our MIPS implementation is simplified by designing only
  -> Data processing instructions(산술/논리) : add, sub, and, or, slt
  -> Memory access instructions(메모리 접근) : lw, sw
  -> Branch instructions(분기) : beq, j


 


 

Design Overview


- Instruction Execution in CPU

  1) Fetch (메모리->CPU로 명령어 가져오기)
     : program counter(PC) 사용 to supply the instruction address and fetch instruction from memory
  2) Decoding (가져온 32bit 명령어 해석하기)
     : Extract opcode (determine what operation should be done)
       opcode 분해해서 덧셈/뺄셈/논리연산/점프/메모리 읽기쓰기 등등 중에 뭔지 해석하기,
       Extract operands (register numbers or immediate from fetched instructions
       피연산자 뽑아오기. R-format이면 레지스터에서만, I-format이면 imm-field에서도.
  3) Execution (실행하기)
     3-1) Use ALU
           - 산술.논리 연산
           - lw/sw 할 메모리 주소값 계산
           - 분기하고자하는 target 주소 계산
     3-2) Access memory for load/store 
  4) Next Fetch
     : PC <- target address(분기하는 경우) or PC + 4(순차적인 경우)




1) Instruction Fetch

   PC와 Adder를 통해서 명령어 가져오기   

  * reset
    : initialize the PC to 0x0000_0000 이라고 가정하자. 실제로는 0xBFC0_0000


- Instruction Fetch Verilog Model

Behavioral modeling
Behavioral modeling

  * always 있을 때만 output을 reg에 담음

Structural modeling



- Generic Memory Model in Verilog

   * input[7:2] 인 이유?

 

 

 

2) Instruction Decoding

    Control Unit이 Opcode랑 Function field를 보고 어떤 operation을 해야하는지 판단하고
    필요시 각 data path element들에게 지침을 내려줌,
    명령어의 특정한 field 값이 immediate field가 될 여지도 있고 register file의 register name을 가리키기 위한
    address가 될 여지도 있기때문에 그런걸 감안해서 register file에 입력 혹은 sign extension unit에 입력으로
    들어가게 해줌.

  -> Opcode and funct fields determine which operation the instruction wants to do
      : Control logic 이 opcode와 funct를 읽어서 무슨 동작을 해야하는지 판단하고,
        판단 결과를 datapath에게 알려줌
  -> Operands 피연산자
      : R type 이면 모든 피연산자가 Register numbers.
        I type 이면 Immediate field도 있음.(연산에 활용하기 위해 32bit로 확장해야함)
                     -> 명령어에 따라 control logic이 판단해서 sign/zero extended 중에 뭐할지 알려줌. 

 

- Register File(data path) in Verilog

전에 했던거임

 


- Sign & Zero Extension in Verilog

 

 

 

3) Instruction Execution #1

    Control Unit은 명령어가 산술/논리 연산인지 혹은 메모리 접근인지에 따라서 다르게 지휘해줌.
    여기서는 산술/논리 연산만 다루었음.

산술/논리 연산

  - Execution of the arithmetic and logical instructions
    R-type
    : 2 source operands from the register file
     ex) add, sub, and, or, ...



    I-type
    : 1source operand from the register file, 1 source operand from the immediate field
     ex) addi, ansi, ori, ...

=> destination register(=target =쓰기 동작 할 레지스터의 정보가 담긴 곳) 이 서로 다름 주의!!

 

- MUX in verilog

 

 

 

 

3) Instruction Execution #2

    Control Unit은 명령어가 산술/논리 연산인지 혹은 메모리 접근인지에 따라서 다르게 지휘해줌.
    여기서는 산술/논리/메모리 연산을 다루었음.

산술/논리/메모리 연산

 
- Execution of the memory access instructions
   lw, sw
   : I-type

 

 

 

3) Instruction Execution #3

    beq, bne : 조건에 따라 분기(conditional)
    j, jal, jr : 무조건 분기(Unconditional)




댓글