Blame SOURCES/0463-jpeg-Optimise-by-replacing-division-with-shifts.patch

d18179
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d18179
From: Vladimir Serbinenko <phcoder@gmail.com>
d18179
Date: Thu, 26 Feb 2015 21:27:32 +0100
d18179
Subject: [PATCH] jpeg: Optimise by replacing division with shifts.
d18179
d18179
(cherry picked from commit 7213c1e02807e760febec06a0f19b11173abc55a)
d18179
---
d18179
 grub-core/video/readers/jpeg.c | 25 ++++++++++++++-----------
d18179
 1 file changed, 14 insertions(+), 11 deletions(-)
d18179
d18179
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
d18179
index 84cf5ceec9..55bd95b797 100644
d18179
--- a/grub-core/video/readers/jpeg.c
d18179
+++ b/grub-core/video/readers/jpeg.c
d18179
@@ -94,7 +94,7 @@ struct grub_jpeg_data
d18179
   jpeg_data_unit_t crdu;
d18179
   jpeg_data_unit_t cbdu;
d18179
 
d18179
-  unsigned vs, hs;
d18179
+  unsigned log_vs, log_hs;
d18179
   int dri;
d18179
   unsigned r1;
d18179
 
d18179
@@ -321,11 +321,14 @@ grub_jpeg_decode_sof (struct grub_jpeg_data *data)
d18179
       ss = grub_jpeg_get_byte (data);	/* Sampling factor.  */
d18179
       if (!id)
d18179
 	{
d18179
-	  data->vs = ss & 0xF;	/* Vertical sampling.  */
d18179
-	  data->hs = ss >> 4;	/* Horizontal sampling.  */
d18179
-	  if ((data->vs > 2) || (data->hs > 2) || (data->vs == 0) || (data->hs == 0))
d18179
+	  grub_uint8_t vs, hs;
d18179
+	  vs = ss & 0xF;	/* Vertical sampling.  */
d18179
+	  hs = ss >> 4;	/* Horizontal sampling.  */
d18179
+	  if ((vs > 2) || (hs > 2) || (vs == 0) || (hs == 0))
d18179
 	    return grub_error (GRUB_ERR_BAD_FILE_TYPE,
d18179
 			       "jpeg: sampling method not supported");
d18179
+	  data->log_vs = (vs == 2);
d18179
+	  data->log_hs = (hs == 2);
d18179
 	}
d18179
       else if (ss != JPEG_SAMPLING_1x1)
d18179
 	return grub_error (GRUB_ERR_BAD_FILE_TYPE,
d18179
@@ -638,10 +641,10 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
d18179
   unsigned c1, vb, hb, nr1, nc1;
d18179
   int rst = data->dri;
d18179
 
d18179
-  vb = data->vs * 8;
d18179
-  hb = data->hs * 8;
d18179
-  nr1 = (data->image_height + vb - 1) / vb;
d18179
-  nc1 = (data->image_width + hb - 1) / hb;
d18179
+  vb = 8 << data->log_vs;
d18179
+  hb = 8 << data->log_hs;
d18179
+  nr1 = (data->image_height + vb - 1) >> (3 + data->log_vs);
d18179
+  nc1 = (data->image_width + hb - 1)  >> (3 + data->log_hs);
d18179
 
d18179
   if (data->bitmap_ptr == NULL)
d18179
     return grub_error(GRUB_ERR_BAD_FILE_TYPE,
d18179
@@ -655,8 +658,8 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
d18179
 	unsigned r2, c2, nr2, nc2;
d18179
 	grub_uint8_t *ptr2;
d18179
 
d18179
-	for (r2 = 0; r2 < data->vs; r2++)
d18179
-	  for (c2 = 0; c2 < data->hs; c2++)
d18179
+	for (r2 = 0; r2 < (1U << data->log_vs); r2++)
d18179
+	  for (c2 = 0; c2 < (1U << data->log_hs); c2++)
d18179
 	    grub_jpeg_decode_du (data, 0, data->ydu[r2 * 2 + c2]);
d18179
 
d18179
 	if (data->color_components >= 3)
d18179
@@ -678,7 +681,7 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
d18179
 	      unsigned i0;
d18179
 	      int yy;
d18179
 
d18179
-	      i0 = (r2 / data->vs) * 8 + (c2 / data->hs);
d18179
+	      i0 = (r2 >> data->log_vs) * 8 + (c2 >> data->log_hs);
d18179
 	      yy = data->ydu[(r2 / 8) * 2 + (c2 / 8)][(r2 % 8) * 8 + (c2 % 8)];
d18179
 
d18179
 	      if (data->color_components >= 3)