From a25b7eccf928d7478465599e45cabbf1cb6fd0c1 Mon Sep 17 00:00:00 2001 From: Mahesh Madhav <67384846+heshpdx@users.noreply.github.com> Date: Wed, 4 Sep 2024 21:38:25 -0700 Subject: [PATCH] optimize computation in librrgraph utils In one hot loop, swap three expensive FDIVs for a single FDIV and three FMULs. --- .../src/utils/alloc_and_load_rr_indexed_data.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.cpp b/libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.cpp index 7eb6ded1579..6b5634de641 100644 --- a/libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.cpp +++ b/libs/librrgraph/src/utils/alloc_and_load_rr_indexed_data.cpp @@ -678,9 +678,10 @@ static void calculate_average_switch(const RRGraphView& rr_graph, int inode, dou } if (num_switches > 0) { - avg_switch_R /= num_switches; - avg_switch_T /= num_switches; - avg_switch_Cinternal /= num_switches; + double inv_num_switches = 1.0 / num_switches; + avg_switch_R *= inv_num_switches; + avg_switch_T *= inv_num_switches; + avg_switch_Cinternal *= inv_num_switches; } VTR_ASSERT(std::isfinite(avg_switch_R));