gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portable bitwise operations library (was Re: Portability Considerati


From: Michael Riedl
Subject: Re: Portable bitwise operations library (was Re: Portability Considerations)
Date: Sat, 23 Mar 2024 13:02:53 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:102.0) Gecko/20100101 Thunderbird/102.11.0

Hallo Alice,

just tried your code with XDS Modula-2 (single pass 32 Bit compiler).

For the implementation module of CardBitOps you need to shift the declaration of powerOf2 to the top of the module, otherwise a single pass compiler will claim about that.

For the test module you are using WriteString for some single char outputs - gives at least a warning (would replace by WriteChar) and the import of Bitwidth is unused (all more or less cosmetics ... ).

Finally, the "0 rotated left by 0" results in an exception (if all is compiled with bound checks enabled):

<snip>

0 shifted left by 0 is 0
0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 -> 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000
0 shifted right by 0 is 0
0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 -> 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000
0 shifted left with carry by 0 is 0
0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 -> 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000
Carry: 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000
0 arithmetically shifted right by 0 is 0
0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 -> 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000 : 0000
0 rotated left by 0 is
#RTS: unhandled exception #1: expression out of bounds at line 270 of CardBitOps.mod

Had a look in the code and replaced

-----

 IF n = 0 THEN

  (* NOP *)

ELSIF shiftFactor = 0 THEN

  (* NOP *)

-----

by

----

 IF (n = 0) OR (shiftFactor = 0) THEN

    (* NOP *)

----

in shl, shr, ashr. I also added

----

  IF (shiftFactor = 0) THEN
    (* NOP *)
    RETURN n
  ELSE

-----

in rotr, rotl and the tests passed. Attached the updated versions (the test module is renamed to not mix it up with your version) and the output of the updated portable code with the XDS compiler.

In the hope that this is helpful (and I did not spoile the code) ...

Gruß

Michael


Am 22.03.24 um 08:49 schrieb Alice Osako:
Eric Streit:
Hi Alice,

imho, I think this list is just perfect for the discussions about Modula2; Telegram Modula2 is not restricted by M2R10, we exchange about any Modula2 stuff (, and Oberon which is not very liked by Benjamin.)

Fair enough then, I will continue posting here unless someone says to stop.

In the meanwhile, I have worked out most of a version of the bitwise library for GNU Modula-2 on x86_64. I did use inline assembly extensively, but if this is a problem I can easily re-write it as stand-alone assembly functions.

See https://github.com/Schol-R-LEA/Modula-2-Portable-Bit-Manipulation for the current status of this project.

Attachment: CardBitOps.mod
Description: audio/mod

Attachment: TstCardBitOps.mod
Description: audio/mod

Attachment: TestResults.xds
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]