gpt4 book ai didi

c++ - clang 和 __rdtscp : What is it and what is the error

转载 作者:行者123 更新时间:2023-11-28 00:29:32 26 4
gpt4 key购买 nike

Clang 决定给我一个错误。它决定对我使用 __rdtscp 大喊大叫(这不是我的代码,我不知道那是什么)

 error: use of undeclared identifier '__rdtscp'
i2 = __rdtscp(&ui2);
^
error: use of undeclared identifier '__rdtscp'
i3 = __rdtscp(&ui3);
^
error: use of undeclared identifier '__rdtscp'
i2 = __rdtscp(&ui2);
^
error: use of undeclared identifier '__rdtscp'
i3 = __rdtscp(&ui3);
^
error: use of undeclared identifier '__rdtscp'
i2 = __rdtscp(&ui2);
^
error: use of undeclared identifier '__rdtscp'
i3 = __rdtscp(&ui3);

我真的很想弄清楚为什么 Clang 不喜欢我。有谁知道 __rdtscp 是什么以及如何让 clang 冷静下来?

最佳答案

假设您正在为 x86 编译,有一个 __rdtscp 内置函数。如果您正在为其他处理架构编译,它将不可用,因为 rdtscp 基本上是 x86 指令的名称。

这段代码适用于我,从昨天开始使用 clang++ 3.5.0:

#include <iostream>
#include <x86intrin.h>

int main()
{
unsigned int dummy;
unsigned long long t1 = __rdtscp(&dummy);
std::cout << "Hello" << std::endl;

unsigned long long t2 = __rdtscp(&dummy);
std::cout << "Time: " << t2 - t1 << std::endl;
}

您需要包含 x86intrin.h 以将 __rdtscp 转换为编译器知道的实际 __builtin_ia32_rdtscp 函数。

关于c++ - clang 和 __rdtscp : What is it and what is the error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23437796/

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