SYSTEM.BIT bug

SYSTEM.BIT bug

Postby luowy » Thu Oct 31, 2019 10:42 am

according to Intel manual, then BT instruction only accept 0..31 immediate offset and range -2^31 to 2^31 - 1 for a register offset,but SYSTEM.BIT seems output wrong code;
Code: Select all
MODULE TestSystemBit;

   IMPORT SYSTEM;
 
   PROCEDURE Do();
      VAR b:BOOLEAN; x,y:INTEGER;
   BEGIN
      b:=SYSTEM.BIT(x,31);
      b:=SYSTEM.BIT(x,200); (*wrong here *)
      b :=SYSTEM.BIT(x,y);    (* seem wrong here *)
   END Do;



END TestSystemBit.
decode
Code: Select all
PROCEDURE Do
00000001H:   55    push  ebp
00000002H:   8B EC    mov  ebp, esp
00000004H:   83 C4 F4    add  esp, -12

00000007H:   8B 45 F8    mov  eax, -8[ebp]       ;;b:=SYSTEM.BIT(x,31);
0000000AH:   0F BA 20 1F    bt  0[eax], 31
0000000EH:   0F 92 C0    setb/setc/setnae  al
00000011H:   88 45 FF    mov  -1[ebp], al

00000014H:   8B 45 F8    mov  eax, -8[ebp]        ;;b:=SYSTEM.BIT(x,200);
00000017H:   0F BA 20 C8    bt  0[eax], -56     ;;wrong here,
                                              ;;correct: MOV EDX, 200;MOV EAX, [EBP-8];BT[EAX], EDX
0000001BH:   0F 92 C0    setb/setc/setnae  al
0000001EH:   88 45 FF    mov  -1[ebp], al

00000021H:   8B 45 F8    mov  eax, -8[ebp]        ;;b :=SYSTEM.BIT(x,y);
00000024H:   8B 55 F4    mov  edx, -12[ebp]
00000027H:   0F A3 10    bt  edx, 0[eax]            ;;seem should be:  BT [EAX], EDX
0000002AH:   0F 92 C0    setb/setc/setnae  al
0000002DH:   88 45 FF    mov  -1[ebp], al

00000030H:   8B E5    mov  esp, ebp
00000032H:   5D    pop  ebp
00000033H:   C3    ret 
comments welcome;

luowy
luowy
 
Posts: 201
Joined: Mon Oct 20, 2014 12:52 pm

Re: SYSTEM.BIT bug

Postby Josef Templ » Fri Nov 01, 2019 8:53 am

SYSTEM.BIT is undocumented and unused in BB.
It is possible that it has been introduced for compatibility with some ETH Oberon version
but later the standard function BITS has been added and SYSTEM.BIT became unnecessary.

My tests show correct behavior of SYSTEM.BIT but you must be aware that
it expects a memory address as its first argument.

> b :=SYSTEM.BIT(x,y); (* seem wrong here *)

It looks very much like a problem in the decoder. The operands are swapped.

- Josef
User avatar
Josef Templ
 
Posts: 2001
Joined: Tue Sep 17, 2013 6:50 am

Re: SYSTEM.BIT bug

Postby luowy » Fri Nov 01, 2019 2:22 pm

Josef Templ wrote:> b :=SYSTEM.BIT(x,y); (* seem wrong here *)

It looks very much like a problem in the decoder. The operands are swapped.

yes,this is a decode problem:
Code: Select all
0F A3 10    bt  edx, 0[eax]
the above is wrong, it should be:
Code: Select all
  0F A3 10    BT   [EAX], EDX 

luowy
luowy
 
Posts: 201
Joined: Mon Oct 20, 2014 12:52 pm

Re: SYSTEM.BIT bug

Postby luowy » Sat Nov 02, 2019 1:58 am

a demo for using SYSTEM.BIT, actually, it is different from BITS;
Code: Select all
MODULE ObxSystemBit;

   IMPORT Log := StdLog, S := SYSTEM;
   
   (* memory manager,  *)
   CONST MaxPage = 512 - 1;   
   VAR bitmap: ARRAY (MaxPage + 1) DIV 32 OF SET; (* 16  *)
   
   PROCEDURE Do();
      VAR b: BOOLEAN; x, y: INTEGER;
   BEGIN
      b := S.BIT(x, 31);   (* ok *)
      b := S.BIT(x, 200); (*wrong here *)
      b := S.BIT(x, y);     (* ok *)
   END Do;
   
   
   PROCEDURE Init();
      VAR i: INTEGER;
   BEGIN
      FOR i := 0 TO LEN(bitmap) - 1 DO
         bitmap[i] := {};
      END;
   END Init;
   
   PROCEDURE Dump();
      VAR i: INTEGER;
   BEGIN
      FOR i := 0 TO LEN(bitmap) - 1 DO
         Log.Set(bitmap[i]); Log.Ln;
      END;
   END Dump;
   
      
   PROCEDURE DumpDirty();
      VAR i: INTEGER;
   BEGIN
      FOR i := 0 TO MaxPage DO
         IF i MOD 32 IN bitmap[i DIV 32] THEN
            Log.Int(i); Log.Ln;
         END;
      END;
   END DumpDirty;
   
   PROCEDURE DumpDirty2();
      VAR i: INTEGER;
   BEGIN
      FOR i := 0 TO MaxPage DO
         IF S.BIT(S.ADR(bitmap), i) THEN
            Log.Int(i); Log.Ln;
         END;
      END;
   END DumpDirty2;
   
   PROCEDURE SetDirty (num: INTEGER);
   BEGIN
      ASSERT((num >= 0)&(num <= MaxPage), 20);
      INCL(bitmap[num DIV 32], num MOD 32);
   END SetDirty;
   
   PROCEDURE Do2* (); (* ObxSystemBit.Do2 *)
      VAR i, x: INTEGER;
   BEGIN
      Init();
      SetDirty(31);
      SetDirty(200);
      SetDirty(511);
      Dump(); Log.Ln;
      DumpDirty();Log.Ln;
      DumpDirty2();
   END Do2;




END ObxSystemBit.
luowy
 
Posts: 201
Joined: Mon Oct 20, 2014 12:52 pm

Re: SYSTEM.BIT bug

Postby Josef Templ » Sat Nov 02, 2019 2:11 pm

in the decoder in PROCEDURE Bit I thnk it is the wrong d value, which sets the output order.
When I use d = 0 it works as expected, with d = 1 it is swapped.
The question is now if this applies to all of the instructions in that group.
Probably, but should be checked.

- Josef
User avatar
Josef Templ
 
Posts: 2001
Joined: Tue Sep 17, 2013 6:50 am


Return to Bugs

Who is online

Users browsing this forum: No registered users and 2 guests