shithub: riscv

Download patch

ref: a99cf56c7d670f6af88cab39de91f1d6ac36416f
parent: 5bf09937da68b5b55e33cc24ea021ed08b2ae6e0
author: cinap_lenrek <[email protected]>
date: Sun Jun 26 11:13:10 EDT 2016

kernel: more (arm) compiler friendly mul64fract()

the arm compiler can lift long->vlong casts on multiplcation
and convert 64x64->64 multiplication into a 32x32->64 one
with optional 64 bit accumulate.

--- a/sys/src/9/port/mul64fract.c
+++ b/sys/src/9/port/mul64fract.c
@@ -21,19 +21,15 @@
 void
 mul64fract(uvlong *r, uvlong a, uvlong b)
 {
-	uvlong bh, bl;
-	uvlong ah, al;
-	uvlong res;
+	ulong bh, bl, ah, al;
 
-	bl = b & 0xffffffffULL;
+	bl = b;
 	bh = b >> 32;
-	al = a & 0xffffffffULL;
+	al = a;
 	ah = a >> 32;
 
-	res = (al*bl)>>32;
-	res += (al*bh);
-	res += (ah*bl);
-	res += (ah*bh)<<32;
-
-	*r = res;
+	*r = (((uvlong)al*(uvlong)bl)>>32)
+	   + ((uvlong)al*(uvlong)bh)
+	   + ((uvlong)ah*(uvlong)bl)
+	   + (((uvlong)ah*(uvlong)bh)<<32);
 }