易截截图软件、单文件、免安装、纯绿色、仅160KB

在linux中的likely和unlikely

在linux中的likely和unlikely
0
推荐
在linux中判断语句经常会看到likely和unlikely,例如:
if(likely(value)){
}
else{
}
简单从表面上看if(likely(value)) == if(value),if(unlikely(value)) == if(value)。
这两个宏对程序运行结果没有影响,只是用于提高程序效率。其实现和gcc编译器密切相关。
具体点说,就是如果你觉得程序运行时候一般sndcmd|=0的可能性比较大,那么就加上likely的macro;反之则加unlikely。
也就是likely和unlikely是一样的,但是实际上执行是不同的,加likely的意识是value的值为真的可能
性更大一些,那么执行if的机会大,而unlikely表示value的值为假的可能性大一些,执行else机会大一些。
加上这种修饰,编译成二进制代码时likely使得if后面的执行语句紧跟着前面的程序,unlikely使得else后
面的语句紧跟着前面的程序,这样就会被cache预读取,增加程序的执行速度,likely和unlikely的实现在
include/linux/compiler.h中:
      9 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
     10 #define __builtin_expect(x, expected_value) (x)
     11 #endif
     12
     13 #define likely(x)   __builtin_expect((x),1)
     14 #define unlikely(x) __builtin_expect((x),0)
__builtin_expect是gcc的一个预处理命令,其解释如下:
long __builtin_expect (long exp, long c)
You may use __builtin_expect to provide the compiler with branch prediction
information. In general, you should prefer to use actual profile feedback for this
(‘-fprofile-arcs’), as programmers are notoriously bad at predicting how their
programs actually perform. However, there are applications in which this data is
hard to collect.
The return value is the value of exp, which should be an integral expression. The
value of c must be a compile-time constant. The semantics of the built-in are that it
is expected that exp == c. For example:
if (__builtin_expect (x, 0))
foo ();
would indicate that we do not expect to call foo, since we expect x to be zero. Since
you are limited to i


相关文档:

Linux:Linux文件命令精通指南

[url=http://www.netdigedu.com/jiagoubaike/13063.html]Linux:Linux文件命令精通指南[/url]
[url=http://www.netdigedu.com]网讯通信学院[/url]
为刚接触 Linux 文件命令的初学者提供的速成教程
虽然 GUI 桌面(如 KDE 和 GNOME)能够帮助用户利用 Linux 特性,而无需关于命令行接口的功能知识,但还是经常会需要更多的 ......

ACE在linux下的安装

本文详细描述了在Linux操作系统上安装和配置“自适应通信环境(ACE)”的过程和注意事项。zCkLinux联盟
文中的描述基于RedHat Linux 9操作系统和ACE 5.4版zCkLinux联盟
准备工作:zCkLinux联盟
1.确保你的Linux操作系统的开发环境(gcc、make……)是完整且可用的。zCkLinux联盟
2.在安装ACE的过程中 ......

Linux内核: 修改TCP/IP调优参数

在TimesTen的优化中,如果涉及到 Replication 或者Cache Group的话,那么针对 TCP/IP相关的参数的优化对性能是有益的。因为它们俩都是通过TCP/IP协议进行数据交互的。在安装文档(install.pdf)的39页有具体的说明:
 
For replication, TCP send and receive buffers should be increased to a minimum of 512KB. To ......

Linux安全设置手册

1、Bios Security
一定要给Bios设置密码,以防通过在Bios中改变启动顺序,而可以从软盘启动。这样可以阻止别人试图用特殊的启动盘启动你的系统,还可以阻止别人进入Bios改动其中的设置(比如允许通过软盘启动等)。
2、LILO Security
在"/etc/lilo.conf"文件中加入下面三个参数:time-out,restricted,password。这三个 ......

Linux常用命令

Linux常用命令清单
 
NO
分类
PS1
命令名
用法及参数
功能注解
 
1
文件管理
#
ls
ls -a
列出当前目录下的所有文件,包括以.头的隐含文件
 
 
文件管理
#
ls
ls -l或ll
列出当前目录下文件的详细信息
 
 
文件管理
#
pwd
pwd
查看当前所在目录的绝对路经
  ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号