On Thu, Feb 07, 2008 at 07:38:08PM +0300, Dmitry Stogov wrote: > According to algorithm "used" and "free" in PHP_MD5Final cannot be more > than 64, so I don't see any reason for unnecessary conversions. Looking > more careful I think they must be changed into php_uint32 in > PHP_MD5Update too.
You're correct, except that it is non-obvious which incurs more type conversions and which of those conversions have a runtime cost and which don't. For example, "&ctx->buffer[used]" on a 64-bit system may have to expand "used" to 64 bits for effective address calculation, which may or may not cost (depends on properties of the architecture and the compiler). Similarly, passing "free" as the size argument to memcpy() may have to expand it to 64 bits to match the ABI and/or the prototype for memcpy(). OK, I've tried to count those likely conversions - and my conclusion is that having "used" and "free" at size_t in both functions results in fewer conversions (or even none) when size_t matches the pointer size and php_uint32 doesn't. Specifically, the only places where anything (that touches these two variables) would need to be zero-extended are: used = saved_lo & 0x3f; ... used = ctx->lo & 0x3f; In both cases, we have a bitwise AND anyway - so the compiler might instead expand the constant to 64-bit (or use an instruction that expands its immediate argument to 64 bits instead of to 32 bits). Anyway, this is obviously not important, so I am fine with your latest patch the way it is, if you prefer to have it that way. Thanks, Alexander -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php