Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/include Use __builtin_constant_p so that we onl...



details:   https://anonhg.NetBSD.org/src/rev/1e72c3bce891
branches:  trunk
changeset: 780132:1e72c3bce891
user:      matt <matt%NetBSD.org@localhost>
date:      Thu Jul 12 17:23:02 2012 +0000

description:
Use __builtin_constant_p so that we only emit asm when
the expression is not a constant.

diffstat:

 sys/arch/arm/include/byte_swap.h |  37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diffs (67 lines):

diff -r e84f264325bc -r 1e72c3bce891 sys/arch/arm/include/byte_swap.h
--- a/sys/arch/arm/include/byte_swap.h  Thu Jul 12 17:20:20 2012 +0000
+++ b/sys/arch/arm/include/byte_swap.h  Thu Jul 12 17:23:02 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: byte_swap.h,v 1.8 2008/04/28 20:23:14 martin Exp $     */
+/*     $NetBSD: byte_swap.h,v 1.9 2012/07/12 17:23:02 matt Exp $       */
 
 /*-
  * Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
@@ -40,16 +40,20 @@
 static __inline uint32_t
 __byte_swap_u32_variable(uint32_t v)
 {
+       uint32_t t1;
+
 #ifdef _ARM_ARCH_6
-       __asm("rev\t%0, %1" : "=r" (v) : "0" (v));
-#else
-       uint32_t t1;
+       if (!__builtin_constant_p(v)) {
+               __asm("rev\t%0, %1" : "=r" (v) : "0" (v));
+               return v;
+       }
+#endif
 
        t1 = v ^ ((v << 16) | (v >> 16));
        t1 &= 0xff00ffffU;
        v = (v >> 8) | (v << 24);
        v ^= (t1 >> 8);
-#endif
+
        return (v);
 }
 
@@ -59,18 +63,23 @@
 {
 
 #ifdef _ARM_ARCH_6
-       __asm("rev16\t%0, %1" : "=r" (v) : "0" (v));
+       if (!__builtin_constant_p(v)) {
+               __asm("rev16\t%0, %1" : "=r" (v) : "0" (v));
+               return v;
+       }
 #elif !defined(__thumb__)
-       __asm volatile(
-               "mov    %0, %1, ror #8\n"
-               "orr    %0, %0, %0, lsr #16\n"
-               "bic    %0, %0, %0, lsl #16"
-       : "=r" (v)
-       : "0" (v));
-#else
+       if (!__builtin_constant_p(v)) {
+               __asm volatile(
+                       "mov    %0, %1, ror #8\n"
+                       "orr    %0, %0, %0, lsr #16\n"
+                       "bic    %0, %0, %0, lsl #16"
+               : "=&r" (v)
+               : "0" (v));
+               return (v);
+       }
+#endif
        v &= 0xffff;
        v = (v >> 8) | (v << 8);
-#endif
 
        return (v);
 }



Home | Main Index | Thread Index | Old Index