-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
AS = $(VASM) | ||
CC = $(VC) | ||
LD = $(VLINK) | ||
|
||
ASFLAGS := -quiet -Fhunk -kick1hunks -nosym -m68000 -no-opt | ||
CFLAGS := -v -O2 -size -cpu=68060 -c99 -k -sc -DDEBUG | ||
LDFLAGS := -sc -Bstatic -Cvbcc -nostdlib -Rshort -b amigahunk -s | ||
|
||
TARGET := timer | ||
OBJECTS := main.o timer.o | ||
INCLUDE := $(wildcard *.h) $(wildcard *.s) | ||
|
||
CRT0 = $(VBCC)/targets/m68k-amigaos/lib/startup.o | ||
LDLIBS = -L$(VBCC)/targets/m68k-amigaos/lib -lvc | ||
|
||
.EXPORT_ALL_VARIABLES: | ||
|
||
.PHONY: clean | ||
|
||
all: $(TARGET) | ||
|
||
clean: | ||
rm -f $(TARGET) $(OBJECTS) $(OBJECTS:.o=.asm) *.txt | ||
|
||
$(TARGET) : $(OBJECTS) Makefile | buildenv | ||
$(LD) $(LDFLAGS) $(CRT0) $(OBJECTS) $(LDLIBS) -o $@ -M$@.txt | ||
|
||
%.o: %.c $(INCLUDE) Makefile | buildenv | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
%.o: %.s Makefile | buildenv | ||
$(AS) $< -o $@ -L $<.txt $(ASFLAGS) -I $(INC_ASM) | ||
|
||
include ../Makefile.build |
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,43 @@ | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
#include <proto/exec.h> | ||
|
||
#define NUMRUNS (10) | ||
#define NUMITERATIONS (10000) | ||
|
||
uint32_t runAsmCode(__reg("d0") uint32_t iterations); | ||
uint32_t getCpuCycle() = | ||
"\tmoveq.l\t#0,d0\n" | ||
"\trept 100\n" | ||
"\tsub.l\t$40400000,d0\t;read CPU clock\n" | ||
"\tadd.l\t$40400000,d0\n" | ||
"\tendr\n"; | ||
|
||
static uint32_t sample() | ||
{ | ||
return getCpuCycle(); | ||
} | ||
|
||
int main() | ||
{ | ||
uint32_t result[NUMRUNS]; | ||
|
||
// Calibrate the cost of reading the cycle counter | ||
Disable(); | ||
for (int i = 0; i < NUMRUNS; ++i) | ||
result[i] = sample(); | ||
Enable(); | ||
for (int i = 0; i < NUMRUNS; ++i) | ||
printf("REPT 100 took %d cycles\n", (int)result[i]); | ||
|
||
// Measure the 5c/7instr loop | ||
Disable(); | ||
for (int i = 0; i < NUMRUNS; ++i) | ||
result[i] = runAsmCode(NUMITERATIONS); | ||
Enable(); | ||
for (int i = 0; i < NUMRUNS; ++i) | ||
printf("%d iterations took %d cycles\n", NUMITERATIONS, (int)result[i]); | ||
|
||
return 0; | ||
} |
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,31 @@ | ||
|
||
; Example program | ||
; This runs a 5-cycle code loop for N iterations (provided in D0), | ||
; and then returns (in D0) the number of CPU cycles used. | ||
|
||
PUBLIC _runAsmCode | ||
|
||
_runAsmCode: | ||
|
||
bset.b #1,$bfe001 ; trigger logic analyzer | ||
tst.b $bfe001 ; delay due to SIO on the 060db | ||
move.l $40400000,a0 ; sample cpu clock counter | ||
|
||
.iter: | ||
addx.l d1,d1 ; pOEP-only | ||
addx.l d1,d1 ; pOEP-only | ||
addx.l d1,d1 ; pOEP-only | ||
addx.l d1,d1 ; pOEP-only | ||
|
||
add.l d1,d1 ; pOEP|sOEP | ||
subq.l #1,d0 ; pOEP|sOEP | ||
bne.s .iter ; is predicted and folded, takes 0 cycles | ||
|
||
sub.l $40400000,a0 ; sample cpu clock counter | ||
bclr.b #1,$bfe001 ; reset logic analyzer | ||
|
||
moveq.l #0,d0 | ||
sub.l a0,d0 | ||
|
||
rts | ||
|