ffs.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * ffs function
  3. *
  4. * Copyright 2004 Hans Leidekker
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "config.h"
  21. #include "wine/port.h"
  22. #ifndef HAVE_FFS
  23. int ffs( int x )
  24. {
  25. unsigned int y = (unsigned int)x;
  26. if (y & 0x00000001) return 1;
  27. if (y & 0x00000002) return 2;
  28. if (y & 0x00000004) return 3;
  29. if (y & 0x00000008) return 4;
  30. if (y & 0x00000010) return 5;
  31. if (y & 0x00000020) return 6;
  32. if (y & 0x00000040) return 7;
  33. if (y & 0x00000080) return 8;
  34. if (y & 0x00000100) return 9;
  35. if (y & 0x00000200) return 10;
  36. if (y & 0x00000400) return 11;
  37. if (y & 0x00000800) return 12;
  38. if (y & 0x00001000) return 13;
  39. if (y & 0x00002000) return 14;
  40. if (y & 0x00004000) return 15;
  41. if (y & 0x00008000) return 16;
  42. if (y & 0x00010000) return 17;
  43. if (y & 0x00020000) return 18;
  44. if (y & 0x00040000) return 19;
  45. if (y & 0x00080000) return 20;
  46. if (y & 0x00100000) return 21;
  47. if (y & 0x00200000) return 22;
  48. if (y & 0x00400000) return 23;
  49. if (y & 0x00800000) return 24;
  50. if (y & 0x01000000) return 25;
  51. if (y & 0x02000000) return 26;
  52. if (y & 0x04000000) return 27;
  53. if (y & 0x08000000) return 28;
  54. if (y & 0x10000000) return 29;
  55. if (y & 0x20000000) return 30;
  56. if (y & 0x40000000) return 31;
  57. if (y & 0x80000000) return 32;
  58. return 0;
  59. }
  60. #endif /* HAVE_FFS */