__builtin_clz的实现 [英] Implementation of __builtin_clz

查看:2441
本文介绍了__builtin_clz的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC的实现(4.6+) __ builtin_clz ?它是否与Intel x86_64(AVX)上的某些CPU指令相对应?

解决方案

<它应该转换成一个位反向扫描指令和一个减法。 BSR给出了前导1的索引,然后你可以从字大小中减去前导零的数目。
$ b

编辑:如果你的CPU支持LZCNT (领先零计数),那么这也可能会实现这个诀窍,但并非所有的x86-64芯片都具有该指令。


What is the implementation of GCC's (4.6+) __builtin_clz? Does it correspond to some CPU instruction on Intel x86_64 (AVX)?

解决方案

It should translate to a Bit Scan Reverse instruction and a subtract. The BSR gives the index of the leading 1, and then you can subtract that from the word size to get the number of leading zeros.

Edit: if your CPU supports LZCNT (Leading Zero Count), then that will probably do the trick too, but not all x86-64 chips have that instruction.

这篇关于__builtin_clz的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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