Intel 移位指令的陷阱(转)
今天发现了一个Intel逻辑左移指令shl的一个bug。
#include <stdio.h>
int main()
{
#define MOVE_CONSTANT_BITS 32
unsigned int move_step=MOVE_CONSTANT_BITS;
unsigned int value1 = 1ul << MOVE_CONSTANT_BITS;
printf("value1 is 0x%X\n", value1);
unsigned int value2 = 1ul << move_step;
printf("value2 is 0x%X\n", value2);
return ;
}
test.c: In function ‘main’:
test.c:8: warning: left shift count >= width of type
value1 is 0x0
value2 is 0x1
- Dump of assembler code for function main:
- 0x080483c4 <main+0>: push %ebp
- 0x080483c5 <main+1>: mov %esp,%ebp
- 0x080483c7 <main+3>: and $0xfffffff0,%esp
- 0x080483ca <main+6>: push %ebx
- 0x080483cb <main+7>: sub $0x2c,%esp
- 0x080483ce <main+10>: movl $0x20,0x14(%esp)
- 0x080483d6 <main+18>: movl $0x0,0x18(%esp)
- 0x080483de <main+26>: mov $0x80484f4,%eax
- 0x080483e3 <main+31>: mov 0x18(%esp),%edx
- 0x080483e7 <main+35>: mov %edx,0x4(%esp)
- 0x080483eb <main+39>: mov %eax,(%esp)
- 0x080483ee <main+42>: call 0x80482f4<printf@plt>
- 0x080483f3 <main+47>: mov 0x14(%esp),%eax
- 0x080483f7 <main+51>: mov $0x1,%edx
- 0x080483fc <main+56>: mov %edx,%ebx
- 0x080483fe <main+58>: mov %eax,%ecx
- 0x08048400 <main+60>: shl %cl,%ebx
- 0x08048402 <main+62>: mov %ebx,%eax
- 0x08048404 <main+64>: mov %eax,0x1c(%esp)
- 0x08048408 <main+68>: mov $0x8048504,%eax
- 0x0804840d <main+73>: mov 0x1c(%esp),%edx
- 0x08048411 <main+77>: mov %edx,0x4(%esp)
- 0x08048415 <main+81>: mov %eax,(%esp)
- 0x08048418 <main+84>: call 0x80482f4<printf@plt>
- 0x0804841d <main+89>: mov $0x0,%eax
- 0x08048422 <main+94>: add $0x2c,%esp
- 0x08048425 <main+97>: pop %ebx
- 0x08048426 <main+98>: mov %ebp,%esp
- 0x08048428 <main+100>: pop %ebp
- 0x08048429 <main+101>: ret
- End of assembler dump.
Description
These instructions shift the bits in the first operand (destination operand) to the left or right by
the number of bits specified in the second operand (count operand). Bits shifted beyond the
destination operand boundary are first shifted into the CF flag, then discarded. At the end of the
shift operation, the CF flag contains the last bit shifted out of the destination operand.
The destination operand can be a register or a memory location. The count operand can be an
immediate value or register CL. The count is masked to five bits, which limits the count range
to 0 to 31. A special opcode encoding is provided for a count of 1.
转自:http://blog.chinaunix.net/uid-23629988-id-127318.html
Intel 移位指令的陷阱(转)的更多相关文章
- Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)
0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 脚本 ...
- Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State
目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...
- Intel微处理器学习笔记(五) 中断
▼ 中断是一个由硬件激发的过程,它中断当前正在执行的任何程序. ▼ 在Intel系列微处理器中,包括INTR和NMI(Non Maskable Interrupt)两个申请中断的引脚和一个响应INTR ...
- Intel大坑之中的一个:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 近期在写一些字符串函数的优化,兴趣使然.但是写的过程中,想要实现 SSE2 128 bit / 64 bit 的按 bit 逻辑位移.遇到了一个大坑,且听我娓娓道来. 我并不想用什么马航370来 ...
- Intel大坑之一:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
缘由 最近在写一些字符串函数的优化,兴趣使然,可是写的过程中,想要实现 128bit 的按 bit 逻辑位移,遇到了一个大坑,且听我娓娓道来. 如果要追究标题,更确切的是丢失的SSE2 128 bit ...
- gcc中的内嵌汇编语言(Intel i386平台)
[转]http://bbs.chinaunix.net/thread-2149855-1-1.html 一.声明 虽然Linux的核心代码大部分是用C语言编写的,但是不可避免的其中还是有一部分是用汇 ...
- 【av68676164(p55-p58)】 Intel CPU和Linux内存管理
7.4.1 Intel CPU物理结构 https://www.cnblogs.com/megachen/p/9768115.html x86实模式 实模式 20位:1M内存空间 地址表示方式:段地址 ...
- Intel汇编程序设计-整数算术指令(上)
第七章 整数算术指令 7.1 简介 每种汇编语言都有进行操作数移位的指令,移位和循环移位指令在控制硬件设备.加密数据,以及实现高速的图形操作时特别有用.本章讲述如何进行移位和循环移位操作以及如何使用移 ...
- Intel Media SDK H264 encoder GOP setting
1 I帧,P帧,B帧,IDR帧,NAL单元 I frame:帧内编码帧,又称intra picture,I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随 ...
随机推荐
- nyoj161 取石子 (四) 威佐夫博弈
思路:详细证明见博弈总结 如何判断威佐夫博弈的奇异局势? 对于状态(a, b),c = b - a,如果是奇异局势必定满足 a == c * (1+√5)/ 2. AC代码 #include < ...
- JDBC底层原理
Class.forName(“com.mysql.jdbc.Driver”)是 强制JVM将com.mysql.jdbc.Driver这个类加载入内存,并将其注册到DriverManager类,然后根 ...
- mysql数据库 调优
mysql调优硬件配置网络带宽mysql运行参数慢查询日志网络架构多实例(一台服务器上运行多个数据库服务)分库分表 当一台数据库服务器处理客户端的请求慢时,可能是哪些原因造成? 硬件配置低:(内存 c ...
- 工业级GBDT算法︱微软开源 的LightGBM(R包正在开发....)
看完一篇介绍文章后,第一个直觉就是这算法已经配得上工业级属性.日前看到微软已经公开了这一算法,而且已经发开python版本,本人觉得等hadoop+Spark这些平台配齐之后,就可以大规模宣传啦~如果 ...
- linux下的framebuffer显示图片
void showbmp2() { int x,y; unsigned char *p; int index=0; struct fb_var_screen ...
- FusionCharts MSBar2D图
1.页面展示 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> ...
- Rwordseg使用
#用于下载安装rJava 和 Rwordseg,如果安装了就注释掉 install.packages("rJava") install.packages("Rwordse ...
- STM32 下的库函数和寄存器操作比较
以 led闪烁中的flashLed函数例子: 库函数操作简单,但是效率不如寄存器操作的高: 寄存器操作很复杂,因为要熟悉上百个寄存器,但是程序效率很高 /**下面是通过直接操作库函数的方式实现IO控制 ...
- org.hibernate.exception.GenericJDBCException: Could not open connection
1.错误描述 org.hibernate.exception.GenericJDBCException: Could not open connection at org.hibernate.exce ...
- 搭建基于eclipse的纯的JavaWeb项目
-----------2016.9.9--------------------- 步骤: 1.搭建一个Java项目 2,字该项目下新建一个文件夹,表示根,名字为webapp(name随意) 3,在we ...