<commit_before>import Abstraction::*;
import RVTypes::*;
import CompareProvisos::*;
import ClientServer::*;
import ConnectalConfig::*;
import GetPut::*;
import RegFile::*;
import Vector::*;
import FIFO::*;
import FIFOF::*;
import HostInterface::*;
import MemTypes::*;
import PrintTrace::*;
// import CacheUtils::*; // for PendMemRespCnt
// TODO: FIXME
typedef Bit#(4) PendMemRespCnt;

import BRAMFIFO::*;
import DefaultValue::*;

interface SharedMemoryBridge;
    // Processor Interface
    interface MainMemoryServer#(MemoryClientType) to_proc;

    // Shared Memory Interfaces
    interface MemReadClient#(DataBusWidth)  to_host_read;
    interface MemWriteClient#(DataBusWidth) to_host_write;

    // Initialize the shared memory with the ref pointer and size.
    // If an address is out of range, it will handled (somehow)
    method Action initSharedMem(Bit#(32) refPointer, Addr memSize);

    // Methods for clearing pending requests before reset
    // TODO: actually implement this
    method Action flushRespReqMem;
    method PendMemRespCnt numberFlyingOperations;
endinterface

// This bridge assumes the shared memory responds to load requests in order
(* synthesize *)
module mkSharedMemoryBridge(SharedMemoryBridge) provisos (EQ#(DataSz, DataBusWidth));
    // TODO: re-implement WORKAROUND_ISSUE_27
    `ifdef WORKAROUND_ISSUE_27
    error("WORKAROUND_ISSUE_27 is not implemented for mkSharedMemoryBridge");
    `endif
    // TODO: re-implement SERIALIZE_MEM_REQS
    `ifdef SERIALIZE_MEM_REQS
    error("SERIALIZE_MEM_REQS is not implemented for mkSharedMemoryBridge");
    `endif

    Bool verbose = False;
    File tracefile = verbose ? stdout : tagged InvalidFile;

    // Bool is for isWrite
    FIFOF#(Tuple2#(Bool, MemoryClientType)) pendingReqs   <- fprintTraceM(tracefile, "SharedMemoryBridge::pendingReqs",   mkSizedFIFOF(16));
    FIFO#(MemRequest)                       readReqFifo   <- fprintTraceM(tracefile, "SharedMemoryBridge::readReqFifo",   mkFIFO);
    FIFO#(MemRequest)                       writeReqFifo  <- fprintTraceM(tracefile, "SharedMemoryBridge::writeReqFifo",  mkFIFO);
    FIFO#(MemData#(DataBusWidth))           writeDataFifo <- fprintTraceM(tracefile, "SharedMemoryBridge::writeDataFifo", mkSizedBRAMFIFO(1024)); // XXX: Not sure where this size came from
    FIFO#(MemData#(DataBusWidth))           readDataFifo  <- fprintTraceM(tracefile, "SharedMemoryBridge::readDataFifo",  mkFIFO);
    FIFO#(Bit#(MemTagSize))                 writeDoneFifo <- fprintTraceM(tracefile, "SharedMemoryBridge::writeDoneFifo", mkFIFO);

    Reg#(SGLId)                             refPointerReg <- mkReg(0);
    Reg#(Addr)                              memSizeReg    <- mkReg(64 << 20); // 64 MB by default
    Reg#(Bool)                              flushRespReq  <- mkReg(False);

    // addr aligned with 8B boundary
    function Addr getDWordAlignAddr(Addr a);
        return {truncateLSB(a), 3'b0};
    endfunction

    // This function adjusts the address to point to a valid location in memory
    // If the memory size is a power of 2, it simply truncates it.
    // Otherwise is uses a weird mask derived form memSizeReg - 1
    function Addr adjustAddress(Addr a);
        // This works really well if the address is a power of 2, otherwise it has<commit_msg>Restricted pending reqs to 1 in SharedMemoryBridge<commit_after>import Abstraction::*;
import RVTypes::*;
import CompareProvisos::*;
import ClientServer::*;
import ConnectalConfig::*;
import GetPut::*;
import RegFile::*;
import Vector::*;
import FIFO::*;
import FIFOF::*;
import HostInterface::*;
import MemTypes::*;
import PrintTrace::*;
// import CacheUtils::*; // for PendMemRespCnt
// TODO: FIXME
typedef Bit#(4) PendMemRespCnt;

import BRAMFIFO::*;
import DefaultValue::*;

interface SharedMemoryBridge;
    // Processor Interface
    interface MainMemoryServer#(MemoryClientType) to_proc;

    // Shared Memory Interfaces
    interface MemReadClient#(DataBusWidth)  to_host_read;
    interface MemWriteClient#(DataBusWidth) to_host_write;

    // Initialize the shared memory with the ref pointer and size.
    // If an address is out of range, it will handled (somehow)
    method Action initSharedMem(Bit#(32) refPointer, Addr memSize);

    // Methods for clearing pending requests before reset
    // TODO: actually implement this
    method Action flushRespReqMem;
    method PendMemRespCnt numberFlyingOperations;
endinterface

// This bridge assumes the shared memory responds to load requests in order
(* synthesize *)
module mkSharedMemoryBridge(SharedMemoryBridge) provisos (EQ#(DataSz, DataBusWidth));
    // TODO: re-implement WORKAROUND_ISSUE_27
    `ifdef WORKAROUND_ISSUE_27
    error("WORKAROUND_ISSUE_27 is not implemented for mkSharedMemoryBridge");
    `endif
    // TODO: re-implement SERIALIZE_MEM_REQS
    `ifdef SERIALIZE_MEM_REQS
    error("SERIALIZE_MEM_REQS is not implemented for mkSharedMemoryBridge");
    `endif

    Bool verbose = False;
    File tracefile = verbose ? stdout : tagged InvalidFile;

    // TODO: Make pendingReqs larger than 1 and add a way to enforce
    // per-address ordering between loads and stores

    // Bool is for isWrite
    FIFOF#(Tuple2#(Bool, MemoryClientType)) pendingReqs   <- fprintTraceM(tracefile, "SharedMemoryBridge::pendingReqs",   mkSizedFIFOF(1));
    FIFO#(MemRequest)                       readReqFifo   <- fprintTraceM(tracefile, "SharedMemoryBridge::readReqFifo",   mkFIFO);
    FIFO#(MemRequest)                       writeReqFifo  <- fprintTraceM(tracefile, "SharedMemoryBridge::writeReqFifo",  mkFIFO);
    FIFO#(MemData#(DataBusWidth))           writeDataFifo <- fprintTraceM(tracefile, "SharedMemoryBridge::writeDataFifo", mkSizedBRAMFIFO(1024)); // XXX: Not sure where this size came from
    FIFO#(MemData#(DataBusWidth))           readDataFifo  <- fprintTraceM(tracefile, "SharedMemoryBridge::readDataFifo",  mkFIFO);
    FIFO#(Bit#(MemTagSize))                 writeDoneFifo <- fprintTraceM(tracefile, "SharedMemoryBridge::writeDoneFifo", mkFIFO);

    Reg#(SGLId)                             refPointerReg <- mkReg(0);
    Reg#(Addr)                              memSizeReg    <- mkReg(64 << 20); // 64 MB by default
    Reg#(Bool)                              flushRespReq  <- mkReg(False);

    // addr aligned with 8B boundary
    function Addr getDWordAlignAddr(Addr a);
        return {truncateLSB(a), 3'b0};
    endfunction

    // This function adjusts the address to point to a valid location in memory
    // If the memory size is a power of 2, it simply truncates it.
    // Otherwise is uses a weird mask derived form memSizeReg - 1
    function Addr adjustAddress(Addr a);
        // This works really well if the address is a power of 2, otherwise it has
{'fraction_non_alphanumeric': 0.09587217043941411, 'fraction_numerical': 0.008729101938156533, 'mean_word_length': 3.4916943521594686, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930136', 'n_tokens_mistral': 2137, 'n_tokens_neox': 1937, 'n_words': 575}