Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Oct 2015 09:37:34 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r289683 - head/sys/ofed/include/linux
Message-ID:  <201510210937.t9L9bYL6005066@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Oct 21 09:37:34 2015
New Revision: 289683
URL: https://svnweb.freebsd.org/changeset/base/289683

Log:
  Remove all comments deriving from Linux.
  Minor rework of ilog2() function.
  
  Suggested by:	emaste @
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/ofed/include/linux/log2.h

Modified: head/sys/ofed/include/linux/log2.h
==============================================================================
--- head/sys/ofed/include/linux/log2.h	Wed Oct 21 08:51:49 2015	(r289682)
+++ head/sys/ofed/include/linux/log2.h	Wed Oct 21 09:37:34 2015	(r289683)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -53,50 +53,10 @@ rounddown_pow_of_two(unsigned long x)
         return (1UL << (flsl(x) - 1));
 }
 
-
-/*
- * deal with unrepresentable constant logarithms
- */
-extern __attribute__((const, noreturn))
-int ____ilog2_NaN(void);
-
-/*
- * non-constant log of base 2 calculators
- * - the arch may override these in asm/bitops.h if they can be implemented
- *   more efficiently than using fls() and fls64()
- * - the arch is not required to handle n==0 if implementing the fallback
- */
-#ifndef CONFIG_ARCH_HAS_ILOG2_U32
-static inline __attribute__((const))
-int __ilog2_u32(u32 n)
-{
-	return flsl(n) - 1;
-}
-#endif
-
-#ifndef CONFIG_ARCH_HAS_ILOG2_U64
-static inline __attribute__((const))
-int __ilog2_u64(u64 n)
-{
-	return flsl(n) - 1;
-}
-#endif
-
-
-/**
- * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value
- * @n - parameter
- *
- * constant-capable log of base 2 calculation
- * - this can be used to initialise global variables from constant data, hence
- *   the massive ternary operator construction
- *
- * selects the appropriately-sized optimised version depending on sizeof(n)
- */
-#define ilog2(n)				\
+#define	ilog2(n)				\
 (						\
 	__builtin_constant_p(n) ? (		\
-		(n) < 1 ? ____ilog2_NaN() :	\
+		(n) < 1 ? -1 :			\
 		(n) & (1ULL << 63) ? 63 :	\
 		(n) & (1ULL << 62) ? 62 :	\
 		(n) & (1ULL << 61) ? 61 :	\
@@ -161,12 +121,10 @@ int __ilog2_u64(u64 n)
 		(n) & (1ULL <<  2) ?  2 :	\
 		(n) & (1ULL <<  1) ?  1 :	\
 		(n) & (1ULL <<  0) ?  0 :	\
-		____ilog2_NaN()			\
-				   ) :		\
+		-1) :				\
 	(sizeof(n) <= 4) ?			\
-	__ilog2_u32(n) :			\
-	__ilog2_u64(n)				\
- )
+	fls((u32)(n)) - 1 : flsll((u64)(n)) - 1	\
+)
 
 #define	order_base_2(x) ilog2(roundup_pow_of_two(x))
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510210937.t9L9bYL6005066>