.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Sandbot (http://forums.bots-united.com/forumdisplay.php?f=85)
-   -   using -ffast-math for bot (http://forums.bots-united.com/showthread.php?t=10112)

tschumann 06-03-2022 06:57

using -ffast-math for bot
 
Has anyone used the -ffast-math gcc compilation flag for a bot? Is it safe? I haven't benchmarked but it does seem a bit iffy to use it.

RoboCop 06-03-2022 19:09

Re: using -ffast-math for bot
 
Personally...no and also
Code:

-O3
can be risky as well.

Also have you used
Code:

-static-libstdc++
to resolve the CXX ABI issue?

The Storm 09-03-2022 10:25

Re: using -ffast-math for bot
 
The flag fast-math is breaking standard compliance regarding floating point calculations and some other mathematical operations. Basically you should get pretty close results regarding floating point numbers, but they will not be 100% correct. Depending on the code, this might not be a problem.

Other thing which is disabled are traps(unix/linux) and async exceptions(Windows) when you try to do some architecture specific invalid math operation like division by zero. In that case the program will directly crash(you will not be able to trap/catch the signal). So it really depends on your code and use cases.

About -O3. This optimization flag does not break the compliance, on the contrary it will follow it more strictly regarding undefined behavior stuff. I.e. if your code is well written and does not rely on undefined behavior working in "specific" way then you will get a free performance boost. However, in large codebases that do not use linters and high warning levels, this is usually not the case so it may seems like -O3 is breaking your code.

tschumann 11-03-2022 13:07

Re: using -ffast-math for bot
 
Quote:

Originally Posted by RoboCop (Post 67450)
Personally...no and also
Code:

-O3
can be risky as well.

Also have you used
Code:

-static-libstdc++
to resolve the CXX ABI issue?

Hm okay - I haven't tested -O3
And not yet - I was having some trouble with VirtualBox continually corrupting my VM but not I have it sorted so I should reinstall Steam and try it.

Quote:

Originally Posted by The Storm (Post 67451)
The flag fast-math is breaking standard compliance regarding floating point calculations and some other mathematical operations. Basically you should get pretty close results regarding floating point numbers, but they will not be 100% correct. Depending on the code, this might not be a problem.

Other thing which is disabled are traps(unix/linux) and async exceptions(Windows) when you try to do some architecture specific invalid math operation like division by zero. In that case the program will directly crash(you will not be able to trap/catch the signal). So it really depends on your code and use cases.

About -O3. This optimization flag does not break the compliance, on the contrary it will follow it more strictly regarding undefined behavior stuff. I.e. if your code is well written and does not rely on undefined behavior working in "specific" way then you will get a free performance boost. However, in large codebases that do not use linters and high warning levels, this is usually not the case so it may seems like -O3 is breaking your code.

Ah I see - it did seem a little risky but I didn't know about the traps/exceptions bit.

Anyway, not that the extra speed is needed but I thought it was worth investigating.

RoboCop 12-03-2022 14:26

Re: using -ffast-math for bot
 
Also, I've just noticed that some or most of your float variable values don't have "f" suffixed for example:-

https://github.com/tschumann/sandbot...s/bot.cpp#L385

Code:

pBot->f_waypoint_time = 0.0;
Instead of:-

Code:

pBot->f_waypoint_time = 0.0f;
If I'm not mistaken, some IDEs like Visual Studio use those "0.0" values as doubles instead of floats aka "0.0f". I think if you refactor and make sure those float values have those "f" suffixes may improve your float precision codes.

tschumann 19-03-2022 07:48

Re: using -ffast-math for bot
 
Yeah I think the compiler figures it out - I know I've had to change a few at times to avoid a warning or error but it seems like newer versions of Visual Studio assume it's a double literal by default, even when assigning to a float.


All times are GMT +2. The time now is 15:41.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.