72 #include <libkern/libkern.h>
74 #pragma clang diagnostic push
75 #pragma clang diagnostic ignored "-Wshorten-64-to-32"
78 qsort(
void *
a,
size_t n,
size_t es,
int (*
cmp)(
const void *,
const void *));
80 static inline char *
med3(
char *,
char *,
char *,
int (*)(
const void *,
const void *));
81 static inline void swapfunc(
char *,
char *,
int,
int);
83 #define min(a, b) (a) < (b) ? a : b
88 #define swapcode(TYPE, parmi, parmj, n) { \
89 long i = (n) / sizeof (TYPE); \
90 TYPE *pi = (TYPE *) (parmi); \
91 TYPE *pj = (TYPE *) (parmj); \
99 #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
100 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
112 if (swaptype == 0) { \
113 long t = *(long *)(a); \
114 *(long *)(a) = *(long *)(b); \
117 swapfunc(a, b, es, swaptype)
119 #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
122 med3(
char *
a,
char *
b,
char *
c,
int (*
cmp)(
const void *,
const void *))
124 return cmp(
a,
b) < 0 ?
130 qsort(
void *
a,
size_t n,
size_t es,
int (*
cmp)(
const void *,
const void *))
132 char *pa, *pb, *
pc, *pd, *
pl, *pm, *pn;
133 int d, swaptype, swap_cnt;
139 for (pm = (
char *)
a + es; pm < (
char *)
a +
n * es; pm += es)
145 pm = (
char *)
a + (
n / 2) * es;
148 pn = (
char *)
a + (
n - 1) * es;
158 pa = pb = (
char *)
a + es;
160 pc = pd = (
char *)
a + (
n - 1) * es;
162 while (pb <=
pc && (
r =
cmp(pb,
a)) <= 0) {
170 while (pb <=
pc && (
r =
cmp(
pc,
a)) >= 0) {
186 for (pm = (
char *)
a + es; pm < (
char *)
a +
n * es; pm += es)
193 pn = (
char *)
a +
n * es;
194 r =
min(pa - (
char *)
a, pb - pa);
196 r =
min((
size_t)(pd -
pc), pn - pd - es);
198 if ((
size_t)(
r = pb - pa) > es)
200 if ((
size_t)(
r = pd -
pc) > es) {
209 #pragma clang diagnostic pop
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
static void swapfunc(char *, char *, int, int)
#define swapcode(TYPE, parmi, parmj, n)
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
static char * med3(char *, char *, char *, int(*)(const void *, const void *))