English Amiga Board


Go Back   English Amiga Board > Support > support.FS-UAE

 
 
Thread Tools
Old 15 August 2015, 23:42   #21
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
The good news is that I have managed to pinpoint "when it started to go wrong" a little better. The flickering occurs when WinUAE 2.7.1b2 changes are merged into FS-UAE. Specifically, custom.cpp (it works with 2.7.1b2 changes and custom.cpp from 2.7.1b1).

The bad news is that custom.cpp saw a lot of changes going from 2.7.1b1 to 2.7.1b2.
FrodeSolheim is offline  
Old 15 August 2015, 23:48   #22
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Hmmm, removing this code seemingly fixes the problem:
Quote:
#ifdef SPEEDUP
/* SPEEDUP code still needs this hack */
int delayoffset = fetchmode_size - (((plfstrt - HARD_DDF_START_REAL) & fetchstart_mask) << 1);
delay1 += delayoffset;
delay2 += delayoffset;
toscr_delay_adjusted[0] = (delay1 & delaymask) << toscr_res;
toscr_delay_adjusted[0] |= shdelay1 >> (RES_MAX - toscr_res);
toscr_delay_adjusted[1] = (delay2 & delaymask) << toscr_res;
toscr_delay_adjusted[1] |= shdelay2 >> (RES_MAX - toscr_res);
#endif
(I realize this might be far from a real solution, but it hopefully gives at least some insight...)
FrodeSolheim is offline  
Old 16 August 2015, 13:16   #23
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
Quote:
Originally Posted by FrodeSolheim View Post
Hmmm, removing this code seemingly fixes the problem:
It should break all horizontally scrolling programs..

But does forcing "delayoffset" to zero also fix it?
Toni Wilen is online now  
Old 16 August 2015, 23:25   #24
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Quote:
Originally Posted by Toni Wilen View Post
It should break all horizontally scrolling programs..
I can confirm this

Quote:
Originally Posted by Toni Wilen View Post
But does forcing "delayoffset" to zero also fix it?
No, still glitching :-/
FrodeSolheim is offline  
Old 17 August 2015, 20:26   #25
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
Too weird..

Does toscr_delay_adjusted[] change when glitch happens? It should not change in WB (at least unless WB screen is horizontally scrolled).
Toni Wilen is online now  
Old 17 August 2015, 22:55   #26
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Quote:
Originally Posted by Toni Wilen View Post
Too weird..
It gets weirder...

Quote:
Originally Posted by Toni Wilen View Post
Does toscr_delay_adjusted[] change when glitch happens? It should not change in WB (at least unless WB screen is horizontally scrolled).
No, at least not for visible vpos (it flips between 0 and 32 when considering all vpos).

But anyway, onto the weird stuff...

Turns out that that the "fix" involving removing some lines did not work in the latest FS-UAE versions. So I went back to the post-2.7.1beta2 merged version where this "fix" removed the flickering.

The strange thing was that setting toscr_delay_adjusted[0] and toscr_delay_adjusted[1] to 0 (after the existing calculations) did not fix the flickering. This was unexpected since they should be 0 by default (static storage), and should also stay 0 when the code is commented out. So manually setting toscr_delay_adjusted[0] and [1] to 0 should have the same effect, except it didn't....

Smells indeed of undefined behavior / compiler optimizations / something...

Testing further, going back to the "fix" of commenting out the lines setting toscr_delay_adjusted[] (now the flickering disappear), but then adding volatile to the declaration (static volatile int toscr_delay_adjusted[2] -- and the flickering reappears .

So, still very strong indications of undefined behavior (of course, I must double-check my test results so far, but...)

EDIT: Disabling compiler optimizations also breaks the "fix" (not surprisingly, as volatile too interferes with optimizations). So presumably, when toscr_delay_adjusted[] is never set, the compiler optimizer assumes (correctly) that this is effectively a constant, and optimizes (away?) some other code as a result. I'm not yet sure if this is just a wild goose chase or not.

Last edited by FrodeSolheim; 17 August 2015 at 23:22.
FrodeSolheim is offline  
Old 18 August 2015, 16:07   #27
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
Does behavior also change if you remove "static"? It should force compiler to not "optimize" it away (if it for some reason does it now).
Toni Wilen is online now  
Old 24 August 2015, 00:19   #28
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Quote:
Originally Posted by Toni Wilen View Post
Does behavior also change if you remove "static"? It should force compiler to not "optimize" it away (if it for some reason does it now).
Yes, this has the same effect as adding volatile (as expected).

The plan now is to make liberal use of #pragma GCC optimize in the source file to selectively disable optimizations for parts of the file at a time, to try to narrow down where something suspicious is happening.
FrodeSolheim is offline  
Old 24 August 2015, 01:28   #29
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
I have fixed it (More details tomorrow, too late already!)

EDIT: the undefined behavior has also been identified now.

Last edited by FrodeSolheim; 24 August 2015 at 01:47.
FrodeSolheim is offline  
Old 24 August 2015, 21:11   #30
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Yesterday I debugged the source, narrowing in on the problem by progressively compiling less and less parts of custom.cpp without optimizations until the behavior changed again. It turned out that the problem was located in long_fetch_64 and the preceeding shift functions.

I suspected there was an issue with the shift operations (implemented using a 2-item uae_u64 array), so I rewrote the shift code using GCC's 128 bit integer (__int128_t), and with this change, the flickering problem disappeared.

After having confirmed that the problem was located, I took a closer look at the shifting code. The problem is the following lines:
Code:
t |= p[0] >> (64 - n);
...
t |= p[1] << (64 - n);
When n is 0 (delay is 0), (64 - n) is 64, and shifting a with shift count == bit length is undefined behavior in C++. What actually happens instead (on my computer, and possibly all x86 computers) is that bits are copied instead of shifted.

This also explains why the flickering disappeared when I disabled the code responsible for setting the delay. When the compiler can prove delay is always 0, the shift functions are simply optimized away.

(I do not really know why the problem does not seem to manifest itself in WinUAE. According to MSVC docs, this shift operation is undefined for MSVC as well. Perhaps it's the same reason the problem does not appear in cycle-exact mode in FS-UAE, i.e. several conditions have to be fulfilled at the same time for the flickering to occur.)

I have submitted a pull request for WinUAE with a fix

Last edited by FrodeSolheim; 24 August 2015 at 21:22.
FrodeSolheim is offline  
Old 24 August 2015, 21:19   #31
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,502
Great. I don't think this was first undefined shift bug

Just wondering why no one said it does not happen in OCS/ECS modes. It would have immediately made it much easier to narrow down. I thought it was all-modes bug because no one said anything.. (long_fetch_64 is AGA only)
Toni Wilen is online now  
Old 19 December 2015, 19:14   #32
jbl007
Registered User
 
Join Date: Mar 2013
Location: Leipzig/Germany
Posts: 466
I'm sorry to dig out this old thread again but I still have problems with emulated AGA Amigas. Visual glitches with the default overscan settings are fixed, but now there are glitches custom overscan settings. Also there a glitches with "Chaos Engine AGA" if the player (and the screen) moves horizontally. Vertical movement is OK.
I tried whdload-version and different disk-variants with different configs, but no change.
uae_chipset=ocs "fixes" the problem, but disables AGA of course...
Tested 2.7.5dev and latest git-master.
Attached Thumbnails
Click image for larger version

Name:	fs-uae-crop-1512191805-01.png
Views:	167
Size:	5.0 KB
ID:	46645   Click image for larger version

Name:	fs-uae-crop-1512191806-01.png
Views:	159
Size:	19.2 KB
ID:	46646   Click image for larger version

Name:	fs-uae-crop-1512191812-01.png
Views:	177
Size:	25.9 KB
ID:	46647  
jbl007 is offline  
Old 22 December 2015, 18:19   #33
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
Yes, I get some flickering here as well, with Banshee (in-game) for example. I have merged UAE code from WinUAE 3.2.2, but flickering still occurs. I've also double-checked with WinUAE in Wine, and the flickering does not appear to happen there, at least not with Banshee. It looks like I'll need to do some tedious debugging...

Last edited by FrodeSolheim; 22 December 2015 at 20:50.
FrodeSolheim is offline  
Old 22 December 2015, 20:51   #34
FrodeSolheim
FS-UAE Developer
 
FrodeSolheim's Avatar
 
Join Date: Dec 2011
Location: Førde, Norway
Age: 43
Posts: 4,043
@jbl007 I have pushed fix to github. Care to test?
FrodeSolheim is offline  
Old 23 December 2015, 17:05   #35
jbl007
Registered User
 
Join Date: Mar 2013
Location: Leipzig/Germany
Posts: 466
Small change, big impact. -> It works now.
jbl007 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen glitches with mouse movement or key press Sparticle Coders. C/C++ 7 31 December 2014 10:11
Questions regarding 030 + CE accuracy vagrant support.WinUAE 2 22 March 2014 02:01
Amiga CD32 Sound Glitches Experiment T support.WinUAE 0 02 April 2009 23:13
Which is your all-time favourite Amiga chipset? Paul_s Nostalgia & memories 15 28 August 2007 05:47

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09273 seconds with 16 queries