<div dir="ltr"><div dir="ltr">On Mon, Feb 1, 2021 at 2:58 AM Ebrahim Byagowi <<a href="mailto:ebraminio@gmail.com" target="_blank">ebraminio@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">To describe in maybe some better way, for example this is all I need to get ceilf floorf etc in a .wasm module being built by -nostdlib -nostdinc<div><div><br></div><div>#define ceilf __builtin_ceilf</div><div>#define floorf __builtin_floorf</div><div>#define abs __builtin_abs</div><div>#define fabs __builtin_fabs</div></div><div><br></div><div>so I wondered if I could get more of libc this way (parts make sense ofc) or at least to know what will be the relation between those builtin implementations and the upcoming libc.</div></div></div></blockquote><div><br></div><div>IIUC, there are two parts to your question:</div><div>1. Can we implement a libc function as a macro resolving to a builtin: Not if the standard requires the function to be a real addressable function. One can choose to also provide a macro, but an addressable function declaration should be available. See section 7.1.4 of the C11 standard for more information.</div><div>2. What is the difference between builtins and the libc flavors of the functions: Typically, builtins resolve to the hardware instruction implementing the operation. If a hardware implementation is not available, the compiler builtin calls into the libc itself. With respect to math functions, you will notice this wilh the `long double` flavors. That said, we have implemented the math functions from first principles (as in, the implementations do not assume any special hardware support) in LLVM libc. However, we are just about starting to add machine specific implementations (<a href="https://reviews.llvm.org/D95850">https://reviews.llvm.org/D95850</a>). This should make the libc functions equivalent to the compiler builtins.</div></div></div>