Hi,
On non x86_64 platforms current implementation of safe_address uses doubles
for 64 bit php which is very expensive on some architectures e.g sparc.
safe_address function calculates nmemb * size + offset and it want to make
sure that it output doesn't overflow. My colleague Richard Smith suggested a
platform independent mechanism to avoid double logic for most common cases
(>99%). In this proposed optimization we can check if the inputs are
sufficiently large enough so that overflow is possible. If overflow is
possible, regular double logic will follow.
This new implementation performs very closely to the assembly version on Linux
x86_64 on micro-benchmark (attached at bottom).
On a ecommerce benchmark on Solaris sparc, new implementation reduced the time
spent in _ecalloc to 50%.
Patch against php 5.3 trunk is attached. Please provide your comments.
Regards,
Basant.
Microbenchmark testing on Linux x86_64 :
Based on the above suggested implementation, I benchmarked 3 implementation of
safe_address on Linux x86_64 (fedora 11) using a micro benchmark. Here are the
results :
For a regular nmemb * size + offset when no overflow possible :
nmemb = 23456 size = 67890 offset = 12345
assembly version of safe_address time diff = 26 ticks
doubles imlementation of safe_address time diff = 72 ticks
proposed safe_address time diff = 30 ticks
For bigger integer multiplication :
nmemb = 2589934591 size = 4294967295 offset = 5
assembly version of safe_address time diff = 26 ticks
doubles imlementation of safe_address time diff = 75 ticks
proposed safe_address time diff = 76 ticks
Here is the micro benchmark link :
http://bitbucket.org/basantk/php53perfpatches/src/tip/safe_address_bench.c