Upcoming commits will add new users.
---
 lib/nx-match.c |   54 +-----------------------------------------------------
 lib/util.c     |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/util.h     |    3 +++
 3 files changed, 56 insertions(+), 53 deletions(-)

diff --git a/lib/nx-match.c b/lib/nx-match.c
index e8aee53..e55680c 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -29,6 +29,7 @@
 #include "openflow/nicira-ext.h"
 #include "packets.h"
 #include "unaligned.h"
+#include "util.h"
 #include "vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(nx_match);
@@ -970,59 +971,6 @@ nxm_check_reg_load(const struct nx_action_reg_load *action,
 
 /* nxm_execute_reg_move(), nxm_execute_reg_load(). */
 
-static void
-bitwise_copy(const void *src_, unsigned int src_len, unsigned int src_ofs,
-             void *dst_, unsigned int dst_len, unsigned int dst_ofs,
-             unsigned int n_bits)
-{
-    const uint8_t *src = src_;
-    uint8_t *dst = dst_;
-
-    src += src_len - (src_ofs / 8 + 1);
-    src_ofs %= 8;
-
-    dst += dst_len - (dst_ofs / 8 + 1);
-    dst_ofs %= 8;
-
-    if (src_ofs == 0 && dst_ofs == 0) {
-        unsigned int n_bytes = n_bits / 8;
-        if (n_bytes) {
-            dst -= n_bytes - 1;
-            src -= n_bytes - 1;
-            memcpy(dst, src, n_bytes);
-
-            n_bits %= 8;
-            src--;
-            dst--;
-        }
-        if (n_bits) {
-            uint8_t mask = (1 << n_bits) - 1;
-            *dst = (*dst & ~mask) | (*src & mask);
-        }
-    } else {
-        while (n_bits > 0) {
-            unsigned int max_copy = 8 - MAX(src_ofs, dst_ofs);
-            unsigned int chunk = MIN(n_bits, max_copy);
-            uint8_t mask = ((1 << chunk) - 1) << dst_ofs;
-
-            *dst &= ~mask;
-            *dst |= ((*src >> src_ofs) << dst_ofs) & mask;
-
-            src_ofs += chunk;
-            if (src_ofs == 8) {
-                src--;
-                src_ofs = 0;
-            }
-            dst_ofs += chunk;
-            if (dst_ofs == 8) {
-                dst--;
-                dst_ofs = 0;
-            }
-            n_bits -= chunk;
-        }
-    }
-}
-
 /* Returns the value of the NXM field corresponding to 'header' at 'ofs_nbits'
  * in 'flow'. */
 uint64_t
diff --git a/lib/util.c b/lib/util.c
index e02f59f..69bcd26 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -725,3 +725,55 @@ is_all_ones(const uint8_t *p, size_t n)
     return true;
 }
 
+void
+bitwise_copy(const void *src_, unsigned int src_len, unsigned int src_ofs,
+             void *dst_, unsigned int dst_len, unsigned int dst_ofs,
+             unsigned int n_bits)
+{
+    const uint8_t *src = src_;
+    uint8_t *dst = dst_;
+
+    src += src_len - (src_ofs / 8 + 1);
+    src_ofs %= 8;
+
+    dst += dst_len - (dst_ofs / 8 + 1);
+    dst_ofs %= 8;
+
+    if (src_ofs == 0 && dst_ofs == 0) {
+        unsigned int n_bytes = n_bits / 8;
+        if (n_bytes) {
+            dst -= n_bytes - 1;
+            src -= n_bytes - 1;
+            memcpy(dst, src, n_bytes);
+
+            n_bits %= 8;
+            src--;
+            dst--;
+        }
+        if (n_bits) {
+            uint8_t mask = (1 << n_bits) - 1;
+            *dst = (*dst & ~mask) | (*src & mask);
+        }
+    } else {
+        while (n_bits > 0) {
+            unsigned int max_copy = 8 - MAX(src_ofs, dst_ofs);
+            unsigned int chunk = MIN(n_bits, max_copy);
+            uint8_t mask = ((1 << chunk) - 1) << dst_ofs;
+
+            *dst &= ~mask;
+            *dst |= ((*src >> src_ofs) << dst_ofs) & mask;
+
+            src_ofs += chunk;
+            if (src_ofs == 8) {
+                src--;
+                src_ofs = 0;
+            }
+            dst_ofs += chunk;
+            if (dst_ofs == 8) {
+                dst--;
+                dst_ofs = 0;
+            }
+            n_bits -= chunk;
+        }
+    }
+}
diff --git a/lib/util.h b/lib/util.h
index 3113e8f..44606b2 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -213,6 +213,9 @@ int ctz(uint32_t);
 
 bool is_all_zeros(const uint8_t *, size_t);
 bool is_all_ones(const uint8_t *, size_t);
+void bitwise_copy(const void *src, unsigned int src_len, unsigned int src_ofs,
+                  void *dst, unsigned int dst_len, unsigned int dst_ofs,
+                  unsigned int n_bits);
 
 #ifdef  __cplusplus
 }
-- 
1.7.2.5

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to