You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strings.h 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _BITS_STRINGS_H
  2. #define _BITS_STRINGS_H
  3. FILE_LICENCE ( GPL2_OR_LATER );
  4. /**
  5. * Find last (i.e. most significant) set bit
  6. *
  7. * @v value Value
  8. * @ret msb Most significant bit set in value (LSB=1), or zero
  9. */
  10. static inline __attribute__ (( always_inline )) int __flsll ( long long value ){
  11. long long msb_minus_one;
  12. /* If the input value is zero, the BSR instruction returns
  13. * ZF=1 and leaves an undefined value in the output register.
  14. * Perform this check in C rather than asm so that it can be
  15. * omitted in cases where the compiler is able to prove that
  16. * the input is non-zero.
  17. */
  18. if ( value ) {
  19. __asm__ ( "bsrq %1, %0"
  20. : "=r" ( msb_minus_one )
  21. : "rm" ( value ) );
  22. return ( msb_minus_one + 1 );
  23. } else {
  24. return 0;
  25. }
  26. }
  27. /**
  28. * Find last (i.e. most significant) set bit
  29. *
  30. * @v value Value
  31. * @ret msb Most significant bit set in value (LSB=1), or zero
  32. */
  33. static inline __attribute__ (( always_inline )) int __flsl ( long value ) {
  34. return __flsll ( value );
  35. }
  36. #endif /* _BITS_STRINGS_H */