Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
8cd6adc7
Commit
8cd6adc7
authored
8 years ago
by
James Willis
Browse files
Options
Downloads
Patches
Plain Diff
Added inline vector functions to calculate the inverse and inverse square root.
parent
a6e392c5
No related branches found
No related tags found
1 merge request
!287
Particle caching
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/vector.h
+32
-12
32 additions, 12 deletions
src/vector.h
with
32 additions
and
12 deletions
src/vector.h
+
32
−
12
View file @
8cd6adc7
...
...
@@ -39,18 +39,6 @@
#define VEC_MACRO(elcount, type) \
__attribute__((vector_size((elcount) * sizeof(type)))) type
/* Define vector reciprocals. vec_rcp and vec_rsqrt do not have the level of
* accuracy we need, so an extra two terms are added. */
#define VEC_RECIPROCAL(x, x_inv) \
x_inv = vec_rcp(x); \
x_inv = vec_sub(x_inv, vec_mul(x_inv, (vec_fma(x, x_inv, vec_set1(-1.0f)))))
#define VEC_RECIPROCAL_SQRT(x, x_inv) \
x_inv = vec_rsqrt(x); \
x_inv = vec_sub( \
x_inv, vec_mul(vec_mul(vec_set1(0.5f), x_inv), \
(vec_fma(x, vec_mul(x_inv, x_inv), vec_set1(-1.0f)))))
/* So what will the vector size be? */
#ifdef HAVE_AVX512_F
#define VEC_HAVE_GATHER
...
...
@@ -268,6 +256,38 @@ typedef union {
int
i
[
VEC_SIZE
];
}
vector
;
/**
* @brief Calculates the inverse ($1/x$) of a vector using intrinsics and a Newton iteration to obtain the correct level of accuracy.
*
* @param x #vector to be inverted.
* @return x_inv #vector inverted x.
*/
__attribute__
((
always_inline
))
INLINE
vector
vec_reciprocal
(
vector
x
)
{
vector
x_inv
;
x_inv
.
v
=
vec_rcp
(
x
.
v
);
x_inv
.
v
=
vec_sub
(
x_inv
.
v
,
vec_mul
(
x_inv
.
v
,
(
vec_fma
(
x
.
v
,
x_inv
.
v
,
vec_set1
(
-
1
.
0
f
)))));
return
x_inv
;
}
/**
* @brief Calculates the inverse and square root ($1/\sqrt{x}$) of a vector using intrinsics and a Newton iteration to obtain the correct level of accuracy.
*
* @param x #vector to be inverted.
* @return x_inv #vector inverted x.
*/
__attribute__
((
always_inline
))
INLINE
vector
vec_reciprocal_sqrt
(
vector
x
)
{
vector
x_inv
;
x_inv
.
v
=
vec_rsqrt
(
x
.
v
);
x_inv
.
v
=
vec_sub
(
x_inv
.
v
,
vec_mul
(
vec_mul
(
vec_set1
(
0
.
5
f
),
x_inv
.
v
),
(
vec_fma
(
x
.
v
,
vec_mul
(
x_inv
.
v
,
x_inv
.
v
),
vec_set1
(
-
1
.
0
f
)))));
return
x_inv
;
}
#else
/* Needed for cache alignment. */
#define VEC_SIZE 16
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment