From patchwork Thu Jun 20 15:00:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 252992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9F9982C00A1 for ; Fri, 21 Jun 2013 01:01:23 +1000 (EST) Received: from localhost ([::1]:33898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpgMT-0003ZK-Fw for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 11:01:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpgMD-0003YI-HR for qemu-devel@nongnu.org; Thu, 20 Jun 2013 11:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpgMC-0004OH-9c for qemu-devel@nongnu.org; Thu, 20 Jun 2013 11:01:05 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:34701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpgMC-0004O7-2n for qemu-devel@nongnu.org; Thu, 20 Jun 2013 11:01:04 -0400 Received: by mail-ee0-f45.google.com with SMTP id c1so4005468eek.4 for ; Thu, 20 Jun 2013 08:01:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=+iqqEoMUKEJ3LRtYerzcpqk8LlGIF1wqv7IJGQickjY=; b=uqTdst3KuV5Ikqi7HgehaMNKvM5gehaxSHkSXrxBAbQ7Xe9O65OIe/cQY1oh7mjWlS xhLXMckh7wYJ7MBY362vZaWLhcMGTUQc+H+fzUD9cjDr1MFt5uDm2HI8l2GZOVoy1DNB ugRDc3pjoq9GZSOHi/GZf5AFORY6vOF1ud/+VyNg/8clLTFHSTwQuWX2s090RbqtZFkB /xrf3ZRDdbl9e57qz/e4ibAtiI0/m4fCgBWvgUamYOTUkpaNdro11kpo2VEzX+Wfrddn 3mRlzWRUdCvEm0gGwdZ0YAzzILdB/In/odi7DddeV2lUvSFgRfSxpTTySx2Nmsfd+vBg wtig== X-Received: by 10.15.107.6 with SMTP id ca6mr7965808eeb.120.1371740463166; Thu, 20 Jun 2013 08:01:03 -0700 (PDT) Received: from playground.lan (net-37-116-217-184.cust.dsl.vodafone.it. [37.116.217.184]) by mx.google.com with ESMTPSA id e44sm964490eeh.11.2013.06.20.08.01.00 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 20 Jun 2013 08:01:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 17:00:57 +0200 Message-Id: <1371740457-27445-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::22d Cc: peter.maydell@linaro.org, rth@twiddle.net Subject: [Qemu-devel] [PATCH] int128: optimize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org For add and sub, carry computation only requires checking one of the arguments (any for add, the LHS for sub because the RHS is negated). For neg, we can similarly optimize computation of the carry. For ge, we can just do lexicographic order. Signed-off-by: Paolo Bonzini --- Will post unit tests soon. include/qemu/int128.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/qemu/int128.h b/include/qemu/int128.h index bfe7678..d36cc7a 100644 --- a/include/qemu/int128.h +++ b/include/qemu/int128.h @@ -55,21 +55,20 @@ static inline Int128 int128_rshift(Int128 a, int n) static inline Int128 int128_add(Int128 a, Int128 b) { - Int128 r = { a.lo + b.lo, a.hi + b.hi }; - r.hi += (r.lo < a.lo) || (r.lo < b.lo); - return r; + uint64_t lo = a.lo + b.lo; + return (Int128) { lo, (lo < a.lo) + a.hi + b.hi }; } static inline Int128 int128_neg(Int128 a) { - a.lo = ~a.lo; - a.hi = ~a.hi; - return int128_add(a, int128_one()); + uint64_t lo = -a.lo; + return (Int128) { lo, ~a.hi + !lo }; } static inline Int128 int128_sub(Int128 a, Int128 b) { - return int128_add(a, int128_neg(b)); + uint64_t lo = a.lo - b.lo; + return (Int128) { lo, (lo < a.lo) + a.hi - b.hi }; } static inline bool int128_nonneg(Int128 a) @@ -89,7 +88,7 @@ static inline bool int128_ne(Int128 a, Int128 b) static inline bool int128_ge(Int128 a, Int128 b) { - return int128_nonneg(int128_sub(a, b)); + return a.hi > b.hi || (a.hi == b.hi && a.lo >= b.lo); } static inline bool int128_lt(Int128 a, Int128 b)