「操作系统」: Conditional Move Instructions(trap)
Not all conditional expressions can be compiled using conditional moves. Most significantly, the abstract code we have shown evaluates both then-expr and else-expr regardless of the test outcome. If one of those two expressions could possibly generate an error condition or a side effect, this could lead to invalid behavior. As an illustration, consider the following C function:
int cread(int *xp){
return (xp ? *xp : );
}
At first, this seems like a good candidate to compile using a conditional move to read the value designated by pointer xp, as shown in the following assembly code:
#Invalid implementation of function cread
#xp in register %edx
movl $, %eax
testl %edx, %edx
cmovne (%edx), %eax
This implementation is invalid, however, since the dereferencing of xp by the cmovne instruction occurs even when the test fails, causing a null pointer dereferencing error.
Instead, this code must be compiled using branching code.
A similar case holds when either of the two branches causes a side effect, as illustrated by the following function:
/*Global variable*/
int lcount = ;
int absdiff_se(int x. int y){
return x < y ? (lcount++, y-x) : x-y;
}
This function increments global variable lcount as part of then-expr. Thus, branching code must be used to ensure this side effect only occurs when the test condition holds.
Usingconditional moves also does not always improve code effciency. For example, if either the then-expr or the else-expr evaluation requires a significant computation, then this effort is wasted when the corresponding condition does not hold. Compilers must take into account the relative performance of wasted computation verus the potential for performance penalty due to branch misprediction. In truth, they do not know how well the branches will follow predictable patterns. GCC only uses conditional moves when the two expressions can be computed very easily, for example, with single add instructions.GCC uses conditional control transfers even in many cases where the cost of branch misprediction would exceed even more complex computations.
「操作系统」: Conditional Move Instructions(trap)的更多相关文章
- 「操作系统」:The most useful condition codes
CF: Carry Flag.The most recent operation generated a carry out of the most significant bit. Used to ...
- 「操作系统」:Linker Use static Libraries
While static libraries are useful and essential tools, they are also a source of confusion to progra ...
- 「MoreThanJava」计算机系统概述
「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...
- 2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐
原文:2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐 image Raspberry Pi** 是一款基于 ARM 的单板计算机,默认运行一款称为 Raspbian ...
- iOS 9,为前端世界都带来了些什么?「译」 - 高棋的博客
2015 年 9 月,Apple 重磅发布了全新的 iPhone 6s/6s Plus.iPad Pro 与全新的操作系统 watchOS 2 与 tvOS 9(是的,这货居然是第 9 版),加上已经 ...
- 「MoreThanJava」机器指令到汇编再到高级编程语言
「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「2014-3-18」multi-pattern string match using aho-corasick
我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...
- 一个只需要点 「下一步」就完成监控 Windows
Cloud Insight 此前已然支持 Linux 操作系统,支持20多中数据库中间件等组件,多种操作,多种搭配,服务器监控玩的其乐无穷啊!但想想还有许多 Windows 的小伙伴没有体验过,所以在 ...
随机推荐
- CSS3滤镜
今天在办公室亲眼目睹了同事使用CSS3滤镜为一张漂亮的照片轮廓加上了阴影,瞬间亮瞎了我的的双眼,见笑了. 所以也迅速尝试使用CSS3滤镜让最新出炉的MUI LOGO也性感一把,试图来愉悦一下大家的双眼 ...
- 实现一个在autolayout下有宽度约束后,自动确定高度的view
我曾经遇到过一个问题:需要实现一个自定义的label(类似于UILabel),同时需要兼顾UILabel的大小自适应的特性.这个label通常宽度是固定的,通过autolayout指定其宽度约束,但不 ...
- ExtJS002Window创建
Ext.onReady(function () { Ext.create('Ext.window.Window', { title: 'window', width: 400, height: 300 ...
- C++时间获取
http://net.pku.edu.cn/~yhf/linux_c/function/04.html asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime ...
- Yii2.0中文开发向导——rules常用规则
public function rules(){ return [ //必须填写 ['email, username, password,agree,verifyPassword,verifyCode ...
- pwntools安装使用方法
pwntools是一个CTF框架和漏洞利用开发库,用Python开发,由rapid设计,旨在让使用者简单快速的编写exploit. pwntools对Ubuntu 12.04和14.04的支持最好,但 ...
- Mathematica
Mathematica是一款科学计算软件,很好地结合了数值和符号计算引擎.图形系统.编程语言.文本系统.和与其他应用程序的高级连接.很多功能在相应领域内处于世界领先地位,它也是使用最广泛的数学软件之一 ...
- Protel99se轻松入门:特殊技巧和高级设置(一)
这里简单介绍一下自动布线和手动布线方面的设置问题 1.如何进入PCB的这个布线规则选项: 2.电气安全距离的设置 3.导线宽度的设置 4.学会了设置图层就可以做单面板以及多层板,而不只是双面板 5.布 ...
- 中国天气网API
中国天气网有三个 API 适用于不同场合的使用. http://m.weather.com.cn/data/101050101.html 这个接口返回的格式如下. { "weatherinf ...
- 10003 Cutting Sticks(区间dp)
Cutting Sticks You have to cut a wood stick into pieces. The most affordable company, The Analog ...