xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/builtins/powitf2.c (revision f7f78b3373aafafa211473d7733a8806c0e402c0)
1156cd587Sjoerg /* ===-- powitf2.cpp - Implement __powitf2 ---------------------------------===
2156cd587Sjoerg  *
3156cd587Sjoerg  *                     The LLVM Compiler Infrastructure
4156cd587Sjoerg  *
5156cd587Sjoerg  * This file is dual licensed under the MIT and the University of Illinois Open
6156cd587Sjoerg  * Source Licenses. See LICENSE.TXT for details.
7156cd587Sjoerg  *
8156cd587Sjoerg  * ===----------------------------------------------------------------------===
9156cd587Sjoerg  *
10156cd587Sjoerg  * This file implements __powitf2 for the compiler_rt library.
11156cd587Sjoerg  *
12156cd587Sjoerg  * ===----------------------------------------------------------------------===
13156cd587Sjoerg  */
14156cd587Sjoerg 
15156cd587Sjoerg #include "int_lib.h"
16156cd587Sjoerg 
17156cd587Sjoerg #if _ARCH_PPC
18156cd587Sjoerg 
19156cd587Sjoerg /* Returns: a ^ b */
20156cd587Sjoerg 
21*f7f78b33Sjoerg COMPILER_RT_ABI long double
__powitf2(long double a,si_int b)22156cd587Sjoerg __powitf2(long double a, si_int b)
23156cd587Sjoerg {
24156cd587Sjoerg     const int recip = b < 0;
25156cd587Sjoerg     long double r = 1;
26156cd587Sjoerg     while (1)
27156cd587Sjoerg     {
28156cd587Sjoerg         if (b & 1)
29156cd587Sjoerg             r *= a;
30156cd587Sjoerg         b /= 2;
31156cd587Sjoerg         if (b == 0)
32156cd587Sjoerg             break;
33156cd587Sjoerg         a *= a;
34156cd587Sjoerg     }
35156cd587Sjoerg     return recip ? 1/r : r;
36156cd587Sjoerg }
37156cd587Sjoerg 
38156cd587Sjoerg #endif
39