如何在C ++程序中适当地使用汇编指令,何时? [英] How to use Assembly instruction appropriately within C++ Program,When?

查看:84
本文介绍了如何在C ++程序中适当地使用汇编指令,何时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





简单地说,我想知道何时以及如何在C ++(我使用Visual C ++)程序边界/环境中集成适当的汇编指令来获取通过优化提高效率和效率(编译时和运行时)。

我已经提到教科书 - 使用汇编代码进行Visual C ++优化,但其中一些主题是设计的对于有经验的人。请提供简单指南 (为什么我们要正确使用它们,何时使用它们以及如何使用?)以及相关示例来解释如何使用程序集/ C ++中针对特定平台或平台的内在指令。

提前感谢。

Hi,

Simply,I want to know when and how to integrate appropriate assembly instructions within C++(I am using Visual C++) program boundary/enviornment to gain more efficient and effectiveness via optimization(Compile-time & Run-time).
I've already referred "Text Book - "Visual C++ Optimization With Assembly Code",but some of its topics were designed for Experienced People.Please provide simple guidelines (Why do we want to use them properly,when to use them and how?) with relevant examples to explain how to use assembly/intrinsic instructions within C++ for specific platform or platform independently.
Thank in advance.

推荐答案

这在几个方面无法回答更好地查找和阅读更多书籍,一本书通常是不够的。



基本请看下面的文章



在C / C ++中使用内联汇编 [ ^ ]
This can't be answer in a couple of lines. Better find and read more books, One book is usually not enough.

For basic please see below article

Using Inline Assembly in C/C++[^]


这句话不能简单回答。当提供所有请求的信息(原因,时间,方式,示例,平台/编译器支持)时,答案可以在此处作为文章发布。



使用内联汇编和内在函数是一个高级主题。如果没有经验到目前为止你必须花些时间和精力阅读。这包括使用过的处理器及其汇编语言的知识。



为什么

减少时间关键代码的执行时间或问题可以否则不会解决(例如使用特定的内在函数)。





仅在必要时才使用。



如何

这取决于使用的编译器和平台(例如,在构建64位应用程序时,MS编译器不支持内联汇编)。请参阅编译器文档。
This cant' be answered in short. When providing all requested information (why, when, how, examples, platform / compiler support) the answer can be posted as article here.

Using inline assembly and intrinsics is an advanced topic. When not having experiences so far you must put some time and effort into reading. This includes knowledge of the used processor and its assembly language.

Why
To reduce execution time of time critical code or when the problem can't be solved otherwise (e.g. using specific intrinsics).

When
Only if really necessary.

How
This depends on the used compiler and platform (e.g. inline assembly is not supported by the MS compiler when building 64-bit applications). See the compiler documentation.


如果您没有经验,那么这种高级优化没有多大意义:您可以更好地微调算法(以及编译器优化设置)。如果你真的需要这样的优化,那么你可能需要获得一些经验(不幸的是没有几何的皇家之路)。
If you are a unexperienced then it doesn't make much sense such kind of advanced optimization: you better fine tune your algorithms (as well compiler optimization settings). If you really need such kind of optimization then you probably have to gain some experience (unfortunately "there is not a Royal Road to geometry").


这篇关于如何在C ++程序中适当地使用汇编指令,何时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆