Skip to content

Commit

Permalink
One more go
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Sep 30, 2023
1 parent 943f9ba commit d116232
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/Platform_Dreamcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,26 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
}
// Borrowed from kos/kernel/arch/dreamcast/kernel/timer.c so it compiles
// with older toolchain versions
#define NS_PER_CYCLE 5
#define _PMCR_CTRL_0 ( *((volatile uint16*)(0xff000084)) )
#define _PMCTR_HIGH_0 ( *((volatile uint32*)(0xff100004)) )
#define _PMCTR_LOW_0 ( *((volatile uint32*)(0xff100008)) )
#define _PMCR_CLR 0x2000
#define _PMCR_PMENABLE 0x8000
#define _PMCR_RUN 0xc000
#define _PMCR_PMM_MASK 0x003f
#define _PMCR_CLOCK_TYPE_SHIFT 8
#define _NS_PER_CYCLE 5
#define _PMCR_COUNT_CPU_CYCLES 0
#define _PMCR_ELAPSED_TIME_MODE 0x23

cc_uint64 Stopwatch_Measure(void) {
uint64 cycles = perf_cntr_count(PRFC0);
return cycles * NS_PER_CYCLE;
uint64 cycles = (uint64)(_PMCTR_HIGH_0 & 0xFFFF) << 32 | _PMCTR_LOW_0;
return cycles * _NS_PER_CYCLE;
}
static void Stopwatch_Init(void) {
perf_cntr_start(PRFC0, PMCR_ELAPSED_TIME_MODE, PMCR_COUNT_CPU_CYCLES);
_PMCR_CTRL_0 &= ~(_PMCR_PMM_MASK | _PMCR_PMENABLE);
_PMCR_CTRL_0 |= _PMCR_CLR;
_PMCR_CTRL_0 = _PMCR_RUN | _PMCR_ELAPSED_TIME_MODE | (_PMCR_COUNT_CPU_CYCLES << _PMCR_CLOCK_TYPE_SHIFT);
}
// NOTE: If using newer toolchain versions, only need this:
// cc_uint64 Stopwatch_Measure(void) { return timer_ns_gettime64(); }
Expand Down
2 changes: 1 addition & 1 deletion third_party/gldc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SOURCE_DIRS := src src/yalloc
C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c))
OBJS := $(notdir $(C_FILES:%.c=%.o))

C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -fno-math-errno -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -flto -fno-fat-lto-objects -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99
C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -fno-math-errno -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99

C_DEFINES = -DDREAMCAST -DNDEBUG -D__DREAMCAST__ -D__arch_dreamcast -D_arch_dreamcast -D_arch_sub_pristine

Expand Down

0 comments on commit d116232

Please sign in to comment.