xref: /optee_os/lib/libutils/ext/qsort_helpers.c (revision fa4b4621b3faaed9903c0eefe39951d7dd57d4ee)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2024, STMicroelectronics
4  */
5 
6 #include <stdlib.h>
7 #include <util.h>
8 
9 #define QSORT_HELPER(name, type)				\
10 static int cmp_ ## name(const void *a, const void *b)		\
11 {								\
12 	const type *ia = a;					\
13 	const type *ib = b;					\
14 								\
15 	return CMP_TRILEAN(*ia, *ib);				\
16 }								\
17 								\
18 void qsort_ ## name(type *aa, size_t n)				\
19 {								\
20 	qsort(aa, n, sizeof(*aa), cmp_ ## name);		\
21 }
22 
23 QSORT_HELPER(int, int);
24 QSORT_HELPER(uint, unsigned int);
25 QSORT_HELPER(long, long int);
26 QSORT_HELPER(ul, unsigned long int);
27 QSORT_HELPER(ll, long long int);
28 QSORT_HELPER(ull, unsigned long long int);
29 QSORT_HELPER(s8, int8_t);
30 QSORT_HELPER(u8, uint8_t);
31 QSORT_HELPER(s16, int16_t);
32 QSORT_HELPER(u16, uint16_t);
33 QSORT_HELPER(s32, int32_t);
34 QSORT_HELPER(u32, uint32_t);
35 QSORT_HELPER(s64, int64_t);
36 QSORT_HELPER(u64, uint64_t);
37