freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] FT_Vector_NormLen: faster vector normalization


From: Werner LEMBERG
Subject: Re: [ft-devel] FT_Vector_NormLen: faster vector normalization
Date: Tue, 30 Jun 2015 16:17:10 +0200 (CEST)

>> Uh, oh, this code is very fragile and not easy to understand...  I
>> tried to remove some compiler warnings (from `clang
>> -Wsign-conversion', see below for the original compiler messages
>> and my bad attempt to fix them), and even such innocently looking
>> changes immediately cause bad rendering results.  For maintainance
>> reasons I thus ask you to improve that, both by adding casts and
>> documentation.
> 
> I knew that would generate some attention.  For that reason I would
> not want to fix the warnings right away just so that more people
> look at the code in the next week or two, if you do not
> mind. Perhaps this will generate some ideas for improvement.

No problem.

> I told you before that I see -Wsign-conversion kind of paranoid.

Mhmm, while walking over the code to remove such warnings, I've
already found some real bugs, so it definitely has some value.
However, your code here is explicitly *relying* on signed/unsigned
conversions, which makes it sensitive to even small changes.

> I wish there was a concise way to say that this entire expression
> should be evaluated unsigned or signed in its entirety, rather than
> going through each term and doing explicit conversions.

Me too.

> Well, C has very specific implicit conversion rules and I relied on
> those a lot, of course.  The key math is in the do-while loop.

I can imagine that introducing some auxiliary variables help clean up
*and clarify* the issue.  Compilers today are smart enough to optimize
them away, causing no loss in speed.

> `difference with 2^32' is a definition of two's complement.  I'll
> add that.

Thanks.


    Werner



reply via email to

[Prev in Thread] Current Thread [Next in Thread]