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 ...
随机推荐
- Mac系统Android 命令行签名
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore keystore文件位置 -signedjar ~/afterSign ...
- spring较为常用注解
@Configuration 从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被Annotat ...
- 全网最详细的Windows里Git client客户端管理工具SourceTree的下载与安装(图文详解)
不多说,直接上干货! 很多人用Git命令行不熟练,那么可以尝试使用SourceTree进行操作. 安装之前的必备 (1)Git的安装 Git学习系列之Windows上安装Git详细步骤(图文详解 ...
- nginx 进程问题
1 nginx的进程分为四种 master worker cacheLoader cacheManager. 实际接收请求的进程是 worker,master监控worker节点,之所以会多进程模式, ...
- Word页眉实现首页不同、奇偶页不同 、更改页眉横线、页眉文字对齐 -- 视频教程(8)
1. 目标 目标1:实现页眉"首页不同,奇偶页不同" 目标2:更改页眉横线 目标3:页眉文字有三部分:第一部分左对齐,第二部分居中,第三部分右对齐 2. 教程 未完 ...... ...
- CentOS7 安装 Docker、最佳Docker学习文档
目录 一.Docker支持 二.安装Docker -1.在新主机上首次安装Docker CE之前,需要设置Docker存储库.之后,就可以从存储库安装和更新Docker. 0.卸载旧版 1.正式安装 ...
- windows 10 如何设定计划任务自动执行 python 脚本?
我用 python 写了一些脚本,有一些是爬虫脚本,比如爬取知乎特定话题的热门问题,有一些是定期的统计分析脚本,输出统计结果到文档中.之前我都是手动执行这些脚本,现在我希望如何这些脚本能自动定时执行. ...
- Redis 多级缓存架构和数据库与缓存双写不一致问题
采用三级缓存:nginx本地缓存+redis分布式缓存+tomcat堆缓存的多级缓存架构 时效性要求非常高的数据:库存 一般来说,显示的库存,都是时效性要求会相对高一些,因为随着商品的不断的交易,库存 ...
- tf.reduce_mean函数用法及有趣区别
sess=tf.Session() a=np.array([1,2,3,5.]) # 此代码保留为浮点数 a1=np.array([1,2,3,5]) # 此代码保留为整数 c=tf.reduce_m ...
- 2019 新华网java面试笔试题 (含面试题解析)
本人3年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.新华网等公司offer,岗位是Java后端开发,最终选择去了新华网. 面试了很多家公司,感觉大部分公司考察的点都差 ...