source: trunk/Softwares/MiBench/src/c/bitcount-bitcnt_1.c @ 131

Last change on this file since 131 was 117, checked in by rosiere, 15 years ago

1) Platforms : add new organization for test
2) Load_Store_Unit : add array to count nb_check in store_queue
3) Issue_queue and Core_Glue : rewrite the issue network
4) Special_Register_Unit : add reset value to register CID
5) Softwares : add multicontext test
6) Softwares : add SPECINT
7) Softwares : add MiBench?
7) Read_queue : inhib access for r0
8) Change Core_Glue (network) - dont yet support priority and load balancing scheme

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 770 bytes
Line 
1/* +++Date last modified: 05-Jul-1997 */
2
3/*
4**  Bit counter by Ratko Tomic
5*/
6
7#include "bitcount-bitops.h"
8
9int CDECL bit_count(long x)
10{
11        int n = 0;
12/*
13** The loop will execute once for each bit of x set, this is in average
14** twice as fast as the shift/test method.
15*/
16        if (x) do
17              n++;
18        while (0 != (x = x&(x-1))) ;
19        return(n);
20}
21
22#ifdef TEST
23
24#include <stdlib.h>
25#include "snip_str.h"               /* For plural_text() macro    */
26
27main(int argc, char *argv[])
28{
29      long n;
30
31      while(--argc)
32      {
33            int i;
34
35            n = atol(*++argv);
36            i = bit_count(n);
37            printf("%ld contains %d bit%s set\n",
38                  n, i, plural_text(i));
39      }
40      return 0;
41}
42
43#endif /* TEST */
Note: See TracBrowser for help on using the repository browser.