- 论坛徽章:
- 0
|
最近在看RHEL4.5的glibc的时候发现了,关于tls的一段内联汇编,里面有这么一段关于线程栈的操作,有意思的是x86和EM64T下都有这段实现,但是汇编级别的指令用的不太一样,如下:
x86
————————————————————————————————————————————————
/* Call the user-provided thread function. */
#define CALL_THREAD_FCT(descr) \
({ void *__res; \
int __ignore1, __ignore2; \
asm volatile ("pushl %%eax\n\t" \
"pushl %%eax\n\t" \
"pushl %%eax\n\t" \
"pushl %%gs:%P4\n\t" \
"call *%%gs:%P3\n\t" \
"addl $16, %%esp" \
: "=a" (__res), "=c" (__ignore1), "=d" (__ignore2) \
: "i" (offsetof (struct pthread, start_routine)), \
"i" (offsetof (struct pthread, arg))); \
__res; })
——————————————————————————————————————————————————————
EM64T:
——————————————————————————————————————————————————————
#define CALL_THREAD_FCT(descr) \
({ void *__res; \
asm volatile ("movq %%fs:%P2, %%rdi\n\t" \
"callq *%%fs:%P1" \
: "=a" (__res) \
: "i" (offsetof (struct pthread, start_routine)), \
"i" (offsetof (struct pthread, arg)) \
: "di", "si", "cx", "dx", "r8", "r9", "r10", "r11", \
"memory", "cc"); \
__res; })
——————————————————————————————————————————————————————
可以看出EM64T,用一个movq就完成了x86用了4个pushl的工作,用一个callq就完成了x86用call+addl的工作,从指令的数量上来看是明显减少了。
但是,对于movq,pushl的指令周期各是多少就不太有把握了,去intel官网上看过manual了,上面只有介绍指令的用法没有涉及到指令周期的说明,看到这里有发过intel指令集的可是直到奔腾级别的,并且没有出现movq,movl,pushl等sse或mmx的指令。
并且在nasm下,试图使用像masm上用/Sc生成list文件的方法看指令周期,但是nasm的list文件里只有指令16进制的生成码,并没有指令周期可以看。
如果大家有intel 指令周期(包含有movl,movq等)的资料或者有linux下取得这些指令的指令周期的方法请不吝赐教,感激不尽! |
|