gcc的__builtin_函数(注意前面是两个下划线)
说明:
GCC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exceptions or variable-length argument lists and will not be documented here because they may change from time to time; we do not recommend general use of these functions.
GCC includes built-in versions of many of the functions in the standard C library. The versions prefixed with __builtin_ will always be treated as having the same meaning as the C library function even if you specify the-fno-builtinoption. (see C Dialect Options) Many of these functions are only optimized in certain cases; if they are not optimized in a particular case, a call to the library function will be emitted.
Returns one plus the index of the least significant 1-bit of x, or
if x is zero, returns zero.
Returns the number of leading 0-bits in x, starting at the most
significant bit position. If x is 0, the result is undefined.
Returns the number of trailing 0-bits in x, starting at the least
significant bit position. If x is 0, the result is undefined.
Returns the number of 1-bits in x.
Returns the parity of x, i.e. the number of 1-bits in x
modulo 2.
(以上内容来源见参考哦)
1.__builtin_parity(unsigned int x)
统计一个数二进制表示中1的个数是偶数还是奇数
2.__builtin_popcount(unsigned int x)
统计一个数的二进制表示中1的个数
3.__builtin_ffs(unsigned int x)
找出一个数的二进制表示中从末尾开始到遇见第一个1的的位置
4.__builtin_clz(unsigned int x)
返回一个数二进制表示中前导零的数目
5.__builtin_ctz(unsigned int x)
返回一个数二进制表示中尾零的数目
试验代码如下:
#include <iostream>
#include <map> #define max_n 200005
using namespace std;
map<int,int> mp;
long long a[max_n];
int n;
int main()
{
cout << __builtin_popcount() << endl; //3:11 output:2
cout << __builtin_popcount() << endl; //7:111 output:3 cout << __builtin_parity() << endl; //output:0
cout << __builtin_parity() << endl; //output:1 cout << __builtin_ffs() << endl; //output:1
cout << __builtin_ffs() << endl;//10:1010 output:2 cout << __builtin_ctz() << endl; //output:0
cout << __builtin_ctz() << endl;//output:1 cout << __builtin_clz() << endl;//output:30
cout << __builtin_clz() << endl;//output:28
return ;
}
更多内置函数参见:http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Other-Builtins.html
gcc的__builtin_函数(注意前面是两个下划线)的更多相关文章
- Python 私有变量中两个下划线 _ _item 与 一个下划线的区别 _item
python中没有常量的说法, 但是可以通过元组实现一个常量 在python的私有变量中, 存在两个下划线 _ _item 与一个下划线 _item 的区别 前面带两个下划线的私有变量: 只能在本类中 ...
- python中有两个下划线__的是内置方法,一个下划线_或者没有下划线的可能是属性,也可能是方法,也可能是类名
python中有两个下划线__的是内置方法,一个下划线_或者没有下划线的可能是属性,也可能是方法,也可能是类名,如果在类中定义的就是类的私有成员. >>> dir(__builtin ...
- 【转】gcc的__builtin_函数介绍
转自:http://blog.csdn.net/jasonchen_gbd/article/details/44948523 GCC提供了一系列的builtin函数,可以实现一些简单快捷的功能来方便程 ...
- [转]gcc的__builtin_函数介绍
链接地址:https://blog.csdn.net/jasonchen_gbd/article/details/44948523
- Python中类的变量,一个下划线与两个下划线的区别
形似 功能 __xx 这是私有变量, 只有内部可以访问,外部不可以访问.但是也不是一定不可以访问,只要以 _类名__xx样式就可以访问 .但最好不要这样做,养成良好编程习惯 _x 这是实例 ...
- gcc 内置函数
关于gcc内置函数和c隐式函数声明的认识以及一些推测 最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候 ...
- 关于gcc内置函数和c隐式函数声明的认识以及一些推测
最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候,你在代码里面引用了一个函数但是没有包含相关的头文件,这个 ...
- 让gcc支持成员函数模板的trick
让gcc支持成员函数模板的trick 罗朝辉 (http://www.cnblogs.com/kesalin/) 本文遵循“署名-非商业用途-保持一致”创作公用协议 gcc 4.7.3 不支持成员 ...
- DirectX:函数可以连接任意两个filter
函数可以连接任意两个filter HRESULT ConnectFilters( IBaseFilter *pSrc, IBaseFilter *pDest ) { IPin *pIn = 0; IP ...
随机推荐
- Docker实践之04-操作容器
目录 一.查看容器列表 二.启动容器 三.终止容器 四.重启容器 五.后台运行容器 六.获取容器输出信息 七.进入容器 八.导出和导入容器 九.删除容器 一.查看容器列表 可以使用命令docker c ...
- elasticsearch-head
elasticsearch-head 是用于监控 Elasticsearch 状态的客户端插件,包括数据可视化.执行增删改查操作等 安装前先安装nodejs 1.下载 地址 2.安装 npm ins ...
- Docker下安装zookeeper(单机 & 集群)
启动Docker后,先看一下我们有哪些选择. 有官方的当然选择官方啦~ 下载: [root@localhost admin]# docker pull zookeeper Using default ...
- DRF框架(五)——context传参,二次封装Response类,两个视图基类(APIView/GenericAPIView),视图扩展类(mixins),子类视图(工具视图),视图集(viewsets),工具视图集
复习 1.整体修改与局部修改 # 序列化get (给前端传递参数) #查询 ser_obj = ModelSerializer(model_obj) #只传递一个参数,默认是instance的参数,查 ...
- Django框架(十三)——Auth模块
Auth模块 一.什么是auth模块 Auth模块是Django自带的用户认证模块 Auth模块是Django自带的用户认证模块,可以实现包括用户注册.用户登录.用户认证.注销.修改密码等功能.默认使 ...
- 前端调试代码 chrom 和 火狐禁用缓存 Disabled cache
前端调试的时候经常遇到缓存问题, chrome : f12 ---> 找到 Disabled caceh 勾上 火狐: f12 找到 禁用缓存
- oracle 数据库触发器,插入更新时间戳
1.首先建立一个测试表 CREATE TABLE TestTragger( UserId int Primary Key, Name VARCHAR() Not Null, CreateTime Ti ...
- docker save load export import的区别
export export命令用于持久化容器(不是镜像).所以,我们就需要通过以下方法得到容器ID: sudo docker ps -a 接着执行导出: sudo docker export < ...
- ASP.NET SignalR 系列(二)之项目创建
一.项目环境 IDE:VisualStudio 2015 SignalR 2.3.0 JQuery版本1.10.1 ,要求必须1.6.4以上 .net Framework 4.6 SignalR2.0 ...
- NEST dynamic 和 alias
/// <summary> /// Dynamic = false无法搜索 /// </summary> public void Dynamicmapping() { var ...