Csound Csound-dev Csound-tekno Search About

Re: [Csnd] Serious bug causes compiler-dependent error

Date1999-11-25 09:51
FromRichard Dobson
SubjectRe: [Csnd] Serious bug causes compiler-dependent error
>From my (far from complete) reading of the C standards, and various
other tomes, this use of a pointer increment in the same expression as
the non-incremented pointer is 'undefined' in terms of code generation.
It's not really a bug, as such - compilers are free to interpret it in
their own way. Wrapping the non-incremented pointer inside brackets
does  not seem to be sufficient to guarantee the required order, as it
is still a coponent of the complete expression, so that "*min++" could
still be calculated first. Out of order exectution, pipelining and all
sorts of other optimisation gizmos can casuse the compiler to do
something we might not expect, and this sort of expression is,
apparently, fair game.

Thus, in principle, the ~same~ compiler might code the first example
differently, at different levels of optimization. It may even be more by
luck than judgement that MSVC does it correctly. I still remember the
first release of VC++ v.5, as the optimizer completely wrecked
floating-point code.

Maybe it is just difficult for a compiler to flag a variable as
dependent on itself?



Richard Dobson

Gabriel Maldonado wrote:
> 
> Hi all,
> I noticed that Intel-compiled ultra-fast version of DirectCsound
> presents a bug due to the compiler parsing.
> This bug is evident in sliderXX opcodes.
> 
> the reason is that the code:
> 
>    **result++ = value * (*max++ - *min) + *min++;   /* scales the output */
> 
> produces a different behaviour different from the two lines:
> 
>    **result++ = value * (*max++ - *min) + *min;   /* scales the output */
>    min++;
> 
> While in MSVC both the two examples are parsed correctly, the Intel
> compiler produces a wrong result in the first example, the correct one being
> the second. So it is not possible to include the same variable in the
> same instruction twice, when the second occurrence of that variable is
> incremented. Please modify standard version to accomplish this drawback.
> Maybe there are other occurrences of this technique in other parts
> of Csound code, so it is necessary to investigate.
> 
> --
> Gabriel Maldonado
> 
> http://web.tiscalinet.it/G-Maldonado
> 
> --
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk

-- 
Test your DAW with my Soundcard Attrition Page!
http://wkweb5.cableinet.co.uk/rwd (LU: 17th September 1999)
CDP: http://www.bath.ac.uk/~masjpf/CDP/CDP.htm (LU: 4th November 1999)
--