[IPOL discuss] Fast DCT using FFTW3

Nicolas Limare nicolas.limare at cmla.ens-cachan.fr
Wed Feb 29 10:42:45 CET 2012


> For example, let's consider a boolean function: "f(x) && g(y) &&
> h(z)". If f(x) is false, then g(y) and h(z) won't be
> called/evaluated.

Thshort-circuit evaluation is not compiler optimization, it is part of
the C language specification:

    «Unlike &, && guarantees left-to-right evaluation: the first
    operand is evaluated, including all side effects; if it is equal
    to 0, the value of the expression is 0. OTHERWISE, the right
    operand is evaluated, and if it is equal to 0, the expression's
    value is 0, otherwise 1.»
                                                      — K&R2 p. 207

> My conclusion is that we should optimize the code my ourselves if these
> optimizations aren't trivial. If so, the compiler can handle them and
> there's no need to avoid writing very clear and clean code.

I agree, if the compilers do the work, we do not need to do it. But I
would add the nuance that gcc may not be enough, I would personally
only feel more confident after observing the optimization from more

My "sqrt(2) example" was too much. But I think that gcc will not
replace the copy loop by a memcpy(), the two loops by a single one
(because there is no knowledge that the image rows are contiguous)
or the division by x by a multiplication by 1/x (because it has a
numerical rouding impact).

Anyway, being correct and readable is more important than being
fast. Maybe I should not have answered like I did.

Nicolas LIMARE - CMLA - ENS Cachan    http://www.cmla.ens-cachan.fr/~limare/
IPOL - image processing on line                          http://www.ipol.im/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20120229/c09ed632/attachment.pgp>

More information about the discuss mailing list