[Oberon] FPGA - Bit reversal
Tomas Kral
thomas.kral at email.cz
Fri Sep 22 11:52:51 CEST 2017
On Fri, 22 Sep 2017 12:22:06 +0300
Alexander Ilin <ajsoft at yandex.ru> wrote:
> PROCEDURE ReverseByte(wd: INTEGER): INTEGER;
> VAR i: INTEGER; rbt, u: SET;
> BEGIN
> u := SYSTEM.VAL(SET, wd);
> rbt := {}; FOR i := 0 TO 7 DO
> IF i IN u THEN INCL(rbt, 7-i) END
> END
> RETURN SYSTEM.VAL(INTEGER, rbt) END ReverseByte;
Hi Alex (or prefer Sasha?),
This is good, it fully utilises Oberon SETs, I have not thought of
that :-)
How would you recommend to further optimise word bit reversal?
PROCEDURE ReverseWord(wd: INTEGER): INTEGER;
VAR i: INTEGER; rwd, u: SET;
BEGIN
u := SYSTEM.VAL(SET, wd);
rwd := {}; FOR i := 0 TO 31 DO
IF i IN u THEN INCL(rwd, 31-i) END
END
RETURN SYSTEM.VAL(INTEGER, rwd) END ReverseWord;
I was also thinking to use WHILE loop and let i run from 0 to 15 and j
from 31 to 16. Not sure if faster with only 16 iterations.
`C' pseudo code gives this, if could be modified for array lookup, as
per Joerg's suggestion on BYTE type reversal.
unsigned int
reverse(register unsigned int x)
{
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
return((x >> 16) | (x << 16));
}
Many thanks.
--
Tomas Kral <thomas.kral at email.cz>
More information about the Oberon
mailing list