xref: /openbsd-src/gnu/llvm/compiler-rt/lib/builtins/powisf2.c (revision 1f9cb04fc6f537ca6cf5a53c28927340cba218a2)
13cab2bb3Spatrick //===-- powisf2.cpp - Implement __powisf2 ---------------------------------===//
23cab2bb3Spatrick //
33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information.
53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63cab2bb3Spatrick //
73cab2bb3Spatrick //===----------------------------------------------------------------------===//
83cab2bb3Spatrick //
93cab2bb3Spatrick // This file implements __powisf2 for the compiler_rt library.
103cab2bb3Spatrick //
113cab2bb3Spatrick //===----------------------------------------------------------------------===//
123cab2bb3Spatrick 
133cab2bb3Spatrick #include "int_lib.h"
143cab2bb3Spatrick 
153cab2bb3Spatrick // Returns: a ^ b
163cab2bb3Spatrick 
__powisf2(float a,int b)17*1f9cb04fSpatrick COMPILER_RT_ABI float __powisf2(float a, int b) {
183cab2bb3Spatrick   const int recip = b < 0;
193cab2bb3Spatrick   float r = 1;
203cab2bb3Spatrick   while (1) {
213cab2bb3Spatrick     if (b & 1)
223cab2bb3Spatrick       r *= a;
233cab2bb3Spatrick     b /= 2;
243cab2bb3Spatrick     if (b == 0)
253cab2bb3Spatrick       break;
263cab2bb3Spatrick     a *= a;
273cab2bb3Spatrick   }
283cab2bb3Spatrick   return recip ? 1 / r : r;
293cab2bb3Spatrick }
30