相关疑难解决方法(0)

什么是严格别名规则?

当询问C中常见的未定义行为时,灵魂比我提到的严格别名规则更加开明.
他们在说什么?

c strict-aliasing undefined-behavior type-punning

778
推荐指数
10
解决办法
19万
查看次数

为什么在函数参数中将`const ull`更改为`const ull&`会导致性能提升?

所以,用下面的代码,改变参数的类型xconst ullconst ull&(有typedef unsigned long long ull)在约25%的加速效果,当用gcc 4.7.2和标志编译-O3 -std=c++11 -g,我想不通为什么会做出如此大的差异.

static void inline single_mult(const std::vector<ull>::iterator& data,
                  const std::vector<ull>::const_iterator& rbegin,
                  const std::vector<ull>::const_iterator& rend,
                  const ull x) {
        ull tmp=0, carry=0, i=0;
        for (auto rhs_it = rbegin; rhs_it != rend; ++rhs_it) {
                tmp = x*(*rhs_it) + data[i] + carry;
                if (tmp >= imax) {
                        carry = tmp >> numbits;
                        tmp &= imax - 1;
                } else { 
                        carry = 0;
                }
                data[i++] …
Run Code Online (Sandbox Code Playgroud)

c++ optimization performance gcc c++11

27
推荐指数
1
解决办法
1401
查看次数