changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: gs: avoid stupid shifts by casting to uint64_t

changeset 7191: 753613b3b8c4
parent 7190: 41fb44a3b2dc
child 7192: 4dc782a90f0b
author: cinap_lenrek@felloff.net
date: Fri, 03 May 2019 21:10:01 +0200
files: sys/src/cmd/gs/src/gdevm40.c sys/src/cmd/gs/src/gdevm48.c sys/src/cmd/gs/src/gdevm56.c sys/src/cmd/gs/src/gdevm64.c sys/src/cmd/gs/src/gxcht.c sys/src/cmd/gs/src/gxclrast.c
description: gs: avoid stupid shifts by casting to uint64_t
     1.1--- a/sys/src/cmd/gs/src/gdevm40.c
     1.2+++ b/sys/src/cmd/gs/src/gdevm40.c
     1.3@@ -62,7 +62,7 @@ mem_full_alpha_device("image40", 40, 0, 
     1.4 
     1.5 /* Unpack a color into its bytes. */
     1.6 #define declare_unpack_color(a, b, c, d, e, color)\
     1.7-	byte a = (byte)(color >> 32);\
     1.8+	byte a = (byte)((uint64_t)color >> 32);\
     1.9 	byte b = (byte)((uint)color >> 24);\
    1.10 	byte c = (byte)((uint)color >> 16);\
    1.11 	byte d = (byte)((uint)color >> 8);\
     2.1--- a/sys/src/cmd/gs/src/gdevm48.c
     2.2+++ b/sys/src/cmd/gs/src/gdevm48.c
     2.3@@ -62,8 +62,8 @@ mem_full_alpha_device("image48", 48, 0, 
     2.4 
     2.5 /* Unpack a color into its bytes. */
     2.6 #define declare_unpack_color(a, b, c, d, e, f, color)\
     2.7-	byte a = (byte)(color >> 40);\
     2.8-	byte b = (byte)(color >> 32);\
     2.9+	byte a = (byte)((uint64_t)color >> 40);\
    2.10+	byte b = (byte)((uint64_t)color >> 32);\
    2.11 	byte c = (byte)((uint)color >> 24);\
    2.12 	byte d = (byte)((uint)color >> 16);\
    2.13 	byte e = (byte)((uint)color >> 8);\
     3.1--- a/sys/src/cmd/gs/src/gdevm56.c
     3.2+++ b/sys/src/cmd/gs/src/gdevm56.c
     3.3@@ -62,9 +62,9 @@ mem_full_alpha_device("image56", 56, 0, 
     3.4 
     3.5 /* Unpack a color into its bytes. */
     3.6 #define declare_unpack_color(a, b, c, d, e, f, g, color)\
     3.7-	byte a = (byte)(color >> 48);\
     3.8-	byte b = (byte)(color >> 40);\
     3.9-	byte c = (byte)(color >> 32);\
    3.10+	byte a = (byte)((uint64_t)color >> 48);\
    3.11+	byte b = (byte)((uint64_t)color >> 40);\
    3.12+	byte c = (byte)((uint64_t)color >> 32);\
    3.13 	byte d = (byte)((uint)color >> 24);\
    3.14 	byte e = (byte)((uint)color >> 16);\
    3.15 	byte f = (byte)((uint)color >> 8);\
     4.1--- a/sys/src/cmd/gs/src/gdevm64.c
     4.2+++ b/sys/src/cmd/gs/src/gdevm64.c
     4.3@@ -67,13 +67,13 @@ mem_full_alpha_device("image64", 64, 0, 
     4.4 #if arch_is_big_endian
     4.5 /* Unpack a color into 32 bit chunks. */
     4.6 #  define declare_unpack_color(abcd, efgh, color)\
     4.7-	bits32 abcd = (bits32)((color) >> 32);\
     4.8+	bits32 abcd = (bits32)((uint64_t)(color) >> 32);\
     4.9 	bits32 efgh = (bits32)(color)
    4.10 #else
    4.11 /* Unpack a color into 32 bit chunks. */
    4.12 #  define declare_unpack_color(abcd, efgh, color)\
    4.13-	bits32 abcd = (bits32)((0x000000ff & ((color) >> 56)) |\
    4.14-		               (0x0000ff00 & ((color) >> 40)) |\
    4.15+	bits32 abcd = (bits32)((0x000000ff & ((uint64_t)(color) >> 56)) |\
    4.16+		               (0x0000ff00 & ((uint64_t)(color) >> 40)) |\
    4.17 		               (0x00ff0000 & ((color) >> 24)) |\
    4.18 		               (0xff000000 & ((color) >> 8)));\
    4.19 	bits32 efgh = (bits32)((0x000000ff & ((color) >> 24)) |\
     5.1--- a/sys/src/cmd/gs/src/gxcht.c
     5.2+++ b/sys/src/cmd/gs/src/gxcht.c
     5.3@@ -233,7 +233,7 @@ gx_dc_ht_colored_write(
     5.4         if (num_comps > 8 * sizeof(uint)) {
     5.5             tmp_mask = (uint)plane_mask;
     5.6             req_size += enc_u_sizew(tmp_mask);
     5.7-            tmp_mask = (uint)(plane_mask >> (8 * sizeof(uint)));
     5.8+            tmp_mask = (uint)((uint64_t)plane_mask >> (8 * sizeof(uint)));
     5.9             req_size += enc_u_sizew(tmp_mask);
    5.10         } else {
    5.11             tmp_mask = (uint)plane_mask;
    5.12@@ -298,7 +298,7 @@ gx_dc_ht_colored_write(
    5.13         if (num_comps > 8 * sizeof(uint)) {
    5.14             tmp_mask = (uint)plane_mask;
    5.15             enc_u_putw(tmp_mask, pdata);
    5.16-            tmp_mask = (uint)(plane_mask >> (8 * sizeof(uint)));
    5.17+            tmp_mask = (uint)((uint64_t)plane_mask >> (8 * sizeof(uint)));
    5.18             enc_u_putw(tmp_mask, pdata);
    5.19         } else {
    5.20             tmp_mask = (uint)plane_mask;
    5.21@@ -418,17 +418,16 @@ gx_dc_ht_colored_read(
    5.22 
    5.23         if (size < 1)
    5.24             return_error(gs_error_rangecheck);
    5.25-
    5.26         if (num_comps > 8 * sizeof(uint)) {
    5.27             enc_u_getw(tmp_mask, pdata);
    5.28             plane_mask = (gx_color_index)tmp_mask;
    5.29             enc_u_getw(tmp_mask, pdata);
    5.30-            plane_mask = (gx_color_index)tmp_mask << (8 * sizeof(uint));
    5.31+            plane_mask = (gx_color_index)((uint64_t)tmp_mask << (8 * sizeof(uint)));
    5.32         } else {
    5.33             enc_u_getw(tmp_mask, pdata);
    5.34             plane_mask = (gx_color_index)tmp_mask;
    5.35         }
    5.36-        devc.colors.colored.plane_mask = plane_mask;
    5.37+       devc.colors.colored.plane_mask = plane_mask;
    5.38         for (i = 0; i < num_comps; i++, plane_mask >>= 1) {
    5.39             if ((plane_mask & 0x1) != 0) {
    5.40                 if (size - (pdata - pdata_start) < 1)
    5.41@@ -437,7 +436,7 @@ gx_dc_ht_colored_read(
    5.42             } else
    5.43                 devc.colors.colored.c_level[i] = 0;
    5.44         }
    5.45-        size -= pdata - pdata_start;
    5.46+       size -= pdata - pdata_start;
    5.47     }
    5.48 
    5.49     if ((flag_bits & dc_ht_colored_alpha_is_max) != 0)
     6.1--- a/sys/src/cmd/gs/src/gxclrast.c
     6.2+++ b/sys/src/cmd/gs/src/gxclrast.c
     6.3@@ -559,16 +559,16 @@ in:				/* Initialize for a new page. */
     6.4 				/* For cases with an even number of bytes */
     6.5 			        case 8:
     6.6 			            data = *cbp++;
     6.7-			            delta = ((gx_color_index)
     6.8-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 48;
     6.9+			            delta = (gx_color_index)(((uint64_t)
    6.10+				        ((data & 0xf0) << 4) + (data & 0x0f)) << 48);
    6.11 			        case 6:
    6.12 			            data = *cbp++;
    6.13-			            delta |= ((gx_color_index)
    6.14-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 32;
    6.15+			            delta |= (gx_color_index)(((uint64_t)
    6.16+				        (((data & 0xf0) << 4) + (data & 0x0f))) << 32);
    6.17 			        case 4:
    6.18 			            data = *cbp++;
    6.19 			            delta |= ((gx_color_index)
    6.20-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 16;
    6.21+				        (((data & 0xf0) << 4) + (data & 0x0f))) << 16;
    6.22 			        case 2:
    6.23 			            data = *cbp++;
    6.24 			            delta |= ((gx_color_index)