Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Short-circuiting in C
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Nobody, post: 4214689"] OpenCL may be closer to C than e.g. GLSL, but it still isn't C. And even if it was, C doesn't define the execution time of any given construct, nor treat it as significant (i.e. a compiler make whatever optimisations it likes so long as the code produces the correct result, regardless of the effect upon execution time). AFAICT, the only reliable way to prevent short-circuting is to either ensure that the later expressions have side-effects such that short-circuiting would change the observable behaviour, or to "hide" their implementation in a different translation unit so that the compiler cannot determine whether short-circuiting will change the observable behaviour. Either approach is likely to impose an unnecessary performance penalty on either or both implementations (CPU and GPU). I don't know whether the latter approach is even possible for OpenCL. Actually, with modern CPUs performing speculative execution, I'm not sure that the "hiding" approach will work. If the CPU hasn't performed the calculation by the time it discovers that the result isn't needed, it will just cancel it. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Short-circuiting in C
Top