shithub: riscv

Download patch

ref: 5f5caa6733fd102b2a188ce57fd61193e1380dbb
parent: 2994fccbe1b881c3fa2838926d22af8aeda89640
author: cinap_lenrek <[email protected]>
date: Fri May 3 17:10:01 EDT 2019

gs: avoid stupid shifts by casting to uint64_t

--- a/sys/src/cmd/gs/src/gdevm40.c
+++ b/sys/src/cmd/gs/src/gdevm40.c
@@ -62,7 +62,7 @@
 
 /* Unpack a color into its bytes. */
 #define declare_unpack_color(a, b, c, d, e, color)\
-	byte a = (byte)(color >> 32);\
+	byte a = (byte)((uint64_t)color >> 32);\
 	byte b = (byte)((uint)color >> 24);\
 	byte c = (byte)((uint)color >> 16);\
 	byte d = (byte)((uint)color >> 8);\
--- a/sys/src/cmd/gs/src/gdevm48.c
+++ b/sys/src/cmd/gs/src/gdevm48.c
@@ -62,8 +62,8 @@
 
 /* Unpack a color into its bytes. */
 #define declare_unpack_color(a, b, c, d, e, f, color)\
-	byte a = (byte)(color >> 40);\
-	byte b = (byte)(color >> 32);\
+	byte a = (byte)((uint64_t)color >> 40);\
+	byte b = (byte)((uint64_t)color >> 32);\
 	byte c = (byte)((uint)color >> 24);\
 	byte d = (byte)((uint)color >> 16);\
 	byte e = (byte)((uint)color >> 8);\
--- a/sys/src/cmd/gs/src/gdevm56.c
+++ b/sys/src/cmd/gs/src/gdevm56.c
@@ -62,9 +62,9 @@
 
 /* Unpack a color into its bytes. */
 #define declare_unpack_color(a, b, c, d, e, f, g, color)\
-	byte a = (byte)(color >> 48);\
-	byte b = (byte)(color >> 40);\
-	byte c = (byte)(color >> 32);\
+	byte a = (byte)((uint64_t)color >> 48);\
+	byte b = (byte)((uint64_t)color >> 40);\
+	byte c = (byte)((uint64_t)color >> 32);\
 	byte d = (byte)((uint)color >> 24);\
 	byte e = (byte)((uint)color >> 16);\
 	byte f = (byte)((uint)color >> 8);\
--- a/sys/src/cmd/gs/src/gdevm64.c
+++ b/sys/src/cmd/gs/src/gdevm64.c
@@ -67,13 +67,13 @@
 #if arch_is_big_endian
 /* Unpack a color into 32 bit chunks. */
 #  define declare_unpack_color(abcd, efgh, color)\
-	bits32 abcd = (bits32)((color) >> 32);\
+	bits32 abcd = (bits32)((uint64_t)(color) >> 32);\
 	bits32 efgh = (bits32)(color)
 #else
 /* Unpack a color into 32 bit chunks. */
 #  define declare_unpack_color(abcd, efgh, color)\
-	bits32 abcd = (bits32)((0x000000ff & ((color) >> 56)) |\
-		               (0x0000ff00 & ((color) >> 40)) |\
+	bits32 abcd = (bits32)((0x000000ff & ((uint64_t)(color) >> 56)) |\
+		               (0x0000ff00 & ((uint64_t)(color) >> 40)) |\
 		               (0x00ff0000 & ((color) >> 24)) |\
 		               (0xff000000 & ((color) >> 8)));\
 	bits32 efgh = (bits32)((0x000000ff & ((color) >> 24)) |\
--- a/sys/src/cmd/gs/src/gxcht.c
+++ b/sys/src/cmd/gs/src/gxcht.c
@@ -233,7 +233,7 @@
         if (num_comps > 8 * sizeof(uint)) {
             tmp_mask = (uint)plane_mask;
             req_size += enc_u_sizew(tmp_mask);
-            tmp_mask = (uint)(plane_mask >> (8 * sizeof(uint)));
+            tmp_mask = (uint)((uint64_t)plane_mask >> (8 * sizeof(uint)));
             req_size += enc_u_sizew(tmp_mask);
         } else {
             tmp_mask = (uint)plane_mask;
@@ -298,7 +298,7 @@
         if (num_comps > 8 * sizeof(uint)) {
             tmp_mask = (uint)plane_mask;
             enc_u_putw(tmp_mask, pdata);
-            tmp_mask = (uint)(plane_mask >> (8 * sizeof(uint)));
+            tmp_mask = (uint)((uint64_t)plane_mask >> (8 * sizeof(uint)));
             enc_u_putw(tmp_mask, pdata);
         } else {
             tmp_mask = (uint)plane_mask;
@@ -418,17 +418,16 @@
 
         if (size < 1)
             return_error(gs_error_rangecheck);
-
         if (num_comps > 8 * sizeof(uint)) {
             enc_u_getw(tmp_mask, pdata);
             plane_mask = (gx_color_index)tmp_mask;
             enc_u_getw(tmp_mask, pdata);
-            plane_mask = (gx_color_index)tmp_mask << (8 * sizeof(uint));
+            plane_mask = (gx_color_index)((uint64_t)tmp_mask << (8 * sizeof(uint)));
         } else {
             enc_u_getw(tmp_mask, pdata);
             plane_mask = (gx_color_index)tmp_mask;
         }
-        devc.colors.colored.plane_mask = plane_mask;
+       devc.colors.colored.plane_mask = plane_mask;
         for (i = 0; i < num_comps; i++, plane_mask >>= 1) {
             if ((plane_mask & 0x1) != 0) {
                 if (size - (pdata - pdata_start) < 1)
@@ -437,7 +436,7 @@
             } else
                 devc.colors.colored.c_level[i] = 0;
         }
-        size -= pdata - pdata_start;
+       size -= pdata - pdata_start;
     }
 
     if ((flag_bits & dc_ht_colored_alpha_is_max) != 0)
--- a/sys/src/cmd/gs/src/gxclrast.c
+++ b/sys/src/cmd/gs/src/gxclrast.c
@@ -559,16 +559,16 @@
 				/* For cases with an even number of bytes */
 			        case 8:
 			            data = *cbp++;
-			            delta = ((gx_color_index)
-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 48;
+			            delta = (gx_color_index)(((uint64_t)
+				        ((data & 0xf0) << 4) + (data & 0x0f)) << 48);
 			        case 6:
 			            data = *cbp++;
-			            delta |= ((gx_color_index)
-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 32;
+			            delta |= (gx_color_index)(((uint64_t)
+				        (((data & 0xf0) << 4) + (data & 0x0f))) << 32);
 			        case 4:
 			            data = *cbp++;
 			            delta |= ((gx_color_index)
-				        ((data & 0xf0) << 4) + (data & 0x0f)) << 16;
+				        (((data & 0xf0) << 4) + (data & 0x0f))) << 16;
 			        case 2:
 			            data = *cbp++;
 			            delta |= ((gx_color_index)