soc/amd/common/block/lpc: Use standard pci_dev_ops_pci
[coreboot.git] / src / commonlib / sort.c
blobcdb94d3c7f2d29169839d8840c483cb08d61a59c
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* This file is part of the coreboot project. */
4 #include <commonlib/helpers.h>
5 #include <commonlib/sort.h>
7 /* Implement a simple Bubble sort algorithm. Reduce the needed number of
8 iterations by taking care of already sorted entries in the list. */
9 void bubblesort(int *v, size_t num_entries, sort_order_t order)
11 size_t i, j;
12 int swapped;
14 /* Make sure there are at least two entries to sort. */
15 if (num_entries < 2)
16 return;
18 for (j = 0; j < num_entries - 1; j++) {
19 swapped = 0;
20 for (i = 0; i < num_entries - j - 1; i++) {
21 switch (order) {
22 case NUM_ASCENDING:
23 if (v[i] > v[i + 1]) {
24 SWAP(v[i], v[i + 1]);
25 swapped = 1;
27 break;
28 case NUM_DESCENDING:
29 if (v[i] < v[i + 1]) {
30 SWAP(v[i], v[i + 1]);
31 swapped = 1;
33 break;
34 default:
35 return;
38 if (!swapped)
39 break;