[Nickle] nickle: Branch 'master' - 2 commits

Keith Packard keithp at keithp.com
Sun Aug 20 00:04:17 PDT 2023


 float.c   |   10 ++++++++++
 natural.c |    9 +++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

New commits:
commit 23f54cb815a1e0a800ed1e035eaaf7408d00632d
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Aug 20 00:03:23 2023 -0700

    natural: Fix bug in optimized multiply by one
    
    Arguments to memcpy were reversed, which ended up destroying
    the first parameter rather than copying it to the result.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/natural.c b/natural.c
index 9d1a2f7..e219271 100644
--- a/natural.c
+++ b/natural.c
@@ -311,7 +311,7 @@ DigitsSubInPlace (digit *x_orig, int xlen, digit *y, int ylen, int off)
 }
 
 static int
-DigitTimes (digit *x, int xlen, digit y, digit *result)
+DigitTimes (const digit *x, int xlen, digit y, digit *result)
 {
     double_digit    q;
     digit	    carry;
@@ -319,7 +319,7 @@ DigitTimes (digit *x, int xlen, digit y, digit *result)
 
     if (y == 1)
     {
-	memcpy (x, result, xlen * sizeof (digit));
+	memcpy (result, x, xlen * sizeof (digit));
 	return xlen;
     }
     carry = 0;
@@ -338,9 +338,10 @@ DigitTimes (digit *x, int xlen, digit y, digit *result)
 }
 
 static int
-DigitsGradeSchool (digit *x_orig, int xlen, digit *y_orig, int ylen, digit *result)
+DigitsGradeSchool (const digit *x_orig, int xlen, const digit *y_orig, int ylen, digit *result)
 {
-    digit	    *x, *y, *r, *rbase, *rloop;
+    const digit	    *x, *y;
+    digit	    *r, *rbase, *rloop;
     double_digit    temp;
     digit	    carry;
     digit	    xd;
commit 5cdad2778c415d26ff74fbf0816c0376baf7f8c3
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Aug 20 00:02:29 2023 -0700

    float: optimize addition of zero
    
    Check for zero in either operand and return the other one.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/float.c b/float.c
index 1aec169..106195e 100644
--- a/float.c
+++ b/float.c
@@ -261,6 +261,9 @@ FpartInit (void)
     return 1;
 }
 
+static Value
+FloatNegate (Value av, int expandOk);
+
 static Value
 FloatAdd (Value av, Value bv, int expandOk, Bool negate)
 {
@@ -274,6 +277,13 @@ FloatAdd (Value av, Value bv, int expandOk, Bool negate)
     unsigned	prec;
     int		alen, blen;
 
+    if (FpartZero(a->mant)) {
+	if (negate)
+	    bv = FloatNegate(bv, expandOk);
+	return bv;
+    } else if (FpartZero(b->mant)) {
+	return av;
+    }
     dist = FpartAdd (a->exp, b->exp, True);
     ret = 0;
     if (NaturalLess (dist->mag, max_int_natural))


More information about the Nickle mailing list