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)的更多相关文章

  1. 「操作系统」:The most useful condition codes

    CF: Carry Flag.The most recent operation generated a carry out of the most significant bit. Used to ...

  2. 「操作系统」:Linker Use static Libraries

    While static libraries are useful and essential tools, they are also a source of confusion to progra ...

  3. 「MoreThanJava」计算机系统概述

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  4. 2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐

    原文:2019 年在 Raspberry Pi 「树莓派」上运行的 10 个操作系统推荐 image Raspberry Pi** 是一款基于 ARM 的单板计算机,默认运行一款称为 Raspbian ...

  5. iOS 9,为前端世界都带来了些什么?「译」 - 高棋的博客

    2015 年 9 月,Apple 重磅发布了全新的 iPhone 6s/6s Plus.iPad Pro 与全新的操作系统 watchOS 2 与 tvOS 9(是的,这货居然是第 9 版),加上已经 ...

  6. 「MoreThanJava」机器指令到汇编再到高级编程语言

    「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...

  7. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  8. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  9. 一个只需要点 「下一步」就完成监控 Windows

    Cloud Insight 此前已然支持 Linux 操作系统,支持20多中数据库中间件等组件,多种操作,多种搭配,服务器监控玩的其乐无穷啊!但想想还有许多 Windows 的小伙伴没有体验过,所以在 ...

随机推荐

  1. JavaScript基础(语法类型转换、运算符、语句)

    1.类型转换: 分为自动转换和强制转换,一般用强制转换. 其他类型转换为整数:parseint(): 其他类型转换为小数:parsefloat(): 判断是否是一个合法的数字类型:isNaN(): 是 ...

  2. Linux新手笔记 源 安装chromium

    centos6.4 32 一.软件源目录/etc/yum.repos.d把新的软件源文件copy到这即可.二.安装chromiumwget http://people.centos.org/hughe ...

  3. SSIS: 使用Lookup 和 Cache transformation 进行数据匹配简单介绍

    本文将讲解Cache transformation的使用方式,并且用Lookup transformation进行匹配. 背景 如下图,我们的产品目标表中有些有尺寸信息有些没有.我们需要用Cache组 ...

  4. Android ListView 删除动画

    Android 的ListView在删除条目时,被删除的条目直接消失,比较生硬,在此实现一下删除动画,大家一起探讨:主要实现原理即是通过Animator来实现被删除条目的动画效果,然后在动画结束时通过 ...

  5. c语言中的字符数组与字符串

    1.字符数组的定义与初始化 字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素. char str[10]={ 'I',' ','a','m',' ',‘h’,'a','p','p','y ...

  6. html5 geolocation API

    清单 1. 检查浏览器支持性if (navigator.geolocation) 清单 2. 单次定位请求 API void getCurrentPosition(updateLocation, op ...

  7. checkbox、select、radio的设置与获取

    参考链接:http://www.cnblogs.com/xiaopin/archive/2011/09/13/2175190.html js版本: <!DOCTYPE html PUBLIC & ...

  8. bzoj 1047 : [HAOI2007]理想的正方形 单调队列dp

    题目链接 1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2369  Solved: 1266[Submi ...

  9. monkeyrunner学习--手机按键

    按下HOME键 device.press('KEYCODE_HOME','DOWN_AND_UP') 按下BACK键 device.press('KEYCODE_BACK','DOWN_AND_UP' ...

  10. python10min系列之多线程下载器

    今天群里看到有人问关于python多线程写文件的问题,联想到这是reboot的架构师班的入学题,我想了一下,感觉坑和考察的点还挺多,可以当成一个面试题来问,简单说一下我的想法和思路吧,涉及的代码和注释 ...