Skip to content

Commit 839d082

Browse files
improve retro rocket BASIC speed by 10x. add clocksp and bench programs to verify improvements
1 parent 6515668 commit 839d082

5 files changed

Lines changed: 272 additions & 54 deletions

File tree

include/taskswitch.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ process_t* proc_cur(uint8_t logical_cpu);
159159
*/
160160
void proc_wait(process_t* proc, pid_t otherpid);
161161

162-
/**
163-
* @brief Execute one atomic BASIC cycle for a process.
164-
*
165-
* @param proc Process to run
166-
*/
167-
void proc_run(process_t* proc);
168-
169162
/**
170163
* @brief Determine if a program has ended.
171164
*
@@ -198,13 +191,6 @@ bool proc_kill_id(pid_t id);
198191
*/
199192
_Noreturn void proc_loop();
200193

201-
/**
202-
* @brief Switch to the next scheduled process.
203-
*
204-
* Implements a round-robin scheduling algorithm.
205-
*/
206-
void proc_timer();
207-
208194
/**
209195
* @brief Get total number of running processes.
210196
*

os/programs/bench.rrbasic

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
REM --- simple retro rocket benchmark ---
2+
3+
DIM results#, 6
4+
5+
total# = 0
6+
minv# = 0
7+
maxv# = 0
8+
9+
FOR run = 1 TO 5
10+
PRINT "Run "; run; " of 5"
11+
12+
start# = TICKS
13+
14+
PRINT "Testing integer operations"
15+
sumi = 0
16+
FOR i = 1 TO 10000
17+
sumi = sumi + i
18+
sumi = sumi - 1
19+
sumi = sumi * 2
20+
sumi = sumi / 2
21+
NEXT
22+
23+
PRINT "Testing real operations"
24+
sumf# = 0.0
25+
FOR i = 1 TO 5000
26+
sumf# = sumf# + 1.1
27+
sumf# = sumf# * 1.0001
28+
sumf# = sumf# / 1.0001
29+
NEXT
30+
31+
PRINT "Tesing string operations"
32+
s$ = "abcdefghijklmnopqrstuvwxyz012345"
33+
FOR i = 1 TO 5000
34+
s$ = MID$(s$, 2, 31) + "x"
35+
NEXT
36+
37+
PRINT "Testing REPEAT/UNTIL"
38+
r = 0
39+
REPEAT
40+
r = r + 1
41+
UNTIL r = 10000
42+
43+
elapsed# = TICKS - start#
44+
45+
results#(run) = elapsed#
46+
total# = total# + elapsed#
47+
48+
IF run = 1 THEN
49+
minv# = elapsed#
50+
maxv# = elapsed#
51+
ELSE
52+
minv# = MINR(minv#, elapsed#)
53+
maxv# = MAXR(maxv#, elapsed#)
54+
ENDIF
55+
NEXT
56+
57+
avg# = total# / 5
58+
59+
PRINT
60+
PRINT "min: "; minv#
61+
PRINT "avg: "; avg#
62+
PRINT "max: "; maxv#

os/programs/clocksp.rrbasic

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
REM > ClockSp
2+
REM Retro Rocket BASIC CPU timing benchmark
3+
REM Based on the BBC BASIC ClockSp program used for Tube co-processor comparison.
4+
REM The reported MHz values are relative, not physical CPU frequencies.
5+
REM Results are only meaningful when compared with other BASIC implementations.
6+
7+
PRINT "BBC BASIC CPU Timing Program"
8+
9+
t# = TICKS
10+
REPEAT
11+
UNTIL TICKS > t# + 50
12+
13+
b# = 1
14+
bi = 1
15+
c# = 1000
16+
ci = 1000
17+
d# = 5100
18+
di = 5100
19+
z# = 0
20+
zi = 0
21+
22+
PRINT "Real REPEAT loop ";
23+
t# = TICKS
24+
a# = z#
25+
REPEAT
26+
a# = a# + b#
27+
UNTIL a# > c#
28+
t# = TICKS - t#
29+
PROCp(40800 / t#)
30+
31+
PRINT "Integer REPEAT loop ";
32+
t# = TICKS
33+
ai = zi
34+
REPEAT
35+
ai = ai + bi
36+
UNTIL ai > ci
37+
t# = TICKS - t#
38+
PROCp(24000 / t#)
39+
40+
PRINT "Real FOR loop ";
41+
t# = TICKS
42+
FOR a# = z# TO d# STEP b#
43+
NEXT
44+
t# = TICKS - t#
45+
PROCp(51000 / t#)
46+
47+
PRINT "Integer FOR loop ";
48+
t# = TICKS
49+
FOR ai = zi TO di STEP bi
50+
NEXT
51+
t# = TICKS - t#
52+
PROCp(17800 / t#)
53+
54+
PRINT "Floating-Point Test ";
55+
a# = 1
56+
t# = 0
57+
reps = 1
58+
59+
REPEAT
60+
t0# = TICKS
61+
FOR r = 1 TO reps
62+
FOR j = 1 TO 29
63+
a# = TAN(ATAN(EXP(LOG(SQR(a# * a#))))) + 1
64+
NEXT
65+
NEXT
66+
t# = TICKS - t0#
67+
reps = reps * 2
68+
UNTIL t# > 0
69+
PROCp((66500 * reps) / t#)
70+
71+
PRINT "Ackermann Recursion ";
72+
m = 3
73+
ackreps = 1
74+
t# = 0
75+
REPEAT
76+
t0# = TICKS
77+
FOR ackr = 1 TO ackreps
78+
FOR n = 1 TO 3
79+
z = FNAck(m, n)
80+
NEXT
81+
NEXT
82+
t# = TICKS - t0#
83+
IF t# = 0 THEN
84+
ackreps = ackreps * 2
85+
ENDIF
86+
UNTIL t# > 0
87+
PROCp((254500 * ackreps) / t#)
88+
89+
PRINT "Combined Average ";
90+
PROCp(FNspeed)
91+
92+
PRINT
93+
PRINT "Compared to a BBC B running at 2.00MHz"
94+
95+
END
96+
97+
DEF FNAck(m, n)
98+
IF m = 0 THEN
99+
= n + 1
100+
ENDIF
101+
102+
IF n = 0 THEN
103+
= FNAck(m - 1, 1)
104+
ENDIF
105+
106+
= FNAck(m - 1, FNAck(m, n - 1))
107+
108+
DEF PROCp(speed#)
109+
PRINT "Speed: "; speed#; "MHz"
110+
ENDPROC
111+
112+
DEF FNspeed
113+
REM use separate variable names instead of LOCAL
114+
115+
tb# = TICKS
116+
REPEAT
117+
UNTIL TICKS > tb# + 50
118+
119+
bb# = 1
120+
bbi = 1
121+
cc# = 1000
122+
cci = 1000
123+
dd# = 5100
124+
ddi = 5100
125+
zz# = 0
126+
zzi = 0
127+
128+
tb# = TICKS
129+
aa# = zz#
130+
REPEAT
131+
aa# = aa# + bb#
132+
UNTIL aa# > cc#
133+
tb# = TICKS - tb#
134+
u# = 40800 / tb#
135+
136+
tb# = TICKS
137+
aai = zzi
138+
REPEAT
139+
aai = aai + bbi
140+
UNTIL aai > cci
141+
tb# = TICKS - tb#
142+
v# = 24000 / tb#
143+
144+
tb# = TICKS
145+
FOR aa# = zz# TO dd# STEP bb#
146+
NEXT
147+
tb# = TICKS - tb#
148+
w# = 51000 / tb#
149+
150+
tb# = TICKS
151+
FOR aai = zzi TO ddi STEP bbi
152+
NEXT
153+
tb# = TICKS - tb#
154+
x# = 17800 / tb#
155+
qq# = 1
156+
reps = 1
157+
tb# = 0
158+
159+
REPEAT
160+
t0# = TICKS
161+
FOR rr = 1 TO reps
162+
FOR jj = 1 TO 29
163+
qq# = TAN(ATAN(EXP(LOG(SQR(qq# * qq#))))) + 1
164+
NEXT
165+
NEXT
166+
tb# = TICKS - t0#
167+
IF tb# = 0 THEN
168+
reps = reps * 2
169+
ENDIF
170+
UNTIL tb# > 0
171+
y# = (66500 * reps) / tb#
172+
173+
= (u# + v# + w# + x# + y#) / 5

src/basic/function.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct basic_double_fn builtin_double[] = {
194194
{ basic_sqrt, "SQRT" },
195195
{ basic_sqrt, "SQR" },
196196
{ basic_atan, "ATAN" },
197+
{ basic_atan, "ATN" },
197198
{ basic_atan2, "ATAN2" },
198199
{ basic_ceil, "CEIL" },
199200
{ basic_round, "ROUND" },
@@ -202,6 +203,7 @@ struct basic_double_fn builtin_double[] = {
202203
{ basic_acs, "ACS" },
203204
{ basic_exp, "EXP" },
204205
{ basic_log, "LOG" },
206+
{ basic_log, "LN" },
205207
{ basic_deg, "DEG" },
206208
{ basic_rad, "RAD" },
207209
{ basic_dataread_real, "DATAREADR" },

0 commit comments

Comments
 (0)