> If you compile this example on your implementation you
> will be able to compare the code generated by each.
>
> If you look at the disassembler listing you will see that
> another CASE benefit (particularly useful in embedded
> systems) is that it uses significantly less code space
> than IF THEN ELSE as long as the selections are not
> too sparse. The total code generated for each version
> of the Soundex procedures is:
>
> IF-THEN-ELSE: 420 Bytes
> CASE: 240 Bytes
Thx. That’s a helpful hint. Unfortunately my compiler (so far) only
implements the "jump-table technique", so it does not fare well (in
terms of code-space requirements) in cases where the sparseness
of values in the case-label range is high, as outlined in [1].
A proper comparison with your technique (using a modified BR
instruction) would probably have to implement some of the other
techniques suggested in [1], such as the search tree (effectively
leading to a modern version of the paper in the process..).
But your numbers are appealing indeed!
-ap
[1] http://bernd-oppolzer.de/CaseStmts.pdf
("The implementation of Case Statements in Pascal”)
> This latest (v6.4) release of Embedded Project Oberon is based on the
> current Project Oberon and Verilog sources from Prof Wirth's site. It’s
> available for no charge for Saanlima Electronics' Pepino LX9 (Spartan-6)
> as well as Digilent's Arty-S7 (Spartan-7), Arty and Cmod-A7 (Artix-7)
> development boards:
>
> http://www.astrobe.com/RISC5
>
Is there a way to run Astrobe for FPGA RISC5 on non-Windows machines?
(I mean without running a Windows VM on another platform)
-ap
Following feedback from Prof Wirth I have managed to improve the performance
of the numeric CASE statement in RISC5 Oberon by implementing a variant of
the Branch Conditional instruction in the RISC5 processor.
The standard branch via register instruction is
BR,cond [Rn]
The new variant of this instruction is
BR,cond PC,[Rn]
i.e. the target of the branch is computed by adding the contents of register
n to the current program counter.
Consequently, the average overhead of any selection in a CASE statement,
including range checking, is now a constant 6 instructions. The average
overhead of any selection in an IF THEN ELSE statement is (N + 1) * 2
instructions. Hence, in situations where there is an equal probability of
each selection occurring CASE is faster than IF whenever there are more than
2 selections.
This latest (v6.4) release of Embedded Project Oberon is based on the
current Project Oberon and Verilog sources from Prof Wirth's site. It's
available for no charge for Saanlima Electronics' Pepino LX9 (Spartan-6) as
well as Digilent's Arty-S7 (Spartan-7), Arty and Cmod-A7 (Artix-7)
development boards:
http://www.astrobe.com/RISC5
Regards,
Chris Burrows
CFB Software
http://www.astrobe.com