操作员的表现| vs运营商+

cal*_*pto 2 c++ math boolean-operations

|之间有什么重大区别吗?和+会影响代码的长期性能?或者都是O(1)?我正在使用的代码是这样的:

uint64_t dostuff(uint64_t a,uint64_t b){
        // the max values of the inputs are 2^32 - 1

        // lots of stuff involving boolean operators
        // that have no way of being substituted by 
        // arithmetic operators

        return (a << 32) + b;
        //or
        return (a << 32) | b;
}
Run Code Online (Sandbox Code Playgroud)

代码将被多次使用,所以我想尽可能加快速度.

ybu*_*ill 5

任何现代计算机都没有性能差异.

这两个运营商虽然有不同的含义.如果该位已设置,|则不执行任何操作,但+将清除该位和所有后续非零位,并将下一个0位设置为1.