Skip to content

Commit

Permalink
Inline memory_{write,fill}
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Jul 27, 2023
1 parent 11ac6e0 commit 6b90241
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
13 changes: 0 additions & 13 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ MEM_READ_IMPL(w, uint32_t);
MEM_READ_IMPL(s, uint16_t);
MEM_READ_IMPL(b, uint8_t);

void memory_write(memory_t *mem,
uint32_t addr,
const uint8_t *src,
uint32_t size)
{
memcpy(mem->mem_base + addr, src, size);
}

#define MEM_WRITE_IMPL(size, type) \
void memory_write_##size(uint32_t addr, const uint8_t *src) \
{ \
Expand All @@ -98,8 +90,3 @@ void memory_write(memory_t *mem,
MEM_WRITE_IMPL(w, uint32_t);
MEM_WRITE_IMPL(s, uint16_t);
MEM_WRITE_IMPL(b, uint8_t);

void memory_fill(memory_t *mem, uint32_t addr, uint32_t size, uint8_t val)
{
memset(mem->mem_base + addr, val, size);
}
20 changes: 15 additions & 5 deletions src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include <stdint.h>
#include <string.h>

/* Directly map a memory with a size of 2^32 bytes. All memory read/write
* operations can access this memory through the memory subsystem.
Expand Down Expand Up @@ -40,15 +41,24 @@ uint8_t memory_read_b(uint32_t addr);
/* read a length of data from memory */
void memory_read(memory_t *m, uint8_t *dst, uint32_t addr, uint32_t size);

void memory_write(memory_t *m,
uint32_t addr,
const uint8_t *src,
uint32_t size);
static inline void memory_write(memory_t *m,
uint32_t addr,
const uint8_t *src,
uint32_t size)
{
memcpy(m->mem_base + addr, src, size);
}

void memory_write_w(uint32_t addr, const uint8_t *src);

void memory_write_s(uint32_t addr, const uint8_t *src);

void memory_write_b(uint32_t addr, const uint8_t *src);

void memory_fill(memory_t *m, uint32_t addr, uint32_t size, uint8_t val);
static inline void memory_fill(memory_t *m,
uint32_t addr,
uint32_t size,
uint8_t val)
{
memset(m->mem_base + addr, val, size);
}

0 comments on commit 6b90241

Please sign in to comment.