Bladerunner engine (and others) and use of float math.

General chat related to ScummVM, adventure gaming, and so on.

Moderator: ScummVM Team

Post Reply
carlo_bramini
Posts: 19
Joined: Sat Aug 08, 2015 3:27 pm

Bladerunner engine (and others) and use of float math.

Post by carlo_bramini »

Hello,
while looking to the source codes, I have noticed some interesting points when reading the sources of the Bladerunner engine. However, this could be applied to many other engines that use floating point math.
Well, let't take this example:

Code: Select all

float x = <some calculations>
float y = sin(x);
I would like to suggest something like this instead:

Code: Select all

float x = <some calculations>
float y = sinf(x);
In short, many parts of the code may take the advantage of using float math functions.
While this calculation:

Code: Select all

float y = sinf(x);
provides the same identical result of:

Code: Select all

float y = sin(x);
the first one is much faster, usually around 50% faster, because sinf() calculates the retun value with much less iteration than sin(), because the reduced number of significant digits of 'float' type against the 'double' one.
The use of float math requires C99 compliant library math, but it seems that's not a problem since configure script also allows to activate C++11.

Actually, the float math functions are already used inside SCUMMVM, but just in one engine.
So, using them in other points, especially in a complex game like Bladerunner, can give some visible improvements in terms of performances.

Developers, what do you think?
Thank you very much for your time.

Sincerely.
User avatar
criezy
ScummVM Developer
Posts: 799
Joined: Sat Sep 23, 2006 10:41 am
Location: West Sussex, UK

Re: Bladerunner engine (and others) and use of float math.

Post by criezy »

What you wrote is correct in C. But I would expect that in C++ the following code would be using single precision floating point math already:

Code: Select all

float x = <some calculations>
float y = sin(x);
Indeed the C++ standard, declares overloaded trigonometric functions for float, double, and long double, and I would expect sin(float) and sinf(float) (which can both be used) to have the same performances.
carlo_bramini
Posts: 19
Joined: Sat Aug 08, 2015 3:27 pm

Re: Bladerunner engine (and others) and use of float math.

Post by carlo_bramini »

criezy wrote: Sun Feb 23, 2020 2:11 pm Indeed the C++ standard, declares overloaded trigonometric functions for float, double, and long double, and I would expect sin(float) and sinf(float) (which can both be used) to have the same performances.
I see. Thank you very much for your quick reply.
So, according to what you said, probably the points where float math functions are used directly need to be fixed for taking advantage of the oveloading?

Sincerely.
Post Reply