OpenCL中的mul_hi函数:“上半部分”是什么意思?

问题描述

我正在尝试调试在OpenCL中运行的并行程序,在该程序中代码在线。我不理解的功能是mul_himad_hi。 OpenCL规范本身非常晦涩,因为它说mul_hi(a,b)计算a和b的乘积的上半部分。

上半部分是什么意思?

感谢您的帮助 胺

解决方法

高半部分是指32位整数的高16位。 您可以独立使用整数的4个字节(或2个半)。这是针对ARGB颜色完成的,例如将4个字节的alpha,红色,绿色和蓝色分别上移8位。

int high = ...; // 16-bit range
int low  = ...; // 16-bit range
int x = high<<16|(low&0xFF); // combine high and low: shift high 16 bits left,zero the upper 16 bits from low with bit mask 0xFF and combine the two with logical or

因此c=mul_hi(a,b);计算出c=(a*b)>>16;ab被相乘,结果的上半部分被下移并返回。 d=mad_hi(a,b,c);等同于d=mul_hi(a,b)+c;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...