From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgw.gov.kz (mgw.gov.kz [89.218.88.242]) by dpdk.org (Postfix) with ESMTP id 090637FB9 for ; Sun, 16 Nov 2014 18:48:47 +0100 (CET) Received: from mgw.gov.kz (mx.ctsat.kz [178.89.4.95]) by mgw.gov.kz with ESMTP id sAGHwwcV029792-sAGHwwcX029792 (version=TLSv1.0 cipher=AES128-SHA bits=128 verify=NO); Sun, 16 Nov 2014 23:58:58 +0600 Received: from EXCASHUB2.rgp.local (192.168.40.53) by EdgeForefront.rgp.local (192.168.40.59) with Microsoft SMTP Server (TLS) id 14.2.247.3; Sun, 16 Nov 2014 23:58:48 +0600 Received: from r220.rgp.local (192.168.59.10) by excashub2.rgp.local (192.168.40.48) with Microsoft SMTP Server (TLS) id 14.2.247.3; Sun, 16 Nov 2014 23:59:04 +0600 From: Yerden Zhumabekov To: Date: Sun, 16 Nov 2014 23:59:20 +0600 Message-ID: <1416160760-16087-5-git-send-email-e_zhumabekov@sts.kz> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1409724351-23786-1-git-send-email-e_zhumabekov@sts.kz> References: <1409724351-23786-1-git-send-email-e_zhumabekov@sts.kz> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.59.10] X-FEAS-SYSTEM-WL: e_zhumabekov@sts.kz Subject: [dpdk-dev] [PATCH v2 4/4] hash: rte_hash_crc() slices data into 8-byte pieces X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Nov 2014 17:48:48 -0000 Calculating hash for data of variable length is more efficient when that data is sliced into 8-byte pieces. The rest part of data is hashed using CRC32 functions with either 8 and 4 byte operands. Signed-off-by: Yerden Zhumabekov --- lib/librte_hash/rte_hash_crc.h | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/librte_hash/rte_hash_crc.h b/lib/librte_hash/rte_hash_crc.h index 178b162..3d8dafe 100644 --- a/lib/librte_hash/rte_hash_crc.h +++ b/lib/librte_hash/rte_hash_crc.h @@ -241,7 +241,7 @@ rte_hash_crc_8byte(uint64_t data, uint32_t init_val) } /** - * Use crc32 instruction to perform a hash. + * Calculate CRC32 hash on user-supplied byte array. * * @param data * Data to perform hash on. @@ -256,23 +256,38 @@ static inline uint32_t rte_hash_crc(const void *data, uint32_t data_len, uint32_t init_val) { unsigned i; - uint32_t temp = 0; - const uint32_t *p32 = (const uint32_t *)data; + uint64_t temp = 0; + const uint64_t *p64 = (const uint64_t *)data; - for (i = 0; i < data_len / 4; i++) { - init_val = rte_hash_crc_4byte(*p32++, init_val); + for (i = 0; i < data_len / 8; i++) { + init_val = rte_hash_crc_8byte(*p64++, init_val); } - switch (3 - (data_len & 0x03)) { + switch (7 - (data_len & 0x07)) { case 0: - temp |= *((const uint8_t *)p32 + 2) << 16; + temp |= (uint64_t) *((const uint8_t *)p64 + 6) << 48; /* Fallthrough */ case 1: - temp |= *((const uint8_t *)p32 + 1) << 8; + temp |= (uint64_t) *((const uint8_t *)p64 + 5) << 40; /* Fallthrough */ case 2: - temp |= *((const uint8_t *)p32); + temp |= (uint64_t) *((const uint8_t *)p64 + 4) << 32; + temp |= *((const uint32_t *)p64); + init_val = rte_hash_crc_8byte(temp, init_val); + break; + case 3: + init_val = rte_hash_crc_4byte(*(const uint32_t *)p64, init_val); + break; + case 4: + temp |= *((const uint8_t *)p64 + 2) << 16; + /* Fallthrough */ + case 5: + temp |= *((const uint8_t *)p64 + 1) << 8; + /* Fallthrough */ + case 6: + temp |= *((const uint8_t *)p64); init_val = rte_hash_crc_4byte(temp, init_val); + /* Fallthrough */ default: break; } -- 1.7.9.5