关于FPU

时间:2017-08-25 14:27:11   收藏:0   阅读:308

关于FPU,比较运算有几个地方需要关注,mark一下。

he result of the comparison is reported in the condition codes field of the Status Word as follows (the C1 bit is not used and the C2 bit was not used in early FPUs):

                           C3   C2   C0  |  ZF  PF  CF
     If ST(0) > source      0    0    0  |  0   0  0
     If ST(0) < source      0    0    1  |  0   0  1
     If ST(0) = source      1    0    0  |  1   0  0
     If ST(0) ? source      1    1    1  |

An Invalid operation exception is detected if ST(0) is empty, or if a data register specified as the source is empty, or if one of the two values is a NAN, setting the related flag in the Status Word. The result would then be indeterminate and return C3=1, C2=1 and C0=1 as indicated above. (Values of INFINITY will be treated as valid operands and yield a valid result without any exception being detected.)

主要是三种比较方式

1、fnstsw ax, c3 / c2 / c0 分别放到AH的0 / 2 / 6位,test ah, 5,只看c0 / c2,c0 / c2 都为1 或都为0, PF =1 , JP跳转

2、fnstsw ax,同上,test ah, 41h,根据比较结果进行判断,JZ / JNZ跳转。

3、fnstsw ax,c3 / c2 / c0对应ZF / PF / CF,setnbe al, al = 1 如果CF =0 ,ZF=0,然后test al, al,JZ/JNZ

变种:fnstsw ax , sahf(将AH对应ZF/PF/CF寄存器值),JA跳转,如果ZF=0 AND CF=0

4、P6 Intel family,使用能改变寄存器的指令,不需要转换。

FUCOMI / FCMOVBE ….

参考链接:

http://www.website.masmforum.com/tutorials/fptute/fpuchap7.htm

原文:http://www.cnblogs.com/f3ngt1ng/p/7427733.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!