mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-03 16:35:46 +00:00
range: Create range.c for code that should not be inline
g_list_insert_sorted_merged() is rather large to be an inline function; move it to its own file. range_merge() and ranges_can_merge() can likewise move, as they are only used internally. Also, it becomes obvious that the condition within range_merge() is already satisfied by its caller, and that the return value is not used. The diffstat is misleading, because of the copyright boilerplate. Backports commit fec0fc0a13ac7f1a1130433a6740cd850c3db34a from qemu
This commit is contained in:
parent
ebeb0e46f8
commit
5e22c7e180
|
@ -231,6 +231,7 @@ copy $(SolutionDir)..\include\unicorn\*.h $(SolutionDir)distro\include\unicorn\
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-error.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-error.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-thread-win32.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-thread-win32.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c" />
|
||||||
|
<ClCompile Include="..\..\..\qemu\util\range.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\vl.c" />
|
<ClCompile Include="..\..\..\qemu\vl.c" />
|
||||||
<ClCompile Include="..\..\..\uc.c" />
|
<ClCompile Include="..\..\..\uc.c" />
|
||||||
<ClCompile Include="..\qapi-types.c" />
|
<ClCompile Include="..\qapi-types.c" />
|
||||||
|
|
|
@ -59,6 +59,9 @@
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c">
|
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c">
|
||||||
<Filter>qemu\util</Filter>
|
<Filter>qemu\util</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\qemu\util\range.c">
|
||||||
|
<Filter>qemu\util</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\..\qemu\hw\core\machine.c">
|
<ClCompile Include="..\..\..\qemu\hw\core\machine.c">
|
||||||
<Filter>qemu\hw\core</Filter>
|
<Filter>qemu\hw\core</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-error.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-error.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-thread-win32.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-thread-win32.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c" />
|
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c" />
|
||||||
|
<ClCompile Include="..\..\..\qemu\util\range.c" />
|
||||||
<ClCompile Include="..\..\..\qemu\vl.c" />
|
<ClCompile Include="..\..\..\qemu\vl.c" />
|
||||||
<ClCompile Include="..\..\..\uc.c" />
|
<ClCompile Include="..\..\..\uc.c" />
|
||||||
<ClCompile Include="..\qapi-types.c" />
|
<ClCompile Include="..\qapi-types.c" />
|
||||||
|
|
|
@ -189,6 +189,9 @@
|
||||||
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c">
|
<ClCompile Include="..\..\..\qemu\util\qemu-timer-common.c">
|
||||||
<Filter>qemu\util</Filter>
|
<Filter>qemu\util</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\..\qemu\util\range.c">
|
||||||
|
<Filter>qemu\util</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\..\uc.c" />
|
<ClCompile Include="..\..\..\uc.c" />
|
||||||
<ClCompile Include="..\qapi-visit.c">
|
<ClCompile Include="..\qapi-visit.c">
|
||||||
<Filter>qemu</Filter>
|
<Filter>qemu</Filter>
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
|
/*
|
||||||
|
* QEMU 64-bit address ranges
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2016 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef QEMU_RANGE_H
|
#ifndef QEMU_RANGE_H
|
||||||
#define QEMU_RANGE_H
|
#define QEMU_RANGE_H
|
||||||
|
|
||||||
|
@ -61,63 +81,8 @@ static inline int ranges_overlap(uint64_t first1, uint64_t len1,
|
||||||
return !(last2 < first1 || last1 < first2);
|
return !(last2 < first1 || last1 < first2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0,1 can merge with 1,2 but don't overlap */
|
GList *g_list_insert_sorted_merged(GList *list, gpointer data,
|
||||||
static inline bool ranges_can_merge(Range *range1, Range *range2)
|
GCompareFunc func);
|
||||||
{
|
|
||||||
return !(range1->end < range2->begin || range2->end < range1->begin);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int range_merge(Range *range1, Range *range2)
|
|
||||||
{
|
|
||||||
if (ranges_can_merge(range1, range2)) {
|
|
||||||
if (range1->end < range2->end) {
|
|
||||||
range1->end = range2->end;
|
|
||||||
}
|
|
||||||
if (range1->begin > range2->begin) {
|
|
||||||
range1->begin = range2->begin;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline GList *g_list_insert_sorted_merged(GList *list,
|
|
||||||
gpointer data,
|
|
||||||
GCompareFunc func)
|
|
||||||
{
|
|
||||||
GList *l, *next = NULL;
|
|
||||||
Range *r, *nextr;
|
|
||||||
|
|
||||||
if (!list) {
|
|
||||||
list = g_list_insert_sorted(list, data, func);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
nextr = data;
|
|
||||||
l = list;
|
|
||||||
while (l && l != next && nextr) {
|
|
||||||
r = l->data;
|
|
||||||
if (ranges_can_merge(r, nextr)) {
|
|
||||||
range_merge(r, nextr);
|
|
||||||
l = g_list_remove_link(l, next);
|
|
||||||
next = g_list_next(l);
|
|
||||||
if (next) {
|
|
||||||
nextr = next->data;
|
|
||||||
} else {
|
|
||||||
nextr = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
l = g_list_next(l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!l) {
|
|
||||||
list = g_list_insert_sorted(list, data, func);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline gint range_compare(gconstpointer a, gconstpointer b)
|
static inline gint range_compare(gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,3 +8,4 @@ util-obj-y += error.o
|
||||||
util-obj-y += crc32c.o
|
util-obj-y += crc32c.o
|
||||||
util-obj-y += host-utils.o
|
util-obj-y += host-utils.o
|
||||||
util-obj-y += getauxval.o
|
util-obj-y += getauxval.o
|
||||||
|
util-obj-y += range.o
|
||||||
|
|
81
qemu/util/range.c
Normal file
81
qemu/util/range.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* QEMU 64-bit address ranges
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015-2016 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "qemu/range.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Operations on 64 bit address ranges.
|
||||||
|
* Notes:
|
||||||
|
* - ranges must not wrap around 0, but can include the last byte ~0x0LL.
|
||||||
|
* - this can not represent a full 0 to ~0x0LL range.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 0,1 can merge with 1,2 but don't overlap */
|
||||||
|
static bool ranges_can_merge(Range *range1, Range *range2)
|
||||||
|
{
|
||||||
|
return !(range1->end < range2->begin || range2->end < range1->begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void range_merge(Range *range1, Range *range2)
|
||||||
|
{
|
||||||
|
if (range1->end < range2->end) {
|
||||||
|
range1->end = range2->end;
|
||||||
|
}
|
||||||
|
if (range1->begin > range2->begin) {
|
||||||
|
range1->begin = range2->begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GList *g_list_insert_sorted_merged(GList *list, gpointer data,
|
||||||
|
GCompareFunc func)
|
||||||
|
{
|
||||||
|
GList *l, *next = NULL;
|
||||||
|
Range *r, *nextr;
|
||||||
|
|
||||||
|
if (!list) {
|
||||||
|
list = g_list_insert_sorted(list, data, func);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextr = data;
|
||||||
|
l = list;
|
||||||
|
while (l && l != next && nextr) {
|
||||||
|
r = l->data;
|
||||||
|
if (ranges_can_merge(r, nextr)) {
|
||||||
|
range_merge(r, nextr);
|
||||||
|
l = g_list_remove_link(l, next);
|
||||||
|
next = g_list_next(l);
|
||||||
|
if (next) {
|
||||||
|
nextr = next->data;
|
||||||
|
} else {
|
||||||
|
nextr = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
l = g_list_next(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!l) {
|
||||||
|
list = g_list_insert_sorted(list, data, func);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
Loading…
Reference in a new issue