source: Deliverables/D4.1/GCC/FastRoundup.c @ 557

Last change on this file since 557 was 169, checked in by mulligan, 9 years ago

Latest test C file: fast roundup to closest power of two.

File size: 269 bytes
Line 
1/* For 16 bit unsigned integers. */
2unsigned int round_up(unsigned int v)
3{
4  v--;
5  v |= v >> 1;
6  v |= v >> 2;
7  v |= v >> 4;
8  v |= v >> 8;
9  v++;
10  return v;
11}
12
13int main()
14{
15  unsigned int f;
16  f = round_up(125);
17  if(f == 128)
18    return 5;
19  else
20    return 7;
21}
Note: See TracBrowser for help on using the repository browser.