vector/ft: refactor to reduce branch miss.
authorsubhransu mohanty <sub.mohanty@samsung.com>
Wed, 2 Oct 2019 06:11:26 +0000 (15:11 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 3 Oct 2019 21:13:52 +0000 (06:13 +0900)
vtune profile shows branch miss in ft_trig_pseudo_polarize and ft_trig_pseudo_rotate
as both the if cases does similar expensive computation move then to start so that
we will not pay high penalty during branch miss.

src/vector/freetype/v_ft_math.cpp

index 0c5d1f6afe1a419157f2d2b7b8d6ee47bf90838e..a3f0af2e4d532672b83f16fa68b72ab0c7dd7cf6 100644 (file)
@@ -206,14 +206,16 @@ static void ft_trig_pseudo_rotate(SW_FT_Vector* vec, SW_FT_Angle theta)
 
     /* Pseudorotations, with right shifts */
     for (i = 1, b = 1; i < SW_FT_TRIG_MAX_ITERS; b <<= 1, i++) {
+        SW_FT_Fixed v1 = ((y + b) >> i);
+        SW_FT_Fixed v2 = ((x + b) >> i);
         if (theta < 0) {
-            xtemp = x + ((y + b) >> i);
-            y = y - ((x + b) >> i);
+            xtemp = x + v1;
+            y = y - v2;
             x = xtemp;
             theta += *arctanptr++;
         } else {
-            xtemp = x - ((y + b) >> i);
-            y = y + ((x + b) >> i);
+            xtemp = x - v1;
+            y = y + v2;
             x = xtemp;
             theta -= *arctanptr++;
         }
@@ -260,14 +262,16 @@ static void ft_trig_pseudo_polarize(SW_FT_Vector* vec)
 
     /* Pseudorotations, with right shifts */
     for (i = 1, b = 1; i < SW_FT_TRIG_MAX_ITERS; b <<= 1, i++) {
+        SW_FT_Fixed v1 = ((y + b) >> i);
+        SW_FT_Fixed v2 = ((x + b) >> i);
         if (y > 0) {
-            xtemp = x + ((y + b) >> i);
-            y = y - ((x + b) >> i);
+            xtemp = x + v1;
+            y = y - v2;
             x = xtemp;
             theta += *arctanptr++;
         } else {
-            xtemp = x - ((y + b) >> i);
-            y = y + ((x + b) >> i);
+            xtemp = x - v1;
+            y = y + v2;
             x = xtemp;
             theta -= *arctanptr++;
         }