1
0

use definitions in consts header whenever possible

This commit is contained in:
Howard Mao
2015-11-05 10:15:02 -08:00
parent fb501e75c0
commit bbf14ddc01
10 changed files with 65 additions and 76 deletions

View File

@ -80,7 +80,7 @@ int main(int argc, char** argv)
for (int i = 0; i < N_MEM_CHANNELS; i++) {
mm[i] = dramsim2 ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
try {
mm[i]->init(memsz_mb*1024*1024 / N_MEM_CHANNELS, mem_width, LINE_SIZE);
mm[i]->init(memsz_mb*1024*1024 / N_MEM_CHANNELS, mem_width, CACHE_BLOCK_BYTES);
} catch (const std::bad_alloc& e) {
fprintf(stderr,
"Failed to allocate %ld bytes (%ld MiB) of memory\n"
@ -94,7 +94,7 @@ int main(int argc, char** argv)
void *mems[N_MEM_CHANNELS];
for (int i = 0; i < N_MEM_CHANNELS; i++)
mems[i] = mm[i]->get_data();
load_mem(mems, loadmem, N_MEM_CHANNELS);
load_mem(mems, loadmem, CACHE_BLOCK_BYTES, N_MEM_CHANNELS);
}
// Instantiate HTIF

View File

@ -117,7 +117,7 @@ void mm_magic_t::tick(
cycle++;
}
void load_mem(void** mems, const char* fn, int nchannels)
void load_mem(void** mems, const char* fn, int line_size, int nchannels)
{
char* m;
ssize_t start = 0;
@ -135,9 +135,9 @@ void load_mem(void** mems, const char* fn, int nchannels)
for (ssize_t i = line.length()-2, j = 0; i >= 0; i -= 2, j++) {
char data = (parse_nibble(line[i]) << 4) | parse_nibble(line[i+1]);
ssize_t addr = start + j;
int channel = (addr / LINE_SIZE) % nchannels;
int channel = (addr / line_size) % nchannels;
m = (char *) mems[channel];
addr = (addr / LINE_SIZE / nchannels) * LINE_SIZE + (addr % LINE_SIZE);
addr = (addr / line_size / nchannels) * line_size + (addr % line_size);
m[addr] = data;
}
start += line.length()/2;

View File

@ -7,9 +7,6 @@
#include <cstring>
#include <queue>
const int LINE_SIZE = 64; // all cores assume this.
const size_t MEM_SIZE = 1L * 1024*1024*1024;
void write_masked_data(
uint8_t *base, uint8_t *data, uint64_t strb, uint64_t size);
@ -148,5 +145,5 @@ class mm_magic_t : public mm_t
uint64_t cycle;
};
void load_mem(void** mems, const char* fn, int channel);
void load_mem(void** mems, const char* fn, int line_size, int nchannels);
#endif

View File

@ -15,9 +15,8 @@ extern "C" {
extern int vcs_main(int argc, char** argv);
static htif_emulator_t* htif;
static unsigned htif_bytes;
static unsigned mem_channels;
static mm_t** mm;
static unsigned htif_bytes = HTIF_WIDTH / 8;
static mm_t* mm[N_MEM_CHANNELS];
static const char* loadmem;
static bool dramsim = false;
@ -43,6 +42,18 @@ int main(int argc, char** argv)
htif = new htif_emulator_t(memsz_mb,
std::vector<std::string>(argv + 1, argv + argc));
for (int i=0; i<N_MEM_CHANNELS; i++) {
mm[i] = dramsim ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
mm[i]->init(MEM_SIZE / N_MEM_CHANNELS, MEM_DATA_BITS / 8, CACHE_BLOCK_BYTES);
}
if (loadmem) {
void *mems[N_MEM_CHANNELS];
for (int i = 0; i < N_MEM_CHANNELS; i++)
mems[i] = mm[i]->get_data();
load_mem(mems, loadmem, CACHE_BLOCK_BYTES, N_MEM_CHANNELS);
}
vcs_main(argc, argv);
abort(); // should never get here
}
@ -83,7 +94,7 @@ void memory_tick(
vc_handle b_id)
{
int c = vc_4stVectorRef(channel)->d;
assert(c < mem_channels);
assert(c < N_MEM_CHANNELS);
mm_t* mmc = mm[c];
uint32_t write_data[mmc->get_word_size()/sizeof(uint32_t)];
@ -146,34 +157,6 @@ void memory_tick(
vc_put4stVector(r_data, d);
}
void htif_init(
vc_handle n_mem_channel,
vc_handle htif_width, vc_handle mem_width)
{
mem_channels = vc_4stVectorRef(n_mem_channel)->d;
int mw = vc_4stVectorRef(mem_width)->d;
assert(mw && (mw & (mw-1)) == 0);
mm = new mm_t*[mem_channels];
for (int i=0; i<mem_channels; i++) {
mm[i] = dramsim ? (mm_t*)(new mm_dramsim2_t) : (mm_t*)(new mm_magic_t);
mm[i]->init(MEM_SIZE / mem_channels, mw/8, LINE_SIZE);
}
if (loadmem) {
void *mems[mem_channels];
for (int i = 0; i < mem_channels; i++)
mems[i] = mm[i]->get_data();
load_mem(mems, loadmem, mem_channels);
}
vec32* w = vc_4stVectorRef(htif_width);
assert(w->d <= 32 && w->d % 8 == 0); // htif_tick assumes data fits in a vec32
htif_bytes = w->d/8;
}
void htif_tick
(
vc_handle htif_in_valid,