On Sun, 13 Jun 2004 11:24:12 +0200, Ard Biesheuvel <[EMAIL PROTECTED]> wrote:
First of all, crc32tab is no longer in the .text segment, so it will not be shared between forked processes, taking more memory space than necessary. Each process will have to initialise it as well, so the init loop will run more than once.
Secondly, compiler optimisation is always more effective working on data known to be constant. So removing 'const' from cr32tab is likely to produce slower code.
Also, you used long int instead of int, which means your code will break on 64-bit platforms.
2) Speed is improved on large amount of data.
I seriously doubt that, as the tight main loop of the function didn't change that much. Using 'register' won't help you here (Windows cl.exe officialy ignores it altogether, GCC is smart enough to figure it out for itself)
Thank you for good explanation and comments. Now I understood that the current crc32 implementation is better than mine. But it consists some ugly bugs (read my comments): PHP_NAMED_FUNCTION(php_if_crc32) { unsigned int crc = ~0; char *p; int len, nr; /*!!! is special sense in [len] var here? Remove it! */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
return;
}
/* !!! there is no error check nr < 0 */
len = 0 ; /* !!! remove it! */ for (len += nr; nr--; ++p) { CRC32(crc, *p); } RETVAL_LONG(~crc); }
Below is corrected function with speed improvement in main cycle
(up to 40% on my compiler)
=========cut========
PHP_NAMED_FUNCTION(php_if_crc32)
{
unsigned int crc = ~0;
unsigned char *p;
int nr;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", (char **)&p, &nr) == FAILURE || nr < 0) return;
if (nr == 0) RETVAL_LONG(0);
do { crc = (crc >> 8) ^ crc32tab[(unsigned char)crc ^ *p++]; } while (--nr);
RETVAL_LONG(~crc);
}
=========cut=========
And do not forget to remove CRC32() definition in crc32.h
-- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php