SHARE
TWEET

Compile-time table for find first set bit index

a guest Jul 22nd, 2011 288 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define b4(x)  x, x, x, x
  2. #define b8(x)  b4(x), b4(x)
  3. #define b16(x) b8(x), b8(x)
  4. #define b32(x) b16(x), b16(x)
  5. #define b64(x) b32(x), b32(x)
  6.  
  7. #define bi2(x) 1+x, x, x
  8. #define bi4(x) bi2(2+x), b4(1+x), b8(0+x)
  9. #define bi8(x) bi4(4+x), b8(1+x), b16(0+x)
  10. #define bi16(x) bi8(8+x), b16(1+x), b32(0+x)
  11. #define bi32(x) bi16(16+x), b32(1+x), b64(0+x)
  12.  
  13. #define bim(d) {-1, bi##d(0)}
  14.  
  15.  
  16. 00 -1
  17. 01 1
  18. 10 0
  19. 11 0
  20. mas2 = bim(2)
  21.  
  22. 0000 -1
  23. 0001 3
  24. 0010 2
  25. 0011 2
  26. 0100 1
  27. 0101 1
  28. 0110 1
  29. 0111 1
  30. 1000 0
  31. 1001 0
  32. 1010 0
  33. 1011 0
  34. 1100 0
  35. 1101 0
  36. 1110 0
  37. 1111 0
  38. mas4 = bim(4)
  39.  
  40. mas8 = bim(8)
  41.  
  42. mas16 = bim(16)
  43.  
  44. mas32 = bim(32)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top