gpt4 book ai didi

c - Intel 64 ISA 中类型转换的说明是什么

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:38 24 4
gpt4 key购买 nike

Intel 64 ISA 中的类型转换说明是什么?

比如将 long int 转换为 double?

我做了这样的测试:

$ cat type_cast.c 
#include <stdio.h>
#include <stdlib.h>

int main()
{
long int a = 8l;
double b;

b = (double)a;

printf("%f", b);

return 0;
}

$ gcc -O0 -g -Wall type_cast.c -o type_cast
$ objdump -S type_cast

主要的部分是:

int main()
{
4004c4: 55 push %rbp
4004c5: 48 89 e5 mov %rsp,%rbp
4004c8: 48 83 ec 10 sub $0x10,%rsp
long int a = 8l;
4004cc: 48 c7 45 f8 08 00 00 movq $0x8,-0x8(%rbp)
4004d3: 00
double b;

b = (double)a;
4004d4: f2 48 0f 2a 45 f8 cvtsi2sdq -0x8(%rbp),%xmm0
4004da: f2 0f 11 45 f0 movsd %xmm0,-0x10(%rbp)

printf("%f", b);
4004df: b8 f8 05 40 00 mov $0x4005f8,%eax
4004e4: f2 0f 10 45 f0 movsd -0x10(%rbp),%xmm0
4004e9: 48 89 c7 mov %rax,%rdi
4004ec: b8 01 00 00 00 mov $0x1,%eax
4004f1: e8 c2 fe ff ff callq 4003b8 <printf@plt>

return 0;
4004f6: b8 00 00 00 00 mov $0x0,%eax
}

它使用 cvtsi2sdq -0x8(%rbp),%xmm0 和 movsd %xmm0,-0x10(%rbp) 将 long int 转换为 double。

我想知道 Intel 64 ISA 中通常使用的其他方法是什么。

最佳答案

由于 SIMD 已经得到很好的实现,您可能找不到其他东西了。当然,您将拥有用于多个同时转换的打包变体 (cvtpi2pd),但这可能不是您要的。

您唯一真正的选择是 fildl/fstpl 对,它会将您的 long int 加载到 x87 浮点堆栈中,然后将其读回到您的堆栈中。

关于c - Intel 64 ISA 中类型转换的说明是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com