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 ...
随机推荐
- [ ceph ] 基本概念、原理、架构介绍
1. Ceph 架构 1.1 Ceph 接口 Ceph 支持三种接口: Object:有原生的API,而且也兼容 Swift 和 S3 的 API Block:支持精简配置.快照.克隆 File:Po ...
- AIX日志相关的命令
常用的命令有: 1.列出简短的出错信息 errpt | more 2.列出所有硬件出错信息 errpt -d H 3.列出所有软件错误信息 errpt -d S 4.列出详细的出错信息 errpt – ...
- 浅谈MVC、MVVM的区别
一.概述 MVC,MVP,MVVM是三种常见的前端架构模式(Architectural Pattern),它通过分离关注点来改进代码组织方式.不同于设计模式(Design Pattern),只是为了解 ...
- Linux crontab 查看所有用户的crontab任务
查看所有用户的crontab任务 - mlzhu007的专栏 - CSDN博客 https://blog.csdn.net/mlzhu007/article/details/81662091 以roo ...
- flask---快速使用
初识falsk django是大而全面的框架,flask是个轻量级的框架. flask快速开发网站 flask可以使用很少的代码就可以直接完成一个项目(6,7行代码),如下: from flask i ...
- 6. 运行Spark SQL CLI
Spark SQL CLI可以很方便的在本地运行Hive元数据服务以及从命令行执行任务查询.需要注意的是,Spark SQL CLI不能与Thrift JDBC服务交互.在Spark目录下执行如下命令 ...
- pytest_02-用例运行规则
用例设计原则 文件名以test_*.py文件和*_test.py 以test_开头的函数 以Test开头的类 以test_开头的方法 所有的包pakege必须要有__init__.py文件 help帮 ...
- APIO2019题解
T1.桥梁(bridges/restriction) Subtask1:暴力,$O(n^2)$. #include<cstdio> #include<algorithm> #d ...
- Java 函数式编程和Lambda表达式
1.Java 8最重要的新特性 Lambda表达式.接口改进(默认方法)和批数据处理. 2.函数式编程 本质上来说,编程关注两个维度:数据和数据上的操作. 面向对象的编程泛型强调让操作围绕数据,这样可 ...
- JVM 参数调优配置
在 tomcat 配置文件 tomcat/bin/catalina.sh 中 配置 JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xss1024K -XX ...