Skip to content

Commit e42fee8

Browse files
committed
Updated Makefile, and introduced a simple decode-to-length benchmark/test tool, requires my psflib library
1 parent 88f0f02 commit e42fee8

File tree

4 files changed

+167
-7
lines changed

4 files changed

+167
-7
lines changed

Makefile

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11

2-
CFLAGS = -c -m32
2+
CFLAGS = -g -c
33

44
OBJS_RECOMPILER_32 = r4300/x86/assemble.o r4300/x86/gbc.o r4300/x86/gcop0.o r4300/x86/gcop1.o r4300/x86/gcop1_d.o r4300/x86/gcop1_l.o r4300/x86/gcop1_s.o r4300/x86/gcop1_w.o r4300/x86/gr4300.o r4300/x86/gregimm.o r4300/x86/gspecial.o r4300/x86/gtlb.o r4300/x86/regcache.o r4300/x86/rjump.o
55

66
OBJS_RECOMPILER_64 = r4300/x86_64/assemble.o r4300/x86_64/gbc.o r4300/x86_64/gcop0.o r4300/x86_64/gcop1.o r4300/x86_64/gcop1_d.o r4300/x86_64/gcop1_l.o r4300/x86_64/gcop1_s.o r4300/x86_64/gcop1_w.o r4300/x86_64/gr4300.o r4300/x86_64/gregimm.o r4300/x86_64/gspecial.o r4300/x86_64/gtlb.o r4300/x86_64/regcache.o r4300/x86_64/rjump.o
77

8-
OBJS = ai/ai_controller.o api/callbacks.o main/main.o main/rom.o main/savestates.o main/util.o memory/memory.o pi/cart_rom.o pi/pi_controller.o r4300/cached_interp.o r4300/cp0.o r4300/cp1.o r4300/exception.o r4300/interupt.o r4300/mi_controller.o r4300/pure_interp.o r4300/r4300.o r4300/r4300_core.o r4300/recomp.o r4300/reset.o r4300/tlb.o rdp/rdp_core.o ri/rdram.o ri/rdram_detection_hack.o ri/ri_controller.o rsp/rsp_core.o rsp_hle/alist.o rsp_hle/alist_audio.o rsp_hle/alist_naudio.o rsp_hle/alist_nead.o rsp_hle/audio.o rsp_hle/cicx105.o rsp_hle/hle.o rsp_hle/jpeg.o rsp_hle/memory.o rsp_hle/mp3.o rsp_hle/musyx.o rsp_hle/plugin.o rsp_lle/rsp.o si/cic.o si/game_controller.o si/n64_cic_nus_6105.o si/pif.o si/si_controller.o usf/usf.o usf/resampler.o vi/vi_controller.o $(OBJS_RECOMPILER_32)
8+
OBJS = ai/ai_controller.o api/callbacks.o main/main.o main/rom.o main/savestates.o main/util.o memory/memory.o pi/cart_rom.o pi/pi_controller.o r4300/cached_interp.o r4300/cp0.o r4300/cp1.o r4300/exception.o r4300/interupt.o r4300/mi_controller.o r4300/pure_interp.o r4300/r4300.o r4300/r4300_core.o r4300/recomp.o r4300/reset.o r4300/tlb.o rdp/rdp_core.o ri/rdram.o ri/rdram_detection_hack.o ri/ri_controller.o rsp/rsp_core.o rsp_hle/alist.o rsp_hle/alist_audio.o rsp_hle/alist_naudio.o rsp_hle/alist_nead.o rsp_hle/audio.o rsp_hle/cicx105.o rsp_hle/hle.o rsp_hle/jpeg.o rsp_hle/memory.o rsp_hle/mp3.o rsp_hle/musyx.o rsp_hle/plugin.o rsp_lle/rsp.o si/cic.o si/game_controller.o si/n64_cic_nus_6105.o si/pif.o si/si_controller.o usf/usf.o usf/resampler.o vi/vi_controller.o $(OBJS_RECOMPILER_64)
99

1010
OPTS = -O3 -DDYNAREC -I.
1111
ROPTS = -O3 -DARCH_MIN_SSE2 -I.
1212

13-
all: liblazyusf.a
13+
all: liblazyusf.a bench
1414

1515
liblazyusf.a : $(OBJS)
1616
$(AR) rcs $@ $^
1717

18+
bench : test/bench.o liblazyusf.a
19+
$(CC) -g -o $@ $^ ../psflib/libpsflib.a -lz
20+
1821
.c.o:
1922
$(CC) $(CFLAGS) $(OPTS) -o $@ $*.c
2023

2124
rsp_lle/rsp.o: rsp_lle/rsp.c
2225
$(CC) $(CFLAGS) $(ROPTS) -o $@ $^
2326

27+
test/bench.o: test/bench.c
28+
$(CC) $(CFLAGS) $(OPTS) -I../psflib -o $@ $^
29+
2430
clean:
25-
rm -f $(OBJS) liblazyusf.a > /dev/null
31+
rm -f $(OBJS) liblazyusf.a test/bench.o bench > /dev/null
2632

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ This is a half assed attempt to replace Project64 with Mupen64plus, for a hoped
33
DONE:
44
* Get it working at all
55
* Verify old x86_64 recompiler works
6-
* Convert x86 recompiler
6+
* Converted x86 recompiler
77

88
TODO:
9-
* Get x86 recompiler working with MSVC 32 bit
109
* Get new recompiler converted and working
10+
11+
Usage notes:
12+
13+
If your platform is x86 or x86_64, you may define ARCH_MIN_SSE2 for the rsp.c inside the rsp_lle subdirectory. You may also define DYNAREC and include the contents of either the r4300/x86 or r4300/x86_64 directories, and exclude the r4300/empty_dynarec.c file.
14+
15+
If you are not either of the above architectures, you include r4300/empty_dynarec.c and do not define DYNAREC, in which case the fastest you get is a cached interpreter, which "compiles" blocks of opcode function pointers and their pre-decoded parameters.
16+
17+
In either case, you do not include the contents of the new_dynarec folder, since that code is not ready for use with this library yet.

r4300/x86/rjump.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void dyna_start(usf_state_t * state, void *code)
9090
pop ebp
9191
}
9292
#elif defined(__GNUC__) && defined(__i386__)
93-
#if defined(__PIC__)
93+
#if defined(__PIC__) && !defined(__APPLE__)
9494
/* for -fPIC (shared libraries) */
9595
#ifndef __GNUC_PREREQ
9696
# if defined __GNUC__ && defined __GNUC_MINOR__

test/bench.c

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
4+
#include "../usf/usf.h"
5+
6+
#include <psflib.h>
7+
8+
unsigned char * state = 0;
9+
10+
unsigned int enable_compare = 0;
11+
unsigned int enable_fifo_full = 0;
12+
13+
unsigned long length_ms = 0;
14+
15+
static void * stdio_fopen( const char * path )
16+
{
17+
return fopen( path, "rb" );
18+
}
19+
20+
static size_t stdio_fread( void *p, size_t size, size_t count, void *f )
21+
{
22+
return fread( p, size, count, (FILE*) f );
23+
}
24+
25+
static int stdio_fseek( void * f, int64_t offset, int whence )
26+
{
27+
return fseek( (FILE*) f, offset, whence );
28+
}
29+
30+
static int stdio_fclose( void * f )
31+
{
32+
return fclose( (FILE*) f );
33+
}
34+
35+
static long stdio_ftell( void * f )
36+
{
37+
return ftell( (FILE*) f );
38+
}
39+
40+
static psf_file_callbacks stdio_callbacks =
41+
{
42+
"\\/:",
43+
stdio_fopen,
44+
stdio_fread,
45+
stdio_fseek,
46+
stdio_fclose,
47+
stdio_ftell
48+
};
49+
50+
static int usf_loader(void * context, const uint8_t * exe, size_t exe_size,
51+
const uint8_t * reserved, size_t reserved_size)
52+
{
53+
if ( exe && exe_size > 0 ) return -1;
54+
55+
return usf_upload_section( state, reserved, reserved_size );
56+
}
57+
58+
#define BORK_TIME 0xC0CAC01A
59+
60+
static unsigned long parse_time_crap(const char *input)
61+
{
62+
unsigned long value = 0;
63+
unsigned long multiplier = 1000;
64+
const char * ptr = input;
65+
unsigned long colon_count = 0;
66+
67+
while (*ptr && ((*ptr >= '0' && *ptr <= '9') || *ptr == ':'))
68+
{
69+
colon_count += *ptr == ':';
70+
++ptr;
71+
}
72+
if (colon_count > 2) return BORK_TIME;
73+
if (*ptr && *ptr != '.' && *ptr != ',') return BORK_TIME;
74+
if (*ptr) ++ptr;
75+
while (*ptr && *ptr >= '0' && *ptr <= '9') ++ptr;
76+
if (*ptr) return BORK_TIME;
77+
78+
ptr = strrchr(input, ':');
79+
if (!ptr)
80+
ptr = input;
81+
for (;;)
82+
{
83+
char * end;
84+
if (ptr != input) ++ptr;
85+
if (multiplier == 1000)
86+
{
87+
double temp = strtod(ptr, &end);
88+
if (temp >= 60.0) return BORK_TIME;
89+
value = (long)(temp * 1000.0f);
90+
}
91+
else
92+
{
93+
unsigned long temp = strtoul(ptr, &end, 10);
94+
if (temp >= 60 && multiplier < 3600000) return BORK_TIME;
95+
value += temp * multiplier;
96+
}
97+
if (ptr == input) break;
98+
ptr -= 2;
99+
while (ptr > input && *ptr != ':') --ptr;
100+
multiplier *= 60;
101+
}
102+
103+
return value;
104+
}
105+
106+
static int usf_info(void * context, const char * name, const char * value)
107+
{
108+
if (!strcasecmp(name, "length") || !strcasecmp(name, "fade"))
109+
length_ms += parse_time_crap(value);
110+
else if (!strcasecmp(name, "_enablecompare") && *value)
111+
enable_compare = 1;
112+
else if (!strcasecmp(name, "_enablefifofull") && *value)
113+
enable_fifo_full = 1;
114+
115+
return 0;
116+
}
117+
118+
int main(int argc, char ** argv)
119+
{
120+
if ( argc == 2 || argc == 3 )
121+
{
122+
int32_t sample_rate;
123+
124+
state = (unsigned char *) malloc(usf_get_state_size());
125+
126+
usf_clear(state);
127+
128+
if ( psf_load( argv[1], &stdio_callbacks, 0x21, usf_loader, 0, usf_info, 0, 1 ) <= 0 )
129+
return 1;
130+
131+
usf_set_compare(state, enable_compare);
132+
usf_set_fifo_full(state, enable_fifo_full);
133+
134+
if (argc == 3)
135+
usf_set_hle_audio(state, 1);
136+
137+
usf_render(state, 0, 0, &sample_rate);
138+
139+
usf_render(state, 0, length_ms * sample_rate / 1000, &sample_rate);
140+
141+
usf_shutdown(state);
142+
143+
free(state);
144+
}
145+
146+
return 0;
147+
}

0 commit comments

Comments
 (0)