MD5 speed improvement ideas
#1
Hi Atom!

I think that you can optimize MD5 algorithm a bit. Daniel Niggebrugge (EmDebr) nor Michail Svarychevski (barsWF) didn't reply me, so i'm trying you Smile

Here comes one of the optimizations (and very little one) of sse2 code.
In steps 35, 39, 43 and 47 (round 3 od MD5 where rotating by 16 bits is performed), you can use:

a = _mm_shufflehi_epi16(a, 0xB1);
a = _mm_shufflelo_epi16(a, 0xB1);

instead of

tmp = _mm_slli_epi32(a, 16);
a = _mm_srli_epi32(a, 32-16);
a = tmp | a;

Or if you are using assembler, the above means that you can use

PSHUFHW xmm0, xmm0, 0xB1
PSHUFLW xmm0, xmm0, 0xB1

for rotating xmm0 register by 16 bits rather than

MOVDQA xmm7, xmm0
PSLLD xmm0, 16
PSRLD xmm7, 16
por xmm0, xmm7

It means you can save 2 instructions and 1 'temporary' xmm register. Round3 includes 4 these operations, so you can totally save up to 8 instructions Smile

I think that there are more improvements which could be done, but without source code of your app, it is enough for now... Wink

hope it helps, have a nice time
Dalibor
Reply


Messages In This Thread
MD5 speed improvement ideas - by Dalibor - 10-09-2010, 08:54 PM
RE: MD5 speed improvement ideas - by D3ad0ne - 10-09-2010, 10:37 PM
RE: MD5 speed improvement ideas - by Dalibor - 10-10-2010, 09:00 AM
RE: MD5 speed improvement ideas - by ksp - 10-10-2010, 09:54 AM
RE: MD5 speed improvement ideas - by atom - 10-10-2010, 10:53 AM
RE: MD5 speed improvement ideas - by Dalibor - 10-10-2010, 10:49 PM
RE: MD5 speed improvement ideas - by atom - 10-11-2010, 12:37 PM
RE: MD5 speed improvement ideas - by Dalibor - 10-11-2010, 10:46 PM
RE: MD5 speed improvement ideas - by atom - 10-13-2010, 10:14 AM
RE: MD5 speed improvement ideas - by Dalibor - 10-14-2010, 03:02 PM
RE: MD5 speed improvement ideas - by atom - 10-15-2010, 01:11 PM
RE: MD5 speed improvement ideas - by atom - 10-15-2010, 03:26 PM
RE: MD5 speed improvement ideas - by Dalibor - 10-16-2010, 12:43 AM
RE: MD5 speed improvement ideas - by D3ad0ne - 10-16-2010, 12:33 AM
RE: MD5 speed improvement ideas - by atom - 10-17-2010, 10:42 AM
RE: MD5 speed improvement ideas - by Dalibor - 10-17-2010, 04:19 PM
RE: MD5 speed improvement ideas - by IvanG - 10-17-2010, 08:12 PM
RE: MD5 speed improvement ideas - by Dalibor - 11-01-2010, 11:15 AM
RE: MD5 speed improvement ideas - by Rolf - 10-17-2010, 04:55 PM
RE: MD5 speed improvement ideas - by D3ad0ne - 10-17-2010, 07:33 PM
RE: MD5 speed improvement ideas - by IvanG - 12-14-2010, 06:55 PM