changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: Sand edges down on GBIT64()/PBIT64() macros.

changeset 7213: c250493e2340
parent 7212: 0ecb36ce48cd
child 7214: d01edc4d026e
author: Ori Bernstein <ori@eigenstate.org>
date: Mon, 06 May 2019 17:26:38 -0700
files: sys/include/fcall.h
description: Sand edges down on GBIT64()/PBIT64() macros.

Now, you can safely use them in unbraced if statements, and
with char*s.
     1.1--- a/sys/include/fcall.h
     1.2+++ b/sys/include/fcall.h
     1.3@@ -61,17 +61,20 @@ struct	Fcall
     1.4 } Fcall;
     1.5 
     1.6 
     1.7-#define	GBIT8(p)	((p)[0])
     1.8-#define	GBIT16(p)	((p)[0]|((p)[1]<<8))
     1.9-#define	GBIT32(p)	((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
    1.10-#define	GBIT64(p)	((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
    1.11-				((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
    1.12+#define	GBIT8(p)	(((uchar*)(p))[0])
    1.13+#define	GBIT16(p)	(((uchar*)(p))[0]|(((uchar*)(p))[1]<<8))
    1.14+#define	GBIT32(p)	(((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\
    1.15+				(((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24))
    1.16+#define	GBIT64(p)	((u32int)(((uchar*)(p))[0]|(((uchar*)(p))[1]<<8)|\
    1.17+				(((uchar*)(p))[2]<<16)|(((uchar*)(p))[3]<<24)) |\
    1.18+			((uvlong)(((uchar*)(p))[4]|(((uchar*)(p))[5]<<8)|\
    1.19+				(((uchar*)(p))[6]<<16)|(((uchar*)(p))[7]<<24)) << 32))
    1.20 
    1.21-#define	PBIT8(p,v)	(p)[0]=(v)
    1.22-#define	PBIT16(p,v)	(p)[0]=(v);(p)[1]=(v)>>8
    1.23-#define	PBIT32(p,v)	(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
    1.24-#define	PBIT64(p,v)	(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
    1.25-			(p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
    1.26+#define	PBIT8(p,v)	do{(p)[0]=(v);}while(0)
    1.27+#define	PBIT16(p,v)	do{(p)[0]=(v);(p)[1]=(v)>>8;}while(0)
    1.28+#define	PBIT32(p,v)	do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;}while(0)
    1.29+#define	PBIT64(p,v)	do{(p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
    1.30+			   (p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56;}while(0)
    1.31 
    1.32 #define	BIT8SZ		1
    1.33 #define	BIT16SZ		2