Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/softint/division.c

    r1b20da0 ra35b458  
    4343        unsigned int result;
    4444        int steps = sizeof(unsigned int) * 8;
    45        
     45
    4646        *remainder = 0;
    4747        result = 0;
    48        
     48
    4949        if (b == 0) {
    5050                /* FIXME: division by zero */
    5151                return 0;
    5252        }
    53        
     53
    5454        if (a < b) {
    5555                *remainder = a;
    5656                return 0;
    5757        }
    58        
     58
    5959        for (; steps > 0; steps--) {
    6060                /* shift one bit to remainder */
    6161                *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1);
    6262                result <<= 1;
    63                
     63
    6464                if (*remainder >= b) {
    6565                        *remainder -= b;
     
    6868                a <<= 1;
    6969        }
    70        
     70
    7171        return result;
    7272}
     
    7777        unsigned long long result;
    7878        int steps = sizeof(unsigned long long) * 8;
    79        
     79
    8080        *remainder = 0;
    8181        result = 0;
    82        
     82
    8383        if (b == 0) {
    8484                /* FIXME: division by zero */
    8585                return 0;
    8686        }
    87        
     87
    8888        if (a < b) {
    8989                *remainder = a;
    9090                return 0;
    9191        }
    92        
     92
    9393        for (; steps > 0; steps--) {
    9494                /* shift one bit to remainder */
    9595                *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1);
    9696                result <<= 1;
    97                
     97
    9898                if (*remainder >= b) {
    9999                        *remainder -= b;
     
    102102                a <<= 1;
    103103        }
    104        
     104
    105105        return result;
    106106}
     
    111111        unsigned int rem;
    112112        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    113        
     113
    114114        if (SGN(a) == SGN(b))
    115115                return result;
    116        
     116
    117117        return -result;
    118118}
     
    123123        unsigned long long rem;
    124124        long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    125        
     125
    126126        if (SGN(a) == SGN(b))
    127127                return result;
    128        
     128
    129129        return -result;
    130130}
     
    149149        unsigned int rem;
    150150        divandmod32(a, b, &rem);
    151        
     151
    152152        /* if divident is negative, remainder must be too */
    153153        if (!(SGN(a)))
    154154                return -((int) rem);
    155        
     155
    156156        return (int) rem;
    157157}
     
    162162        unsigned long long rem;
    163163        divandmod64(a, b, &rem);
    164        
     164
    165165        /* if divident is negative, remainder must be too */
    166166        if (!(SGN(a)))
    167167                return -((long long) rem);
    168        
     168
    169169        return (long long) rem;
    170170}
     
    190190        unsigned int rem;
    191191        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    192        
     192
    193193        if (SGN(a) == SGN(b)) {
    194194                *c = rem;
    195195                return result;
    196196        }
    197        
     197
    198198        *c = -rem;
    199199        return -result;
     
    210210        unsigned long long rem;
    211211        long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    212        
     212
    213213        if (SGN(a) == SGN(b)) {
    214214                *c = rem;
    215215                return result;
    216216        }
    217        
     217
    218218        *c = -rem;
    219219        return -result;
Note: See TracChangeset for help on using the changeset viewer.