From patchwork Mon Dec 7 11:09:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 57764 Delivered-To: patch@linaro.org Received: by 10.112.147.194 with SMTP id tm2csp1078613lbb; Mon, 7 Dec 2015 03:09:28 -0800 (PST) X-Received: by 10.140.101.51 with SMTP id t48mr36497445qge.71.1449486568262; Mon, 07 Dec 2015 03:09:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 97si18113573qkt.81.2015.12.07.03.09.27; Mon, 07 Dec 2015 03:09:28 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 540866198A; Mon, 7 Dec 2015 11:09:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id B48EC6183E; Mon, 7 Dec 2015 11:09:21 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 61A7E618C6; Mon, 7 Dec 2015 11:09:20 +0000 (UTC) Received: from mail-ob0-f173.google.com (mail-ob0-f173.google.com [209.85.214.173]) by lists.linaro.org (Postfix) with ESMTPS id 377246182B for ; Mon, 7 Dec 2015 11:09:19 +0000 (UTC) Received: by obcse5 with SMTP id se5so108970935obc.3 for ; Mon, 07 Dec 2015 03:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=xEhKViAra3QsM6c/ieCVCBcLPjGXRCF8d5kqxihTqTA=; b=Bh1/iOIEA7BTR4IJCbBWjJt45h0org4ArH1PUS/zfnhtpbDNmOm26ZBgyJRZa8ayRP l/+enOZ20xb0n/KQJey7GIvrIax96IfnhFhRIafKcf8DP4uktTIxJrW0Y9tABIyr5G/T gEuGYUwIM3/wuLDo4kHr0o16gAVYwSrD0/JPzHNjCuBVKMj2G6mjRbFgNjUTiqZJ/YTi Lsbj5OTGlBK5Aw3l+CJDJaWIM1YFwXe03i/kEdfU/o+HotWtyZIKrqlcJiyyGub/v+oj n042gZwZGb2DSwtY5qrRx8k7Roj3MmyRZbA/Tgt4v3YNxVIYSW1DPSgS6/O8dn+eVSw3 azwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xEhKViAra3QsM6c/ieCVCBcLPjGXRCF8d5kqxihTqTA=; b=dcow8BL2380ivvuXF6VpBIXA2Hcv8xUSECQYFIXsx71utZSI48itKea0aJ7cvm5AD7 whLATO8n8rAV7c1OfoX0LJ1NYvRfsXe5i6n4iL4WVJx8RHSpWwPo5JUCkEl4kKzJsMvT QI94p+5J5dzasXxeFpt+VtvUWoZk2RCGknLW4onAK6biWxAYb7E0M40uWftfrnTyGm14 2JYdTdLu1ZQvz8UhQShKezdentawGQKDnlOHCX0qkWgpwlDKQ899ASO2zmwwOQh8xdhE 0D+wxO4ndEsPmfbb5uM3iIpIbP6j+gWS2xPeWBHLM/gQrsEysDKiW7npwyJwqgva9QyS mMGA== X-Gm-Message-State: ALoCoQmN3LbA5KoC9lVvKjvwnD6duWnKqK4Ex7cfkcvFgeH/hPwbudEljBZV+9NY1O8qtXh3wykG X-Received: by 10.182.186.34 with SMTP id fh2mr18567081obc.65.1449486558717; Mon, 07 Dec 2015 03:09:18 -0800 (PST) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id jy5sm11466022obb.13.2015.12.07.03.09.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Dec 2015 03:09:18 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 7 Dec 2015 05:09:13 -0600 Message-Id: <1449486553-16699-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: Architecture patch Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: tm: use odp_hash_crc32c() api to avoid arch issues X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Change the internal hash_name_and_kind() function to eliminate the use of architecture-specific hash instructions. This eliminates build issues surrounding ARM variants. Future optimizations will use the arch directory consistent with other ODP modules. Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_name_table.c | 184 +------------------------------- 1 file changed, 2 insertions(+), 182 deletions(-) diff --git a/platform/linux-generic/odp_name_table.c b/platform/linux-generic/odp_name_table.c index 10a760e..b4a9081 100644 --- a/platform/linux-generic/odp_name_table.c +++ b/platform/linux-generic/odp_name_table.c @@ -48,140 +48,6 @@ #define SECONDARY_HASH_HISTO_PRINT 1 - /* #define USE_AES */ - -#if defined __x86_64__ || defined __i386__ - -#ifdef USE_AES - -typedef long long int v2di __attribute__((vector_size(16))); - -static const v2di HASH_CONST1 = { 0x123456, 0xFEBCDA383 }; -static const v2di HASH_CONST2 = { 0x493BA3F689, 0x102F5D73A8C }; - -#define PLATFORM_HASH_STATE v2di - -#define PLATFORM_HASH32_INIT(hash_state, name_len) \ - ({ \ - hash_state = HASH_CONST1; \ - hash_state[0] ^= name_len; \ - }) - -#define PLATFORM_HASH32(hash_state, name_word) \ - ({ \ - v2di data; \ - \ - data[0] = name_word; \ - data[1] = name_word << 1; \ - hash_state = __builtin_ia32_aesenc128(hash_state, data); \ - }) - -#define PLATFORM_HASH32_FINISH(hash_state, kind) \ - ({ \ - uint64_t result; \ - v2di data; \ - \ - data[0] = name_kind; \ - data[1] = name_kind << 7; \ - hash_state = __builtin_ia32_aesenc128(hash_state, data); \ - hash_state = __builtin_ia32_aesenc128(hash_state, \ - HASH_CONST2); \ - hash_state = __builtin_ia32_aesenc128(hash_state, \ - HASH_CONST1); \ - result = (uint64_t)hash_state[0] ^ hash_state[1]; \ - result = result ^ result >> 32; \ - (uint32_t)result; \ - }) - -#else - -#define PLATFORM_HASH_STATE uint64_t - -#define PLATFORM_HASH32_INIT(hash_state, name_len) \ - ({ \ - hash_state = (uint64_t)name_len; \ - hash_state |= hash_state << 8; \ - hash_state |= hash_state << 16; \ - hash_state |= hash_state << 32; \ - }) - -#define PLATFORM_HASH32(hash_state, name_word) \ - ({ \ - uint64_t temp; \ - \ - temp = ((uint64_t)name_word) * 0xFEFDFCF5; \ - hash_state = hash_state * 0xFF; \ - hash_state ^= temp ^ (uint64_t)name_word; \ - }) - -#define PLATFORM_HASH32_FINISH(hash_state, kind) \ - ({ \ - hash_state ^= (((uint32_t)kind) << 13); \ - hash_state = hash_state * 0xFEFDFCF5; \ - hash_state = hash_state ^ hash_state >> 32; \ - hash_state = hash_state % 0xFEEDDCCBBAA1; \ - hash_state = hash_state ^ hash_state >> 32; \ - (uint32_t)hash_state; \ - }) - -#endif - -#elif defined(__tile_gx__) - -#define PLATFORM_HASH_STATE uint32_t - -#define PLATFORM_HASH32_INIT(hash_state, name_len) \ - ({ \ - hash_state = 0xFEFDFCF5; \ - hash_state = __insn_crc_32_32(hash_state, name_len); \ - }) - -#define PLATFORM_HASH32(hash_state, name_word) \ - ({ \ - hash_state = __insn_crc_32_32(hash_state, name_word); \ - }) - -#define PLATFORM_HASH32_FINISH(hash_state, kind) \ - ({ \ - hash_state = __insn_crc_32_32(hash_state, kind); \ - hash_state = __insn_crc_32_32(hash_state, 0xFFFFFFFF); \ - hash_state = __insn_crc_32_32(hash_state, 0xFEFDFCF5); \ - (uint32_t)hash_state; \ - }) - -#elif defined(__arm__) || defined(__aarch64__) - -#define PLATFORM_HASH_STATE uint32_t - -static inline uint32_t __crc32w(uint32_t crc, uint32_t value) -{ - __asm__("crc32w %w[c], %w[c], %w[v]":[c]"+r"(crc):[v]"r"(value)); - return crc; -} - -#define PLATFORM_HASH32_INIT(hash_state, name_len) \ - ({ \ - hash_state = 0xFEFDFCF5; \ - hash_state = __crc32w(hash_state, name_len); \ - }) - -#define PLATFORM_HASH32(hash_state, name_word) \ - ({ \ - __crc32w(hash_state, name_word); \ - }) - -#define PLATFORM_HASH32_FINISH(hash_state, kind) \ - ({ \ - hash_state = __crc32w(hash_state, kind); \ - hash_state = __crc32w(hash_state, 0xFFFFFFFF); \ - hash_state = __crc32w(hash_state, 0xFEFDFCF5); \ - (uint32_t)hash_state; \ - }) - -#else -#error "Need to define PLATFORM_DEPENDENT_HASH32 macro" -#endif - typedef struct name_tbl_entry_s name_tbl_entry_t; /* It is important for most platforms that the following struct fit within @@ -227,7 +93,7 @@ typedef struct { * NOT zero then this values points to a (linked list of) name_table_entry_t * records AND the bottom 6 bits are the length of this list. */ -typedef uint64_t hash_tbl_entry_t; +typedef uintptr_t hash_tbl_entry_t; typedef struct { hash_tbl_entry_t hash_entries[SECONDARY_HASH_TBL_SIZE]; @@ -275,53 +141,7 @@ static void aligned_free(void *mem_ptr) static uint32_t hash_name_and_kind(const char *name, uint8_t name_kind) { - PLATFORM_HASH_STATE hash_state; - uint32_t name_len, name_word, hash_value; - uint32_t bytes[4]; - - name_len = strlen(name); - PLATFORM_HASH32_INIT(hash_state, name_len); - - while (4 <= name_len) { - /* Get the next four characters. Note that endianness doesn't - * matter here! Also note that this assumes that there is - * either no alignment loading restrictions OR that name is - * 32-bit aligned. Shouldn't be too hard to add code to deal - * with the case when this assumption is false. - */ - /* name_word = *((uint32_t *)name); */ - bytes[0] = name[0]; - bytes[1] = name[1]; - bytes[2] = name[2]; - bytes[3] = name[3]; - name_word = (bytes[3] << 24) | (bytes[2] << 16) | - (bytes[1] << 8) | bytes[0]; - PLATFORM_HASH32(hash_state, name_word); - - name_len -= 4; - name += 4; - } - - if (name_len != 0) { - name_word = 0; - - if (2 <= name_len) { - /* name_word = (uint32_t)*((uint16_t *)name); */ - bytes[0] = name[0]; - bytes[1] = name[1]; - name_word |= (bytes[1] << 8) | bytes[0]; - name_len -= 2; - name += 2; - } - - if (name_len == 1) - name_word |= ((uint32_t)*name) << 16; - - PLATFORM_HASH32(hash_state, name_word); - } - - hash_value = PLATFORM_HASH32_FINISH(hash_state, name_kind); - return hash_value; + return odp_hash_crc32c(name, strlen(name), name_kind); } static uint32_t linked_list_len(name_tbl_entry_t *name_tbl_entry)