From c184d2602d62225997fd1c5eae9fd602f7924d5b Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 1 Nov 2015 12:09:03 +0100 Subject: [PATCH 1/3] 5c: handle (rare) MULU instruction in peephole optimizer --- sys/src/cmd/5c/peep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sys/src/cmd/5c/peep.c b/sys/src/cmd/5c/peep.c index 3d624a93d..0c126c0d8 100644 --- a/sys/src/cmd/5c/peep.c +++ b/sys/src/cmd/5c/peep.c @@ -306,6 +306,7 @@ subprop(Reg *r0) case AAND: case AEOR: case AMUL: + case AMULU: case ADIV: case ADIVU: @@ -977,6 +978,7 @@ copyu(Prog *p, Adr *v, Adr *s) case AAND: case AEOR: case AMUL: + case AMULU: case ADIV: case ADIVU: case AADDF: @@ -1112,6 +1114,7 @@ a2type(Prog *p) case AAND: case AEOR: case AMUL: + case AMULU: case ADIV: case ADIVU: return D_REG; From d901fbe4f1e7191b757355384504d7560e8d040e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 1 Nov 2015 12:10:10 +0100 Subject: [PATCH 2/3] libmp: add mpvecdigmuladd()/mpvecdigmulsub() assembly routines for arm --- sys/src/libmp/arm/mkfile | 8 +++++--- sys/src/libmp/arm/mpvecdigmuladd.s | 19 +++++++++++++++++++ sys/src/libmp/arm/mpvecdigmulsub.s | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 sys/src/libmp/arm/mpvecdigmuladd.s create mode 100644 sys/src/libmp/arm/mpvecdigmulsub.s diff --git a/sys/src/libmp/arm/mkfile b/sys/src/libmp/arm/mkfile index e90c8b6ab..c939f5c41 100644 --- a/sys/src/libmp/arm/mkfile +++ b/sys/src/libmp/arm/mkfile @@ -2,12 +2,14 @@ objtype=arm Date: Sun, 1 Nov 2015 12:12:41 +0100 Subject: [PATCH 3/3] libmp: optimize case x/0xffffffff in mpdigdiv() (helps arm) --- sys/src/libmp/port/mpdigdiv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/src/libmp/port/mpdigdiv.c b/sys/src/libmp/port/mpdigdiv.c index 4a73bb3a4..32b166765 100644 --- a/sys/src/libmp/port/mpdigdiv.c +++ b/sys/src/libmp/port/mpdigdiv.c @@ -21,6 +21,19 @@ mpdigdiv(mpdigit *dividend, mpdigit divisor, mpdigit *quotient) return; } + // very common case + if(~divisor == 0){ + lo += hi; + if(lo < hi){ + hi++; + lo++; + } + if(lo+1 == 0) + hi++; + *quotient = hi; + return; + } + // at this point we know that hi < divisor // just shift and subtract till we're done q = 0;