This is an automated email from Gerrit.

Andrey Smirnov ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/2105

-- gerrit

commit eeba70e53f8016039080b39e9255a3945090616a
Author: Andrey Smirnov <[email protected]>
Date:   Thu Mar 20 20:03:28 2014 -0700

    src/helper/binarybuffer.h: Add 16 bit version of the helper functions
    
    Change-Id: I117e567ec0f8a2814112dc61c00814db14cb1e7b
    Signed-off-by: Andrey Smirnov <[email protected]>

diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h
index 9c20bcd..5489ec0 100644
--- a/src/helper/binarybuffer.h
+++ b/src/helper/binarybuffer.h
@@ -30,6 +30,34 @@
  * Support functions to access arbitrary bits in a byte array
  */
 
+
+/**
+ * Sets @c num bits in @c _buffer, starting at the @c first bit,
+ * using the bits in @c value.  This routine fast-paths writes
+ * of little-endian, byte-aligned, 16-bit words.
+ * @param _buffer The buffer whose bits will be set.
+ * @param first The bit offset in @c _buffer to start writing (0-15).
+ * @param num The number of bits from @c value to copy (1-16).
+ * @param value Up to 16 bits that will be copied to _buffer.
+ */
+static inline void buf_set_u16(void *_buffer,
+       unsigned first, unsigned num, uint32_t value)
+{
+       uint8_t *buffer = _buffer;
+
+       if ((num == 16) && (first == 0)) {
+               buffer[1] = (value >> 8) & 0xff;
+               buffer[0] = (value >> 0) & 0xff;
+       } else {
+               for (unsigned i = first; i < first + num; i++) {
+                       if (((value >> (i - first)) & 1) == 1)
+                               buffer[i / 8] |= 1 << (i % 8);
+                       else
+                               buffer[i / 8] &= ~(1 << (i % 8));
+               }
+       }
+}
+
 /**
  * Sets @c num bits in @c _buffer, starting at the @c first bit,
  * using the bits in @c value.  This routine fast-paths writes
@@ -99,6 +127,33 @@ static inline void buf_set_u64(void *_buffer,
 
 /**
  * Retrieves @c num bits from @c _buffer, starting at the @c first bit,
+ * returning the bits in a 16-bit word.  This routine fast-paths reads
+ * of little-endian, byte-aligned, 16-bit words.
+ * @param _buffer The buffer whose bits will be read.
+ * @param first The bit offset in @c _buffer to start reading (0-15).
+ * @param num The number of bits from @c _buffer to read (1-16).
+ * @returns Up to 32-bits that were read from @c _buffer.
+ */
+static inline uint16_t buf_get_u16(const void *_buffer,
+       unsigned first, unsigned num)
+{
+       const uint8_t *buffer = _buffer;
+
+       if ((num == 16) && (first == 0)) {
+               return ((uint32_t)buffer[1]) << 8 |
+                       ((uint32_t)buffer[0]) << 0;
+       } else {
+               uint16_t result = 0;
+               for (unsigned i = first; i < first + num; i++) {
+                       if (((buffer[i / 8] >> (i % 8)) & 1) == 1)
+                               result |= 1 << (i - first);
+               }
+               return result;
+       }
+}
+
+/**
+ * Retrieves @c num bits from @c _buffer, starting at the @c first bit,
  * returning the bits in a 32-bit word.  This routine fast-paths reads
  * of little-endian, byte-aligned, 32-bit words.
  * @param _buffer The buffer whose bits will be read.

-- 

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to