]> git.saurik.com Git - apple/xnu.git/blobdiff - libkern/mkext.c
xnu-1699.22.81.tar.gz
[apple/xnu.git] / libkern / mkext.c
index e1fc062e1853cf35a00b2b837b5c4958ece649d8..86238fc35a48b39f2f39c26af44379668f16434c 100644 (file)
  * 
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
+#include <stdint.h> // For uintptr_t.
 #include <string.h>
 #include <libkern/mkext.h>
 
+
 #define BASE 65521L /* largest prime smaller than 65536 */
-#define NMAX 5000  
-// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
+#define NMAX 5552  // the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
 
 #define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
 #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
@@ -45,6 +46,23 @@ mkext_adler32(uint8_t *buf, int32_t len)
     unsigned long s2 = 0; // (adler >> 16) & 0xffff;
     int k;
 
+#if defined _ARM_ARCH_6
+
+       /* align buf to 16-byte boundary */
+    while ((((uintptr_t)buf)&15)&&(len>0)) { /* not on a 16-byte boundary */
+        len--;
+        s1 += *buf++;
+        s2 += s1;
+        if (s1 >= BASE) s1 -= BASE;
+    }
+       s2 %= BASE;
+
+       if (len>=16) {
+               return adler32_vec(s1, s2, buf, len);
+       }
+
+#endif
+
     while (len > 0) {
         k = len < NMAX ? len : NMAX;
         len -= k;