Ignore:
Timestamp:
2012-04-08T08:07:21Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1196df6
Parents:
ce6de59 (diff), f3378ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

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

    rce6de59 r3b5c119  
    2727 */
    2828
    29 /** @addtogroup genarch 
     29/** @addtogroup genarch
    3030 * @{
    3131 */
     
    3535#include <genarch/softint/division.h>
    3636
    37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x))
    38 #define SGN(x) ((x) >= 0 ? 1 : 0)
    39                                      
     37#define ABSVAL(x)  ((x) > 0 ? (x) : -(x))
     38#define SGN(x)     ((x) >= 0 ? 1 : 0)
     39
    4040static unsigned int divandmod32(unsigned int a, unsigned int b,
    4141    unsigned int *remainder)
     
    5656                return 0;
    5757        }
    58 
     58       
    5959        for (; steps > 0; steps--) {
    6060                /* shift one bit to remainder */
     
    6868                a <<= 1;
    6969        }
    70 
     70       
    7171        return result;
    7272}
    73 
    7473
    7574static unsigned long long divandmod64(unsigned long long a,
     
    7776{
    7877        unsigned long long result;
    79         int steps = sizeof(unsigned long long) * 8; 
     78        int steps = sizeof(unsigned long long) * 8;
    8079       
    8180        *remainder = 0;
     
    9190                return 0;
    9291        }
    93 
     92       
    9493        for (; steps > 0; steps--) {
    9594                /* shift one bit to remainder */
     
    103102                a <<= 1;
    104103        }
    105 
     104       
    106105        return result;
    107106}
    108107
    109108/* 32bit integer division */
    110 int __divsi3(int a, int b)
    111 {
    112         unsigned int rem;
    113         int result;
    114        
    115         result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    116 
     109int __divsi3(int a, int b)
     110{
     111        unsigned int rem;
     112        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
     113       
    117114        if (SGN(a) == SGN(b))
    118115                return result;
     116       
    119117        return -result;
    120118}
    121119
    122120/* 64bit integer division */
    123 long long __divdi3(long long a, long long b)
    124 {
    125         unsigned long long rem;
    126         long long result;
    127        
    128         result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    129 
     121long long __divdi3(long long a, long long b)
     122{
     123        unsigned long long rem;
     124        long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
     125       
    130126        if (SGN(a) == SGN(b))
    131127                return result;
     128       
    132129        return -result;
    133130}
     
    143140unsigned long long __udivdi3(unsigned long long a, unsigned long long b)
    144141{
    145         unsigned long long  rem;
     142        unsigned long long rem;
    146143        return divandmod64(a, b, &rem);
    147144}
     
    154151       
    155152        /* if divident is negative, remainder must be too */
    156         if (!(SGN(a))) {
     153        if (!(SGN(a)))
    157154                return -((int) rem);
    158         }
    159155       
    160156        return (int) rem;
     
    162158
    163159/* 64bit remainder of the signed division */
    164 long long __moddi3(long long a,long long b)
     160long long __moddi3(long long a, long long b)
    165161{
    166162        unsigned long long rem;
     
    168164       
    169165        /* if divident is negative, remainder must be too */
    170         if (!(SGN(a))) {
     166        if (!(SGN(a)))
    171167                return -((long long) rem);
    172         }
    173168       
    174169        return (long long) rem;
     
    191186}
    192187
     188int __divmodsi3(int a, int b, int *c)
     189{
     190        unsigned int rem;
     191        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
     192       
     193        if (SGN(a) == SGN(b)) {
     194                *c = rem;
     195                return result;
     196        }
     197       
     198        *c = -rem;
     199        return -result;
     200}
     201
     202unsigned int __udivmodsi3(unsigned int a, unsigned int b,
     203    unsigned int *c)
     204{
     205        return divandmod32(a, b, c);
     206}
     207
     208long long __divmoddi3(long long a, long long b, long long *c)
     209{
     210        unsigned long long rem;
     211        long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
     212       
     213        if (SGN(a) == SGN(b)) {
     214                *c = rem;
     215                return result;
     216        }
     217       
     218        *c = -rem;
     219        return -result;
     220}
     221
    193222unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
    194223    unsigned long long *c)
Note: See TracChangeset for help on using the changeset viewer.