[Tux3] Question about 212c59f7565f

OGAWA Hirofumi hirofumi at mail.parknet.co.jp
Tue Aug 4 10:54:49 PDT 2009


Michael Pattrick <mpattrick at rhinovirus.org> writes:

> Oh yes, you're right, I guess sizeof is calculated after the
> preprocessor is done...
>
> The following should be portable:
> #if LONG_MAX == LLONG_MAX
>
> Although, it is a tad less apparent what it is doing.
>
> GCC also offers __WORDSIZE == 64 but I dont think anyone else does.

Maybe, I found a bit better way. SuSv3 seems to define LONG_BIT in
limits.h.  If it's not portable enough, I hope we can find again :)

Thanks.
-- 
OGAWA Hirofumi <hirofumi at mail.parknet.co.jp>



diff -puN user/Makefile~utility-cleanup user/Makefile
--- tux3/user/Makefile~utility-cleanup	2009-08-05 02:48:24.000000000 +0900
+++ tux3-hirofumi/user/Makefile	2009-08-05 02:48:24.000000000 +0900
@@ -40,7 +40,7 @@ binaries = $(testbin) $(tux3bin) $(fuseb
 tuxdeps		= Makefile trace.h kernel/trace.h
 diskiodeps	= diskio.c diskio.h
 bufferdeps	= buffer.c buffer.h diskio.h err.h list.h
-utilitydeps	= $(bufferdeps) $(diskiodeps) utility.c
+utilitydeps	= $(bufferdeps) $(diskiodeps) utility.c utility.h
 basedeps	= $(tuxdeps) err.h list.h buffer.h diskio.h tux3.h \
 	kernel/tux3.h hexdump.c lockdebug.h
 ballocdeps	= kernel/balloc.c
diff -puN user/utility.h~utility-cleanup user/utility.h
--- tux3/user/utility.h~utility-cleanup	2009-08-05 02:48:24.000000000 +0900
+++ tux3-hirofumi/user/utility.h	2009-08-05 02:48:24.000000000 +0900
@@ -3,7 +3,7 @@
 
 #include <limits.h>
 
-#define BITS_PER_LONG		(sizeof(unsigned long) * CHAR_BIT)
+#define BITS_PER_LONG		LONG_BIT	/* xopen define this */
 #define BITOP_WORD(nr)		((nr) / BITS_PER_LONG)
 #define ffz(x)			__ffs(~(x))
 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
@@ -19,11 +19,12 @@ static __always_inline unsigned long __f
 {
 	int num = 0;
 
-	if (BITS_PER_LONG == 64 && !(word & 0xffffffff)) {
+#if BITS_PER_LONG == 64
+	if ((word & 0xffffffff) == 0) {
 		num += 32;
-		word >>= 16; /* work around idiotic gcc warning */
-		word >>= 16; /* work around idiotic gcc warning */
+		word >>= 32;
 	}
+#endif
 	if ((word & 0xffff) == 0) {
 		num += 16;
 		word >>= 16;
_

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list