Bug 49011 - [PATCH] Speed up MD5 on Little Endian Machines
Summary: [PATCH] Speed up MD5 on Little Endian Machines
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR-util (show other bugs)
Version: 1.3.9
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2010-03-28 14:27 UTC by Stefan Fuhrmann
Modified: 2013-04-05 20:25 UTC (History)
0 users



Attachments
MD5 speedup patch (974 bytes, patch)
2010-03-28 14:27 UTC, Stefan Fuhrmann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Fuhrmann 2010-03-28 14:27:42 UTC
Created attachment 25199 [details]
MD5 speedup patch

The patch attached eliminates unnecessary
buffer copy and clean-up operations on 
little-endian machines (e.g. x86 & friends).

Calling decode() will convert the buffer
'block' from little-endian to machine-endian
in 'x'. That is only necessary on big-endian
machines.

Net runtime savings: ~15%.

[[[
If we are on a little-endian machine, we
can read directly from the input buffer.

* crypto/apr_md5.c
  (MD5Transform): optmimize by translating 
  buffers & cleaning them up on big-endian
  machines only.

patch by stefanfuhrmann < at > alice-dsl.de
]]]
Comment 1 Stefan Fritsch 2010-09-18 04:05:20 UTC
I don't think your patch is correct in general because block may be 1-byte aligned but x must be 4-byte aligned. It would work on x86 but it may fail on other architectures that don't support unaligned access.

One has to check the alignment and do a memcpy if the input block is not properly aligned.
Comment 2 Stefan Fritsch 2013-03-23 23:19:55 UTC
committed different version with alignment checks:
r1460244
Comment 3 Stefan Fritsch 2013-03-24 08:04:52 UTC
1.5 commit: r1460281
Comment 4 Stefan Fritsch 2013-04-05 20:25:30 UTC
fixed in 1.5.2