Numeric CASE vs IF THEN ELSE Performance
I'll post a message on the Astrobe Forum and this mailing list when it is available.
Ok. We can compare notes then. I have carried forward the implementation of the numeric CASE statement from Ceres Oberon to FPGA Oberon (but of course using the regular BR instruction, i.e. using BR,cond [Rn] and not BR,cond PC,[Rn]). If the performance with your *modified* BR instruction really is demonstrably better AND the new instruction becomes part of the RISC instruction set, then it is perhaps worth making the implementation of the numeric CASE available to everyone. -ap
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Andreas Pirklbauer Sent: Sunday, 10 June 2018 3:55 AM To: ETH Oberon and related systems Subject: [Oberon] Numeric CASE vs IF THEN ELSE Performance
I'll post a message on the Astrobe Forum and this mailing list when it is available.
Ok. We can compare notes then. I have carried forward the implementation of the numeric CASE statement from Ceres Oberon to FPGA Oberon (but of course using the regular BR instruction, i.e. using BR,cond [Rn] and not BR,cond PC,[Rn]).
If the performance with your *modified* BR instruction really is demonstrably better AND the new instruction becomes part of the RISC instruction set, then it is perhaps worth making the implementation of the numeric CASE available to everyone.
I have some example code and output to illustrate all of this but unfortunately this mailing list is not a suitable medium: * Attaching files, showing screenshots and including formatted code snippets are problematic. * Everybody is bombarded with copies of the files even if they have 0% interest in the discussion. Consequently I have relaunched this discussion on the Astrobe forum: http://www.astrobe.com/forum/viewforum.php?f=13 The Soundex-inspired example code included there has an Astrobe compiler listing file which shows the actual code generated for each statement in a disassembler-style listing, and a screenshot of the output showing the actual results running on an Arty development board. 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 Regards, Chris Burrows CFB Software http://www.astrobe.com/RISC5
The Soundex-inspired example code included there has an Astrobe compiler listing file which shows the actual code generated for each statement in a disassembler-style listing, and a screenshot of the output showing the actual results running on an Arty development board.
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
For the special case of Soundex, neither IF-THEN nor CASE are perfect as we don’t want to execute statements per character but we want to map characters to their phonetic type: labial (1), guttural (2), dental-mute (3), palatal (4), nasal (5), dental-fricative (6) and vowels/silent (0). So, an ARRAY is the best (speed and storage-wise) data structure to hold that mapping. PROCEDURE SoundexArray(ch: CHAR): INTEGER; RETURN ORD( map[ ORD(ch)-ORD("A") ] ) - ORD("0") END SoundexArray; BEGIN (* ABCDEFGHIJKLMNOPQRSTUVWXYZ *) map := "01230120022455012623010202" END Soundex.Run ARRAY: 56 Bytes one-time initialization + string constant: 63 Bytes BTW: the runtime behaviour of the IF implementation can be optimized a little bit by rearranging the different IFs / ORs by taking the letter frequency into account. (vowels: 49%, dental-mute: 13%, guttural: 12%, nasal: 9%, labial: 7%, dental-fricative: 6%, palatal: 4%). The code size can shrink a little by using an ELSE to combine the eight gutturals. br Jörg
participants (3)
-
Andreas Pirklbauer -
Chris Burrows -
Jörg