关于FPU

关于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

posted @ 2017-08-25 13:57  封停  阅读(654)  评论(0编辑  收藏  举报