diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2020-08-31 11:25:19 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2020-08-31 11:25:19 -0400 |
commit | 385a621b9487456c3167f204b02cb0ea0752191d (patch) | |
tree | f8646458ea5b1b49af192d162ed0713c73c6cca6 | |
parent | 4ed07ca38b99abdca750c6612c512f30965f1714 (diff) |
- Optimized the memory read/write functions a bit more.
- Added a memcopy() function, for later on.
-rw-r--r-- | disasm.c | 7 | ||||
-rw-r--r-- | sux.h | 33 | ||||
-rw-r--r-- | test/fib.s | 3 | ||||
-rw-r--r-- | test/nop.s | 8 |
4 files changed, 40 insertions, 11 deletions
@@ -51,10 +51,7 @@ void disasm(struct sux *cpu, uint8_t lines, uint8_t opcode, uint8_t prefix, uint case IMM : case REL : addrsize = (1 << rs)-1; break; } - - for (uint8_t i = 0; i < addrsize+1; i++) { - mask.u8[i] = (i == addrsize && addrsize != 0xFF) ? 0x7F : 0xFF; - } + mask.u64 = (-(uint64_t)1 >> ((7 - addrsize) * 8)); value = read_value(cpu, 0, cpu->pc, addrsize, 0, 0); if ((prefix >> 6) == 1 || (prefix >> 6) == 2 || optype[opcode] == REL) { switch (addrsize) { @@ -67,7 +64,7 @@ void disasm(struct sux *cpu, uint8_t lines, uint8_t opcode, uint8_t prefix, uint case 6 : case 7 : sign = ((int64_t)value < 0) ? "-" : "+"; break; } - value &= mask.u64; + value = (sign[0] == '-') ? (~value + 1) & mask.u64 : value; } switch (optype[opcode]) { case BREG: @@ -49,6 +49,13 @@ extern int get_key(WINDOW *scr); extern void io(uint64_t address, uint8_t rw); extern void init_scr(); + +static inline void *memcopy(void *dst, void *src, size_t n) { + uint8_t *d = dst, *s = src; + for (; n; *d++ = *s++, n--); + return dst; +} + static inline uint64_t read_value(struct sux *cpu, uint64_t reg, uint64_t address, uint8_t size, uint8_t inc_clk, uint8_t check_io) { #if (IO || debug) && !branch #if keypoll @@ -61,18 +68,34 @@ static inline uint64_t read_value(struct sux *cpu, uint64_t reg, uint64_t addres pthread_mutex_unlock(&mutex); #endif #endif - size = (size > 7) ? 7 : size; - uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8)); #if getclk cpu->clk += inc_clk; #endif - return (reg & ~mask) | (*(uint64_t *)(addr+address) & mask); + size = (size > 7) ? 7 : size; + #if 1 + if (size < 7) { + uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8)); + return (reg & ~mask) | (*(uint64_t *)(addr+address) & mask); + } else { + return *(uint64_t *)(addr+address); + } + #else + return *(uint64_t *)memcopy(®, addr+address, size+1); + #endif } static inline void write_value(struct sux *cpu, uint64_t value, uint64_t address, uint8_t size, uint8_t inc_clk, uint8_t check_io) { size = (size > 7) ? 7 : size; - uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8)); - *(uint64_t *)(addr+address) = (*(uint64_t *)(addr+address) & ~mask) | (value & mask); + #if 1 + if (size < 7) { + uint64_t mask = (-(uint64_t)1 >> ((7 - size) * 8)); + *(uint64_t *)(addr+address) = (*(uint64_t *)(addr+address) & ~mask) | (value & mask); + } else { + *(uint64_t *)(addr+address) = value; + } + #else + memcopy(addr+address, &value, size+1); + #endif #if (IO || debug) && !branch #if keypoll pthread_mutex_lock(&mutex); @@ -63,6 +63,9 @@ fib2: bcs start2 ; Start all over again, if the carry flag was set. bra fib2 ; Otherwise, keep looping. + +.org $FFC0 +.qword init ; Set up the thread vectors. .org $FF50 .qword init2 @@ -1,3 +1,4 @@ +.org $8000 reset: cps nop_loop: @@ -7,6 +8,11 @@ nop_loop: nop nop nop + nop + nop bra nop_loop + +.org $FFC0 +.qword reset a -done +d |