From 67a6a9512a52fee34a452752787dc80577fa7838 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 26 Feb 2015 22:07:22 +0100 Subject: [PATCH] raid6: Optimize by removing division. --- grub-core/disk/raid6_recover.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/raid6_recover.c b/grub-core/disk/raid6_recover.c index f9ec632fb..aa674f6ca 100644 --- a/grub-core/disk/raid6_recover.c +++ b/grub-core/disk/raid6_recover.c @@ -63,6 +63,16 @@ grub_raid6_init_table (void) } } +static unsigned +mod_255 (unsigned x) +{ + while (x > 0xff) + x = (x >> 8) + (x & 0xff); + if (x == 0xff) + return 0; + return x; +} + static grub_err_t grub_raid6_recover (struct grub_diskfilter_segment *array, int disknr, int p, char *buf, grub_disk_addr_t sector, grub_size_t size) @@ -162,11 +172,11 @@ grub_raid6_recover (struct grub_diskfilter_segment *array, int disknr, int p, grub_crypto_xor (qbuf, qbuf, buf, size); - c = ((255 ^ bad1) - + (255 ^ powx_inv[(powx[bad2 + (bad1 ^ 255)] ^ 1)])) % 255; + c = mod_255((255 ^ bad1) + + (255 ^ powx_inv[(powx[bad2 + (bad1 ^ 255)] ^ 1)])); grub_raid_block_mulx (c, qbuf, size); - c = ((unsigned) bad2 + c) % 255; + c = mod_255((unsigned) bad2 + c); grub_raid_block_mulx (c, pbuf, size); grub_crypto_xor (pbuf, pbuf, qbuf, size);