2009-08-07 20:30:09 +00:00
|
|
|
//===-- powisf2.cpp - Implement __powisf2 ---------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
// This file implements __powisf2 for the compiler_rt library.
|
2019-04-28 22:47:49 +00:00
|
|
|
//
|
2009-08-07 20:30:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
// Returns: a ^ b
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2020-06-30 11:06:52 +03:00
|
|
|
COMPILER_RT_ABI float __powisf2(float a, int b) {
|
2009-06-26 16:47:03 +00:00
|
|
|
const int recip = b < 0;
|
|
|
|
float r = 1;
|
|
|
|
while (1) {
|
|
|
|
if (b & 1)
|
|
|
|
r *= a;
|
|
|
|
b /= 2;
|
|
|
|
if (b == 0)
|
|
|
|
break;
|
|
|
|
a *= a;
|
|
|
|
}
|
|
|
|
return recip ? 1 / r : r;
|
|
|
|
}
|