Explorar el Código

ARM: Use own lj_bswap(). Reduce min. req. version of GCC to 4.2.

Mike Pall hace 14 años
padre
commit
0b606061db
Se han modificado 3 ficheros con 30 adiciones y 4 borrados
  1. 2 2
      doc/install.html
  2. 5 1
      src/lj_arch.h
  3. 23 1
      src/lj_def.h

+ 2 - 2
doc/install.html

@@ -123,8 +123,8 @@ operating system, CPU and compilers:
 </tr>
 </tr>
 <tr class="odd">
 <tr class="odd">
 <td class="compatcpu">ARM</td>
 <td class="compatcpu">ARM</td>
-<td class="compatos">GCC 4.3+</td>
-<td class="compatos">GCC 4.3+</td>
+<td class="compatos">GCC 4.2+</td>
+<td class="compatos">GCC 4.2+</td>
 <td class="compatos compatno">&nbsp;</td>
 <td class="compatos compatno">&nbsp;</td>
 <td class="compatos compatno">&nbsp;</td>
 <td class="compatos compatno">&nbsp;</td>
 </tr>
 </tr>

+ 5 - 1
src/lj_arch.h

@@ -173,7 +173,11 @@
 #if __GNUC__ < 4
 #if __GNUC__ < 4
 #error "Need at least GCC 4.0 or newer"
 #error "Need at least GCC 4.0 or newer"
 #endif
 #endif
-#elif LJ_TARGET_ARM || LJ_TARGET_PPC
+#elif LJ_TARGET_ARM
+#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
+#error "Need at least GCC 4.2 or newer"
+#endif
+#elif LJ_TARGET_PPC
 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
 #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
 #error "Need at least GCC 4.3 or newer"
 #error "Need at least GCC 4.3 or newer"
 #endif
 #endif

+ 23 - 1
src/lj_def.h

@@ -131,7 +131,29 @@ static LJ_AINLINE uint32_t lj_fls(uint32_t x)
 #define lj_fls(x)	((uint32_t)(__builtin_clz(x)^31))
 #define lj_fls(x)	((uint32_t)(__builtin_clz(x)^31))
 #endif
 #endif
 
 
-#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
+#if defined(__arm__)
+static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
+{
+  uint32_t r;
+#if __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6T2__ || __ARM_ARCH_6Z__ ||\
+    __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__
+  __asm__("rev %0, %1" : "=r" (r) : "r" (x));
+  return r;
+#else
+#ifdef __thumb__
+  r = x ^ lj_ror(x, 16);
+#else
+  __asm__("eor %0, %1, %1, ror #16" : "=r" (r) : "r" (x));
+#endif
+  return ((r & 0xff00ffffu) >> 8) ^ lj_ror(x, 8);
+#endif
+}
+
+static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
+{
+  return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
+}
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
 static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
 {
 {
   return (uint32_t)__builtin_bswap32((int32_t)x);
   return (uint32_t)__builtin_bswap32((int32_t)x);