rv64: rv64i.lisp

RV64I semantics (a few instructions so far: the skeleton of docs/isa.md).

0/1 a fixed bit, name a field,   a bit the decoder ignores

addi source

addi rd rs1 (simm imm12)

Add Immediate

"ADDI adds the sign-extended 12-bit immediate to register rs1. Arithmetic
overflow is ignored and the result is simply the low XLEN bits of the
result."

rv-i:

313029282726252423222120191817161514131211109876543210
imm12rs1000rd0010011
(defrv addi (:asm "addi" rd rs1 (simm imm12)) (:doc "Add Immediate")
  (set-gpr rd (wrap 64 (+ (gpr rs1) (i-imm)))))

add source

add rd rs1 rs2

Add

"ADD performs the addition of rs1 and rs2. SUB performs the subtraction
of rs2 from rs1. Overflows are ignored and the low XLEN bits of results
are written to the destination rd."

rv-i:

313029282726252423222120191817161514131211109876543210
0000000rs2rs1000rd0110011
(defrv add (:asm "add" rd rs1 rs2) (:doc "Add")
  (set-gpr rd (wrap 64 (+ (gpr rs1) (gpr rs2)))))

sub source

sub rd rs1 rs2

Subtract

rv-i:

313029282726252423222120191817161514131211109876543210
0100000rs2rs1000rd0110011
(defrv sub (:asm "sub" rd rs1 rs2) (:doc "Subtract")
  (set-gpr rd (wrap 64 (- (gpr rs1) (gpr rs2)))))

and source

and rd rs1 rs2

AND

"AND, OR, and XOR perform bitwise logical operations."

rv-i:

313029282726252423222120191817161514131211109876543210
0000000rs2rs1111rd0110011
(defrv and (:asm "and" rd rs1 rs2) (:doc "AND")
  (set-gpr rd (logand (gpr rs1) (gpr rs2))))

or source

or rd rs1 rs2

OR

rv-i:

313029282726252423222120191817161514131211109876543210
0000000rs2rs1110rd0110011
(defrv or (:asm "or" rd rs1 rs2) (:doc "OR")
  (set-gpr rd (logior (gpr rs1) (gpr rs2))))

xor source

xor rd rs1 rs2

Exclusive OR

rv-i:

313029282726252423222120191817161514131211109876543210
0000000rs2rs1100rd0110011
(defrv xor (:asm "xor" rd rs1 rs2) (:doc "Exclusive OR")
  (set-gpr rd (logxor (gpr rs1) (gpr rs2))))

sll source

sll rd rs1 rs2

Shift Left Logical

"SLL, SRL, and SRA perform logical left, logical right, and arithmetic
right shifts on the value in register rs1 by the shift amount held in
register rs2. In RV64I, only the low 6 bits of rs2 are considered for the
shift amount." (4.2.2)

rv-i:

313029282726252423222120191817161514131211109876543210
0000000rs2rs1001rd0110011
(defrv sll (:asm "sll" rd rs1 rs2) (:doc "Shift Left Logical")
  (set-gpr rd (wrap 64 (ash (gpr rs1) (wrap 6 (gpr rs2))))))

ld source

ld rd (simm imm12) rs1

Load Doubleword

"The LD instruction loads a 64-bit value from memory into register rd";
"The effective address is obtained by adding register rs1 to the
sign-extended 12-bit offset." (2.6)

rv64-i:

313029282726252423222120191817161514131211109876543210
imm12rs1011rd0000011
(defrv ld (:asm "ld" rd (simm imm12) rs1) (:doc "Load Doubleword")
  (set-gpr rd (rv-load 64 (+ (gpr rs1) (i-imm)))))

sd source

sd rs2 (s-off imm12hi imm12lo) rs1

Store Doubleword

"The SD, SW, SH, and SB instructions store 64-bit, 32-bit, 16-bit, and
8-bit values from the low bits of register rs2 to memory"

rv64-i:

313029282726252423222120191817161514131211109876543210
imm12hirs2rs1011imm12lo0100011
(defrv sd (:asm "sd" rs2 (s-off imm12hi imm12lo) rs1) (:doc "Store Doubleword")
  (rv-store 64 (+ (gpr rs1) (s-imm)) (gpr rs2)))

bne source

bne rs1 rs2 (b-rel bimm12hi bimm12lo)

Branch if Not Equal

"The 12-bit B-immediate encodes signed offsets in multiples of 2 bytes.
The offset is sign-extended and added to the address of the branch
instruction to give the target address." "BEQ and BNE take the branch if
registers rs1 and rs2 are equal or unequal respectively."

rv-i:

313029282726252423222120191817161514131211109876543210
bimm12hirs2rs1001bimm12lo1100011
(defrv bne (:asm "bne" rs1 rs2 (b-rel bimm12hi bimm12lo)) (:doc "Branch if Not Equal")
  (when (/= (gpr rs1) (gpr rs2))
    (branch-to (+ (rv64-pc cpu) (b-imm)))))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.