<div dir="ltr">Hello Tim,<br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
> I spent the last three days trying to compile a version of LLVM that would<br>
> allow me to compile sources that contain these intrinsics, but with no success.<br>
<br>
</div>Ok. This we can probably help with. Did you manage to build a version<br>
of Clang (preferably from git/subversion)?<br></blockquote><div><br></div><div>Yes, I managed to build the latest (r191291) svn revision of LLVM + clang.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

If so, you're probably having problems cross-compiling. Renato's<br>
recently worked on some documentation in this area:<br>
<a href="http://clang.llvm.org/docs/CrossCompilation.html" target="_blank">http://clang.llvm.org/docs/CrossCompilation.html</a>.<br>
<br>
But for a quick hack, you could try:<br>
<br>
$ cat > neon.c<br>
#include <arm_neon.h><br>
<br>
float32x4_t my_func(float32x4_t lhs, float32x4_t rhs) {<br>
  return vaddq_f32(lhs, rhs);<br>
}<br>
$ clang --target=arm-linux-gnueabihf -mcpu=cortex-a15 -ffreestanding<br>
-O3 -S -o - neon.c<br>
<br>
("ffreestanding" will dodge any issues with your supporting toolchain,<br>
but won't work for larger tests. You've got to actually solve the<br>
issues before you start running code).<br></blockquote><div><br></div><div>This works, which is great! My confusion came from not knowing the combination of flags for cross-compiling for ARM, and for getting "#error "NEON support not enabled"" when getting it wrong, which combined with the outdated knowledge of the internet lead me to believe that NEON is not supported.</div>
<div><br></div><div>I will read that cross compilation guide before asking further questions about this set of flags.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im"><br>
> In the process I found out that clang doesn't support NEON (as per<br>
> <a href="http://blog.llvm.org/2010/04/arm-advanced-simd-neon-intrinsics-and.html" target="_blank">http://blog.llvm.org/2010/04/arm-advanced-simd-neon-intrinsics-and.html</a>),<br>
<br>
</div>That's rather out of date, I'm afraid. 32-bit ARM does support both<br>
NEON intrinsics and a reasonable amount of LLVM's own<br>
auto-vectorisation (which is in its early stages, but we have some<br>
kind of loop and SLP vectorisation going on).<br>
<div class="im"><br>
> but there has been at least some effort in adding it<br>
> (<a href="https://www.codeaurora.org/patches/quic/llvm/32040/clang-Initial-Neon-support.patch" target="_blank">https://www.codeaurora.org/patches/quic/llvm/32040/clang-Initial-Neon-support.patch</a>).<br>
<br>
</div>That patch is part of the effort to implement NEON (instructions and<br>
intrinsics) on the 64-bit ARM architecture (AArch64).<br></blockquote><div><br></div><div>Great! It seemed quite confusing that this is the main official information one gets when searching for "arm neon clang llvm", especially when parts of the documentation (<a href="http://clang.llvm.org/docs/LanguageExtensions.html#langext-vectors">http://clang.llvm.org/docs/LanguageExtensions.html#langext-vectors</a>) claim that clang supports NEON. I am happy that it actually does.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
> I also tried compiling LLVM 2.9 + llvm-gcc but that failed too many times<br>
> and I gave up.<br>
<br>
</div>Yep. llvm-gcc is long dead, and LLVM 2.9 isn't much healthier.<br></blockquote><div><br></div><div>I was thinking it was just me being a noob. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
> current plan is to implement the ARM NEON intrinsics as a shared library,<br>
> using attributes as in:</div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<span style="color:rgb(34,34,34)"> </span><br></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
</div>That would probably be possible, but very bad from a performance<br>
perspective. The whole point of NEON intrinsics is to speed up vector<br>
code; if you've got the overhead of a call/return for each intrinsic<br>
and completely fixed registers around even that you'll be in for a<br>
world of pain.<br>
<div class="im"><br>
> Ideally, I want to be able to compile C code that includes ARM NEON<br>
> intrinsics to other targets (TI processors, e.g.).<br>
<br>
</div>Now that's going to be harder. LLVM itself doesn't support any TI<br>
processors, for a start. And many of the NEON intrinsics (those with<br>
more complex semantics) compile to LLVM IR with LLVM-level intrinsics,<br>
which are only supported in the ARM backend.<br>
<br>
Your shared library idea would work semantically, of course. But I'm<br>
not sure what useful information could be extracted from it.<br></blockquote><div><br></div><div>That was my plan for adding NEON support in clang, which as I know now has been thankfully done by someone who is more aware of how the platform works. The TI processors were a bad example, PowerPC is maybe a better one, as I just checked and there is a backend in LLVM for such processors. My current goal is exactly to add support for such LLVM-level intrinsics to a non-ARM backend, in order to make ARM-specific C code (one that contains NEON intrinsics) compilable for another target.</div>
<div><br>Thanks a lot for your time and help. I will try to setup my cross compilation toolchain and ask again if I get seriously stuck.<br><br>Cheers,</div><div> - Stan</div></div></div><br clear="all"><div><br></div>-- <br>
<div dir="ltr"><div>Stan Manilov<br></div>1st year Ph.D. student<br><div><div><div>2013 Graduate in BSc Computer Science and Mathematics<br></div><div>The University of Edinburgh<br></div></div></div></div></div>