Fwd: Single-Precision Software Floating Point?

Mark Vander Voord mvandervoord at gmail.com
Thu May 19 17:00:10 UTC 2005


Ralf:

-fsingle-precision-constants is exactly what I was looking for.  I
also think that using consts in most cases would be a good change for
me, as type-checking is enforced then.

Thanks for your help!

Mark

---------- Forwarded message ----------
From: Ralf Corsepius <ralf.corsepius at rtems.org>
Date: May 19, 2005 12:52 PM
Subject: Re: Single-Precision Software Floating Point?
To: Mark Vander Voord <mvandervoord at gmail.com>


On Thu, 2005-05-19 at 11:18 -0400, Mark Vander Voord wrote:
> My problem is this.  The AU1100 (without any additional offboard
> support) requires me to use the software floating point library, which
> works well, except that it is slow.  It is especially slow when doing
> double-precision operations, and we don't require that kind of
> precision for our application.
>
> In the code, I declare all variables as floats, and I use sinf instead
> of sin, etc. to use single precision.
>
> In our project, we use a lot of constants in the form of macros.
> These are all declared as 3.4, etc... without the "f" (like 3.4f).
> When we go to use them, like to say:
>
> float x,y;
> float x = y + 4.5;
>
> the y is being converted to a double, multiplied by 4.5 using the
> double-precision multiply, then converted back to a single float and
> put into x.

Sounds like a case for:
-fsingle-precision-constant

cf. info gcc

> I know that we can go through our code and fix this by declaring all
> constants as 3.4f, etc., but is there a universal way to do this?
> (like a compiler switch or something?)  We don't intend to EVER use
> doubles in this project, and it seems like less maintainance to only
> have to set it once, instead of having to insure that all changes
> follow additional guidelines.

Well what I have done in similar situations is an old "c++-programmers
trick: Don't use defines, use "const" or "static const variables". In
many cases the compiler recognizes them as constants and optimizes them
away.

Another trick would be to use explicit typecasts, something similar to
#define SCALAR float
SCALAR x = a + (SCALAR) 4.5;

Ralf

PS.: I'd prefer to keep such discussions on the list (Off cause, unless
somebody corresponds something confidential), because others might also
be able to help.



More information about the users mailing list