From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQAwq-0005u9-RM for qemu-devel@nongnu.org; Sun, 29 Sep 2013 02:57:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQAwk-0002TA-29 for qemu-devel@nongnu.org; Sun, 29 Sep 2013 02:57:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQAwj-0002T6-Qn for qemu-devel@nongnu.org; Sun, 29 Sep 2013 02:57:37 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8T6vbA0013505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 29 Sep 2013 02:57:37 -0400 Received: from redhat.com (vpn1-5-44.ams2.redhat.com [10.36.5.44]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r8T6vZLD026769 for ; Sun, 29 Sep 2013 02:57:36 -0400 Date: Sun, 29 Sep 2013 09:59:58 +0300 From: "Michael S. Tsirkin" Message-ID: <1380437951-21788-4-git-send-email-mst@redhat.com> References: <1380437951-21788-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1380437951-21788-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 03/14] range: add min/max operations on ranges List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Signed-off-by: Michael S. Tsirkin --- include/qemu/range.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/qemu/range.h b/include/qemu/range.h index 4a0780d..aae9720 100644 --- a/include/qemu/range.h +++ b/include/qemu/range.h @@ -17,6 +17,24 @@ struct Range { uint64_t end; /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */ }; +static inline void range_extend(Range *range, Range *extend_by) +{ + if (!extend_by->begin && !extend_by->end) { + return; + } + if (!range->begin && !range->end) { + *range = *extend_by; + return; + } + if (range->begin > extend_by->begin) { + range->begin = extend_by->begin; + } + /* Compare last byte in case region ends at ~0x0LL */ + if (range->end - 1 < extend_by->end - 1) { + range->end = extend_by->end; + } +} + /* Get last byte of a range from offset + length. * Undefined for ranges that wrap around 0. */ static inline uint64_t range_get_last(uint64_t offset, uint64_t len) -- MST