linux icc查看汇编代码,如何在Linux上执行原子操作,在x86,arm,GCC和icc上工作?(How to perform atomic operations on Linux that ...

如何在Linux上执行原子操作,在x86,arm,GCC和icc上工作?(How to perform atomic operations on Linux that work on x86, arm, GCC and icc?)

每个现代操作系统都提供一些原子操作:

Windows具有Interlocked* API

FreeBSD有

Solaris有

Mac OS X具有

任何类似于Linux的?

我需要它在大多数Linux支持的平台上工作,包括:x86,x86_64和arm 。

我需要它至少在GCC和英特尔编译器上工作。

我不需要使用像glib或qt这样的第三个标准库。

我需要它在C ++中工作(C不需要)

问题:

所有平台(ARM)都不支持GCC原子内置__sync_* ,并且Intel编译器不支持。

AFAIK 不应该在用户空间中使用,我还没有成功地使用它。 此外,我不知道它是否可以与英特尔编译器配合使用。

有什么建议么?

我知道有很多相关的问题,但有些问题指向__sync* ,这对我来说是不可行的(ARM),有些则指向asm/atomic.h 。

也许有一个内联汇编库为GCC(ICC支持gcc程序集)执行此操作?

编辑:

有一个非常部分的添加操作解决方案(允许实现原子计数器但不锁定需要CAS的自由结构):

如果使用libstc++ (Intel Compiler使用libstdc++ ),则可以使用或中定义的__gnu_cxx::__exchange_and_add 。 取决于编译器版本。

但是我仍然希望看到支持CAS的内容。

Every Modern OS provides today some atomic operations:

Windows has Interlocked* API

FreeBSD has

Solaris has

Mac OS X has

Anything like that for Linux?

I need it to work on most Linux supported platforms including: x86, x86_64 and arm.

I need it to work on at least GCC and Intel Compiler.

I need not to use 3rd par library like glib or qt.

I need it to work in C++ (C not required)

Issues:

GCC atomic builtins __sync_* are not supported on all platforms (ARM) and are not supported by the Intel compiler.

AFAIK should not be used in user space and I haven't successfully used it at all. Also, I'm not sure if it would work with Intel compiler.

Any suggestions?

I know that there are many related questions but some of them point to __sync* which is not feasible for me (ARM) and some point to asm/atomic.h.

Maybe there is an inline assembly library that does this for GCC (ICC supports gcc assembly)?

Edit:

There is a very partial solution for add operations only (allows implementing atomic counter but not lock free-structures that require CAS):

If you use libstc++ (Intel Compiler uses libstdc++) then you can use __gnu_cxx::__exchange_and_add that defined in or . Depends on compiler version.

However I'd still like to see something that supports CAS.

原文:https://stackoverflow.com/questions/2287451

更新时间:2019-11-21 01:40

最满意答案

项目正在使用:

http://packages.debian.org/source/sid/libatomic-ops

如果你想要简单的操作,如CAS,你不能只是使用arch的特定的实现从内核,并用自动工具/ cmake的用户空间的arch检查? 就许可而言,尽管内核是GPL,但我认为这些操作的内联程序集是由Intel / AMD提供的,而不是内核具有许可证。 它们恰好在内核源代码中容易访问。

Projects are using this:

If you want simple operations such as CAS, can't you just just use the arch-specific implementations out of the kernel, and do arch checks in user-space with autotools/cmake? As far as licensing goes, although the kernel is GPL, I think it's arguable that the inline assembly for these operations is provided by Intel/AMD, not that the kernel has a license on them. They just happen to be in an easily accessible form in the kernel source.

2011-01-14

相关问答

您引用的PDF是从1999年开始的,并且已过时。 最新的英特尔文档 ,特别是Volume-3A讲述了一个不同的故事。 例如,在Core-i7处理器上,您仍然必须确保您的数据不会跨越缓存行,否则操作不能保证是原子性的。 关于第3A卷,系统编程,对于x86 / x64英特尔明确指出: 8.1.1有保证的原子操作 Intel486处理器(以及更新的处理器)确保了以下基本内存操作始终以原子方式进行: 读或写一个字节 读取或写入在16位边界上对齐的单词 读取或写入在32位边界上对齐的双字 Pentium处理

...

ARM是RISC (精简指令集计算)架构,而x86是CISC (复杂指令集计算)架构。 这方面的核心区别在于,ARM指令只对具有少量指令的寄存器进行操作,用于加载和保存数据到/存储器,而x86也可以直接对存储器进行操作。 直到v8 ARM是一个本机32位架构,有利于四个字节的操作。 所以ARM是一个更简单的架构,导致小的硅面积和大量的省电功能,而x86在功耗和生产方面成为一个强大的动力。 关于“ x86架构是否专门设计使用键盘,而ARM预计将要移动? ”的问题。 x86不是专门设计用于键盘的,也不

...

如果在小端平台上将8位数组类型转换为short(16位),那么在执行相同操作时,您将获得与大端平台上获得的结果不同的结果。 编译器无法帮助你,因为这只是endianess的本质...... If you cast an 8 bit array type to short (16 bit) on a little endian platform, you'll get a different result than what you get on a big endian platform when

...

项目正在使用: http://packages.debian.org/source/sid/libatomic-ops 如果你想要简单的操作,如CAS,你不能只是使用arch的特定的实现从内核,并用自动工具/ cmake的用户空间的arch检查? 就许可而言,尽管内核是GPL,但我认为这些操作的内联程序集是由Intel / AMD提供的,而不是内核具有许可证。 它们恰好在内核源代码中容易访问。 Projects are using this: http://packages.debian.org/

...

好问题。 我的直觉是它会检查/proc/cpuinfo 。 实际上,它取决于它已编译运行的体系结构。 似乎host_detect_local_cpu是负责该功能的函数。 它的工作是用good -march=<...>或一组与当前cpu尽可能匹配的标志( -mmmx , -mno-avx等)替换-march=native 。 i386和arm示例。 i386直接使用cpuid来检查每个可能的功能。 arm检查/proc/cpuinfo中的CPU part行,并有一个表,从CPU部分值映射到体系结构的

...

解决方法 注释prebuilts / tools / gcc-sdk / gcc的第23-38行 例如: http : //pastebin.com/qH0BYcSF Workaround Comment out lines 23-38 of prebuilts/tools/gcc-sdk/gcc Example: http://pastebin.com/qH0BYcSF

首先,Android应用程序(纯Java)实际上并不是“为ARM编译的,就像Java应用程序被编译成中间Java字节码以便由任何支持JVM的平台执行一样,用Java编写的Android应用程序编译成Dalvik字节码可以在任何支持Dalvik VM的平台上运行,在这方面,运行x86或ARM或MIPS的Android应用程序与Java应用程序在x86,SPARC,POWER等上的运行方式类似。 当然,如果一个应用程序包含本机代码,那么该应用程序需要包含对x86的支持,以便在x86模拟器或实际的x86

...

使用互锁操作,以下是一些示例代码: LONGLONG AtomicRead(LONGLONG* p)

{

return InterlockedCompareExchange64(p, 0, 0);

}

这将比较交换对零,并将p设置为零,如果它已经等于零 - 这是一个noop。 InterlockedCompareExchange返回由p指向的原始64位值。 Use the Interlocked operations, here's some sample code: LONGLONG

...

C ++ 11是您的选择吗? 如果是这样,也许你可以在结果上调用std::isnormal ,参见例如http://en.cppreference.com/w/cpp/numeric/math/isnormal 。 As said in the question, it seems that fenv.h has a flag FE_UNDERFLOW that on some architectures at least indicate a subnormal/denormal result.

...

GCC应支持或运行multilib以消除此错误。 GCC should support or run with multilib to eliminate this error.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux系统上安装ICC编译器的步骤如下: 1. 首先,确保你已经下载了相应版本的ICC安装包。根据引用的信息,你使用的是2011.11.339版本的ICC,支持ia32和x86_64架构。将安装包保存在你喜欢的位置。 2. 接下来,根据引用的指引,可以按照以下步骤进行安装和配置: - 打开终端,并使用命令行切换到存放ICC安装包的目录。 - 运行命令 `tar -xzvf <ICC安装包名称>` 解压安装包。 - 进入解压后的目录: `cd <解压后的目录名称>` - 运行 `sudo ./install.sh` 启动安装程序。 - 按照安装程序的指示进行安装,可以选择安装路径和其他配置选项。 3. 在安装过程中,如果遇到缺少依赖库的问题,可以参考引用中提供的解决方法来安装缺失的库文件。根据你的系统和网络状态,选择相应的解决方案。 4. 安装完成后,你就可以在终端中使用ICC编译器了。可以通过运行 `icc -v` 命令来验证安装是否成功,并查看版本信息。 总结起来,安装ICC编译器的步骤包括下载安装包、解压安装包、运行安装程序进行安装、解决依赖库问题(如果有)、验证安装成功。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [linux安装icc步骤,怎麼安装不到 icc?](https://blog.csdn.net/weixin_39973271/article/details/116968637)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [【Intel Parallel编译器(icc icpc ifort)Linux-centos7系统安装配置】](https://blog.csdn.net/weixin_41914699/article/details/128903368)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值