xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/powisf2.c (revision 580744621f33383027108364dcadad718df46ffe)
1 //===-- powisf2.cpp - Implement __powisf2 ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements __powisf2 for the compiler_rt library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "int_lib.h"
14 
15 // Returns: a ^ b
16 
17 COMPILER_RT_ABI float __powisf2(float a, si_int b) {
18   const int recip = b < 0;
19   float r = 1;
20   while (1) {
21     if (b & 1)
22       r *= a;
23     b /= 2;
24     if (b == 0)
25       break;
26     a *= a;
27   }
28   return recip ? 1 / r : r;
29 }
30