Skip to content
Snippets Groups Projects
Commit 60dc6582 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Declare some functions as 'const' to help GCC's auto-vectorizer

parent 303c62a2
Branches
Tags
2 merge requests!566Periodic gravity calculation,!565Mesh force task
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
* *
* Computes \f$x^\gamma\f$. * Computes \f$x^\gamma\f$.
*/ */
__attribute__((always_inline)) INLINE static float pow_gamma(float x) { __attribute__((always_inline, const)) INLINE static float pow_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -141,7 +141,7 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) { ...@@ -141,7 +141,7 @@ __attribute__((always_inline)) INLINE static float pow_gamma(float x) {
* *
* Computes \f$x^{(\gamma-1)}\f$. * Computes \f$x^{(\gamma-1)}\f$.
*/ */
__attribute__((always_inline)) INLINE static float pow_gamma_minus_one( __attribute__((always_inline, const)) INLINE static float pow_gamma_minus_one(
float x) { float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -175,8 +175,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one( ...@@ -175,8 +175,8 @@ __attribute__((always_inline)) INLINE static float pow_gamma_minus_one(
* *
* Computes \f$x^{-(\gamma-1)}\f$. * Computes \f$x^{-(\gamma-1)}\f$.
*/ */
__attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one( __attribute__((always_inline, const)) INLINE static float
float x) { pow_minus_gamma_minus_one(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -212,7 +212,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one( ...@@ -212,7 +212,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma_minus_one(
* @param x Argument * @param x Argument
* @return One over the argument to the power given by the adiabatic index * @return One over the argument to the power given by the adiabatic index
*/ */
__attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) { __attribute__((always_inline, const)) INLINE static float pow_minus_gamma(
float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -252,8 +253,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) { ...@@ -252,8 +253,8 @@ __attribute__((always_inline)) INLINE static float pow_minus_gamma(float x) {
* @param x Argument * @param x Argument
* @return Argument to the power two divided by the adiabatic index minus one * @return Argument to the power two divided by the adiabatic index minus one
*/ */
__attribute__((always_inline)) INLINE static float pow_two_over_gamma_minus_one( __attribute__((always_inline, const)) INLINE static float
float x) { pow_two_over_gamma_minus_one(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -292,7 +293,7 @@ __attribute__((always_inline)) INLINE static float pow_two_over_gamma_minus_one( ...@@ -292,7 +293,7 @@ __attribute__((always_inline)) INLINE static float pow_two_over_gamma_minus_one(
* @return Argument to the power two times the adiabatic index divided by the * @return Argument to the power two times the adiabatic index divided by the
* adiabatic index minus one * adiabatic index minus one
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
pow_two_gamma_over_gamma_minus_one(float x) { pow_two_gamma_over_gamma_minus_one(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -336,7 +337,7 @@ pow_two_gamma_over_gamma_minus_one(float x) { ...@@ -336,7 +337,7 @@ pow_two_gamma_over_gamma_minus_one(float x) {
* @return Argument to the power the adiabatic index minus one divided by two * @return Argument to the power the adiabatic index minus one divided by two
* times the adiabatic index * times the adiabatic index
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
pow_gamma_minus_one_over_two_gamma(float x) { pow_gamma_minus_one_over_two_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -373,7 +374,7 @@ pow_gamma_minus_one_over_two_gamma(float x) { ...@@ -373,7 +374,7 @@ pow_gamma_minus_one_over_two_gamma(float x) {
* @return Inverse argument to the power the adiabatic index plus one divided by * @return Inverse argument to the power the adiabatic index plus one divided by
* two times the adiabatic index * two times the adiabatic index
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
pow_minus_gamma_plus_one_over_two_gamma(float x) { pow_minus_gamma_plus_one_over_two_gamma(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -408,7 +409,8 @@ pow_minus_gamma_plus_one_over_two_gamma(float x) { ...@@ -408,7 +409,8 @@ pow_minus_gamma_plus_one_over_two_gamma(float x) {
* @param x Argument * @param x Argument
* @return Argument to the power one over the adiabatic index * @return Argument to the power one over the adiabatic index
*/ */
__attribute__((always_inline)) INLINE static float pow_one_over_gamma(float x) { __attribute__((always_inline, const)) INLINE static float pow_one_over_gamma(
float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -441,8 +443,8 @@ __attribute__((always_inline)) INLINE static float pow_one_over_gamma(float x) { ...@@ -441,8 +443,8 @@ __attribute__((always_inline)) INLINE static float pow_one_over_gamma(float x) {
* *
* @param x Argument * @param x Argument
*/ */
__attribute__((always_inline)) INLINE static float pow_three_gamma_minus_two( __attribute__((always_inline, const)) INLINE static float
float x) { pow_three_gamma_minus_two(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
...@@ -476,7 +478,7 @@ __attribute__((always_inline)) INLINE static float pow_three_gamma_minus_two( ...@@ -476,7 +478,7 @@ __attribute__((always_inline)) INLINE static float pow_three_gamma_minus_two(
* *
* @param x Argument * @param x Argument
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
pow_three_gamma_minus_five_over_two(float x) { pow_three_gamma_minus_five_over_two(float x) {
#if defined(HYDRO_GAMMA_5_3) #if defined(HYDRO_GAMMA_5_3)
......
...@@ -45,7 +45,7 @@ struct eos_parameters {}; ...@@ -45,7 +45,7 @@ struct eos_parameters {};
* @param density The density \f$\rho\f$. * @param density The density \f$\rho\f$.
* @param entropy The entropy \f$S\f$. * @param entropy The entropy \f$S\f$.
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
gas_internal_energy_from_entropy(float density, float entropy) { gas_internal_energy_from_entropy(float density, float entropy) {
return entropy * pow_gamma_minus_one(density) * return entropy * pow_gamma_minus_one(density) *
...@@ -60,8 +60,8 @@ gas_internal_energy_from_entropy(float density, float entropy) { ...@@ -60,8 +60,8 @@ gas_internal_energy_from_entropy(float density, float entropy) {
* @param density The density \f$\rho\f$. * @param density The density \f$\rho\f$.
* @param entropy The entropy \f$S\f$. * @param entropy The entropy \f$S\f$.
*/ */
__attribute__((always_inline)) INLINE static float gas_pressure_from_entropy( __attribute__((always_inline, const)) INLINE static float
float density, float entropy) { gas_pressure_from_entropy(float density, float entropy) {
return entropy * pow_gamma(density); return entropy * pow_gamma(density);
} }
...@@ -75,8 +75,8 @@ __attribute__((always_inline)) INLINE static float gas_pressure_from_entropy( ...@@ -75,8 +75,8 @@ __attribute__((always_inline)) INLINE static float gas_pressure_from_entropy(
* @param pressure The pressure \f$P\f$. * @param pressure The pressure \f$P\f$.
* @return The entropy \f$A\f$. * @return The entropy \f$A\f$.
*/ */
__attribute__((always_inline)) INLINE static float gas_entropy_from_pressure( __attribute__((always_inline, const)) INLINE static float
float density, float pressure) { gas_entropy_from_pressure(float density, float pressure) {
return pressure * pow_minus_gamma(density); return pressure * pow_minus_gamma(density);
} }
...@@ -89,8 +89,8 @@ __attribute__((always_inline)) INLINE static float gas_entropy_from_pressure( ...@@ -89,8 +89,8 @@ __attribute__((always_inline)) INLINE static float gas_entropy_from_pressure(
* @param density The density \f$\rho\f$. * @param density The density \f$\rho\f$.
* @param entropy The entropy \f$S\f$. * @param entropy The entropy \f$S\f$.
*/ */
__attribute__((always_inline)) INLINE static float gas_soundspeed_from_entropy( __attribute__((always_inline, const)) INLINE static float
float density, float entropy) { gas_soundspeed_from_entropy(float density, float entropy) {
return sqrtf(hydro_gamma * pow_gamma_minus_one(density) * entropy); return sqrtf(hydro_gamma * pow_gamma_minus_one(density) * entropy);
} }
...@@ -103,7 +103,7 @@ __attribute__((always_inline)) INLINE static float gas_soundspeed_from_entropy( ...@@ -103,7 +103,7 @@ __attribute__((always_inline)) INLINE static float gas_soundspeed_from_entropy(
* @param density The density \f$\rho\f$ * @param density The density \f$\rho\f$
* @param u The internal energy \f$u\f$ * @param u The internal energy \f$u\f$
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
gas_entropy_from_internal_energy(float density, float u) { gas_entropy_from_internal_energy(float density, float u) {
return hydro_gamma_minus_one * u * pow_minus_gamma_minus_one(density); return hydro_gamma_minus_one * u * pow_minus_gamma_minus_one(density);
...@@ -117,7 +117,7 @@ gas_entropy_from_internal_energy(float density, float u) { ...@@ -117,7 +117,7 @@ gas_entropy_from_internal_energy(float density, float u) {
* @param density The density \f$\rho\f$ * @param density The density \f$\rho\f$
* @param u The internal energy \f$u\f$ * @param u The internal energy \f$u\f$
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
gas_pressure_from_internal_energy(float density, float u) { gas_pressure_from_internal_energy(float density, float u) {
return hydro_gamma_minus_one * u * density; return hydro_gamma_minus_one * u * density;
...@@ -132,7 +132,7 @@ gas_pressure_from_internal_energy(float density, float u) { ...@@ -132,7 +132,7 @@ gas_pressure_from_internal_energy(float density, float u) {
* @param pressure The pressure \f$P\f$. * @param pressure The pressure \f$P\f$.
* @return The internal energy \f$u\f$. * @return The internal energy \f$u\f$.
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
gas_internal_energy_from_pressure(float density, float pressure) { gas_internal_energy_from_pressure(float density, float pressure) {
return hydro_one_over_gamma_minus_one * pressure / density; return hydro_one_over_gamma_minus_one * pressure / density;
} }
...@@ -145,7 +145,7 @@ gas_internal_energy_from_pressure(float density, float pressure) { ...@@ -145,7 +145,7 @@ gas_internal_energy_from_pressure(float density, float pressure) {
* @param density The density \f$\rho\f$ * @param density The density \f$\rho\f$
* @param u The internal energy \f$u\f$ * @param u The internal energy \f$u\f$
*/ */
__attribute__((always_inline)) INLINE static float __attribute__((always_inline, const)) INLINE static float
gas_soundspeed_from_internal_energy(float density, float u) { gas_soundspeed_from_internal_energy(float density, float u) {
return sqrtf(u * hydro_gamma * hydro_gamma_minus_one); return sqrtf(u * hydro_gamma * hydro_gamma_minus_one);
...@@ -159,8 +159,8 @@ gas_soundspeed_from_internal_energy(float density, float u) { ...@@ -159,8 +159,8 @@ gas_soundspeed_from_internal_energy(float density, float u) {
* @param density The density \f$\rho\f$ * @param density The density \f$\rho\f$
* @param P The pressure \f$P\f$ * @param P The pressure \f$P\f$
*/ */
__attribute__((always_inline)) INLINE static float gas_soundspeed_from_pressure( __attribute__((always_inline, const)) INLINE static float
float density, float P) { gas_soundspeed_from_pressure(float density, float P) {
const float density_inv = 1.f / density; const float density_inv = 1.f / density;
return sqrtf(hydro_gamma * P * density_inv); return sqrtf(hydro_gamma * P * density_inv);
...@@ -176,16 +176,16 @@ __attribute__((always_inline)) INLINE static float gas_soundspeed_from_pressure( ...@@ -176,16 +176,16 @@ __attribute__((always_inline)) INLINE static float gas_soundspeed_from_pressure(
* @param us The internal unit system. * @param us The internal unit system.
* @param params The parsed parameters. * @param params The parsed parameters.
*/ */
__attribute__((always_inline)) INLINE static void eos_init( INLINE static void eos_init(struct eos_parameters *e,
struct eos_parameters *e, const struct phys_const *phys_const, const struct phys_const *phys_const,
const struct unit_system *us, struct swift_params *params) {} const struct unit_system *us,
struct swift_params *params) {}
/** /**
* @brief Print the equation of state * @brief Print the equation of state
* *
* @param e The #eos_parameters * @param e The #eos_parameters
*/ */
__attribute__((always_inline)) INLINE static void eos_print( INLINE static void eos_print(const struct eos_parameters *e) {
const struct eos_parameters *e) {
message("Equation of state: Ideal gas."); message("Equation of state: Ideal gas.");
...@@ -199,8 +199,8 @@ __attribute__((always_inline)) INLINE static void eos_print( ...@@ -199,8 +199,8 @@ __attribute__((always_inline)) INLINE static void eos_print(
* @param h_grpsph The HDF5 group in which to write * @param h_grpsph The HDF5 group in which to write
* @param e The #eos_parameters * @param e The #eos_parameters
*/ */
__attribute__((always_inline)) INLINE static void eos_print_snapshot( INLINE static void eos_print_snapshot(hid_t h_grpsph,
hid_t h_grpsph, const struct eos_parameters *e) { const struct eos_parameters *e) {
io_write_attribute_f(h_grpsph, "Adiabatic index", hydro_gamma); io_write_attribute_f(h_grpsph, "Adiabatic index", hydro_gamma);
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
* Similarly for dx < -b. * Similarly for dx < -b.
* *
*/ */
__attribute__((always_inline)) INLINE static double nearest( __attribute__((always_inline, const)) INLINE static double nearest(
const double dx, const double box_size) { const double dx, const double box_size) {
return ((dx > 0.5 * box_size) return ((dx > 0.5 * box_size)
...@@ -67,7 +67,7 @@ __attribute__((always_inline)) INLINE static double nearest( ...@@ -67,7 +67,7 @@ __attribute__((always_inline)) INLINE static double nearest(
* Similarly for dx < -b. * Similarly for dx < -b.
* *
*/ */
__attribute__((always_inline)) INLINE static float nearestf( __attribute__((always_inline, const)) INLINE static float nearestf(
const float dx, const float box_size) { const float dx, const float box_size) {
return ((dx > 0.5f * box_size) return ((dx > 0.5f * box_size)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @param x The number of interest. * @param x The number of interest.
* @return >0 if positive, 0 if negative. * @return >0 if positive, 0 if negative.
*/ */
__attribute__((always_inline)) INLINE static int signf(float x) { __attribute__((always_inline, const)) INLINE static int signf(float x) {
#ifdef __GNUC__ #ifdef __GNUC__
return !signbit(x); return !signbit(x);
#else #else
...@@ -39,7 +39,8 @@ __attribute__((always_inline)) INLINE static int signf(float x) { ...@@ -39,7 +39,8 @@ __attribute__((always_inline)) INLINE static int signf(float x) {
* @param x The first number * @param x The first number
* @param y The second number * @param y The second number
*/ */
__attribute__((always_inline)) INLINE static int same_signf(float x, float y) { __attribute__((always_inline, const)) INLINE static int same_signf(float x,
float y) {
return signf(x) == signf(y); return signf(x) == signf(y);
} }
......
...@@ -51,7 +51,8 @@ typedef char timebin_t; ...@@ -51,7 +51,8 @@ typedef char timebin_t;
* *
* @param bin The time bin of interest. * @param bin The time bin of interest.
*/ */
static INLINE integertime_t get_integer_timestep(timebin_t bin) { __attribute__((const)) static INLINE integertime_t
get_integer_timestep(timebin_t bin) {
if (bin <= 0) return 0; if (bin <= 0) return 0;
return 1LL << (bin + 1); return 1LL << (bin + 1);
...@@ -62,7 +63,8 @@ static INLINE integertime_t get_integer_timestep(timebin_t bin) { ...@@ -62,7 +63,8 @@ static INLINE integertime_t get_integer_timestep(timebin_t bin) {
* *
* Assumes that integertime_t maps to an unsigned long long. * Assumes that integertime_t maps to an unsigned long long.
*/ */
static INLINE timebin_t get_time_bin(integertime_t time_step) { __attribute__((const)) static INLINE timebin_t
get_time_bin(integertime_t time_step) {
/* ((int) log_2(time_step)) - 1 */ /* ((int) log_2(time_step)) - 1 */
return (timebin_t)(62 - intrinsics_clzll(time_step)); return (timebin_t)(62 - intrinsics_clzll(time_step));
...@@ -74,7 +76,8 @@ static INLINE timebin_t get_time_bin(integertime_t time_step) { ...@@ -74,7 +76,8 @@ static INLINE timebin_t get_time_bin(integertime_t time_step) {
* @param bin The time bin of interest. * @param bin The time bin of interest.
* @param timeBase the minimal time-step size of the simulation. * @param timeBase the minimal time-step size of the simulation.
*/ */
static INLINE double get_timestep(timebin_t bin, double timeBase) { __attribute__((const)) static INLINE double get_timestep(timebin_t bin,
double timeBase) {
return get_integer_timestep(bin) * timeBase; return get_integer_timestep(bin) * timeBase;
} }
...@@ -86,8 +89,8 @@ static INLINE double get_timestep(timebin_t bin, double timeBase) { ...@@ -86,8 +89,8 @@ static INLINE double get_timestep(timebin_t bin, double timeBase) {
* @param ti_current The current time on the integer time line. * @param ti_current The current time on the integer time line.
* @param bin The time bin of interest. * @param bin The time bin of interest.
*/ */
static INLINE integertime_t get_integer_time_begin(integertime_t ti_current, __attribute__((const)) static INLINE integertime_t
timebin_t bin) { get_integer_time_begin(integertime_t ti_current, timebin_t bin) {
const integertime_t dti = get_integer_timestep(bin); const integertime_t dti = get_integer_timestep(bin);
if (dti == 0) if (dti == 0)
...@@ -103,8 +106,8 @@ static INLINE integertime_t get_integer_time_begin(integertime_t ti_current, ...@@ -103,8 +106,8 @@ static INLINE integertime_t get_integer_time_begin(integertime_t ti_current,
* @param ti_current The current time on the integer time line. * @param ti_current The current time on the integer time line.
* @param bin The time bin of interest. * @param bin The time bin of interest.
*/ */
static INLINE integertime_t get_integer_time_end(integertime_t ti_current, __attribute__((const)) static INLINE integertime_t
timebin_t bin) { get_integer_time_end(integertime_t ti_current, timebin_t bin) {
const integertime_t dti = get_integer_timestep(bin); const integertime_t dti = get_integer_timestep(bin);
if (dti == 0) if (dti == 0)
...@@ -118,7 +121,8 @@ static INLINE integertime_t get_integer_time_end(integertime_t ti_current, ...@@ -118,7 +121,8 @@ static INLINE integertime_t get_integer_time_end(integertime_t ti_current,
* *
* @param time The current point on the time line. * @param time The current point on the time line.
*/ */
static INLINE timebin_t get_max_active_bin(integertime_t time) { __attribute__((const)) static INLINE timebin_t
get_max_active_bin(integertime_t time) {
if (time == 0) return num_time_bins; if (time == 0) return num_time_bins;
...@@ -134,8 +138,8 @@ static INLINE timebin_t get_max_active_bin(integertime_t time) { ...@@ -134,8 +138,8 @@ static INLINE timebin_t get_max_active_bin(integertime_t time) {
* @param ti_current The current point on the time line. * @param ti_current The current point on the time line.
* @param ti_old The last synchronisation point on the time line. * @param ti_old The last synchronisation point on the time line.
*/ */
static INLINE timebin_t get_min_active_bin(integertime_t ti_current, __attribute__((const)) static INLINE timebin_t
integertime_t ti_old) { get_min_active_bin(integertime_t ti_current, integertime_t ti_old) {
const timebin_t min_bin = get_max_active_bin(ti_current - ti_old); const timebin_t min_bin = get_max_active_bin(ti_current - ti_old);
return (ti_old > 0) ? min_bin : (min_bin - 1); return (ti_old > 0) ? min_bin : (min_bin - 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment