1. 15 12月, 2016 1 次提交
  2. 17 1月, 2016 1 次提交
    • M
      include/linux/kernel.h: change abs() macro so it uses consistent return type · 8f57e4d9
      Michal Nazarewicz 提交于
      Rewrite abs() so that its return type does not depend on the
      architecture and no unexpected type conversion happen inside of it.  The
      only conversion is from unsigned to signed type.  char is left as a
      return type but treated as a signed type regradless of it's actual
      signedness.
      
      With the old version, int arguments were promoted to long and depending
      on architecture a long argument might result in s64 or long return type
      (which may or may not be the same).
      
      This came after some back and forth with Nicolas.  The current macro has
      different return type (for the same input type) depending on
      architecture which might be midly iritating.
      
      An alternative version would promote to int like so:
      
      	#define abs(x)	__abs_choose_expr(x, long long,			\
      			__abs_choose_expr(x, long,			\
      			__builtin_choose_expr(				\
      				sizeof(x) <= sizeof(int),		\
      				({ int __x = (x); __x<0?-__x:__x; }),	\
      				((void)0))))
      
      I have no preference but imagine Linus might.  :] Nicolas argument against
      is that promoting to int causes iconsistent behaviour:
      
      	int main(void) {
      		unsigned short a = 0, b = 1, c = a - b;
      		unsigned short d = abs(a - b);
      		unsigned short e = abs(c);
      		printf("%u %u\n", d, e);  // prints: 1 65535
      	}
      
      Then again, no sane person expects consistent behaviour from C integer
      arithmetic.  ;)
      
      Note:
      
        __builtin_types_compatible_p(unsigned char, char) is always false, and
        __builtin_types_compatible_p(signed char, char) is also always false.
      Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
      Reviewed-by: NNicolas Pitre <nico@linaro.org>
      Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
      Cc: Wey-Yi Guy <wey-yi.w.guy@intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      8f57e4d9
  3. 16 12月, 2015 1 次提交
  4. 02 12月, 2015 1 次提交
  5. 18 11月, 2015 1 次提交
  6. 13 5月, 2014 1 次提交
  7. 01 1月, 2014 1 次提交
  8. 27 5月, 2013 1 次提交
  9. 06 3月, 2013 1 次提交
  10. 24 1月, 2013 1 次提交
  11. 07 12月, 2012 1 次提交
  12. 06 6月, 2012 2 次提交
  13. 24 4月, 2012 1 次提交
  14. 18 4月, 2012 1 次提交
  15. 17 4月, 2012 1 次提交
  16. 13 4月, 2012 1 次提交
  17. 09 3月, 2012 1 次提交
  18. 08 3月, 2012 4 次提交
  19. 07 3月, 2012 2 次提交
  20. 18 2月, 2012 1 次提交
  21. 25 1月, 2012 1 次提交
  22. 07 1月, 2012 1 次提交
  23. 16 12月, 2011 1 次提交
  24. 09 12月, 2011 1 次提交
  25. 29 11月, 2011 2 次提交
  26. 26 11月, 2011 2 次提交
  27. 20 9月, 2011 1 次提交
  28. 30 8月, 2011 3 次提交
  29. 09 8月, 2011 1 次提交
  30. 21 7月, 2011 2 次提交