๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Computer Architecture(COSE222)

[์ปดํ“จํ„ฐ๊ตฌ์กฐ] CH4. RISC-V & RISC-V Instruction #1

CISC VS RISC

- CISC (Complex Instruction Set Computer)

  1. ํ•˜๋‚˜์˜ instruction์ด ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ณต์žกํ•œ ์ž‘์—…์„ ํ•จ ex. move in x86
  2. instruction์˜ ๊ธธ์ด๊ฐ€ ๊ฐ€๋ณ€์ 
  3. ex. x86(Intel, AMD), Motorola 68k

- RISC (Reduced Instruction Set Computer)

  1. ๊ฐ instruction์ด ํ•˜๋‚˜์˜ ์ž‘์€(unit) ์ž‘์—…๋งŒ ํ•จ. ex. add, lw, sw, beq
  2. instruction์˜ ๊ธธ์ด๊ฐ€ ๊ณ ์ •๋จ
  3. Load/Store Architecture
  4. ex. RISC-V, ARM, MIPS

์‚ฌ์‹ค ์ด ๊ทธ๋ฆผ์ด ์™œ ์—ฌ๊ธฐ ๊ทธ๋ ค์ ธ ์žˆ๋Š”์ง€ ํ–ˆ๋Š”๋ฐ ์ผ๋‹จ ์žˆ์œผ๋‹ˆ๊นŒ ์„ค๋ช…์„ ํ•ด๋ณด๋„๋ก ํ•˜์ฃ 

์˜ˆ๋ฅผ ๋“ค์–ด COPY๋ผ๋Š” ๋ช…๋ น์„ ์ˆ˜ํ–‰ํ•œ๋‹ค๊ณ  ์น˜์ž. hello๋ผ๋Š” ๋ฌธ์ž์—ด์„ ๋ณต์‚ฌํ•˜๋ ค๊ณ  ํ•œ๋‹ค.
hello๋Š” ํ˜„์žฌ ๋ฉ”๋ชจ๋ฆฌ์— 100๋ฒˆ์ง€๋ถ€ํ„ฐ 104๋ฒˆ์ง€์— ์ €์žฅ๋˜์–ด ์žˆ๊ณ , ์šฐ๋ฆฐ 200๋ฒˆ์ง€๋ถ€ํ„ฐ 204๋ฒˆ์ง€๊นŒ์ง€๋กœ ๋ณต์‚ฌํ•˜๋ ค ํ•œ๋‹ค.

CPU์— source index๋Š” 100, destination index๋Š” 200, ๊ทธ๋ฆฌ๊ณ  ์˜ฎ๊ฒจ์•ผ ํ•  ๊ฐœ์ˆ˜๊ฐ€ 5์ด๋ฏ€๋กœ count 5๋กœ ์‹œ์ž‘ํ•œ๋‹ค.
100๋ฒˆ์ง€์— ์žˆ๋Š” h๋ฅผ 200 ๋ฒˆ์ง€์— ์ €์žฅํ•˜๊ณ , count 1 ๊ฐ์†Œ, DI์™€ SI๋Š” 1 ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.
count๊ฐ€ 0์ด ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๋ฉด ๋!

RISC-V ISA

: RISC-V๋Š” ISAs์™€ ๊ด€๋ จ๋œ ์ œํ’ˆ๊ตฐ(?) ์ž„

  • RV32I : 32-bit architecture, base instruction set for Integer
  • RV64I : 64-bit architecture, base instruction set for Integer
  • RV32E : Subset of RV32I for small microcontrollers
  • RV128I : 128-bit architecture

โ–ช M extension: Integer multiplication and division instructions
โ–ช A extension: Atomic instructions
โ–ช F extension: Single-precision floating-point instructions
โ–ช D extension: Double-precision floating-point instructions
โ–ช Q extension: Quad-precision floating-point instructions
โ–ช C extension: Compressed instructions

 


Instructions

CPU์— ํ•„์š”ํ•œ instructions ์— ๋ญ๊ฐ€ ์žˆ๋Š”์ง€ ์•Œ์•„๋ณด๋„๋ก ํ•ฉ์‹œ๋‹ค!

instruction์—๋Š” ํฌ๊ฒŒ ์„ธ ๊ฐ€์ง€ ๋ถ„๋ฅ˜๊ฐ€ ์žˆ์Œ.

  1. Data processing instructions (Arithmetic and Logical)
  2. Memory access instructions (Load/Store)
  3. Branch instructions

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์•„๋งˆ 1๋ฒˆ๋งŒ ๋‹ค๋ฃฐ ๊ฒƒ ๊ฐ™๋‹น

 

 

์ฐธ๊ณ 
CPU๊ฐ€ 1GHz ๋ผ๊ณ  ํ•˜๋ฉด 10^9 Hz ์ด๊ณ , 1์ดˆ์— 10^9 ๋ฒˆ์˜ ๊ธฐ๋ณธ ์—ฐ์‚ฐ(+, -, *, /) ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ.

์ด๋Ÿฌํ•œ instruction ๋“ค์ด ์กด์žฌํ•œ๋‹ค.

 

 

A memory hierarchy

higher level ์ผ ์ˆ˜๋ก ์†๋„๋Š” ๋” ๋น ๋ฅด์ง€๋งŒ ๋น„์šฉ์ด ํ›จ์”ฌ ๋น„์‹ธ๊ณ , lower level ์ผ ์ˆ˜๋ก ์‹ผ ๋Œ€์‹  ์†๋„๊ฐ€ ๋Š๋ฆฌ๋‹ค

 

Overview of CPU Operation

add x5, x6, x7 # x5 = x6 + x7

 

์ด๋ ‡๊ฒŒ ์ƒ๊ธด instruction์ด ์žˆ์„ ๋•Œ, x6, x7 ์€ source operand๊ฐ€ ๋˜๋ฉฐ, x5๊ฐ€ destination์ด ๋œ๋‹ค.
(# ์ดํ•˜๋Š” ์ฃผ์„์ž„)

 

์‚ฐ์ˆ  ๋ช…๋ น์˜ ํ”ผ์—ฐ์‚ฐ์ž(operand)๋Š” ๋ ˆ์ง€์Šคํ„ฐ๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” CPU ๋‚ด๋ถ€์˜ ํŠน์ •ํ•œ ์œ„์น˜๋‚˜, instructions์˜ immediate field ์—์„œ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
(๋’ท ๋ถ€๋ถ„ ์•Œ์•„์•ผ ์ดํ•ด๊ฐ)

 

Register์€ ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ๋ณผ ์ˆ˜ ์žˆ์Œ!!
(Cash๋Š” ๋ณผ ์ˆ˜ ์—†์Œ)

RISC-V์—๋Š” 32๊ฐœ์˜ 32bit register๋กœ ๊ตฌ์„ฑ๋œ ๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์ด ์žˆ๋‹ค ใ…‡ใ…‡

RV32I Register File

1. ๋ ˆ์ง€์Šคํ„ฐ๋Š” flip-flops์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

(32-bit register๋Š” 32๊ฐœ์˜ flip-flops์ด ํ•„์š”ํ•จ)

2. CPU ๋‚ด๋ถ€์˜ architectural register๋“ค์˜ ์ง‘ํ•ฉ์„ register file์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

  • ๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์€ flip-flops์ด๋‚˜ SRAM์œผ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค
  • RV32I ๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์€ 32๊ฐœ์˜ 32-bit registers๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
    (๋‘ ๊ฐœ์˜ read ports์™€ ํ•œ ๊ฐœ์˜ write port)
  • ๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์€ ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ๋‚˜ ์บ์‹œ์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ๋น ๋ฆ„.
    ์™œ๋ƒ๋ฉด ๋ ˆ์ง€์Šคํ„ฐ ์ˆ˜๊ฐ€ ๋งค์šฐ ์ œํ•œ๋˜์–ด ์žˆ๊ณ , CPU ๋‚ด๋ถ€์— ์žˆ๊ธฐ ๋•Œ๋ฌธ!
  • ๊ทธ๋ž˜์„œ ์ปดํŒŒ์ผ๋Ÿฌ๋Š” high-level code๋ฅผ assembly code๋กœ ๋ฒˆ์—ญํ•  ๋•Œ ๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•จ.

์ฐธ๊ณ ๋กœ ๋ณด๊ธฐ๋งŒ ํ•˜์ž

(๋ ˆ์ง€์Šคํ„ฐ ํŒŒ์ผ์„ flip-flop ์œผ๋กœ ๊ตฌํ˜„ํ•ด๋†“์€ ๊ฒƒ์ด ํ”ผํ”ผํ‹ฐ์— ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ๋งŒ ํ•˜์ž)

 

 

RISC-V Instruction Formats

Instruction Categories
  1. Arithmetic and Logical(Integer)
  2. Load/Store
  3. Jump and Branch

4๊ฐœ์˜ instruction formats ๋ชจ๋‘ 32 bits ์˜ ํฌ๊ธฐ๋ฅผ ๊ฐ–๋Š”๋‹ค.

 

RISC-V Instruction Fields

32 bit๋กœ ๊ตฌ์„ฑ๋˜๋Š” instruction์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ field๋“ค์ด ์žˆ๋‹ค.

  • opcode, funct7, funct3 ์€ ์–ด๋–ค operation์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š”์ง€ ๋ช…์‹œํ•œ๋‹ค. ์ด ์…‹์„ ํ•ฉ์ณ์„œ ์ด 2^17 = 128*1024 ๊ฐœ์˜ ๊ฐ๊ธฐ ๋‹ค๋ฅธ operations์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • rs1 ์€ ์ฒซ๋ฒˆ์งธ source operand์˜ register ์ฃผ์†Œ๋ผ๊ณ  ๋ณด๋ฉด ๋จ
  • rs2 ๋Š” ๋‹น์—ฐํžˆ ๋‘ ๋ฒˆ์งธ source operand ์˜ register ์ฃผ์†Œ
  • rd๋Š” destination operand์˜ register

* ์ฐธ๊ณ  : encoding space๋ฅผ ๋ฌด์กฐ๊ฑด ์ „๋ถ€ ๋‹ค ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์•„๋‹˜.


RV32I Arithmetic Instructions (add, sub, addi)

1. add
  • R-Type instruction

add rd, rs1, rs2
ex.
add t0, s1, s2 # t0 <= s1 + s2
rd = t0, rs1 = s1, rs2 = s2

  • opcode : add ๊ฐ€ ์ €์žฅ๋œ 51๋ฒˆ์ง€
  • rs1๊ณผ rs2๋Š” s1, s2์ด๋ฏ€๋กœ ์ด๋“ค์ด ์ €์žฅ๋œ ๊ณณ์€ ๋ ˆ์ง€์Šคํ„ฐ์˜ 9๋ฒˆ์ง€์™€ 18๋ฒˆ์ง€
  • rd ์—ญ์‹œ t0๊ฐ€ ์ €์žฅ๋œ ๊ณณ์€ 5๋ฒˆ์ง€
  • ์ด ์ˆซ์ž๋ฅผ binary๋กœ ํ‘œํ˜„ํ•˜๋ฉด

funct7 : 0000000 (7bit)
rs2 : 10010 (5bit)
rs1 : 01001 (5bit)
funct3 : 000 (3bit)
rd : 00101 (5bit)
opcode : 0110011 (7bit)

4๊ฐœ์”ฉ ๋Š์–ด์„œ 16์ง„์ˆ˜๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋!

2. sub
  • R-Type instruction

sub rd, rs1, rs2
ex.
sub t2, s3, s4 # t2 <= s3 + s4
rd = t2, rs1 = s3, rs2 = s4'


Immediate ๋ž€ ?

  • R-format instruction์˜ ๊ฒฝ์šฐ ๋ ˆ์ง€์Šคํ„ฐ์—์„œ 3๊ฐœ์˜ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ค์ง€๋งŒ,
    I-format instruction์˜ ๊ฒฝ์šฐ, ํ•œ ๊ฐœ์˜ ํ”ผ์—ฐ์‚ฐ์ž๋ฅผ instruction ์ž๊ธฐ ์ž์‹ ์—๊ฒŒ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Œ
  • ๊ทธ ๊ฐ’์„ immediates๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ์™œ? ๋ฐ”๋กœ instructions์—์„œ ๋ฐ”๋กœ! ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ!
    register๋‚˜ memory access๋ฅผ ํ•„์š”๋กœ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • 12 bit์˜ immediate field๋Š” 2์˜ ๋ณด์ˆ˜๋ฅผ ํ™œ์šฉํ•  ๊ฒฝ์šฐ -2^11 ~ +2^11-1 ์˜ ๋ฒ”์œ„๊นŒ์ง€ ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • ์ปดํ“จํ„ฐ ์‚ฐ์ˆ ์˜ ํ•˜๋“œ์›จ์–ด ์„ค๊ณ„์—์„œ 2์˜ ๋ณด์ˆ˜๋ฅผ ํ™œ์šฉํ•จ์œผ๋กœ์จ, unsigned number์™€ signed number์˜ ๋ง์…ˆ ๋บ„์…ˆ์„ ํŽธ๋ฆฌํ•˜๊ณ  ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Œ!
2์˜ ๋ณด์ˆ˜

n-bit number N ์ด ์ด์ง„์ˆ˜๋กœ ์ฃผ์–ด์กŒ์„ ๋•Œ, N์˜ 2์˜ ๋ณด์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜๋œ๋‹ค.

2^n - N for N != 0
0       for N = 0

ex. 4 bit ์ผ ๋•Œ, 3์€ 4'b0011์ด๊ณ  ์ด์˜ 2์˜ ๋ณด์ˆ˜๋Š” 3: 2^4-3 = 4'b1101

์ข€ ๋” ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด

2์ง„์ˆ˜์—์„œ 0,1์„ ๋’ค์ง‘์–ด์ฃผ๊ณ  1์„ ๋”ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.
'''''
4
= 0000 0100
-> 1111 1011
+1
= 1111 1100 = -4

N bit ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฒ”์œ„๋Š”

  • Unsigned : [ 0, 2^N-1 ]
  • Sign/Magnitude : [ -(2^(N-1) -1), 2^(N-1) -1]
  • 2์˜ ๋ณด์ˆ˜ : [ -2^(N-1) , 2^(N-1) -1]

๋งŒ์•ฝ 12 bit๋ผ๋ฉด

  • Unsigned : 0~4095
  • Sign/Magnitude : -2047 ~ +2047
  • 2์˜ ๋ณด์ˆ˜ : -2048 ~ +2047

์˜ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค!

๊ทธ๋ฆฌ๊ณ  ์–ด๋–ค ์ˆซ์ž๊ฐ€ +์ธ์ง€ -์ธ์ง€๋Š” int๋กœ ์„ ์–ธํ–ˆ๋Š”์ง€ unsigned๋กœ ์„ ์–ธํ–ˆ๋Š”์ง€ ๋ด์„œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์˜ ํ•ด์„์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง„๋‹ค.


3. addi
  • I-Type instruction

addi rd, rs1, imm12
ex.
addi t0, s3, -12 # t0 <= s3 + (-12)
rd = t0, rs1 = s3, imm12 = -12

  • imm12 ์— ํ• ๋‹น๋œ bit๋Š” ์ด 12 bit
  • ๋”ฐ๋ผ์„œ ๋‹ค๋ฅธ ํ”ผ์—ฐ์‚ฐ์ž(32 bit)์™€ ๋งž์ถ”๋ ค๋ฉด 20bit๋ฅผ ๋ฌด์–ธ๊ฐ€๋กœ ์ฑ„์›Œ์•ผ ํ•จ. ์ด ๋•Œ ๋‚˜์˜ค๋Š” ๊ฐœ๋…์ด extension
  1. zero-ext : ์ž๋ฃŒํ˜•์˜ ํ™•์žฅ ์‹œ ๋น„์—ˆ๋˜ ๋ถ€๋ถ„์„ 0์œผ๋กœ ์ฑ„์šด๋‹ค
  2. sign-ext : ์ž๋ฃŒํ˜•์˜ ํ™•์žฅ ์‹œ ๋น„์—ˆ๋˜ ๋ถ€๋ถ„์„ MSB(๊ฐ€์žฅ ์™ผ์ชฝ์˜ ๋น„ํŠธ)๋กœ ์ฑ„์šด๋‹ค.

add, sub ์ฒ˜๋Ÿผ arith inst ์—๋Š” SE ๋ฅผ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๊ณ ,
andi ์™€ ๊ฐ™์€ logical inst ์—๋Š” ZE๋ฅผ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

 

RV32I Logical Instructions (and, or, xor, andi, ori, xori)

-> logical instructions์€ 2๊ฐœ์˜ source operands์— ๋Œ€ํ•ด bit-by-bit ์—ฐ์‚ฐ ์ˆ˜ํ–‰ ํ›„ destination register์— ๊ฐ’์„ ์“ฐ๋Š” ๊ฒƒ.

1. AND Instruction

-> bits masking ์— ์œ ์šฉํ•จ(์ผ๋ถ€ ๋น„ํŠธ๋งŒ ์‚ด๋ฆฌ๊ณ , ๋‚˜๋จธ์ง€ ์‹น 0์œผ๋กœ ์ดˆ๊ธฐํ™”)

2. OR Instruction

-> bits combine์— ์œ ์šฉํ•จ (๋ช‡ ๋น„ํŠธ๋ฅผ 1๋กœ ์„ค์ •ํ•˜๊ณ , ๋‚˜๋จธ์ง€๋Š” ๊ทธ๋Œ€๋กœ ๋‘”๋‹ค)

3. XOR Instruction

-> bits๋ฅผ invert(reverse)ํ•˜๊ฑฐ๋‚˜ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•  ๋•Œ ์œ ์šฉํ•จ

์ฒซ ๋ฒˆ์งธ ๊ฒฝ์šฐ ๋น„ํŠธ๋ฅผ 1111...๊ณผ xorํ•˜๋ฉด ๋น„ํŠธ๊ฐ€ ๋’ค์ง‘ํžˆ๊ณ 
์•„๋ž˜์˜ ๊ฒฝ์šฐ ๊ฐ™์€ ๋น„ํŠธ๋ฅผ xorํ•˜๋ฉด 0์œผ๋กœ ์ดˆ๊ธฐํ™”๋œ๋‹ค.

์œ„ ์„ธ ๊ฐ€์ง€ ๋ชจ๋‘ R-Type Instruction

4. andi, ori, xori
  • I-Type instruction
  • immediates in these are sign-extended
  • (๋ญ์—ฌ ์•ž์—์„  ze ์ฃผ๋กœ ์“ด๋‹ค๋งค ๋ญ์—ฌ)

Revisiting Basic Shifting

one left shift = 2๋ฐฐ
one right shift = 1/2 ๋ฐฐ

1. Revisiting Logical Shift

  1. Logical shift left
    • MSB : shifted out
    • LSB : shifted in with a 0
    • ex) 1100 1011 << 1 = 100 1011 0
      1100 1011 << 3 = 0 1011 000
  2. Logical shift right
    • MSB : shifted in with a 0
    • LSB : shifted out
    • ex) 1100 1011 >> 1 = 0 110 0101
      1100 1011 >> 3 = 000 1 1001

Logical shifts๋Š” unsigned integer๋ฅผ 2์˜ ์ œ๊ณฑ์ˆ˜๋กœ ๋‚˜๋ˆ„๊ฑฐ๋‚˜, 2์˜ ์ œ๊ณฑ์ˆ˜๋ฅผ ๊ณฑํ•  ๋•Œ ํŽธ๋ฆฌํ•˜๋‹ค.
(( logical shift right๋Š” ๋‚˜๋ˆ ์„œ integer ๊ฐ€ ์•„๋‹ˆ๋ฉด ๋ฒ„๋ฆผํ•œ๋‹ค))

2. Revisiting Arithmetic Shift

  1. Arithmetic shift left
    • MSB : shifted out, ๊ทธ๋Ÿฌ๋‚˜ overflow/underflow๋ฅผ ์กฐ์‹ฌํ•  ๊ฒƒ
    • LSB : shifted in with a 0
    • ex) 1100 <<< 1 = 100 0
      1100 <<< 3 = 0 000 (incorrect!) => underflow
  2. Arithmetic shift right
    • MSB : Retain its sign bit (๋ฐ€๋ฆฐ ๋ถ€๋ถ„์— ๊ฐ€์žฅ ์™ผ์ชฝ ๋น„ํŠธ ์ด์–ด์„œ ํ™•์žฅํ•ด์ฃผ๊ธฐ)
    • LSB : Shifted out
    • ex) 1100 >>> 1 = 1 110 (retain sign bit)
      1100 >>> 3 = 111 1
    Arithmetic shifts๋Š” signed integer์„ 2์˜ ์ œ๊ณฑ์ˆ˜๋กœ ๋‚˜๋ˆ„๊ฑฐ๋‚˜ ๊ณฑํ•  ๋•Œ ํŽธ๋ฆฌํ•˜๋‹ค!
    ((๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋‚˜๋ˆ ์„œ integer๊ฐ€ ์•„๋‹ˆ๋ฉด ๋ฒ„๋ฆฐ๋‹ค))

RV32I Shift Instructions (sll, srl, sra, slli, srli, srai)

-> Shift-left operation์€ 2์˜ ์ œ๊ณฑ์ˆ˜๋กœ ๊ณฑํ•˜๊ธฐ
-> Shift-right operation์€ 2์˜ ์ œ๊ณฑ์ˆ˜๋กœ ๋‚˜๋ˆ„๊ธฐ

1. sll, srl, sra
  • R type instructions
  • sll rd, rs1, rs2[4:0] : shift left logical
  • srl rd, rs1, rs2[4:0] : shift right logical
  • sla rd, rs1, rs2[4:0] : shift right arithmetic (sign-extension)

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์“ด๋‹ค

2. slli, srli, srai
  • Specialization of I type
  • shift rs1 by up to 31 bits (5-bit shamt field)

 

  • slli rd, rs1, shamt : shift left logical
  • srli rd, rs1, shamt : shift right logical
  • srai rd, rs1, shamt : shift right arithmetic (sign-extension)