Comments (5)
I often use | instead of || because | does not require a branch and hence does not interfere with compiler pipelining; see Branches on
https://en.wikipedia.org/wiki/Instruction_pipelining#Branches
Often a compiler will require parentheses to make sure that the expressions are grouped in the intended order, but that does not seem to be a problem in the case above. Perhaps it is because no branch is required to implement the || in the case above (branches are required if there is more than one || or &&).
What compiler and verison and flags are you using ?
from cppad.
I see. I'm in over my head on compiler details, but is it really a tradeoff between | not requiring branching and || not requiring evaluation of the second argument if the first is true? Would the compiler prefer to have slightly more "correct" code ( || for logical arguments, right?) and then be the one to decide how to implement it? In your code, is bool_a | bool_b
really equivalent to something like static_cast<int>(bool_a) | static_cast<int>(bool_b)
? (I am trying to make sense of info here, here, and here about type handling of arithmetic operators like bitwise | and the implicit conversions that are done, but I am very likely not following it all.)
The compiler is:
clang++ --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.4.0
We don't control the compiler flags because they are generated by "R CMD install", R's script for building packages, including C++ compilation steps. We can see the lines it generates, and the clang++ line includes "-Wall". For this and other reasons, it would be nice for us to quiet the warnings, so I just wanted to ask about them. If you have your reasons and don't want to change your code, that's fine and we'll go from there, but just wanted to know.
from cppad.
Looking at the file bin/run_cmake.sh
https://github.com/coin-or/CppAD/blob/master/bin/run_cmake.sh
you will find the following text:
#
# cppad_cxx_flags
# clang++ 14.05 is warnings on bitwise operations with logical operands.
# These are used for speed, but maybe they do not help much ?
if [ "$clang" == 'yes' ]
then
cppad_cxx_flags="$cppad_cxx_flags -Wno-bitwise-instead-of-logical"
fi
Perhaps you can add this flag to your "R CMD install" ?
https://stackoverflow.com/questions/10921153/c-compilation-flags-from-r
from cppad.
Thanks for pointing to that. The "other reasons" I was referring to (aside from R CMD install) are that our package generates C++ and compiles it on the fly on each user's system, so we've generally avoided trying to tune compiler flags for systems we don't manage. But anyway we'll look into it. Thanks and I'll close this now.
from cppad.
It is hard to predict what an arbitrary compiler might warn for. If there is a way for you to check the compiler, then I would suggest only adding -Wno-bitwise-instead-of-logical when the compiler is clang++.
In general, it is a good idea to bring up warnings like this and make a decision if we will suppress the warning or change the source code. As the comment in bin/run_cmake.sh suggests, perhaps we should try changing all the | and & logical operations to || and && and see if it makes a difference on the speed of the program.
from cppad.
Related Issues (20)
- Linking error "undefined reference to `CppAD::local::temp_file()'" HOT 4
- solution vector is empty HOT 10
- Undefined reference to temp_file HOT 2
- ipopt and cppad tests HOT 11
- Problem to Link with CppAD and Ipopt HOT 16
- CppAD::cg::CGException: what(): GreaterThanZero cannot be called for non-parameters HOT 5
- Potential build mistake in third party tool in use of NDEBUG flag - CppAD compiled in Release HOT 13
- Static library for non-windows builds HOT 2
- User's Guide URL on README.md 404s HOT 8
- bin/get_colpack.sh Script Error HOT 6
- Exception thrown in val_graph optimizer HOT 3
- Name of function is cleared after val_graph optimization
- License question about the meaning of EPL-2.0 OR GPL-2.0-or-later HOT 3
- CppAD exception while running parallel loop HOT 13
- About Eigen. I can't store the scalar result of a matrix operation at the index location of another std::vector or Eigen::Vector. HOT 5
- Could NOT find GOOGLEHASH (missing: GOOGLEHASH_COMPILE) HOT 4
- make check_cppad_ipopt Failure HOT 14
- No installed conda 'base' environment found on macos-latest.
- ADFun::optimize gives compile error with std::complex HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppad.