Hi, Lately, I have been wondering how a compiler like GCC or Clang implements builtin functions like sqrt, sin, and also more bit-specific things like bcmp and ffs. Originially, these were all deferred to the C library where they might still have a "backup implementation", but I don't understand why a compiler would choose the non-builtin version, as it should know its version is faster (or that's the way it should be at least). - How does LLVM cope with builtin's that are target specific? Does the Target backend know of all these specialized instructions? - Does LLVM have a representation for all C library functions that have or might have a future hardware implementation? Or is this mostly handled by the whole toolchain (Clang adds target-specific info into the LLVM bitcode which is forced to produce the asm instruction if the target supports it)? - Is it possible to code a sqrt or sin in LLVM bitcode that will use the hardware instruction if it's compiled for a certain target? I know these are probably questions born out of misunderstanding, but that's why I'm asking. It's important to know what LLVM could provide if I say were to always bypass the system C library for these "builtins". Thanks! Ruben -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120120/afb69aef/attachment.html>
Le 20 janv. 2012 à 14:38, Ruben Van Boxem a écrit :> Hi, > > Lately, I have been wondering how a compiler like GCC or Clang implements builtin functions like sqrt, sin, and also more bit-specific things like bcmp and ffs. Originially, these were all deferred to the C library where they might still have a "backup implementation", but I don't understand why a compiler would choose the non-builtin version, as it should know its version is faster (or that's the way it should be at least). > > - How does LLVM cope with builtin's that are target specific? Does the Target backend know of all these specialized instructions? > - Does LLVM have a representation for all C library functions that have or might have a future hardware implementation? Or is this mostly handled by the whole toolchain (Clang adds target-specific info into the LLVM bitcode which is forced to produce the asm instruction if the target supports it)? > - Is it possible to code a sqrt or sin in LLVM bitcode that will use the hardware instruction if it's compiled for a certain target?See the LLVM language reference for the list of supported intrinsics: http://llvm.org/docs/LangRef.html#int_libc -- Jean-Daniel
2012/1/20 Jean-Daniel Dupas <devlists at shadowlab.org>> > Le 20 janv. 2012 à 14:38, Ruben Van Boxem a écrit : > > > Hi, > > > > Lately, I have been wondering how a compiler like GCC or Clang > implements builtin functions like sqrt, sin, and also more bit-specific > things like bcmp and ffs. Originially, these were all deferred to the C > library where they might still have a "backup implementation", but I don't > understand why a compiler would choose the non-builtin version, as it > should know its version is faster (or that's the way it should be at least). > > > > - How does LLVM cope with builtin's that are target specific? Does the > Target backend know of all these specialized instructions? > > - Does LLVM have a representation for all C library functions that have > or might have a future hardware implementation? Or is this mostly handled > by the whole toolchain (Clang adds target-specific info into the LLVM > bitcode which is forced to produce the asm instruction if the target > supports it)? > > - Is it possible to code a sqrt or sin in LLVM bitcode that will use > the hardware instruction if it's compiled for a certain target? > > > See the LLVM language reference for the list of supported intrinsics: > http://llvm.org/docs/LangRef.html#int_libcThanks for that. I still wonder what happens to stuff like log1p, which translates to a machine instruction on x86. Can the LLVM backend discover that this operation is called for, and use the native instruction in this case? Thanks, Ruben> > -- Jean-Daniel > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120121/0e63bd7e/attachment.html>
Maybe Matching Threads
- [LLVMdev] Implementation of builtins/intrinsics
- [RFC] Adding a -memeq-lib-function flag to allow the user to specify a memeq function.
- [RFC] Adding a -memeq-lib-function flag to allow the user to specify a memeq function.
- [RFC] Adding a -memeq-lib-function flag to allow the user to specify a memeq function.
- [RFC] Adding a -memeq-lib-function flag to allow the user to specify a memeq function.