gmime r1500 - in trunk: . gmime
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1500 - in trunk: . gmime
- Date: Sun, 2 Nov 2008 03:29:11 +0000 (UTC)
Author: fejj
Date: Sun Nov 2 03:29:11 2008
New Revision: 1500
URL: http://svn.gnome.org/viewvc/gmime?rev=1500&view=rev
Log:
2008-11-01 Jeffrey Stedfast <fejj novell com>
* gmime/gmime-parser.c (nearest_pow): Implement using asm on i386
- this code path isn't normally built, but it's fun to
micro-optimize anyway ;-)
* gmime/gmime-gpg-context.c (status_backup): Use next_alloc_size()
macro - same as gmime-parser.c
Modified:
trunk/ChangeLog
trunk/gmime/gmime-gpg-context.c
trunk/gmime/gmime-parser.c
Modified: trunk/gmime/gmime-gpg-context.c
==============================================================================
--- trunk/gmime/gmime-gpg-context.c (original)
+++ trunk/gmime/gmime-gpg-context.c Sun Nov 2 03:29:11 2008
@@ -1180,27 +1180,49 @@
return 0;
}
-static size_t
+#ifdef ALLOC_NEAREST_POW2
+static inline size_t
nearest_pow (size_t num)
{
- size_t n = num > 0 ? num - 1 : 0;
+ size_t n;
+ if (num == 0)
+ return 0;
+
+ n = num - 1;
+#if defined (__GNUC__) && defined (__i386__)
+ __asm__("bsrl %1,%0\n\t"
+ "jnz 1f\n\t"
+ "movl $-1,%0\n"
+ "1:" : "=r" (n) : "rm" (n));
+ n = (1 << (n + 1));
+#else
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
+#endif
return n;
}
+#define next_alloc_size(n) nearest_pow (n)
+#else
+static inline size_t
+next_alloc_size (size_t n)
+{
+ return ((n + 63) / 64) * 64;
+}
+#endif
+
#define status_backup(gpg, start, len) G_STMT_START { \
if (gpg->statusleft <= len) { \
size_t slen, soff; \
\
soff = gpg->statusptr - gpg->statusbuf; \
- slen = nearest_pow (soff + len + 1); \
+ slen = next_alloc_size (soff + len + 1); \
\
gpg->statusbuf = g_realloc (gpg->statusbuf, slen); \
gpg->statusptr = gpg->statusbuf + soff; \
Modified: trunk/gmime/gmime-parser.c
==============================================================================
--- trunk/gmime/gmime-parser.c (original)
+++ trunk/gmime/gmime-parser.c Sun Nov 2 03:29:11 2008
@@ -764,14 +764,26 @@
static inline size_t
nearest_pow (size_t num)
{
- size_t n = num > 0 ? num - 1 : 0;
+ size_t n;
+ if (num == 0)
+ return 0;
+
+ n = num - 1;
+#if defined (__GNUC__) && defined (__i386__)
+ __asm__("bsrl %1,%0\n\t"
+ "jnz 1f\n\t"
+ "movl $-1,%0\n"
+ "1:" : "=r" (n) : "rm" (n));
+ n = (1 << (n + 1));
+#else
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
+#endif
return n;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]