summaryrefslogtreecommitdiff
path: root/pysc-v/InstructionSets/RV64I.py
blob: 72b8bcb8e1b8ed60a2b93738e4eecfe4ed5ee267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from .instructions import Instruction, InstructionSet
from ctypes import c_uint32
from .RV32I import *

RV64I = InstructionSet()

class ShiftImm64(ShiftImm):
    # NOTE: This is an special type used for shifting operations because they
    # have 7 bits left after the maximum shift (5bits -> 32 rotations)
    # they can apply.
    # In RV64I they can indicate rotation with 1 bit more (64 rotations) so
    # they use a funct6 instead.
    funct6 = None
    funct3 = None
    opcode = None

    def __init__(self, rd, rs, imm):
        self.rd  = rd
        self.rs  = rs
        self.imm = imm

    def compile(self):
        return c_uint32(
            (self.funct6 << 26) +\
            (self.imm    << 20) +\
            (self.rs     << 15) +\
            (self.funct3 << 12) +\
            (self.rd     <<  7) +\
            self.opcode
        )

@RV64I.instruction
class slli(ShiftImm64):
    name    = "slli"
    opcode  = 0b0010011
    funct3  = 0b001
    funct6  = 0b000000

@RV64I.instruction
class srli(ShiftImm64):
    name    = "srli"
    opcode  = 0b0010011
    funct3  = 0b101
    funct6  = 0b000000

@RV64I.instruction
class srai(ShiftImm64):
    name    = "srai"
    opcode  = 0b0010011
    funct3  = 0b101
    funct6  = 0b010000

@RV64I.instruction
class sd(S):
    name    = "sd"
    opcode  = 0b0100011
    funct3  = 0b011

@RV64I.instruction
class ld(I):
    name    = "ld"
    opcode  = 0b0000011
    funct3  = 0b011