在C或C ++中>> =的含义是什么? [英] What is the meaning of >>= in C or C++?

查看:262
本文介绍了在C或C ++中>> =的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C或C ++中>> = 符号的含义是什么?它有什么特别的名字吗?



我有一个CUDA代码中的 for 循环,看起来像这样

  for(int offset = blockDim.x; offset> 0; offset>> = 1)
{
//一些代码
}

如何使用 >> = / code>符号是右移的赋值形式,即 x>> = y; x>> y; (除非重载意味着不同的东西)。



右移1相当于除以2.该代码看起来像个人不信任编译器做最基本的优化,应该等效于:

  for(int offset = blockDim.x ; offset> 0; offset / = 2){...} 

这里:



http://en.wikipedia.org/wiki / Binary_shift#Bit_shifts


What is the meaning of the >>= symbol in C or C++? Does it have any particular name?

I have this for loop in some CUDA code which looks like this

for(int offset=blockDim.x; offset>0; offset >>=1)
{
   //Some code 
}

How does the offset variable get modfied with the >>= operator?

解决方案

The >>= symbol is the assignment form of right-shift, that is x >>= y; is short for x = x >> y; (unless overloaded to mean something different).

Right shifting by 1 is equivalent to divide by 2. That code looks like someone doesn't trust the compiler to do the most basic optimizations, and should be equivalent to:

for( int offset = blockDim.x; offset > 0; offset /= 2 ){ ... }

More information about bitwise operations here:

http://en.wikipedia.org/wiki/Binary_shift#Bit_shifts

这篇关于在C或C ++中>> =的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆