From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRSVo-0006Zl-DX for qemu-devel@nongnu.org; Mon, 17 Aug 2015 18:04:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRSVm-0004OO-5A for qemu-devel@nongnu.org; Mon, 17 Aug 2015 18:04:12 -0400 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:34558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRSVm-0004OK-0H for qemu-devel@nongnu.org; Mon, 17 Aug 2015 18:04:10 -0400 Received: by qkcs67 with SMTP id s67so51976851qkc.1 for ; Mon, 17 Aug 2015 15:04:09 -0700 (PDT) Received: from bigtime.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by smtp.gmail.com with ESMTPSA id b47sm7450056qge.44.2015.08.17.15.04.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 15:04:09 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Mon, 17 Aug 2015 15:03:34 -0700 Message-Id: <1439849015-11127-2-git-send-email-rth@twiddle.net> In-Reply-To: <1439849015-11127-1-git-send-email-rth@twiddle.net> References: <1439849015-11127-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH 1/2] target-alpha: Rewrite helper_cmpbge using bit tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Not quite as good as using a proper host vector compare, but certainly better than a loop. Signed-off-by: Richard Henderson --- target-alpha/int_helper.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/target-alpha/int_helper.c b/target-alpha/int_helper.c index 74f38cb..4a6e955 100644 --- a/target-alpha/int_helper.c +++ b/target-alpha/int_helper.c @@ -58,20 +58,33 @@ uint64_t helper_zap(uint64_t val, uint64_t mask) return helper_zapnot(val, ~mask); } -uint64_t helper_cmpbge(uint64_t op1, uint64_t op2) +uint64_t helper_cmpbge(uint64_t a, uint64_t b) { - uint8_t opa, opb, res; - int i; - - res = 0; - for (i = 0; i < 8; i++) { - opa = op1 >> (i * 8); - opb = op2 >> (i * 8); - if (opa >= opb) { - res |= 1 << i; - } - } - return res; + uint64_t mask = 0x00ff00ff00ff00ffULL; + uint64_t test = 0x0100010001000100ULL; + uint64_t al, ah, bl, bh, cl, ch; + + /* Separate the bytes to avoid false positives. */ + al = a & mask; + bl = b & mask; + ah = (a >> 8) & mask; + bh = (b >> 8) & mask; + + /* "Compare". If a byte in B is greater than a byte in A, + it will clear the test bit. */ + cl = ((al | test) - bl) & test; + ch = ((ah | test) - bh) & test; + + /* Fold all of the test bits into a contiguous set. */ + /* ch=.......a...............c...............e...............g........ */ + /* cl=.......b...............d...............f...............h........ */ + cl += ch << 1; + /* cl=......ab..............cd..............ef..............gh........ */ + cl |= cl << 14; + /* cl=......abcd............cdef............efgh............gh........ */ + cl |= cl << 28; + /* cl=......abcdefgh........cdefgh..........efgh............gh........ */ + return cl >> 50; } uint64_t helper_minub8(uint64_t op1, uint64_t op2) -- 2.4.3