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 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随 ...
随机推荐
- python更新数据库脚本两种方法
最近项目的两次版本迭代中,根据业务需求的变化,需要对数据库进行更新,两次分别使用了不同的方式进行更新. 第一种:使用python的MySQLdb模块利用原生的sql语句进行更新 import MySQ ...
- Python基础学习参考(五):字符串和编码
一.字符串 前面已经介绍过字符串,通过单引号或者双引号表示的一种数据类型.下面就再来进一步的细说一下字符串.字符串是不可变的,当你定义好以后就不能改变它了,可以进一步的说,字符串是一种特殊的元组,元 ...
- jqeury显示前几个,隐藏后几个,点击后隐藏前几个显示后几个
<script type="text/javascript"> $(".ul li").each(function(){ if($(this).in ...
- java线程池技术(二): 核心ThreadPoolExecutor介绍
版权声明:本文出自汪磊的博客,转载请务必注明出处. Java线程池技术属于比较"古老"而又比较基础的技术了,本篇博客主要作用是个人技术梳理,没什么新玩意. 一.Java线程池技术的 ...
- Hi3531支持2GByte内存
型号为K4B4G1646B-HCKO 1.修改DDRC_RNKCFG 为 0x142 2.修改arch/arm/mach-godnet/include/mach/vmalloc.h 扩大 vmallo ...
- 安装Apache提示APR not found的解决办法
不知道为什么在安装apache2.2.22版本的时候没有任何问题,直接使用命令 ./configure --prefix=/home/www/www_test/software/apache-2.2. ...
- Java之List排序
1.Java封装类 Student.java: /** * @Title:Student.java * @Package:com.you.data * @Description: * @Author: ...
- studio设置File Templates
从项目的整体风格考虑,对所有类要进行必要的说明,就注释说明来说首先需要说明是作者,文件创建时间,业务功能说明,这几项是基本的内容,而添加这些说明内容以前可能手动的添加文件标题头,这种做法现在都非常过时 ...
- I2C总线通讯协议
I2C总线通讯协议 1. I2C总线简介 I2C是Inter-Integrated Circuit的简称,读作:I-squared-C.由飞利浦公司于1980年代提出,为了让主板.嵌入式系统或手机用以 ...
- 由js深拷贝引起的对内存空间的一些思考
数据类型 js常用数据类型分为基本类型和引用类型 基本类型:null.undefined.数值型.字符串型.布尔型 引用类型:数组.对象 内存空间 var a = [1, 2, 3]; var b = ...