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
6ab4cf22
Commit
6ab4cf22
authored
8 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
switched all uses of cbrtf to icbrtf.
parent
7c41a311
No related branches found
No related tags found
1 merge request
!266
Cube root
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/adiabatic_index.h
+16
-13
16 additions, 13 deletions
src/adiabatic_index.h
src/cbrt.h
+1
-1
1 addition, 1 deletion
src/cbrt.h
tests/testCbrt.c
+4
-7
4 additions, 7 deletions
tests/testCbrt.c
with
21 additions
and
21 deletions
src/adiabatic_index.h
+
16
−
13
View file @
6ab4cf22
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include
<math.h>
#include
<math.h>
/* Local headers. */
/* Local headers. */
#include
"cbrt.h"
#include
"const.h"
#include
"const.h"
#include
"debug.h"
#include
"debug.h"
#include
"error.h"
#include
"error.h"
...
@@ -110,8 +111,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) {
...
@@ -110,8 +111,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3)
#if defined(HYDRO_GAMMA_5_3)
const
float
cbrt
=
cbrtf
(
x
);
/* x^(1/3) */
const
float
i
cbrt
=
i
cbrtf
(
x
);
/* x^(
-
1/3) */
return
cbrt
*
cbrt
*
x
;
/* x^(5/3) */
return
x
*
x
*
icbrt
;
/* x^(5/3) */
#elif defined(HYDRO_GAMMA_7_5)
#elif defined(HYDRO_GAMMA_7_5)
...
@@ -119,7 +120,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) {
...
@@ -119,7 +120,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) {
#elif defined(HYDRO_GAMMA_4_3)
#elif defined(HYDRO_GAMMA_4_3)
return
cbrtf
(
x
)
*
x
;
/* x^(4/3) */
const
float
icbrt
=
icbrtf
(
x
);
/* x^(-1/3) */
return
x
*
x
*
icbrt
*
icbrt
;
/* x^(4/3) */
#elif defined(HYDRO_GAMMA_2_1)
#elif defined(HYDRO_GAMMA_2_1)
...
@@ -144,8 +146,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one(
...
@@ -144,8 +146,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one(
#if defined(HYDRO_GAMMA_5_3)
#if defined(HYDRO_GAMMA_5_3)
const
float
cbrt
=
cbrtf
(
x
);
/* x^(1/3) */
const
float
i
cbrt
=
i
cbrtf
(
x
);
/* x^(
-
1/3) */
return
cbrt
*
cbrt
;
/* x^(2/3) */
return
x
*
i
cbrt
;
/* x^(2/3) */
#elif defined(HYDRO_GAMMA_7_5)
#elif defined(HYDRO_GAMMA_7_5)
...
@@ -153,7 +155,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one(
...
@@ -153,7 +155,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one(
#elif defined(HYDRO_GAMMA_4_3)
#elif defined(HYDRO_GAMMA_4_3)
return
cbrtf
(
x
);
/* x^(1/3) */
const
float
icbrt
=
icbrtf
(
x
);
/* x^(-1/3) */
return
x
*
icbrt
*
icbrt
;
/* x^(1/3) */
#elif defined(HYDRO_GAMMA_2_1)
#elif defined(HYDRO_GAMMA_2_1)
...
@@ -178,8 +181,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
...
@@ -178,8 +181,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
#if defined(HYDRO_GAMMA_5_3)
#if defined(HYDRO_GAMMA_5_3)
const
float
cbrt
_inv
=
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
const
float
i
cbrt
=
i
cbrtf
(
x
);
/* x^(-1/3) */
return
cbrt
_inv
*
cbrt
_inv
;
/* x^(-2/3) */
return
i
cbrt
*
i
cbrt
;
/* x^(-2/3) */
#elif defined(HYDRO_GAMMA_7_5)
#elif defined(HYDRO_GAMMA_7_5)
...
@@ -187,7 +190,7 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
...
@@ -187,7 +190,7 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
#elif defined(HYDRO_GAMMA_4_3)
#elif defined(HYDRO_GAMMA_4_3)
return
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
return
i
cbrtf
(
x
);
/* x^(-1/3) */
#elif defined(HYDRO_GAMMA_2_1)
#elif defined(HYDRO_GAMMA_2_1)
...
@@ -214,9 +217,9 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
...
@@ -214,9 +217,9 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3)
#if defined(HYDRO_GAMMA_5_3)
const
float
cbrt
_inv
=
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
const
float
i
cbrt
=
i
cbrtf
(
x
);
/* x^(-1/3) */
const
float
cbrt
_inv
2
=
cbrt
_inv
*
cbrt
_inv
;
/* x^(-2/3) */
const
float
i
cbrt2
=
i
cbrt
*
i
cbrt
;
/* x^(-2/3) */
return
cbrt
_inv
*
cbrt
_inv
2
*
cbrt
_inv
2
;
/* x^(-5/3) */
return
i
cbrt
*
i
cbrt2
*
i
cbrt2
;
/* x^(-5/3) */
#elif defined(HYDRO_GAMMA_7_5)
#elif defined(HYDRO_GAMMA_7_5)
...
@@ -224,7 +227,7 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
...
@@ -224,7 +227,7 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
#elif defined(HYDRO_GAMMA_4_3)
#elif defined(HYDRO_GAMMA_4_3)
const
float
cbrt_inv
=
1
.
f
/
cbrtf
(
x
);
/* x^(-1/3) */
const
float
cbrt_inv
=
i
cbrtf
(
x
);
/* x^(-1/3) */
const
float
cbrt_inv2
=
cbrt_inv
*
cbrt_inv
;
/* x^(-2/3) */
const
float
cbrt_inv2
=
cbrt_inv
*
cbrt_inv
;
/* x^(-2/3) */
return
cbrt_inv2
*
cbrt_inv2
;
/* x^(-4/3) */
return
cbrt_inv2
*
cbrt_inv2
;
/* x^(-4/3) */
...
...
This diff is collapsed.
Click to expand it.
src/cbrt.h
+
1
−
1
View file @
6ab4cf22
...
@@ -76,7 +76,7 @@ __attribute__((always_inline)) inline float icbrtf(float x_in) {
...
@@ -76,7 +76,7 @@ __attribute__((always_inline)) inline float icbrtf(float x_in) {
exponent_rem
>
0
exponent_rem
>
0
?
(
exponent_rem
>
1
?
5.61231024154687e-01
f
:
7.07106781186548e-01
f
)
?
(
exponent_rem
>
1
?
5.61231024154687e-01
f
:
7.07106781186548e-01
f
)
:
8.90898718140339e-01
f
;
:
8.90898718140339e-01
f
;
// Scale the result and set the correct sign.
// Scale the result and set the correct sign.
res
=
copysignf
(
res
*
exponent_scale
,
x_in
);
res
=
copysignf
(
res
*
exponent_scale
,
x_in
);
...
...
This diff is collapsed.
Click to expand it.
tests/testCbrt.c
+
4
−
7
View file @
6ab4cf22
...
@@ -18,10 +18,10 @@
...
@@ -18,10 +18,10 @@
******************************************************************************/
******************************************************************************/
// Standard includes.
// Standard includes.
#include
<math.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<unistd.h>
#include
<math.h>
// Local includes.
// Local includes.
#include
"cbrt.h"
#include
"cbrt.h"
...
@@ -71,8 +71,7 @@ int main(int argc, char *argv[]) {
...
@@ -71,8 +71,7 @@ int main(int argc, char *argv[]) {
acc_ours
+=
icbrtf
(
data
[
k
]);
acc_ours
+=
icbrtf
(
data
[
k
]);
}
}
message
(
"icbrtf took %.3f %s (acc = %.8e)."
,
message
(
"icbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
acc_ours
);
/* Third run to check the speed of the cube root. */
/* Third run to check the speed of the cube root. */
acc_exact
=
0
.
0
f
;
acc_exact
=
0
.
0
f
;
...
@@ -91,8 +90,7 @@ int main(int argc, char *argv[]) {
...
@@ -91,8 +90,7 @@ int main(int argc, char *argv[]) {
acc_ours
+=
data
[
k
]
*
temp
*
temp
;
acc_ours
+=
data
[
k
]
*
temp
*
temp
;
}
}
message
(
"x * icbrtf^2 took %.3f %s (acc = %.8e)."
,
message
(
"x * icbrtf^2 took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
acc_ours
);
/* Fourth run to check the speed of (.)^(2/3). */
/* Fourth run to check the speed of (.)^(2/3). */
acc_exact
=
0
.
0
f
;
acc_exact
=
0
.
0
f
;
...
@@ -111,8 +109,7 @@ int main(int argc, char *argv[]) {
...
@@ -111,8 +109,7 @@ int main(int argc, char *argv[]) {
acc_ours
+=
data
[
k
]
*
icbrtf
(
data
[
k
]);
acc_ours
+=
data
[
k
]
*
icbrtf
(
data
[
k
]);
}
}
message
(
"x * icbrtf took %.3f %s (acc = %.8e)."
,
message
(
"x * icbrtf took %.3f %s (acc = %.8e)."
,
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
clocks_from_ticks
(
getticks
()
-
tic_ours
),
clocks_getunit
(),
acc_ours
);
acc_ours
);
return
0
;
return
0
;
}
}
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