_byteswap_uint64()带有clang-cl的代码不正确

发布于 2025-01-30 17:45:21 字数 338 浏览 4 评论 0原文

如果我使用MSVC的_byteswap_uint64()与MSVC兼容的编译器clang-cl使用_byteswap_uint64(),则代码会生成对外部库函数的调用_byteswap_uint64(),该函数可以执行众所周知的掩码和移位。在MSVC的情况下,我只是获得X86 BSWAP指令,该指令从486开始就在那里,因此在这里不应有任何处理器优化级别。 Clang -Cl了解许多命令行选项MSVC也不理解-March =本机。因此,如果我有-march =天然,代码仍然是对提到函数的调用。
我通过IDE使用Clang-Cl 13(从Visual Studio Installer安装)。
有没有一种方法可以像MSVC一样获得正确的代码?

If I use the _byteswap_uint64() intrinsic of MSVC with the mostly MSVC compatible compiler clang-cl the code generates a call to the external library function _byteswap_uint64() which does the well known mask and shift orgy. Whith MSVC I simply get a x86 BSWAP instruction which is there since the 486 so there shouldn't be any processor optimization level relevant here. clang-cl understands a lot of command line options MSVC doesn't understand, even -march=native. So if I have -march=native the code is still a call to the mentioned function.
I use clang-cl 13 through the IDE (installed from the Visual Studio installer).
Is there a way to get proper code like with MSVC ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2025-02-06 17:45:21

我知道了。只需将特定的特定内在物质与条件编译中:

#include <cstdint>
#include <intrin.h>

uint64_t swapThis( uint64_t value )
{
#if defined(__llvm__)
    return __builtin_bswap64( value );
#elif defined(_MSC_VER)
    return _byteswap_uint64( value );
#endif
}

clang _在Windows下的clang-cl不定义,而仅在Windows下方使用Clang ++定义,因此我必须使用_ llvm

I've got it. Simply use the clang specific intrinsics with conditional compilation:

#include <cstdint>
#include <intrin.h>

uint64_t swapThis( uint64_t value )
{
#if defined(__llvm__)
    return __builtin_bswap64( value );
#elif defined(_MSC_VER)
    return _byteswap_uint64( value );
#endif
}

clang_ isn't defined with clang-cl under Windows but only with clang++ under Windows, so I had to use _llvm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文