[Spice-commits] 5 commits - common/log.c common/marshaller.c common/marshaller.h common/quic.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed Jan 27 10:39:38 PST 2016


 common/log.c        |    2 +-
 common/marshaller.c |    7 +++++--
 common/marshaller.h |    2 +-
 common/quic.c       |   46 +++++++---------------------------------------
 4 files changed, 14 insertions(+), 43 deletions(-)

New commits:
commit 75cb2701d33bf49887e0f9175b2c42e56047e7e7
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu May 7 18:58:11 2015 +0100

    Use code to compute a bit mask
    
    Code is in the slow path, this reduce space needed for data+code.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index a32a530..88cf143 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -194,16 +194,7 @@ static const unsigned long int bppmask[33] = {
     0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff /* [32] */
 };
 
-static const unsigned int bitat[32] = {
-    0x00000001, 0x00000002, 0x00000004, 0x00000008,
-    0x00000010, 0x00000020, 0x00000040, 0x00000080,
-    0x00000100, 0x00000200, 0x00000400, 0x00000800,
-    0x00001000, 0x00002000, 0x00004000, 0x00008000,
-    0x00010000, 0x00020000, 0x00040000, 0x00080000,
-    0x00100000, 0x00200000, 0x00400000, 0x00800000,
-    0x01000000, 0x02000000, 0x04000000, 0x08000000,
-    0x10000000, 0x20000000, 0x40000000, 0x80000000 /* [31]*/
-};
+#define bitat(n) (1u<<(n))
 
 
 #define TABRAND_TABSIZE 256
@@ -371,7 +362,7 @@ static void golomb_coding_slow(QuicFamily *family, const BYTE n, const unsigned
                                unsigned int * const codewordlen)
 {
     if (n < family->nGRcodewords[l]) {
-        (*codeword) = bitat[l] | (n & bppmask[l]);
+        (*codeword) = bitat(l) | (n & bppmask[l]);
         (*codewordlen) = (n >> l) + l + 1;
     } else {
         (*codeword) = n - family->nGRcodewords[l];
commit 580adf7c36d07bc9cb8bcb4092fea3dea3ec361c
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu May 7 18:56:40 2015 +0100

    Avoid to call ceil_log_2 twice with same value
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index 0e6c948..a32a530 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -394,9 +394,9 @@ static void family_init(QuicFamily *family, int bpc, int limit)
         altcodewords = bppmask[bpc] + 1 - (altprefixlen << l);
 
         family->nGRcodewords[l] = (altprefixlen << l);
-        family->notGRcwlen[l] = altprefixlen + ceil_log_2(altcodewords);
-        family->notGRprefixmask[l] = bppmask[32 - altprefixlen]; /* needed for decoding only */
         family->notGRsuffixlen[l] = ceil_log_2(altcodewords); /* needed for decoding only */
+        family->notGRcwlen[l] = altprefixlen + family->notGRsuffixlen[l];
+        family->notGRprefixmask[l] = bppmask[32 - altprefixlen]; /* needed for decoding only */
 
         for (b = 0; b < 256; b++) {
             unsigned int code, len;
commit 6e04b9475107d70e44df51bbb2fa05a12e06d6c3
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu May 7 18:56:04 2015 +0100

    Constification
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index 0c5fc1c..0e6c948 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -540,7 +540,7 @@ static inline void encode_ones(Encoder *encoder, unsigned int n)
 
 #define MELCSTATES 32 /* number of melcode states */
 
-static int J[MELCSTATES] = {
+static const int J[MELCSTATES] = {
     0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7,
     7, 8, 9, 10, 11, 12, 13, 14, 15
 };
commit daf406a1799d4a83dc12f88b2ba717383d3c51a9
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu May 7 18:55:51 2015 +0100

    zeroLUT has same content of lzeroes
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/quic.c b/common/quic.c
index a9bd215..0c5fc1c 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -540,31 +540,11 @@ static inline void encode_ones(Encoder *encoder, unsigned int n)
 
 #define MELCSTATES 32 /* number of melcode states */
 
-static int zeroLUT[256]; /* table to find out number of leading zeros */
-
 static int J[MELCSTATES] = {
     0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7,
     7, 8, 9, 10, 11, 12, 13, 14, 15
 };
 
-/* creates the bit counting look-up table. */
-static void init_zeroLUT(void)
-{
-    int i, j, k, l;
-
-    j = k = 1;
-    l = 8;
-    for (i = 0; i < 256; ++i) {
-        zeroLUT[i] = l;
-        --k;
-        if (k == 0) {
-            k = j;
-            --l;
-            j *= 2;
-        }
-    }
-}
-
 static void encoder_init_rle(CommonState *state)
 {
     state->melcstate = 0;
@@ -645,7 +625,7 @@ static int decode_run(Encoder *encoder)
 
     do {
         register int temp, hits;
-        temp = zeroLUT[(BYTE)(~(encoder->io_word >> 24))];/* number of leading ones in the
+        temp = lzeroes[(BYTE)(~(encoder->io_word >> 24))];/* number of leading ones in the
                                                                       input stream, up to 8 */
         for (hits = 1; hits <= temp; hits++) {
             runlen += encoder->rgb_state.melcorder;
@@ -686,7 +666,7 @@ static int decode_channel_run(Encoder *encoder, Channel *channel)
 
     do {
         register int temp, hits;
-        temp = zeroLUT[(BYTE)(~(encoder->io_word >> 24))];/* number of leading ones in the
+        temp = lzeroes[(BYTE)(~(encoder->io_word >> 24))];/* number of leading ones in the
                                                                       input stream, up to 8 */
         for (hits = 1; hits <= temp; hits++) {
             runlen += channel->state.melcorder;
@@ -1709,7 +1689,4 @@ void quic_init(void)
 
     family_init(&family_8bpc, 8, DEFmaxclen);
     family_init(&family_5bpc, 5, DEFmaxclen);
-#if defined(RLE) && defined(RLE_STAT)
-    init_zeroLUT();
-#endif
 }
commit 07b3150cb1c3a028a0b2631f6a1aa6605372a99a
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Aug 17 11:38:08 2015 +0100

    common: constify some declarations
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/log.c b/common/log.c
index 607aa82..a9bbebc 100644
--- a/common/log.c
+++ b/common/log.c
@@ -43,7 +43,7 @@ static int abort_level = -1;
 
 static GLogLevelFlags spice_log_level_to_glib(SpiceLogLevel level)
 {
-    static GLogLevelFlags glib_levels[] = {
+    static const GLogLevelFlags glib_levels[] = {
         [ SPICE_LOG_LEVEL_ERROR ] = G_LOG_LEVEL_ERROR,
         [ SPICE_LOG_LEVEL_CRITICAL ] = G_LOG_LEVEL_CRITICAL,
         [ SPICE_LOG_LEVEL_WARNING ] = G_LOG_LEVEL_WARNING,
diff --git a/common/marshaller.c b/common/marshaller.c
index c967371..c1d208e 100644
--- a/common/marshaller.c
+++ b/common/marshaller.c
@@ -347,9 +347,12 @@ uint8_t *spice_marshaller_add(SpiceMarshaller *m, const uint8_t *data, size_t si
     return ptr;
 }
 
-uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, uint8_t *data, size_t size)
+uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, const uint8_t *data, size_t size)
 {
-    return spice_marshaller_add_ref_full(m, data, size, NULL, NULL);
+    /* the cast to no-const here is safe as data is used for writing only if
+     * free_data pointer is not NULL
+     */
+    return spice_marshaller_add_ref_full(m, (uint8_t *) data, size, NULL, NULL);
 }
 
 void spice_marshaller_add_ref_chunks(SpiceMarshaller *m, SpiceChunks *chunks)
diff --git a/common/marshaller.h b/common/marshaller.h
index b698b69..9f9c3ad 100644
--- a/common/marshaller.h
+++ b/common/marshaller.h
@@ -37,7 +37,7 @@ void spice_marshaller_destroy(SpiceMarshaller *m);
 uint8_t *spice_marshaller_reserve_space(SpiceMarshaller *m, size_t size);
 void spice_marshaller_unreserve_space(SpiceMarshaller *m, size_t size);
 uint8_t *spice_marshaller_add(SpiceMarshaller *m, const uint8_t *data, size_t size);
-uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, uint8_t *data, size_t size);
+uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, const uint8_t *data, size_t size);
 uint8_t *spice_marshaller_add_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
                                        spice_marshaller_item_free_func free_data, void *opaque);
 void     spice_marshaller_add_ref_chunks(SpiceMarshaller *m, SpiceChunks *chunks);


More information about the Spice-commits mailing list