[Oberon] Bit manipulation in Oberon-07

Jörg joerg.straube at iaeth.ch
Sun Oct 28 08:15:02 CET 2018


Chris

I‘m still puzzeled why to introduce a SYSTEM procedure, when the generated code by the RISC5 compiler is not more efficient than if you program it with „normal“ Oberon means.

Let’s look at the „original“ UBFX assembler instruction with LSB and width, not your enhanced version with LSB, MSB.

UBFX(dst, src, 5, 10) can simply be written as   dst := src DIV b5 MOD b10;

We only have to define once in the declaration part of the module the constants b0..b31 as follows

IMPORT S := SYSTEM;
CONST
  b0 = S.VAL(INTEGER, {0});
  b1 = S.VAL(INTEGER, {1});
  ...
  b31 = S.VAL(INTEGER, {31});

Obviously you are free to add as many new procedures to your compiler if you feel need to do so. Personally I find it confusing when you name the function identical to the ARM assembler instruction BUT modify the meaning of the parameters. Why not name it UBFM? „UBFX lsb, wid“ is an alias for „UBFM lsb, lsb+wid-1“, basically exactly your modified definition of your enhanced UBFX.

BTW: the task the original poster in the Astrobe forum asked (sending the address and control phase to the W5500 chip) can be programmed MUCH simpler as follows

PROCEDURE w5500Send(offset: INTEGER; blockselect: BYTE; 
                     buffer: ARRAY OF BYTE; len: INTEGER);
BEGIN
  (* select chip *)             S.PUT(spiCtrl, W5500);
  (* address phase *)      SPI(offset DIV 256); SPI(offset MOD 256); 
  (* control phase *)        SPI(blockselect*8 + 4);  (* assuming VDM *)
  (* data phase *)             FOR i := 0 TO len-1 DO SPI(buf[i]) END;
  (* deselect the chip *)  S.PUT(spiCtrl, 0);
END;

To be on the safe side, we could insert three ASSERTs like
   ASSERT(offset < 10000H); ASSERT(blockselect < 32); ASSERT (len < LEN(buffer));
But I ommitted these to speed up a little...

br
Jörg

Am 28.10.2018 um 02:22 schrieb Chris Burrows <chris at cfbsoftware.com>:

>> -----Original Message-----
>> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
>> Skulski, Wojciech
>> Sent: Sunday, 28 October 2018 9:46 AM
>> To: ETH Oberon and related systems
>> Subject: Re: [Oberon] Bit manipulation in Oberon-07
>> 
>>> Portability is not a realistic aim when working with hardware-
>> defined
>>> interfaces,
>> 
>> Same here. Meanwhile we will adopt your example procedures in our
>> code.
>> 
> 
> If you are working with beginners, you might want to make the functions a
> little more robust to quickly draw attention to common errors. Because all
> of the parameters are integers I have discovered (just by writing the test
> program) that it is easy to make mistakes. If the parameters are not used in
> the correct order the resulting problems can be tricky to diagnose. If
> performance is not a crucial issue then it is wise to add some
> parameter-checking assertions so that these sorts of errors are detected
> ASAP. 
> 
> e.g. check that MSB and LSB are in the correct order; LSB and MSB are both
> in the range 0..31 and that the bitfield parameter to BFI is not larger than
> the space allocated to it. I have updated the sample code to do this, but as
> this email server tends to make a mess of code-formatting, I have presented
> the revised code on the corresponding discussion on the Astrobe forum:
> 
> http://www.astrobe.com/forum/viewtopic.php?f=4&t=588
> 
> Regards,
> Chris
> 
> Chris Burrows
> CFB Software
> http://www.astrobe.com/RISC5
> 
> 
> 
> 
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list