From a0bd1cd97214a09a2c7897c0d0ea241cb508e959 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 24 Oct 2012 16:31:52 +0000 Subject: [PATCH] 2012-10-24 18:30 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/hbmlzo/core.c * LZO_ADLER32() changed to use core checksum function. it's equivalent to HB_ADLER32( , 1 ) * src/rtl/hbadler.c % hb_adler32(): applied the loop unrolling optimization found in the mzlo implementation. --- harbour/ChangeLog | 9 +++++++++ harbour/contrib/hbmlzo/core.c | 7 ++----- harbour/src/rtl/hbadler.c | 27 +++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 056a8ecb32..bf332dcd1d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,15 @@ The license applies to all entries newer than 2009-04-28. */ +2012-10-24 18:30 UTC+0200 Viktor Szakats (harbour syenar.net) + * contrib/hbmlzo/core.c + * LZO_ADLER32() changed to use core checksum function. + it's equivalent to HB_ADLER32( , 1 ) + + * src/rtl/hbadler.c + % hb_adler32(): applied the loop unrolling optimization + found in the mzlo implementation. + 2012-10-24 15:35 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/include/hbexprb.c ! fixed typo in function IDs. diff --git a/harbour/contrib/hbmlzo/core.c b/harbour/contrib/hbmlzo/core.c index 0a566610f0..f81138e1ad 100644 --- a/harbour/contrib/hbmlzo/core.c +++ b/harbour/contrib/hbmlzo/core.c @@ -54,6 +54,7 @@ #include "hbapi.h" #include "hbapierr.h" +#include "hbchksum.h" #include "hbinit.h" #include "hbvm.h" @@ -266,11 +267,7 @@ HB_FUNC( LZO_ADLER32 ) const char * src = hb_parc( 1 ); if( src ) - { - lzo_uint32 checksum = lzo_adler32( 0, NULL, 0 ); - - hb_retnint( ( HB_MAXINT ) lzo_adler32( checksum, ( lzo_bytep ) src, hb_parclen( 1 ) ) ); - } + hb_retnint( ( HB_MAXINT ) hb_adler32( 1, ( lzo_bytep ) src, hb_parclen( 1 ) ) ); else hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } diff --git a/harbour/src/rtl/hbadler.c b/harbour/src/rtl/hbadler.c index de9b91465f..7e78c5cf39 100644 --- a/harbour/src/rtl/hbadler.c +++ b/harbour/src/rtl/hbadler.c @@ -59,6 +59,12 @@ #define BASE 65521 /* largest prime smaller than 65536 */ #define NMAX 5552 /* largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ +#define LOOP_DO1( buf, i ) s1 += buf[ i ]; s2 += s1 +#define LOOP_DO2( buf, i ) LOOP_DO1( buf, i ); LOOP_DO1( buf, i + 1 ); +#define LOOP_DO4( buf, i ) LOOP_DO2( buf, i ); LOOP_DO2( buf, i + 2 ); +#define LOOP_DO8( buf, i ) LOOP_DO4( buf, i ); LOOP_DO4( buf, i + 4 ); +#define LOOP_DO16( buf, i ) LOOP_DO8( buf, i ); LOOP_DO8( buf, i + 8 ); + HB_U32 hb_adler32( HB_U32 adler, const void * buf, HB_SIZE len ) { HB_U32 s1 = adler & 0xffff; @@ -71,12 +77,25 @@ HB_U32 hb_adler32( HB_U32 adler, const void * buf, HB_SIZE len ) { HB_ISIZ n = len < NMAX ? len : NMAX; len -= n; - do + if( n >= 16 ) { - s1 += *ucbuf++; - s2 += s1; + do + { + LOOP_DO16( ucbuf, 0 ); + ucbuf += 16; + n -= 16; + } + while( n >= 16 ); + } + if( n ) + { + do + { + s1 += *ucbuf++; + s2 += s1; + } + while( --n ); } - while( --n ); s1 %= BASE; s2 %= BASE; }