Chinaunix首页 | 论坛 | 博客
  • 博客访问: 263718
  • 博文数量: 38
  • 博客积分: 2208
  • 博客等级: 大尉
  • 技术积分: 374
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-22 13:50
个人简介

没有介绍

文章分类

全部博文(38)

文章存档

2017年(2)

2014年(1)

2012年(2)

2011年(5)

2008年(28)

分类: LINUX

2008-08-08 07:27:18

get_current 使用宏的原因
==================== include/asmi386/
current.h 6 13 ====================
6 static inline struct task_struct * get_current(void)
7 {
8 struct task_struct *current;
9 __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
10 return current;
11 }
12
13 #define current get_current()

一条AND指令的执行只需4个CPU时钟周期,而一条从寄存器到寄存器的MOV指令也才2个CPU时钟周期,所有,像这样在需要时才临时把它计算出来反而效率比直接使用current全局变量要高。

阅读(1663) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~