[Oberon] FPGA - Bit reversal

Tomas Kral thomas.kral at email.cz
Fri Sep 22 09:54:04 CEST 2017

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);
> 		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;
> 		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;
> 		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>

More information about the Oberon mailing list