summaryrefslogtreecommitdiff
path: root/src/commonlib/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/commonlib/include')
-rw-r--r--src/commonlib/include/commonlib/helpers.h5
-rw-r--r--src/commonlib/include/commonlib/sort.h27
2 files changed, 32 insertions, 0 deletions
diff --git a/src/commonlib/include/commonlib/helpers.h b/src/commonlib/include/commonlib/helpers.h
index 03f430635d..adc43ca98b 100644
--- a/src/commonlib/include/commonlib/helpers.h
+++ b/src/commonlib/include/commonlib/helpers.h
@@ -38,6 +38,11 @@
#define ABS(a) (((a) < 0) ? (-(a)) : (a))
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
#define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
+#define SWAP(a, b) do { \
+ typeof(a) tmp = a; \
+ a = (typeof(a)) b; \
+ b = (typeof(b)) tmp; \
+ } while (0)
/*
* Divide positive or negative dividend by positive divisor and round
* to closest integer. Result is undefined for negative divisors and
diff --git a/src/commonlib/include/commonlib/sort.h b/src/commonlib/include/commonlib/sort.h
new file mode 100644
index 0000000000..3d94d25d40
--- /dev/null
+++ b/src/commonlib/include/commonlib/sort.h
@@ -0,0 +1,27 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2019 Siemens AG
+ *
+ * This program 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; version 2 of the License.
+ *
+ * This program 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 General Public License for more details.
+ */
+#ifndef _COMMONLIB_SORT_H_
+#define _COMMONLIB_SORT_H_
+
+#include <stddef.h>
+
+typedef enum {
+ NUM_ASCENDING,
+ NUM_DESCENDING
+} sort_order_t;
+
+void bubblesort(int *v, size_t num_entries, sort_order_t order);
+
+#endif /* _COMMONLIB_SORT_H_ */