-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
byuu says: Note: for Windows users, please go to nall/intrinsics.hpp line 60 and correct the typo from "DISPLAY_WINDOW" to "DISPLAY_WINDOWS" before compiling, otherwise things won't work at all. This will be a really major WIP for the core SNES emulation, so please test as thoroughly as possible. I rewrote the 65816 CPU core's dispatcher from a jump table to a switch table. This was so that I could pass class variables as parameters to opcodes without crazy theatrics. With that, I killed the regs.r[N] stuff, the flag_t operator|=, &=, ^= stuff, and all of the template versions of opcodes. I also removed some stupid pointless flag tests in xcn and pflag that would always be true. I sure hope that AWJ is happy with this; because this change was so that my flag assignments and branch tests won't need to build regs.P into a full 8-bit variable anymore. It does of course incur a slight performance hit when you pass in variables by-value to functions, but it should help with binary size (and thus cache) by reducing a lot of extra functions. (I know I could have used template parameters for some things even with a switch table, but chose not to for the aforementioned reasons.) Overall, it's about a ~1% speedup from the previous build. The CPU core instructions were never a bottleneck, but I did want to fix the P flag building stuff because that really was a dumb mistake v_v'
- Loading branch information
1 parent
ddffcd7
commit 6b44980
Showing
8 changed files
with
198 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
libco.arm (2015-06-18) | ||
author: byuu | ||
license: public domain | ||
*/ | ||
|
||
#define LIBCO_C | ||
#include "libco.h" | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/mman.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
static thread_local unsigned long co_active_buffer[64]; | ||
static thread_local cothread_t co_active_handle = 0; | ||
static void (*co_swap)(cothread_t, cothread_t) = 0; | ||
|
||
static unsigned long co_swap_function[] = { | ||
0xe8a16ff0, /* stmia r1!, {r4-r11,sp,lr} */ | ||
0xe8b0aff0, /* ldmia r0!, {r4-r11,sp,pc} */ | ||
0xe12fff1e, /* bx lr */ | ||
}; | ||
|
||
void co_init() { | ||
unsigned long addr = (unsigned long)co_swap_function; | ||
unsigned long base = addr - (addr % sysconf(_SC_PAGESIZE)); | ||
unsigned long size = (addr - base) + sizeof co_swap_function; | ||
mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC); | ||
} | ||
|
||
cothread_t co_active() { | ||
if(!co_active_handle) co_active_handle = &co_active_buffer; | ||
return co_active_handle; | ||
} | ||
|
||
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { | ||
unsigned long* handle = 0; | ||
if(!co_swap) { | ||
co_init(); | ||
co_swap = (void (*)(cothread_t, cothread_t))co_swap_function; | ||
} | ||
if(!co_active_handle) co_active_handle = &co_active_buffer; | ||
size += 256; | ||
size &= ~15; | ||
|
||
if(handle = (unsigned long*)malloc(size)) { | ||
unsigned long* p = (unsigned long*)((unsigned char*)handle + size); | ||
handle[8] = (unsigned long)p; | ||
handle[9] = (unsigned long)entrypoint; | ||
} | ||
|
||
return handle; | ||
} | ||
|
||
void co_delete(cothread_t handle) { | ||
free(handle); | ||
} | ||
|
||
void co_switch(cothread_t handle) { | ||
cothread_t co_previous_handle = co_active_handle; | ||
co_swap(co_active_handle = handle, co_previous_handle); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
/* | ||
libco | ||
auto-selection module | ||
license: public domain | ||
*/ | ||
|
||
#if defined(__GNUC__) && defined(__i386__) | ||
#include "x86.c" | ||
#elif defined(__GNUC__) && defined(__amd64__) | ||
#include "amd64.c" | ||
#elif defined(__GNUC__) && defined(_ARCH_PPC) | ||
#include "ppc.c" | ||
#elif defined(__GNUC__) | ||
#include "sjlj.c" | ||
#elif defined(_MSC_VER) && defined(_M_IX86) | ||
#include "x86.c" | ||
#elif defined(_MSC_VER) && defined(_M_AMD64) | ||
#include "amd64.c" | ||
#if defined(__clang__) || defined(__GNUC__) | ||
#if defined(__i386__) | ||
#include "x86.c" | ||
#elif defined(__amd64__) | ||
#include "amd64.c" | ||
#elif defined(__arm__) | ||
#include "arm.c" | ||
#elif defined(_ARCH_PPC) | ||
#include "ppc.c" | ||
#elif defined(_WIN32) | ||
#include "fiber.c" | ||
#else | ||
#include "sjlj.c" | ||
#endif | ||
#elif defined(_MSC_VER) | ||
#include "fiber.c" | ||
#if defined(_M_IX86) | ||
#include "x86.c" | ||
#elif defined(_M_AMD64) | ||
#include "amd64.c" | ||
#else | ||
#include "fiber.c" | ||
#endif | ||
#else | ||
#error "libco: unsupported processor, compiler or operating system" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
libco | ||
version: 0.16 (2010-12-24) | ||
version: 0.17 (2015-06-18) | ||
author: byuu | ||
license: public domain | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
#define LIBCO_C | ||
#include "libco.h" | ||
|
||
#include <stdlib.h> | ||
#include <signal.h> | ||
#include <setjmp.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters