orl*_*rlp 4 c floating-point x86 context-switch
在一些文章中,他们建议使用fistp指令以快速方式转换float-> integer.这取决于CPU的当前舍入模式,因此您必须进行设置.
但是这个舍入模式是否可以在程序运行期间被其他程序更改?通过操作系统?
更糟糕的是,这是一种可能的情况(伪代码)吗?
set_rounding_mode(ROUND_TRUNCATE);
/* process gets switched out and other process sets the rounding mode to round */
int x = round_with_fistp(0.6);
printf("%d\n", x); // prints 1
Run Code Online (Sandbox Code Playgroud)
没有理智的通用操作系统会跨进程和线程共享舍入模式.它应该仅在线程请求它时更改,并且更改应该仅对该线程是本地的.但是,您可能会遇到某些库(尤其是第三方)更改它,有时(或始终)无法恢复它并迫使您实施变通方法.
| 归档时间: |
|
| 查看次数: |
402 次 |
| 最近记录: |