Use assert()s for optimization?
Alex Rosenberg
alexr@spies.com
Sat Nov 8 12:41:00 GMT 2003
On Nov 7, 2003, at 1:00 AM, Richard Guenther wrote:
> On Thu, 6 Nov 2003, Richard Guenther wrote:
>
>> On Thu, 6 Nov 2003, Falk Hueffner wrote:
>>
>>> Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> writes:
>>>
>>>> Is there a way to turn an assert() into optimization hints for gcc?
>>>> Like in
>>>>
>>>> double mysqrt(double x)
>>>> {
>>>> assert(x >= 0.0);
>>>> return sqrt(x);
>>>> }
...
> double mysqrt(double x)
> {
> if (!(x >= 0.0))
> abort();
> return sqrt(x);
> }
... should be transformed into ....
> if (!(x >= 0)) {
> ??
> } else {
> return sqrt(x);
> }
Unfortunately, assert(exp) is guaranteed not to evaluate "exp" when
NDEBUG is set.
In this case, evaluating "x >= 0.0" may result in a change to the FP
exception state.
This transformation is interesting only in the case where the
expression has no side-effects.
+------------------------------------------------------------+
| Alexander M. Rosenberg <mailto:alexr@_spies.com> |
| Nobody cares what I say. Remove the underscore to mail me. |
More information about the Gcc
mailing list