English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   support.WinUAE (http://eab.abime.net/forumdisplay.php?f=5)
-   -   Bitfields BFFFO (http://eab.abime.net/showthread.php?t=80393)

flype 21 November 2015 11:59

Bitfields BFFFO
 
Hi tony,

i think i found a diff between UAE and real 030 using BFFFO

here some isolated small code (i use devpac/monam) :

Code:

    MACHINE MC68030

Start:
    clr.l  d4
    move.l  #$1badcafe,d0
    move.l  #$20,d1
    move.l  #$20,d2
    bfffo  d0{d2:d1},d3 ; uae => 0000 0003 ; 030 => 0000 0023
    move.w  ccr,d4      ; uae => 0000 0000 ; 030 => 0000 0000
    stop    #-1

On UAE :
D3 = 0000 0003
D4 = 0000 0000

On my A1200/030 :
D3 = 0000 0023
D4 = 0000 0000

flype 21 November 2015 13:54

other test :

here all BFFFO results (D4) are not the ones i can see on my 1200 (D3).

Code:

    MACHINE MC68030

Start:
    lea    values,a0
Loop:
    move.l  (a0)+,d0
    beq    Exit
    move.l  (a0)+,d1
    move.l  (a0)+,d2
    move.l  (a0)+,d3
    bfffo  d0{d1:d2},d4
    bra    Loop
Exit:
    stop    #-1

values:
    ;              d0, d1, d2,  d3
    dc.l    $1badcafe,$ff,$ff,$0103 ; uae : d4=$0023
    dc.l    $1badcafe,$7f,$7f,$0083 ; uae : d4=$0023
    dc.l    $1badcafe,$20,$20,$0023 ; uae : d4=$0003
    dc.l    $1badcafe,$20,$03,$0023 ; uae : d4=$0003
    dc.l    $1badcafe,$20,$02,$0022 ; uae : d4=$0002
    dc.l    $1badcafe,$20,$01,$0021 ; uae : d4=$0001
    dc.l    0


Toni Wilen 21 November 2015 13:59

Confirmed.

Interesting unexpected behavior, low 5 bits are used for offset when EA is register but when calculating result, all 32-bits are used.

(For example D0 = 0, D2 = 7FFFFFE0: D3 = 80000000)

amilo3438 21 November 2015 14:29

whether it happens in jit mode also!?

Edit:
I wonder if somewhere there is already a better jit 680x0 emulation of existing and whether it could be used?

Toni Wilen 21 November 2015 14:31

No difference. JIT does not translate bitfield instructions, no one has bothered to implement them. They are very rare anyway.

flype 21 November 2015 14:37

Quote:

Originally Posted by Toni Wilen (Post 1051946)
Confirmed.

Interesting unexpected behavior, low 5 bits are used for offset when EA is register but when calculating result, all 32-bits are used.

(For example D0 = 0, D2 = 7FFFFFE0: D3 = 80000000)

Yep, other samples :

Code:

    ;              d0,      d1,      d2,      d3
    dc.l    $ffffff00,$ffffff00,$7fffffe0,$ffffff00 ; uae : d4=$00000000
    dc.l    $00000000,$ffffffff,$7fffffe0,$0000001f ; uae : d4=$0000003f
    dc.l    $00000000,$00000000,$7fffffe0,$00000020 ; uae : d4=$00000020 (ok)
    dc.l    $00000000,$00000020,$7fffffe0,$00000040 ; uae : d4=$00000020
    dc.l    $1badcafe,$000000ff,$000000ff,$00000103 ; uae : d4=$00000023
    dc.l    $1badcafe,$0000007f,$0000007f,$00000083 ; uae : d4=$00000023
    dc.l    $1badcafe,$00000020,$00000020,$00000023 ; uae : d4=$00000003
    dc.l    $1badcafe,$00000020,$00000003,$00000023 ; uae : d4=$00000003
    dc.l    $1badcafe,$00000020,$00000002,$00000022 ; uae : d4=$00000002
    dc.l    $1badcafe,$00000020,$00000001,$00000021 ; uae : d4=$00000001


Toni Wilen 21 November 2015 15:29

http://www.winuae.net/files/b/winuae.7z should fix it.

flype 21 November 2015 15:58

Great, thank you tony for fast reply (as always),
i need now to wait for fsuae release as i use only linux atm.

Toni Wilen 21 November 2015 16:02

Here is patch then :)

Code:

diff --git a/gencpu.cpp b/gencpu.cpp
index e8a2aa6..e52660e 100644
--- a/gencpu.cpp
+++ b/gencpu.cpp
@@ -5065,6 +5068,8 @@ bccl_not68020:
                        printf ("\tuae_u32 bdata[2];\n");
                        printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n");
                        printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n");
+                        if (curi->mnemo == i_BFFFO)
+                                printf("\tuae_u32 offset2 = offset;\n");
                        if (curi->dmode == Dreg) {
                                printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg);\n");
                                printf ("\toffset &= 0x1f;\n");
@@ -5096,8 +5101,8 @@ bccl_not68020:
                                break;
                        case i_BFFFO:
                                printf ("\t{ uae_u32 mask = 1 << (width - 1);\n");
-                                printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n");
-                                printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = offset;\n");
+                                printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset2++; }}\n");
+                                printf ("\tm68k_dreg (regs, (extra >> 12) & 7) = offset2;\n");
                                break;
                        case i_BFSET:
                                printf ("\ttmp = 0xffffffffu >> (32 - width);\n");


amilo3438 21 November 2015 16:07

Quote:

Originally Posted by flype (Post 1051961)
i need now to wait for fsuae release as i use only linux atm.

No need to Wait, you can use WINE, right? (According to some users it works fine.)

http://www.pjhutchison.org/uae_wine.html

flype 21 November 2015 16:09

well maybe, i had problem with wine + winuae some times ago.
i should retry.

flype 21 November 2015 16:41

Quote:

Originally Posted by Toni Wilen (Post 1051956)

using the testcase here, it reports no more error :)

Code:

    MACHINE MC68030

Start:
    clr.l  d5              ; error counter
    lea    values,a0        ; load values
    move.l  (a0)+,d7        ; number of rows
Loop:
    move.l  (a0)+,d0        ; load d0
    move.l  (a0)+,d1        ; load d1
    move.l  (a0)+,d2        ; load d2
    move.l  (a0)+,d3        ; load d3
    bfffo  d0{d1:d2},d4    ; bitfield operation
    sub.l  d3,d4            ; check result
    beq    Next1            ; d4 = 0 ?
    addi.l  #1,d5            ; else, increment error counter
Next1:
    dbf    d7,Loop          ; continue
Exit:
    stop    #-1              ; stop

values:
    dc.l    9
    ;              d0,      d1,      d2,      d3
    dc.l    $ffffff00,$ffffff00,$7fffffe0,$ffffff00 ;
    dc.l    $00000000,$ffffffff,$7fffffe0,$0000001f ;
    dc.l    $00000000,$00000000,$7fffffe0,$00000020 ;
    dc.l    $00000000,$00000020,$7fffffe0,$00000040 ;
    dc.l    $1badcafe,$000000ff,$000000ff,$00000103 ;
    dc.l    $1badcafe,$0000007f,$0000007f,$00000083 ;
    dc.l    $1badcafe,$00000020,$00000020,$00000023 ;
    dc.l    $1badcafe,$00000020,$00000003,$00000023 ;
    dc.l    $1badcafe,$00000020,$00000002,$00000022 ;
    dc.l    $1badcafe,$00000020,$00000001,$00000021 ;

EDIT: also ok with another bigger testcase.

meynaf 21 November 2015 16:55

Quote:

Originally Posted by Toni Wilen (Post 1051950)
No difference. JIT does not translate bitfield instructions, no one has bothered to implement them. They are very rare anyway.

Beware, as they are not really very rare ; just uncommon. DM2 for example is just full of them. I found many in HOMM2 too. My code uses them quite a lot as well.

They are real programming gems when knowing how to use them.

But they are quite complicated to implement, for sure.

Toni Wilen 21 November 2015 17:03

So that makes two programs (I only knew DM2 previously). Which in my opinion makes it extremely rare :)

meynaf 21 November 2015 17:06

Other programs of mine do (like my picture viewer).
Lots of Mac programs using the same compiler as HOMM2 used, also do.

Extremely rare is something like CHK2 ;)

flype 21 November 2015 17:12

Just checked also the CCR results.

All good here, same on real 030 and WinUAE with the latest fix.

Code:

    MACHINE MC68030

Start:
    clr.l  d5              ; bitfield result
    clr.l  d6              ; bitfield ccr
    lea    values,a0        ; load rows
    move.l  (a0)+,d7        ; load number of rows
Loop:
    move.l  (a0)+,d0        ; load <ea>
    move.l  (a0)+,d1        ; load offset
    move.l  (a0)+,d2        ; load width
    move.l  (a0)+,d3        ; load precalc result
    move.l  (a0)+,d4        ; load precalc ccr
    bfffo  d0{d1:d2},d5    ; store bitfield result
    move.w  ccr,d6          ; store bitfield ccr
    sub.l  d3,d5            ; check bitfield result
    sub.l  d4,d6            ; check bitfield ccr
    dbf    d7,Loop          ; continue
Exit:
    stop    #-1              ; stop

values:
    dc.l    9
    ;              d0,      d1,      d2,      d3,      d4
    dc.l    $ffffff00,$ffffff00,$7fffffe0,$ffffff00,$00000008
    dc.l    $00000000,$ffffffff,$7fffffe0,$0000001f,$00000004
    dc.l    $00000000,$00000000,$7fffffe0,$00000020,$00000004
    dc.l    $00000000,$00000020,$7fffffe0,$00000040,$00000004
    dc.l    $1badcafe,$000000ff,$000000ff,$00000103,$00000000
    dc.l    $1badcafe,$0000007f,$0000007f,$00000083,$00000000
    dc.l    $1badcafe,$00000020,$00000020,$00000023,$00000000
    dc.l    $1badcafe,$00000020,$00000003,$00000023,$00000004
    dc.l    $1badcafe,$00000020,$00000002,$00000022,$00000004
    dc.l    $1badcafe,$00000020,$00000001,$00000021,$00000004


flype 21 November 2015 18:34

One word to say that i found this bug while writing cross-testcases for the Vampire/Apollo and UAE and real 680x0. We spend huge amount of time to ensure that Apollo is 100% 68k compatible and we are happy to share this effort to UAE or others if something wrong is detected. And, last word, thanks Tony for UAE, that is of great help in doing this task.

Galahad/FLT 21 November 2015 18:59

Quote:

Originally Posted by Toni Wilen (Post 1051983)
So that makes two programs (I only knew DM2 previously). Which in my opinion makes it extremely rare :)

Pretty sure Speris Legacy uses it as well, used for making save games as small as possible to fit in Cd32 NVram.

flype 21 November 2015 19:05

Please, what is DM2 ? DiskMaster 2, Dungeon Master 2, what else ?

meynaf 21 November 2015 20:19

Quote:

Originally Posted by flype (Post 1052005)
Please, what is DM2 ? DiskMaster 2, Dungeon Master 2, what else ?

Dungeon Master 2.


All times are GMT +2. The time now is 18:56.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.

Page generated in 0.04598 seconds with 11 queries