summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-04-08 08:31:25 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-04-08 08:31:25 -0400
commit8c92b1248596d3ad70a8dcdbd6b6548641bc09a9 (patch)
tree3fc26a7a9f072e04015b5699731ad36a0364150c
parent554ba694ab54fe5d318fb3b3065808361df50f0b (diff)
downloadroux-8c92b1248596d3ad70a8dcdbd6b6548641bc09a9.tar.gz
use union for punning in emit
-rw-r--r--emit.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/emit.c b/emit.c
index 4d8bd67..02f5880 100644
--- a/emit.c
+++ b/emit.c
@@ -614,7 +614,11 @@ emitdat(Dat *d, FILE *f)
 typedef struct FBits FBits;
 
 struct FBits {
-	int64_t bits;
+	union {
+		int64_t n;
+		float f;
+		double d;
+	} bits;
 	int wide;
 	FBits *link;
 };
@@ -630,10 +634,10 @@ stashfp(int64_t n, int w)
 	/* does a dumb de-dup of fp constants
 	 * this should be the linker's job */
 	for (pb=&stash, i=0; (b=*pb); pb=&b->link, i++)
-		if (n == b->bits && w == b->wide)
+		if (n == b->bits.n && w == b->wide)
 			return i;
 	b = emalloc(sizeof *b);
-	b->bits = n;
+	b->bits.n = n;
 	b->wide = w;
 	b->link = 0;
 	*pb = b;
@@ -656,8 +660,8 @@ emitfin(FILE *f)
 				"%sfp%d:\n"
 				"\t.quad %"PRId64
 				" /* %f */\n",
-				locprefix, i, b->bits,
-				*(double *)&b->bits
+				locprefix, i, b->bits.n,
+				b->bits.d
 			);
 	for (b=stash, i=0; b; b=b->link, i++)
 		if (!b->wide)
@@ -665,8 +669,8 @@ emitfin(FILE *f)
 				"%sfp%d:\n"
 				"\t.long %"PRId64
 				" /* %lf */\n",
-				locprefix, i, b->bits & 0xffffffff,
-				*(float *)&b->bits
+				locprefix, i, b->bits.n & 0xffffffff,
+				b->bits.f
 			);
 	while ((b=stash)) {
 		stash = b->link;