forked from parallella/pal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp_inv.c
40 lines (38 loc) · 835 Bytes
/
p_inv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <pal.h>
/**
*
* Element wise inversion (reciprocal) of elements in 'a'.
*
* @param a Pointer to input vector
*
* @param c Pointer to output vector
*
* @param n Size of 'a' and 'c' vector.
*
* @param p Number of processor to use (task parallelism)
*
* @param team Team to work with
*
* @return None
*
*/
#include <math.h>
void p_inv_f32(const float *a, float *c, int n, int p, p_team_t team)
{
int i;
float cur;
for (i = 0; i < n; i++) {
cur = *(a + i);
union {
float f;
uint32_t x;
} u = {cur};
/* First approximation */
u.x = 0x7EEEEBB3 - u.x;
/* Refine */
u.f = u.f * (2 - u.f * cur);
u.f = u.f * (2 - u.f * cur);
u.f = u.f * (2 - u.f * cur);
*(c + i) = u.f;
}
}