Changeset 31286 in project


Ignore:
Timestamp:
08/25/14 19:25:10 (5 years ago)
Author:
sjamaan
Message:

numbers: Move the refactored C functions down, so they're grouped together. This makes it easier to see what remains to be done.

Location:
release/4/numbers/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/numbers/trunk/numbers-c.c

    r31285 r31286  
    391391}
    392392
    393 /* Eventually this will probably need to be integrated into C_2_plus. */
    394 static void /* REFACTORED */
    395 C_u_2_fixnum_plus(C_word c, C_word self, C_word k, C_word x, C_word y)
    396 {
    397   C_word z, ab[C_SIZEOF_BIGNUM(2)], *a = ab;
    398 
    399   /* Exceptional situation: this will cause a real overflow */
    400   if (x == C_fix(C_MOST_NEGATIVE_FIXNUM) && y == C_fix(C_MOST_NEGATIVE_FIXNUM)) {
    401     C_kontinue(k, C_bignum2(&a, 1, 0, 2));
    402   } else {
    403     z = C_unfix(x) + C_unfix(y);
    404 
    405     /* This code "knows" that both fixnums and bignums have 2 reserved bits */
    406     if(!C_fitsinfixnump(z)) {
    407       C_kontinue(k, C_bignum2(&a, (z < 0), labs(z) & (C_uword)BIGNUM_DIGIT_MASK, 1));
    408     } else {
    409       C_kontinue(k, C_fix(z));
    410     }
    411   }
    412 }
    413 
    414 
    415393static void
    416394fix_plus_big(C_word c, C_word self, C_word k, C_word x, C_word y)
     
    523501    }
    524502  }
    525 }
    526 
    527 static void
    528 C_fixnum_gcd(C_word c, C_word self, C_word k, C_word x, C_word y)
    529 {
    530    C_word r;
    531    
    532    x = C_unfix(x);
    533    y = C_unfix(y);
    534    
    535    if (x < 0) x = -x;
    536    if (y < 0) y = -y;
    537    
    538    while(y != 0) {
    539      r = x % y;
    540      x = y;
    541      y = r;
    542    }
    543    C_kontinue(k, C_fix(x));
    544503}
    545504
     
    16231582}
    16241583
    1625 /* TODO: This should probably be renamed C_fixnum_negate to replace
    1626  * what's in core.  Unfortunately, that one is allocating inline.
    1627  * That one may be renamed to C_u_i_fixnum_negate() or some such.
    1628  * TODO: Convert this to be an inline function and move to header?
    1629  */
    1630 static void /* REFACTORED */
    1631 C_u_fixnum_neg(C_word c, C_word self, C_word k, C_word x)
    1632 {
    1633   /* Exceptional situation: this will cause an overflow to itself */
    1634   if (x == C_fix(C_MOST_NEGATIVE_FIXNUM)) { /* C_fitsinfixnump(x) */
    1635     C_word ab[C_SIZEOF_BIGNUM(2)], *a = ab;
    1636     C_kontinue(k, C_bignum2(&a, 0, 0, 1));
    1637   } else {
    1638     C_kontinue(k, C_fix(-C_unfix(x)));
    1639   }
    1640 }
    1641 
    16421584static void
    16431585big_neg(C_word c, C_word self, C_word k, C_word x)
     
    23932335  }
    23942336}
     2337
     2338/**
     2339 * Below you will find the functions that have been refactored to
     2340 * match the "core" style.
     2341 */
     2342
     2343/* Eventually this will probably need to be integrated into C_2_plus. */
     2344static void
     2345C_u_2_fixnum_plus(C_word c, C_word self, C_word k, C_word x, C_word y)
     2346{
     2347  C_word z, ab[C_SIZEOF_BIGNUM(2)], *a = ab;
     2348
     2349  /* Exceptional situation: this will cause a real overflow */
     2350  if (x == C_fix(C_MOST_NEGATIVE_FIXNUM) && y == C_fix(C_MOST_NEGATIVE_FIXNUM)) {
     2351    C_kontinue(k, C_bignum2(&a, 1, 0, 2));
     2352  } else {
     2353    z = C_unfix(x) + C_unfix(y);
     2354
     2355    /* This code "knows" that both fixnums and bignums have 2 reserved bits */
     2356    if(!C_fitsinfixnump(z)) {
     2357      C_kontinue(k, C_bignum2(&a, (z < 0), labs(z) & (C_uword)BIGNUM_DIGIT_MASK, 1));
     2358    } else {
     2359      C_kontinue(k, C_fix(z));
     2360    }
     2361  }
     2362}
     2363
     2364/* TODO: This should probably be renamed C_fixnum_negate to replace
     2365 * what's in core.  Unfortunately, that one is allocating inline.
     2366 * That one may be renamed to C_u_i_fixnum_negate() or some such.
     2367 * TODO: Convert this to be an inline function and move to header?
     2368 */
     2369static void
     2370C_u_fixnum_neg(C_word c, C_word self, C_word k, C_word x)
     2371{
     2372  /* Exceptional situation: this will cause an overflow to itself */
     2373  if (x == C_fix(C_MOST_NEGATIVE_FIXNUM)) { /* C_fitsinfixnump(x) */
     2374    C_word ab[C_SIZEOF_BIGNUM(2)], *a = ab;
     2375    C_kontinue(k, C_bignum2(&a, 0, 0, 1));
     2376  } else {
     2377    C_kontinue(k, C_fix(-C_unfix(x)));
     2378  }
     2379}
     2380
     2381static void
     2382C_fixnum_gcd(C_word c, C_word self, C_word k, C_word x, C_word y)
     2383{
     2384   C_word r;
     2385   
     2386   x = C_unfix(x);
     2387   y = C_unfix(y);
     2388   
     2389   if (x < 0) x = -x;
     2390   if (y < 0) y = -y;
     2391   
     2392   while(y != 0) {
     2393     r = x % y;
     2394     x = y;
     2395     y = r;
     2396   }
     2397   C_kontinue(k, C_fix(x));
     2398}
  • release/4/numbers/trunk/numbers-c.h

    r31285 r31286  
    156156
    157157
    158 /*
     158/**
    159159 * Below is a duplication of the above, as port of a refactoring to
    160160 * fit CHICKEN naming conventions and general C style.  This should
     
    184184  C_word *p = *ptr, p0 = (C_word)p;
    185185
    186   /**
    187    * TODO: Rewrite to fit into the bit representation, get rid of
     186  /* TODO: Rewrite to fit into the bit representation, get rid of
    188187   * structure wrapper and tag vector.  Also, remove the unnecessary
    189188   * extra length slot if possible...
Note: See TracChangeset for help on using the changeset viewer.