Perf plot
This commit is contained in:
committed by
Linus Baumberger
parent
ca969564a6
commit
e7af3103e8
@@ -170,46 +170,55 @@ Pedestrian *init_pedestrians(int n_p) {
|
||||
|
||||
Board init_board_without_obstacles() { return Board(BOARD_LENGTH, BOARD_WIDTH, 0, nullptr); }
|
||||
|
||||
// vectorized expf for a __m256 (8 lanes), no libm call.
|
||||
// same trick as the double polyexp: exp(x) = 2^n * exp(r) where n = round(x / ln2), r = x - n*ln2.
|
||||
// after range reduce r is in [-ln2/2, ln2/2] ~= [-0.347, 0.347].
|
||||
// degree-5 taylor is enough for float (worst-case abs error ~1e-5, way under 1cm verify tolerance).
|
||||
// 2^n is free via the schraudolph bit trick on the ieee 754 exponent slot.
|
||||
// float layout: sign(1) | exp(8, bias 127) | mantissa(23), so we shift the biased exponent by 23.
|
||||
// simd expf, degree-12 taylor on the [-ln2/2, ln2/2] reduced range,
|
||||
// schraudolph 2^n bit trick on the exponent slot.
|
||||
// # 128 MULTs, 112 ADDs
|
||||
static inline __m256 exp256_ps(__m256 x) {
|
||||
// n = round(x * log2(e))
|
||||
const __m256 log2e = _mm256_set1_ps(1.4426950408889634f);
|
||||
__m256 nf = _mm256_round_ps(_mm256_mul_ps(x, log2e),
|
||||
_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC);
|
||||
__m256 nf = _mm256_round_ps(_mm256_mul_ps(x, log2e), _MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC); // # 8 MULTs
|
||||
|
||||
// r = x - n * ln(2)
|
||||
const __m256 ln2 = _mm256_set1_ps(0.6931471805599453f);
|
||||
__m256 r = _mm256_fnmadd_ps(nf, ln2, x);
|
||||
__m256 r = _mm256_fnmadd_ps(nf, ln2, x); // # 8 MULTs, 8 ADDs
|
||||
|
||||
// poly(r) ~ exp(r), degree-5 horner from highest coeff downwards
|
||||
const __m256 c5 = _mm256_set1_ps(1.0f / 120.0f);
|
||||
const __m256 c4 = _mm256_set1_ps(1.0f / 24.0f);
|
||||
const __m256 c3 = _mm256_set1_ps(1.0f / 6.0f);
|
||||
const __m256 c2 = _mm256_set1_ps(0.5f);
|
||||
const __m256 c1 = _mm256_set1_ps(1.0f);
|
||||
const __m256 c0 = _mm256_set1_ps(1.0f);
|
||||
const __m256 c13 = _mm256_set1_ps(c13_scalar);
|
||||
const __m256 c12 = _mm256_set1_ps(c12_scalar);
|
||||
const __m256 c11 = _mm256_set1_ps(c11_scalar);
|
||||
const __m256 c10 = _mm256_set1_ps(c10_scalar);
|
||||
const __m256 c9 = _mm256_set1_ps(c9_scalar);
|
||||
const __m256 c8 = _mm256_set1_ps(c8_scalar);
|
||||
const __m256 c7 = _mm256_set1_ps(c7_scalar);
|
||||
const __m256 c6 = _mm256_set1_ps(c6_scalar);
|
||||
const __m256 c5 = _mm256_set1_ps(c5_scalar);
|
||||
const __m256 c4 = _mm256_set1_ps(c4_scalar);
|
||||
const __m256 c3 = _mm256_set1_ps(c3_scalar);
|
||||
const __m256 c2 = _mm256_set1_ps(c2_scalar);
|
||||
const __m256 c1 = _mm256_set1_ps(c1_scalar);
|
||||
const __m256 c0 = _mm256_set1_ps(c0_scalar);
|
||||
|
||||
__m256 p = c5;
|
||||
__m256 p = c13;
|
||||
|
||||
// # 13 * (8 MULTs, 8 ADDs)
|
||||
// # = 104 MULTs, 104 ADDs
|
||||
p = _mm256_fmadd_ps(p, r, c12);
|
||||
p = _mm256_fmadd_ps(p, r, c11);
|
||||
p = _mm256_fmadd_ps(p, r, c10);
|
||||
p = _mm256_fmadd_ps(p, r, c9);
|
||||
p = _mm256_fmadd_ps(p, r, c8);
|
||||
p = _mm256_fmadd_ps(p, r, c7);
|
||||
p = _mm256_fmadd_ps(p, r, c6);
|
||||
p = _mm256_fmadd_ps(p, r, c5);
|
||||
p = _mm256_fmadd_ps(p, r, c4);
|
||||
p = _mm256_fmadd_ps(p, r, c3);
|
||||
p = _mm256_fmadd_ps(p, r, c2);
|
||||
p = _mm256_fmadd_ps(p, r, c1);
|
||||
p = _mm256_fmadd_ps(p, r, c0);
|
||||
|
||||
// 2^n via bit trick: float bias 127, exponent slot at bit 23.
|
||||
// padding lanes (sb_e=0, pos=1e9) overflow this, but the active mask zeroes them out
|
||||
// before accumulation so the garbage doesnt matter.
|
||||
__m256i ni = _mm256_cvtps_epi32(nf);
|
||||
__m256i ni = _mm256_cvtps_epi32(nf);
|
||||
__m256i biased = _mm256_add_epi32(ni, _mm256_set1_epi32(127));
|
||||
__m256i scaled = _mm256_slli_epi32(biased, 23);
|
||||
__m256 pow2n = _mm256_castsi256_ps(scaled);
|
||||
__m256 pow2n = _mm256_castsi256_ps(scaled);
|
||||
|
||||
return _mm256_mul_ps(p, pow2n);
|
||||
return _mm256_mul_ps(p, pow2n); // # 8 MULTs
|
||||
}
|
||||
|
||||
int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, const char *dump_path) {
|
||||
@@ -249,15 +258,21 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
||||
const __m256 v_np = _mm256_set1_ps((float)n_p);
|
||||
const __m256 v_exp_min = _mm256_set1_ps(-87.0f); // clamp for polyexp, below this exp(x) ~ 0 anyway
|
||||
|
||||
// # flops per iteration (one pass of the outer time loop):
|
||||
// # ADDs: n_p * 22 + n_p * n_p_pad * 29 + n_p * board.n_obstacles * 10 + n_p * 7
|
||||
// # MULTs: n_p * 4 + n_p * n_p_pad * 40 + n_p * board.n_obstacles * 13 + n_p * 16
|
||||
// # DIVs: n_p * n_p_pad * 1 + n_p * board.n_obstacles + n_p * 2
|
||||
// # SQRTs: n_p * n_p_pad * 3 + n_p * board.n_obstacles + n_p * 3
|
||||
// # EXPs: n_p * board.n_obstacles
|
||||
for (int t = 0; t < n_iter; t++) {
|
||||
|
||||
for (int i = 0; i < n_p; i++) {
|
||||
|
||||
float desired_velocity_x = e_x[i] * desired_v0[i];
|
||||
float desired_velocity_y = e_y[i] * desired_v0[i];
|
||||
float desired_velocity_x = e_x[i] * desired_v0[i]; // # 1 MULT
|
||||
float desired_velocity_y = e_y[i] * desired_v0[i]; // # 1 MULT
|
||||
|
||||
float f_alpha_dt_x = (desired_velocity_x - curr_vel_x[i]) * dt_times_tau_alpha_inv;
|
||||
float f_alpha_dt_y = (desired_velocity_y - curr_vel_y[i]) * dt_times_tau_alpha_inv;
|
||||
float f_alpha_dt_x = (desired_velocity_x - curr_vel_x[i]) * dt_times_tau_alpha_inv; // # 1 MULT, 1 ADD
|
||||
float f_alpha_dt_y = (desired_velocity_y - curr_vel_y[i]) * dt_times_tau_alpha_inv; // # 1 MULT, 1 ADD
|
||||
|
||||
const __m256 pix = _mm256_set1_ps(pos_x[i]);
|
||||
const __m256 piy = _mm256_set1_ps(pos_y[i]);
|
||||
@@ -269,7 +284,7 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
||||
__m256 acc_y = _mm256_setzero_ps();
|
||||
|
||||
for (int j = 0; j < n_p_pad; j += 8) {
|
||||
__m256 j_idx = _mm256_add_ps(_mm256_set1_ps((float)j), lane_off);
|
||||
__m256 j_idx = _mm256_add_ps(_mm256_set1_ps((float)j), lane_off); // # 8 ADDs
|
||||
|
||||
__m256 m_neq_i = _mm256_cmp_ps(j_idx, v_i, _CMP_NEQ_OQ);
|
||||
__m256 m_in_range = _mm256_cmp_ps(j_idx, v_np, _CMP_LT_OQ);
|
||||
@@ -281,90 +296,90 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
||||
__m256 sbe_jy = _mm256_loadu_ps(&sb_e_y[j]);
|
||||
__m256 sb_jsq = _mm256_loadu_ps(&sb_sq[j]);
|
||||
|
||||
__m256 r_ab_x = _mm256_sub_ps(pix, pjx);
|
||||
__m256 r_ab_y = _mm256_sub_ps(piy, pjy);
|
||||
__m256 r_ab_n2 = _mm256_fmadd_ps(r_ab_x, r_ab_x, _mm256_mul_ps(r_ab_y, r_ab_y));
|
||||
__m256 r_ab_n = _mm256_sqrt_ps(r_ab_n2);
|
||||
__m256 r_ab_x = _mm256_sub_ps(pix, pjx); // # 8 ADDs
|
||||
__m256 r_ab_y = _mm256_sub_ps(piy, pjy); // # 8 ADDs
|
||||
__m256 r_ab_n2 = _mm256_fmadd_ps(r_ab_x, r_ab_x, _mm256_mul_ps(r_ab_y, r_ab_y)); // # 16 MULTs, 8 ADDs
|
||||
__m256 r_ab_n = _mm256_sqrt_ps(r_ab_n2); // # 8 SQRTs
|
||||
r_ab_n = _mm256_max_ps(r_ab_n, v_eps);
|
||||
|
||||
__m256 r_ab2_x = _mm256_sub_ps(r_ab_x, sbe_jx);
|
||||
__m256 r_ab2_y = _mm256_sub_ps(r_ab_y, sbe_jy);
|
||||
__m256 r_ab2_n2 = _mm256_fmadd_ps(r_ab2_x, r_ab2_x, _mm256_mul_ps(r_ab2_y, r_ab2_y));
|
||||
__m256 r_ab2_n = _mm256_sqrt_ps(r_ab2_n2);
|
||||
__m256 r_ab2_x = _mm256_sub_ps(r_ab_x, sbe_jx); // # 8 ADDs
|
||||
__m256 r_ab2_y = _mm256_sub_ps(r_ab_y, sbe_jy); // # 8 ADDs
|
||||
__m256 r_ab2_n2 = _mm256_fmadd_ps(r_ab2_x, r_ab2_x, _mm256_mul_ps(r_ab2_y, r_ab2_y)); // # 16 MULTs, 8 ADDs
|
||||
__m256 r_ab2_n = _mm256_sqrt_ps(r_ab2_n2); // # 8 SQRTs
|
||||
r_ab2_n = _mm256_max_ps(r_ab2_n, v_eps);
|
||||
|
||||
__m256 r_sum = _mm256_add_ps(r_ab_n, r_ab2_n);
|
||||
__m256 two_b_sq = _mm256_fmsub_ps(r_sum, r_sum, sb_jsq);
|
||||
__m256 r_sum = _mm256_add_ps(r_ab_n, r_ab2_n); // # 8 ADDs
|
||||
__m256 two_b_sq = _mm256_fmsub_ps(r_sum, r_sum, sb_jsq); // # 8 MULTs, 8 ADDs
|
||||
two_b_sq = _mm256_max_ps(two_b_sq, v_eps_sq);
|
||||
__m256 two_b = _mm256_sqrt_ps(two_b_sq);
|
||||
__m256 two_b = _mm256_sqrt_ps(two_b_sq); // # 8 SQRTs
|
||||
|
||||
// simd polynomial expf, no libm call. replaces the 8-iter scalar loop that gcc refused to unroll.
|
||||
// clamp e_arg >= -87 first: exp(-87) ~ 1.6e-38 is already basically 0, and the schraudolph 2^n
|
||||
// bit trick blows up if (nf + 127) goes negative (which happens for padding lanes where e_arg ~ -4.7e9).
|
||||
__m256 e_arg = _mm256_mul_ps(two_b, v_neg_2s_inv);
|
||||
__m256 e_arg = _mm256_mul_ps(two_b, v_neg_2s_inv); // # 8 MULTs
|
||||
e_arg = _mm256_max_ps(e_arg, v_exp_min);
|
||||
__m256 e_val = exp256_ps(e_arg);
|
||||
__m256 e_val = exp256_ps(e_arg); // # 128 MULTs, 112 ADDs
|
||||
|
||||
__m256 numer = _mm256_mul_ps(_mm256_mul_ps(r_sum, v_neg_v0_div_2s), e_val);
|
||||
__m256 denom = _mm256_mul_ps(_mm256_mul_ps(two_b, r_ab_n), r_ab2_n);
|
||||
__m256 denom_safe = _mm256_blendv_ps(v_one, denom, active);
|
||||
__m256 smc = _mm256_div_ps(numer, denom_safe);
|
||||
__m256 numer = _mm256_mul_ps(_mm256_mul_ps(r_sum, v_neg_v0_div_2s), e_val); // # 16 MULTs
|
||||
__m256 denom = _mm256_mul_ps(_mm256_mul_ps(two_b, r_ab_n), r_ab2_n); // # 16 MULTs
|
||||
__m256 denom_safe = _mm256_blendv_ps(v_one, denom, active); // bitwise, no flop
|
||||
__m256 smc = _mm256_div_ps(numer, denom_safe); // # 8 DIVs
|
||||
|
||||
__m256 sm_r_ab = _mm256_mul_ps(smc, r_ab2_n);
|
||||
__m256 sm_r_ab2 = _mm256_mul_ps(smc, r_ab_n);
|
||||
__m256 sm_r_ab = _mm256_mul_ps(smc, r_ab2_n); // # 8 MULTs
|
||||
__m256 sm_r_ab2 = _mm256_mul_ps(smc, r_ab_n); // # 8 MULTs
|
||||
|
||||
__m256 f_x = _mm256_fmadd_ps(r_ab2_x, sm_r_ab2, _mm256_mul_ps(r_ab_x, sm_r_ab));
|
||||
__m256 f_y = _mm256_fmadd_ps(r_ab2_y, sm_r_ab2, _mm256_mul_ps(r_ab_y, sm_r_ab));
|
||||
__m256 f_x = _mm256_fmadd_ps(r_ab2_x, sm_r_ab2, _mm256_mul_ps(r_ab_x, sm_r_ab)); // # 16 MULTs, 8 ADDs
|
||||
__m256 f_y = _mm256_fmadd_ps(r_ab2_y, sm_r_ab2, _mm256_mul_ps(r_ab_y, sm_r_ab)); // # 16 MULTs, 8 ADDs
|
||||
|
||||
__m256 f_norm_sq = _mm256_fmadd_ps(f_x, f_x, _mm256_mul_ps(f_y, f_y));
|
||||
__m256 rhs = _mm256_mul_ps(f_norm_sq, v_cos_phi_sq);
|
||||
__m256 e_dot_f = _mm256_fmadd_ps(eix, f_x, _mm256_mul_ps(eiy, f_y));
|
||||
__m256 e_dot_f_sq = _mm256_mul_ps(e_dot_f, e_dot_f);
|
||||
__m256 f_norm_sq = _mm256_fmadd_ps(f_x, f_x, _mm256_mul_ps(f_y, f_y)); // # 16 MULTs, 8 ADDs
|
||||
__m256 rhs = _mm256_mul_ps(f_norm_sq, v_cos_phi_sq); // # 8 MULTs
|
||||
__m256 e_dot_f = _mm256_fmadd_ps(eix, f_x, _mm256_mul_ps(eiy, f_y)); // # 16 MULTs, 8 ADDs
|
||||
__m256 e_dot_f_sq = _mm256_mul_ps(e_dot_f, e_dot_f); // # 8 MULTs
|
||||
|
||||
__m256 c1 = _mm256_cmp_ps(e_dot_f, v_zero, _CMP_LT_OQ);
|
||||
__m256 c2 = _mm256_cmp_ps(e_dot_f_sq, rhs, _CMP_GT_OQ);
|
||||
__m256 cond = _mm256_and_ps(c1, c2);
|
||||
__m256 w_val = _mm256_blendv_ps(v_dt_neg, v_c_neg_dt, cond);
|
||||
|
||||
__m256 f_x_safe = _mm256_and_ps(f_x, active);
|
||||
__m256 f_y_safe = _mm256_and_ps(f_y, active);
|
||||
acc_x = _mm256_fmadd_ps(f_x_safe, w_val, acc_x);
|
||||
acc_y = _mm256_fmadd_ps(f_y_safe, w_val, acc_y);
|
||||
__m256 f_x_safe = _mm256_and_ps(f_x, active); // bitwise, no flop
|
||||
__m256 f_y_safe = _mm256_and_ps(f_y, active); // bitwise, no flop
|
||||
acc_x = _mm256_fmadd_ps(f_x_safe, w_val, acc_x); // # 8 MULTs, 8 ADDs
|
||||
acc_y = _mm256_fmadd_ps(f_y_safe, w_val, acc_y); // # 8 MULTs, 8 ADDs
|
||||
}
|
||||
|
||||
__m256 hsum = _mm256_hadd_ps(acc_x, acc_y);
|
||||
__m256 hsum = _mm256_hadd_ps(acc_x, acc_y); // # 8 ADDs
|
||||
__m128 hsum_lo = _mm256_castps256_ps128(hsum);
|
||||
__m128 hsum_hi = _mm256_extractf128_ps(hsum, 1);
|
||||
__m128 sum4 = _mm_add_ps(hsum_lo, hsum_hi);
|
||||
sum4 = _mm_hadd_ps(sum4, sum4);
|
||||
__m128 sum4 = _mm_add_ps(hsum_lo, hsum_hi); // # 4 ADDs
|
||||
sum4 = _mm_hadd_ps(sum4, sum4); // # 4 ADDs
|
||||
alignas(16) float sum_out[4];
|
||||
_mm_store_ps(sum_out, sum4);
|
||||
f_alpha_dt_x += sum_out[0];
|
||||
f_alpha_dt_y += sum_out[1];
|
||||
f_alpha_dt_x += sum_out[0]; // # 1 ADD
|
||||
f_alpha_dt_y += sum_out[1]; // # 1 ADD
|
||||
|
||||
for (int k = 0; k < board.n_obstacles; k++) {
|
||||
|
||||
float v1_x = pos_x[i] - board.obstacles[k].start_x;
|
||||
float v1_y = pos_y[i] - board.obstacles[k].start_y;
|
||||
float v1_x = pos_x[i] - board.obstacles[k].start_x; // # 1 ADD
|
||||
float v1_y = pos_y[i] - board.obstacles[k].start_y; // # 1 ADD
|
||||
float v2_x = board.obstacles[k].obstacle_v_x;
|
||||
float v2_y = board.obstacles[k].obstacle_v_y;
|
||||
|
||||
float projection = (v1_x * v2_x + v1_y * v2_y) * board.obstacles[k].length_sq_inv;
|
||||
float projection = (v1_x * v2_x + v1_y * v2_y) * board.obstacles[k].length_sq_inv; // # 3 MULTs, 1 ADD
|
||||
|
||||
if (projection < 0.0)
|
||||
projection = 0.0;
|
||||
else if (projection > 1.0)
|
||||
projection = 1.0;
|
||||
|
||||
float r_aB_x = pos_x[i] - (board.obstacles[k].start_x + board.obstacles[k].obstacle_v_x * projection);
|
||||
float r_aB_y = pos_y[i] - (board.obstacles[k].start_y + board.obstacles[k].obstacle_v_y * projection);
|
||||
float r_aB_x = pos_x[i] - (board.obstacles[k].start_x + board.obstacles[k].obstacle_v_x * projection); // # 1 MULT, 2 ADDs
|
||||
float r_aB_y = pos_y[i] - (board.obstacles[k].start_y + board.obstacles[k].obstacle_v_y * projection); // # 1 MULT, 2 ADDs
|
||||
|
||||
float r_aB_norm = sqrt(r_aB_x * r_aB_x + r_aB_y * r_aB_y);
|
||||
float r_aB_norm = sqrt(r_aB_x * r_aB_x + r_aB_y * r_aB_y); // # 2 MULTs, 1 ADD, 1 SQRT
|
||||
r_aB_norm = r_aB_norm > EPS ? r_aB_norm : EPS;
|
||||
|
||||
float scalar_mult = (NEG_U0_AB_div_R * exp(r_aB_norm * NEG_R_INV)) / r_aB_norm;
|
||||
float f_alpha_B_neg_x = r_aB_x * scalar_mult;
|
||||
float f_alpha_B_neg_y = r_aB_y * scalar_mult;
|
||||
float scalar_mult = (NEG_U0_AB_div_R * exp(r_aB_norm * NEG_R_INV)) / r_aB_norm; // # 2 MULTs, 1 EXP, 1 DIV
|
||||
float f_alpha_B_neg_x = r_aB_x * scalar_mult; // # 1 MULT
|
||||
float f_alpha_B_neg_y = r_aB_y * scalar_mult; // # 1 MULT
|
||||
|
||||
float w_val;
|
||||
|
||||
@@ -375,28 +390,28 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
||||
else
|
||||
w_val = c_neg_times_dt;
|
||||
|
||||
float f_alpha_B_dt_x = f_alpha_B_neg_x * w_val;
|
||||
float f_alpha_B_dt_y = f_alpha_B_neg_y * w_val;
|
||||
float f_alpha_B_dt_x = f_alpha_B_neg_x * w_val; // # 1 MULT
|
||||
float f_alpha_B_dt_y = f_alpha_B_neg_y * w_val; // # 1 MULT
|
||||
|
||||
f_alpha_dt_x += f_alpha_B_dt_x;
|
||||
f_alpha_dt_y += f_alpha_B_dt_y;
|
||||
f_alpha_dt_x += f_alpha_B_dt_x; // # 1 ADD
|
||||
f_alpha_dt_y += f_alpha_B_dt_y; // # 1 ADD
|
||||
}
|
||||
|
||||
w_x[i] += f_alpha_dt_x;
|
||||
w_y[i] += f_alpha_dt_y;
|
||||
w_x[i] += f_alpha_dt_x; // # 1 ADD
|
||||
w_y[i] += f_alpha_dt_y; // # 1 ADD
|
||||
}
|
||||
|
||||
for (int i = 0; i < n_p; i++) {
|
||||
|
||||
float w_norm = sqrt(w_x[i] * w_x[i] + w_y[i] * w_y[i]);
|
||||
float w_norm = sqrt(w_x[i] * w_x[i] + w_y[i] * w_y[i]); // # 2 MULTs, 1 ADD, 1 SQRT
|
||||
float w_norm2 = w_norm > EPS ? w_norm : EPS;
|
||||
float correction_factor = min(1.0f, v_max[i] / w_norm2);
|
||||
float correction_factor = min(1.0f, v_max[i] / w_norm2); // # 1 DIV
|
||||
|
||||
curr_vel_x[i] = w_x[i] * correction_factor;
|
||||
curr_vel_y[i] = w_y[i] * correction_factor;
|
||||
curr_vel_x[i] = w_x[i] * correction_factor; // # 1 MULT
|
||||
curr_vel_y[i] = w_y[i] * correction_factor; // # 1 MULT
|
||||
|
||||
pos_x[i] = pos_x[i] + curr_vel_x[i] * dt;
|
||||
pos_y[i] = pos_y[i] + curr_vel_y[i] * dt;
|
||||
pos_x[i] = pos_x[i] + curr_vel_x[i] * dt; // # 1 MULT, 1 ADD
|
||||
pos_y[i] = pos_y[i] + curr_vel_y[i] * dt; // # 1 MULT, 1 ADD
|
||||
|
||||
if (color[i] == 0 && pos_x[i] > (BOARD_LENGTH - 1.5)) {
|
||||
pos_x[i] = 1.0;
|
||||
@@ -417,22 +432,22 @@ int run_simulation(Pedestrian *pedestrians, Board &board, int n_p, int n_iter, c
|
||||
|
||||
pos_y[i] = clamp(pos_y[i], WALL_EPS, BOARD_WIDTH_MINUS_WALL_EPS);
|
||||
|
||||
float ex = destination_x[i] - pos_x[i];
|
||||
float ey = destination_y[i] - pos_y[i];
|
||||
float ex = destination_x[i] - pos_x[i]; // # 1 ADD
|
||||
float ey = destination_y[i] - pos_y[i]; // # 1 ADD
|
||||
|
||||
float e_norm = sqrt(ex * ex + ey * ey);
|
||||
float e_norm = sqrt(ex * ex + ey * ey); // # 2 MULTs, 1 ADD, 1 SQRT
|
||||
float e_norm2 = e_norm > EPS ? e_norm : EPS;
|
||||
float e_norm_inv = 1.0 / e_norm2;
|
||||
float e_norm_inv = 1.0 / e_norm2; // # 1 DIV
|
||||
|
||||
e_x[i] = ex * e_norm_inv;
|
||||
e_y[i] = ey * e_norm_inv;
|
||||
e_x[i] = ex * e_norm_inv; // # 1 MULT
|
||||
e_y[i] = ey * e_norm_inv; // # 1 MULT
|
||||
|
||||
float velocity_norm_sq = curr_vel_x[i] * curr_vel_x[i] + curr_vel_y[i] * curr_vel_y[i];
|
||||
float velocity_norm = sqrt(velocity_norm_sq);
|
||||
float velocity_norm_sq = curr_vel_x[i] * curr_vel_x[i] + curr_vel_y[i] * curr_vel_y[i]; // # 2 MULTs, 1 ADD
|
||||
float velocity_norm = sqrt(velocity_norm_sq); // # 1 SQRT
|
||||
|
||||
sb_sq[i] = velocity_norm_sq * delta_t_sq;
|
||||
sb_e_x[i] = e_x[i] * (velocity_norm * delta_t);
|
||||
sb_e_y[i] = e_y[i] * (velocity_norm * delta_t);
|
||||
sb_sq[i] = velocity_norm_sq * delta_t_sq; // # 1 MULT
|
||||
sb_e_x[i] = e_x[i] * (velocity_norm * delta_t); // # 2 MULTs (vel_norm*delta_t shared with next line)
|
||||
sb_e_y[i] = e_y[i] * (velocity_norm * delta_t); // # 1 MULT
|
||||
|
||||
#if !BENCHMARK
|
||||
if (dump_path && (t % dump_interval == 0)) {
|
||||
|
||||
Reference in New Issue
Block a user