bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

Some "math", "sinus" or "fpu" problem. Maybe bug in "-m68060" or "-ffast-math". #178

Closed mateusz83 closed 2 years ago

mateusz83 commented 2 years ago

Hello, So far I was using Windows setup.exe version from 22 March 2021. A few days ago I switched to Windows/WSL-Ubuntu and get the most recent grom github repository ans "make all" (not ndk 3.2)

On Windows I was using these compiler flags for a long time without issues: -Wall -noixemul -O3 -m68060 -mtune=68060 -mhard-float -fomit-frame-pointer -lm

After switching to Linux recent version I noticed that up/down movement in my FPS engine is no longer smooth sin() result. Instead It feels like sin() output is cut or rounded so the movement is no longer smooth but very jaggy. Please see the example video: https://www.youtube.com/watch?v=5YxbBHIyQlQ

The code is very simple:

#define RC_PLAYER_Z_SPEED           9   
#define RC_PLAYER_Z_MAX             8.0f

float RC_player_z, RC_player_z_accumulation;

{
RC_player_z_accumulation += RC_PLAYER_Z_SPEED * delta_time;
RC_player_z = sinf(RC_player_z_accumulation) * RC_PLAYER_Z_MAX;
}

I tried to test different flags, and finally noticed that after adding "-ffast-math" the movement is very smooth again ! -Wall -noixemul -m68060 -mtune=68060 -mhard-float -ffast-math -O3 -fomit-frame-pointer

Unfortunately in my case -ffast-math makes my appliaction not stable and it crashes after while - so I can't use it.

Thank You in advance.

bebbo commented 2 years ago

the difference is using fsin or calling a library function: http://franke.ms/cex/z/E8nxz3

stuttering: what library is used to link against?

crashing: fsinis handled by the 68060 support library. maybe that one is buggy?

mateusz83 commented 2 years ago

Thank you for answering..

  1. I tried use sin()instead sinf() and I got rid of -ffast-math It worked SMOOTH like it should but... crashes in a while.. (just like when using sinf() and -ffast-math).

  2. I am only using standard C libs: #include <math.h> I have no additional libs in linker only -lm

  3. When I deleted my 68060.library - both sin() and sinf() worked jagged (without -ffast-math) After adding -fast-math it was smooth but crashed.

  4. Tested on WinUAE and A1200+V1200

bebbo commented 2 years ago

questions:

mateusz83 commented 2 years ago
  1. yes - Windows setup.exe version from 22 March 2021 was OK, I was using it all the time (I switched to linux maybe 1-2 weeks ago to be up to date)

  2. Of course - here are the sources: http://mstanisz.website.pl/tmp/amiga/msRay_devpack_v0.31.zip

    • You will find the mentioned code in EngineCommonLibs/RC_Raycaster.cfile in RC_Read_Input() function
    • the engine compiles from EngineFrameworkAmiga/src/AMIGA_Framework.c
    • exe build in in the: TheGameOutput/
bebbo commented 2 years ago

what I noticed so far: I changed the order of initializing the fpu and loading the libraries. Please try using the libnix folder from your windows version and check if it behaves ok again.

mateusz83 commented 2 years ago

I copied libnix from window to linux, and the movement is still jagged, also everything looks very different: https://i.ibb.co/JRRgJCs/Przechwytywanie.jpg

bebbo commented 2 years ago

you have to recompile all once the fix is live. But your program crashes reliably here:

    // Free multi screen buffers.
    if (FRM_mbuf_screen_buffer[0]) FreeScreenBuffer(FRM_screen, FRM_mbuf_screen_buffer[0]);

maybe it writes outside the buffer?

mateusz83 commented 2 years ago

Hi, thank you very much for help. Should I get it from: https://franke.ms/download/amiga-gcc.tgz? or by git clone https://github.com/bebbo/amiga-gcc ?

I tried bygit cloneandmake allbut there was still jagged. Then I download the daily prebuild from link and un-tar on linux/wsl - but I get this mesage during compilation: /opt/amiga/libexec/gcc/m68k-amigaos/6.5.0b/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory

bebbo commented 2 years ago

Hi, thank you very much for help. Should I get it from: https://franke.ms/download/amiga-gcc.tgz?

this get's an update every night

or by git clone https://github.com/bebbo/amiga-gcc ?

and this is usually up to date one hour (building and testing takes its time) after a push to the devel1 branch.

I tried bygit cloneandmake allbut there was still jagged. Then I download the daily prebuild from link and un-tar on linux/wsl - but I get this mesage during compilation: /opt/amiga/libexec/gcc/m68k-amigaos/6.5.0b/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory

you have missing dependencies, check the https://github.com/bebbo/amiga-gcc/blob/master/README.md and install what's needed to build - that's sufficient to run.

mateusz83 commented 2 years ago

Hello, So I tried today again with fresh reinstalled wsl/ubuntu on Windows.

  1. I downloaded from git hub and make all. The sinus is smooth also with '-ffast-math' and without it. I don't know why but that line of code RC_player_z = sinf(RC_player_z_accumulation) * RC_PLAYER_Z_MAX make crash after a two seconds in both cases. Maybe its some bug in my code. When I comment that line I had no crash. I also use sinf() and cosf() in diferent place that works.

  2. I also tried with downloading prebuild from *.tgz archive.. but in this case I still I got that problem withlibmpfr.so.4 during compilation. I can't download that package: libmpfr.so.4.

Anyway I try to do something with that line of code.. if no I will just switch back to the 22 march version..

Thanks for help! Mateusz

bebbo commented 2 years ago

that's my built version - with the uncommented line, I mentioned above. frm060_128.zip

It crashes here, if you leave the room and hit the border.

bebbo commented 2 years ago

rty this to have movement wíthout using sinf:

//        RC_player_z = sinf(RC_player_z_accumulation) * RC_PLAYER_Z_MAX;
        static int index;
        static float f[] = { -1.0, -0.7, -0.3, -0.1, 0.1, 0.3, 0.7, 1.0};
        RC_player_z = f[7 & ++index] * RC_PLAYER_Z_MAX;     
mateusz83 commented 2 years ago

Thanks so much for help! I like the idea with array instead of sinf()

bebbo commented 2 years ago

to verify that your code draws only inside:

mateusz83 commented 2 years ago

Thats a very good trick, I will try that today..