Changeset 7fe9c5b in mainline


Ignore:
Timestamp:
2007-08-03T09:35:00Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0368fb59
Parents:
b76a2217
Message:

Minor cleanup of softint.

File:
1 edited

Legend:

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

    rb76a2217 r7fe9c5b  
    3535#include <genarch/softint/division.h>
    3636
    37 #define ABSVAL(x) ( (x) > 0 ? (x) : -(x))
    38 #define SGN(x) ( (x) >= 0 ? 1 : 0 )
     37#define ABSVAL(x) ((x) > 0 ? (x) : -(x))
     38#define SGN(x) ((x) >= 0 ? 1 : 0)
    3939                                     
    40 static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder)
     40static unsigned int divandmod32(unsigned int a, unsigned int b,
     41    unsigned int *remainder)
    4142{
    4243        unsigned int result;
     
    5152        }
    5253       
    53         if ( a < b) {
     54        if (a < b) {
    5455                *remainder = a;
    5556                return 0;
    5657        }
    5758
    58         for ( ; steps > 0; steps--) {
     59        for (; steps > 0; steps--) {
    5960                /* shift one bit to remainder */
    60                 *remainder = ( (*remainder) << 1) | (( a >> 31) & 0x1);
     61                *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1);
    6162                result <<= 1;
    6263               
    6364                if (*remainder >= b) {
    64                                 *remainder -= b;
    65                                 result |= 0x1;
     65                        *remainder -= b;
     66                        result |= 0x1;
    6667                }
    6768                a <<= 1;
     
    7273
    7374
    74 static unsigned long long divandmod64(unsigned long long a, unsigned long long b, unsigned long long *remainder)
     75static unsigned long long divandmod64(unsigned long long a,
     76    unsigned long long b, unsigned long long *remainder)
    7577{
    7678        unsigned long long result;
     
    8587        }
    8688       
    87         if ( a < b) {
     89        if (a < b) {
    8890                *remainder = a;
    8991                return 0;
    9092        }
    9193
    92         for ( ; steps > 0; steps--) {
     94        for (; steps > 0; steps--) {
    9395                /* shift one bit to remainder */
    94                 *remainder = ( (*remainder) << 1) | ((a >> 63) & 0x1);
     96                *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1);
    9597                result <<= 1;
    9698               
    9799                if (*remainder >= b) {
    98                                 *remainder -= b;
    99                                 result |= 0x1;
     100                        *remainder -= b;
     101                        result |= 0x1;
    100102                }
    101103                a <<= 1;
     
    111113        int result;
    112114       
    113         result = (int)divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    114 
    115         if ( SGN(a) == SGN(b)) return result;
     115        result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
     116
     117        if (SGN(a) == SGN(b))
     118                return result;
    116119        return -result;
    117120}
     
    123126        long long result;
    124127       
    125         result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    126 
    127         if ( SGN(a) == SGN(b)) return result;
     128        result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
     129
     130        if (SGN(a) == SGN(b))
     131                return result;
    128132        return -result;
    129133}
     
    151155        /* if divident is negative, remainder must be too */
    152156        if (!(SGN(a))) {
    153                 return -((int)rem);
    154         }
    155        
    156         return (int)rem;
     157                return -((int) rem);
     158        }
     159       
     160        return (int) rem;
    157161}
    158162
     
    165169        /* if divident is negative, remainder must be too */
    166170        if (!(SGN(a))) {
    167                 return -((long long)rem);
    168         }
    169        
    170         return (long long)rem;
     171                return -((long long) rem);
     172        }
     173       
     174        return (long long) rem;
    171175}
    172176
     
    187191}
    188192
    189 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c)
     193unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
     194    unsigned long long *c)
    190195{
    191196        return divandmod64(a, b, c);
Note: See TracChangeset for help on using the changeset viewer.