- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a question concerning use cpu_specific function call. Why the compiler does not make function embedding in a code in this case:
[bash]#pragma region CountOnBits UINT8but makes embedding in case:
__declspec(cpu_specific(generic))
UINT __forceinline CountOnBits( CUINT8 Data )
{
return OnBitsArray[Data];
}
__declspec(cpu_specific(core_i7_sse4_2))
UINT __forceinline CountOnBits( CUINT8 Data )
{
return _mm_popcnt_u32( Data );
}
__declspec(cpu_dispatch(generic, core_i7_sse4_2))
UINT __forceinline CountOnBits( CUINT8 Data )
{
// Empty function body informs the compiler to generate the
// CPU-dispatch function listed in the cpu_dispatch clause.
}[/bash]
[bash]UINT __forceinline CountOnBits_Simple(UINT8 Data)
{
return OnBitsArray[Data];
}[/bash]
Is it possible achieved the identical results?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler does not inline ("embed") the function becausebothvariants are compiled, and at start-up of the program it is decided, which function is used depending on the platform.Such amechanism is impossible, if the function is inlined.
In case of such a short function like CountOnBits_Simple, it is understandable that you don't want to pay the penalty of an extra function call. You therefore have two alternatives:
1. Generate different binaries for different platforms, i.e. use #ifdefs to compile the 2 different versions.
2. Use the dispatching mechanism on a higher level in your call stack. By this I mean that you use cpu_dispatch for the function that calls CountOnBits_Simple. Assuming that this function is normally not inlined, you won't introduce an additional call overhead.
Kind regards
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will use the second variant.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page