[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft-devel] assembler or builtin?
From: |
Werner LEMBERG |
Subject: |
Re: [ft-devel] assembler or builtin? |
Date: |
Sat, 12 Jul 2014 16:58:28 +0900 (JST) |
> The proposed patch is attached. It utilizes gcc builtins to optimize
> FT_MSB. FT_CONFIG_OPTION_NO_ASSEMBLER will disable it if necessary.
> Please comment.
LGTM. I suggest the slightly modified patch as attached.
Werner
diff --git a/builds/unix/ftconfig.in b/builds/unix/ftconfig.in
index 2cf6708..f22867c 100644
--- a/builds/unix/ftconfig.in
+++ b/builds/unix/ftconfig.in
@@ -569,6 +569,22 @@ FT_BEGIN_HEADER
#endif /* __GNUC__ && __x86_64__ */
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 4 ) )
+
+#if FT_SIZEOF_INT == 4
+
+#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clz( x ) )
+
+#elif FT_SIZEOF_LONG == 4
+
+#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clzl( x ) )
+
+#endif
+
+#endif
+#endif /* __GNUC__ */
+
#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
diff --git a/include/config/ftconfig.h b/include/config/ftconfig.h
index d98a311..98cccc5 100644
--- a/include/config/ftconfig.h
+++ b/include/config/ftconfig.h
@@ -536,6 +536,22 @@ FT_BEGIN_HEADER
#endif /* __GNUC__ && __x86_64__ */
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 4 ) )
+
+#if FT_SIZEOF_INT == (32 / FT_CHAR_BIT)
+
+#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clz( x ) )
+
+#elif FT_SIZEOF_LONG == (32 / FT_CHAR_BIT)
+
+#define FT_MSB_BUILTIN( x ) ( 31 - __builtin_clzl( x ) )
+
+#endif
+
+#endif
+#endif /* __GNUC__ */
+
#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index 2216880..09168bc 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -103,6 +103,12 @@
FT_BASE_DEF ( FT_Int )
FT_MSB( FT_UInt32 z )
{
+#ifdef FT_MSB_BUILTIN
+
+ return FT_MSB_BUILTIN( z );
+
+#else
+
FT_Int shift = 0;
/* determine msb bit index in `shift' */
@@ -133,6 +139,8 @@
}
return shift;
+
+#endif /* FT_MSB_BUILTIN */
}