]> git.ozlabs.org Git - ccan/blob - ccan/ilog/_info
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / ilog / _info
1 /**
2  * ilog - Integer logarithm.
3  *
4  * ilog_32() and ilog_64() compute the minimum number of bits required to store
5  * an unsigned 32-bit or 64-bit value without any leading zero bits.
6  *
7  * This can also be thought of as the location of the highest set bit, with
8  * counting starting from one (so that 0 returns 0, 1 returns 1, and 2**31
9  * returns 32).
10  *
11  * When the value is known to be non-zero ilog32_nz() and ilog64_nz() can
12  * compile into as few as two instructions, one of which may get optimized out
13  * later.
14  *
15  * STATIC_ILOG_32 and STATIC_ILOG_64 allow computation on compile-time
16  * constants, so other compile-time constants can be derived from them.
17  *
18  * Example:
19  *  #include <stdio.h>
20  *  #include <limits.h>
21  *  #include <ccan/ilog/ilog.h>
22  *
23  *  int main(void){
24  *    int i;
25  *    printf("ilog32(0x%08X)=%i\n",0,ilog32(0));
26  *    for(i=1;i<=STATIC_ILOG_32(USHRT_MAX);i++){
27  *      uint32_t v;
28  *      v=(uint32_t)1U<<(i-1);
29  *      //Here we know v is non-zero, so we can use ilog32_nz().
30  *      printf("ilog32(0x%08X)=%i\n",v,ilog32_nz(v));
31  *    }
32  *    return 0;
33  *  }
34  *
35  * License: CC0 (Public domain)
36  * Author: Timothy B. Terriberry <tterribe@xiph.org>
37  */
38 #include "config.h"
39 #include <string.h>
40 #include <stdio.h>
41
42 int main(int _argc,const char *_argv[]){
43   /*Expect exactly one argument.*/
44   if(_argc!=2)return 1;
45   if(strcmp(_argv[1],"depends")==0){
46     printf("ccan/compiler\n");
47     return 0;
48   }
49   return 1;
50 }