blob: 4eaf7ff2fbd5058efe3aae40065699e5f7e3182c [file] [log] [blame]
George Landerda55ef92015-11-19 12:05:06 +00001/*
Szabolcs Nagy1b945972018-05-14 14:46:40 +01002 * poly.c
George Landerda55ef92015-11-19 12:05:06 +00003 *
Szabolcs Nagy11253b02018-11-12 11:10:57 +00004 * Copyright (c) 1998-2018, Arm Limited.
5 * SPDX-License-Identifier: MIT
George Landerda55ef92015-11-19 12:05:06 +00006 */
7
Szabolcs Nagy0d51c042018-04-25 13:26:22 +01008double __kernel_poly(const double *coeffs, int n, double x)
George Landerda55ef92015-11-19 12:05:06 +00009{
10 double result = coeffs[--n];
11
12 while ((n & ~0x6) != 0) /* Loop until n even and < 8 */
13 result = (result * x) + coeffs[--n];
14
15 switch (n)
16 {
17 case 6: result = (result * x) + coeffs[5];
18 result = (result * x) + coeffs[4];
19 case 4: result = (result * x) + coeffs[3];
20 result = (result * x) + coeffs[2];
21 case 2: result = (result * x) + coeffs[1];
22 result = (result * x) + coeffs[0];
23 }
24 return result;
25}