Increase MAXTHREADS
[Rockbox.git] / firmware / general.c
blob7f4348046c91b85b52fa32b2d75776b9020bcd69
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Michael Sevakis
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <limits.h>
20 #include "config.h"
21 #include "general.h"
23 int round_value_to_list32(unsigned long value,
24 const unsigned long list[],
25 int count,
26 bool signd)
28 unsigned long dmin = ULONG_MAX;
29 int idmin = -1, i;
31 for (i = 0; i < count; i++)
33 unsigned long diff;
35 if (list[i] == value)
37 idmin = i;
38 break;
41 if (signd ? ((long)list[i] < (long)value) : (list[i] < value))
42 diff = value - list[i];
43 else
44 diff = list[i] - value;
46 if (diff < dmin)
48 dmin = diff;
49 idmin = i;
53 return idmin;
54 } /* round_value_to_list32 */
56 /* Number of bits set in src_mask should equal src_list length */
57 int make_list_from_caps32(unsigned long src_mask,
58 const unsigned long *src_list,
59 unsigned long caps_mask,
60 unsigned long *caps_list)
62 int i, count;
63 unsigned long mask;
65 for (mask = src_mask, count = 0, i = 0;
66 mask != 0;
67 src_mask = mask, i++)
69 unsigned long test_bit;
70 mask &= mask - 1; /* Zero lowest bit set */
71 test_bit = mask ^ src_mask; /* Isolate the bit */
72 if (test_bit & caps_mask) /* Add item if caps has test bit set */
73 caps_list[count++] = src_list ? src_list[i] : (unsigned long)i;
76 return count;
77 } /* make_list_from_caps32 */