Linker errors when using intrinsic function via function pointer

The code below doesn't compile with visual studio 2013. I get linker Error unresolved external symbol(LNK 2019) for the mm functions. If i use the functions directly, it all links fine. Why it doesn't compile? And is there a work-around

#include "emmintrin.h" #include <smmintrin.h> #include <intrin.h> __m128i (*load)(const __m128i*) = NULL; if (it::isAligned<16>(ucpSrc, iXOffset * sizeof(unsigned char)) ) load = &_mm_load_si128; else load = &_mm_lddqu_si128;


Where some compilers such as gcc and clang use some special annotation on such methods (static extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__)) for gcc, or static __inline__ __attribute__((__always_inline__, __nodebug__)) for clang), others (like Intel on Windows and cl, don't and probably do something special under the hood.

Key thing is that these functions are not meant to be considered as functions. They will not show any preamble, implement standard ABI. Those are just a C-syntax way to invoke some assembly instruction, more readable than a __asm (...)

I believe you can accomplish this function pointer thing with:

__m128i load_aligned (const __m128i* p) { return _mm_load_si128(p); } __m128i load_unaligned (const __m128i* p) { return _mm_lddqu_si128(p); } __m128i (*load)(const __m128i*) = NULL; void f(bool a) { if (a) load = load_aligned; else load = load_unaligned; } int main() { __m128i a, b ; f(argc != 0); return 0; }

I would highlight a performance note though: using a function pointer is going to be immensely more expensive than simply using the unaligned load all the time. The overhead of unaligned loads is about a few percents when memory is aligned where calling a function pointer will force you respect the ABI, hence store registers on the stack, most probably go through a few cache misses, etc.


  • how to find function boundaries in binary code
  • Is there a pre-defined built-in function to convert a number to its binary format in C++?
  • Const variable in C++ function body
  • Is C++ compilable with OpenMP and boost on MacOS?
  • How do I compile a C/C++ program through windows command prompt?
  • Correct implementation of List Iterator methods
  • Cannot save model when using ember render helper
  • How to render a pixel array most efficiently to a window in c++?
  • How to copy styled text in JTextPane
  • Doctrine2 bulk import try to work with another entity
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • Regarding starting the threads on a condition
  • Unable to send e-mail through Java
  • configure: error: no acceptable C compiler found in $PATH
  • NUnit 3.0 TestCase const custom object arguments
  • Undefined references when compiling gSOAP client
  • how does System.Web.HttpRequest::PathInfo work?
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • Reading a file into a multidimensional array
  • How to remove a SwiftyJSON element?
  • RxJava debounce by arbitrary value
  • Object and struct member access and address offset calculation
  • pyodbc doesn't report sql server error
  • NSScanner Loop Question
  • Display java JPanel in a JFrame
  • Appending Character to Character Array In C
  • how to adjust image in a panel in Java swing?
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • AES padding and writing the ciphertext to a disk file
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Convert array of 8 bytes to signed long in C++
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • LevelDB C iterator
  • How can i traverse a binary tree from right to left in java?