Hi Yoshifuji,

 /*
+ * find the first different bit between two addresses
+ * length of address must be a multiple of 32bits
+ */
+static inline int __ipv6_addr_diff(const void *token1, const void *token2, int 
addrlen)
+{
+       const __u32 *a1 = token1, *a2 = token2;
+       int i;
+
+       addrlen >>= 2;
+
+       for (i = 0; i < addrlen; i++) {
+               __u32 xb = a1[i] ^ a2[i];
+               if (xb) {
+                       int j = 31;
+
+                       xb = ntohl(xb);
+                       while ((xb & (1 << j)) == 0)
+                               j--;
+
+                       return (i * 32 + 31 - j);
+               }
+       }

I did a few performance measurements in userspace on this function like was done for ipv6_addr_equal() a year ago and found the following patch speeds it up a little since it avoids the exclusive-OR (which can be expensive) except when necessary. The line numbers are wrong since I couldn't get to your git:// through our firewall. I'll look at the other diffs more closely later.

Thanks,

-Brian
Signed-off-by: Brian Haley <[EMAIL PROTECTED]>

*** adiff.h     2005-11-08 16:32:00.000000000 -0500
--- bdiff.h     2005-11-08 16:32:47.000000000 -0500
***************
*** 6,13 ****
        addrlen >>= 2;
  
        for (i = 0; i < addrlen; i++) {
!               __u32 xb = a1[i] ^ a2[i];
!               if (xb) {
                        int j = 31;
  
                        xb = ntohl(xb);
--- 6,13 ----
        addrlen >>= 2;
  
        for (i = 0; i < addrlen; i++) {
!               if (a1[i] != a2[i]) {
!                       __u32 xb = a1[i] ^ a2[i];
                        int j = 31;
  
                        xb = ntohl(xb);

Reply via email to