[Oberon] FPGA - Bit reversal
Jörg
joerg.straube at iaeth.ch
Fri Sep 22 10:04:30 CEST 2017
Tomas
in C: >>4
In Oberon: DIV 16
As 16 is a power of two, the Oberon compiler will automatically convert the division into a shift operation.
In C: <<4
In Oberon: * 16
As 16 is a power of 2, the Oberon compiler will automatically convert the multiplication into a shift operation.
Jörg
> Am 22.09.2017 um 09:54 schrieb Tomas Kral <thomas.kral at email.cz>:
>
> On Fri, 22 Sep 2017 00:12:10 +0200
> Jörg <joerg.straube at iaeth.ch> wrote:
>
> Hi Joerg,
>
>> Your „WriteBin" could also look like this:
>>
>> PROCEDURE WriteBin(wd, n: INTEGER);
>> VAR i: INTEGER;
>> BEGIN
>> FOR i := 0 TO n-1 DO
>> IF ODD(wd) THEN Out.Ch("1“) ELSE Out.Ch("0“)
>> END; wd := wd DIV 2
>> END;
>> Out.Ln
>> END WriteBin;
>
> This is by far the simplest, you may have noticed that my code suffers
> porting from `C' pseudo code, which is not simple and efficient on
> Oberon platforms. Need to learn more about simplicity.
>
>> The fastest ReverseByte is the following;
>>
>> PROCEDURE ReverseByte(wd: BYTE): BYTE;
>> BEGIN
>> RETURN rev8[wd]
>> END ReverseByte;
>>
>> „rev8“ is an ARRAY 256 OF BYTE you would have to initialize once in
>> the beginning. If you don’t want to spend 256 bytes of memory, you
>> could do it in two steps like this
>
> Aha, these are the lookup tables, I saw in `C' as well, I was afraid
> of wasting memory on static constructs.
>
>> PROCEDURE ReverseByte(wd: BYTE): BYTE;
>> BEGIN
>> RETURN rev4[wd MOD 16]*16 + rev4[wd DIV 16]
>> END ReverseByte;
>
> And this seems still faster to FOR loop over 7 bits.
>
>
> Many thanks.
>
> --
> Tomas Kral <thomas.kral at email.cz>
> --
> 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