什麼是C++的內在函數

來源:互聯網
上載者:User

     想必很多學C++的都沒聽說過內在函數,我也是初次聽見。什麼是內在函數?英文是Intrinsic Function。這是一種編譯器特殊函數,它的行為類似與C++的內嵌函式,但是由於它是編譯器提供的,所以編譯器對其更加瞭解更利於最佳化。比如說memcpy等就是內在函數。如果編譯器有選擇/Optimization,那麼編譯器在產生代碼的時候將直接插入運行代碼而不是調用該函數,這和內嵌函式差不多,但是如上所說,由於編譯器對其的瞭解,這個最佳化會更好。
       在vc++中,AbnormalTermination也是一個內在函數。
       下面是維基百科的一些介紹:
       This article is about compiler intrinsic functions. For X toolkit, see Intrinsics.
       In compiler theory, an intrinsic function is a function available in a given language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically-generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.
       Compilers that implement intrinsic functions generally enable them only when the user has requested optimization, falling back to a default implementation provided by the language runtime environment otherwise.
       Intrinsic functions are often used to explicitly implement vectorization and parallelization in languages which do not address such constructs. Altivec and OpenMP are examples of APIs which use intrinsic functions to declare, respectively, vectorizable and multiprocessor-aware operations during compilation. The compiler parses the intrinsic functions and converts them into vector math or multiprocessing object code appropriate for the target platform.
       Microsoft and Intel's C/C++ compilers as well as GCC implement intrinsics that map directly to the x86 SIMD instructions (MMX, SSE, SSE2, SSE3, SSSE3, SSE4). In the latest version of the Microsoft compiler (VC2005 as well as VC2008) inline assembly is not available when compiling for 64 bit Windows, therefore intrinsics are necessary. To compensate for the lack of inline assembly, new intrinsics have been added that map to standard assembly instructions that are not normally accessible through C/C++ (e.g.: bit scan).

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.