Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 5a6a42f in mainline


Ignore:
Timestamp:
2012-04-07T12:34:19Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
956a22c
Parents:
df955955
Message:

unify softint cstyle
add udivmodsi3

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • boot/genarch/include/division.h

    rdf955955 r5a6a42f  
    3333#define BOOT_DIVISION_H_
    3434
    35 /* 32bit integer division */
    3635extern int __divsi3(int, int);
    37 
    38 /* 64bit integer division */
    3936extern long long __divdi3(long long, long long);
    4037
    41 /* 32bit unsigned integer division */
    4238extern unsigned int __udivsi3(unsigned int, unsigned int);
    43 
    44 /* 64bit unsigned integer division */
    4539extern unsigned long long __udivdi3(unsigned long long, unsigned long long);
    4640
    47 /* 32bit remainder of the signed division */
    4841extern int __modsi3(int, int);
    49 
    50 /* 64bit remainder of the signed division */
    5142extern long long __moddi3(long long, long long);
    5243
    53 /* 32bit remainder of the unsigned division */
    5444extern unsigned int __umodsi3(unsigned int, unsigned int);
    55 
    56 /* 64bit remainder of the unsigned division */
    5745extern unsigned long long __umoddi3(unsigned long long, unsigned long long);
    5846
     47extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *);
    5948extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long,
    6049    unsigned long long *);
  • boot/genarch/src/division.c

    rdf955955 r5a6a42f  
    7373{
    7474        unsigned long long result;
    75         int steps = sizeof(unsigned long long) * 8; 
     75        int steps = sizeof(unsigned long long) * 8;
    7676       
    7777        *remainder = 0;
     
    104104
    105105/* 32bit integer division */
    106 int __divsi3(int a, int b) 
     106int __divsi3(int a, int b)
    107107{
    108108        unsigned int rem;
     
    116116
    117117/* 64bit integer division */
    118 long long __divdi3(long long a, long long b) 
     118long long __divdi3(long long a, long long b)
    119119{
    120120        unsigned long long rem;
     
    155155
    156156/* 64bit remainder of the signed division */
    157 long long __moddi3(long long a,long long b)
     157long long __moddi3(long long a, long long b)
    158158{
    159159        unsigned long long rem;
     
    183183}
    184184
     185unsigned int __udivmodsi3(unsigned int a, unsigned int b,
     186    unsigned int *c)
     187{
     188        return divandmod32(a, b, c);
     189}
     190
    185191unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
    186192    unsigned long long *c)
  • kernel/genarch/include/softint/division.h

    rdf955955 r5a6a42f  
    3636#define KERN_DIVISION_H_
    3737
    38 /* 32bit integer division */
    39 int __divsi3(int a, int b);
     38extern int __divsi3(int, int);
     39extern long long __divdi3(long long, long long);
    4040
    41 /* 64bit integer division */
    42 long long __divdi3(long long a, long long b);
     41extern unsigned int __udivsi3(unsigned int, unsigned int);
     42extern unsigned long long __udivdi3(unsigned long long, unsigned long long);
    4343
    44 /* 32bit unsigned integer division */
    45 unsigned int __udivsi3(unsigned int a, unsigned int b);
     44extern int __modsi3(int, int);
     45extern long long __moddi3(long long, long long);
    4646
    47 /* 64bit unsigned integer division */
    48 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);
     47extern unsigned int __umodsi3(unsigned int, unsigned int);
     48extern unsigned long long __umoddi3(unsigned long long, unsigned long long);
    4949
    50 /* 32bit remainder of the signed division */
    51 int __modsi3(int a, int b);
    52 
    53 /* 64bit remainder of the signed division */
    54 long long __moddi3(long long a, long long b);
    55 
    56 /* 32bit remainder of the unsigned division */
    57 unsigned int __umodsi3(unsigned int a, unsigned int b);
    58 
    59 /* 64bit remainder of the unsigned division */
    60 unsigned long long __umoddi3(unsigned long long a, unsigned long long b);
    61 
    62 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c);
     50extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *);
     51extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long,
     52    unsigned long long *);
    6353
    6454#endif
  • kernel/genarch/src/softint/division.c

    rdf955955 r5a6a42f  
    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
     188unsigned int __udivmodsi3(unsigned int a, unsigned int b,
     189    unsigned int *c)
     190{
     191        return divandmod32(a, b, c);
     192}
     193
    193194unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
    194195    unsigned long long *c)
  • uspace/lib/softint/generic/division.c

    rdf955955 r5a6a42f  
    3737#include <division.h>
    3838
    39 #define ABSVAL(x) ( (x) > 0 ? (x) : -(x))
    40 #define SGN(x) ( (x) >= 0 ? 1 : 0 )
    41                                      
    42 static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder)
     39#define ABSVAL(x)  ((x) > 0 ? (x) : -(x))
     40#define SGN(x)     ((x) >= 0 ? 1 : 0)
     41
     42static unsigned int divandmod32(unsigned int a, unsigned int b,
     43    unsigned int *remainder)
    4344{
    4445        unsigned int result;
     
    5354        }
    5455       
    55         if ( a < b) {
     56        if (a < b) {
    5657                *remainder = a;
    5758                return 0;
    5859        }
    59 
    60         for ( ; steps > 0; steps--) {
     60       
     61        for (; steps > 0; steps--) {
    6162                /* shift one bit to remainder */
    62                 *remainder = ( (*remainder) << 1) | (( a >> 31) & 0x1);
     63                *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1);
    6364                result <<= 1;
    6465               
    6566                if (*remainder >= b) {
    66                                 *remainder -= b;
    67                                 result |= 0x1;
     67                        *remainder -= b;
     68                        result |= 0x1;
    6869                }
    6970                a <<= 1;
    7071        }
    71 
     72       
    7273        return result;
    7374}
    7475
    75 
    76 static unsigned long long divandmod64(unsigned long long a, unsigned long long b, unsigned long long *remainder)
     76static unsigned long long divandmod64(unsigned long long a,
     77    unsigned long long b, unsigned long long *remainder)
    7778{
    7879        unsigned long long result;
    79         int steps = sizeof(unsigned long long) * 8; 
     80        int steps = sizeof(unsigned long long) * 8;
    8081       
    8182        *remainder = 0;
     
    8788        }
    8889       
    89         if ( a < b) {
     90        if (a < b) {
    9091                *remainder = a;
    9192                return 0;
    9293        }
    93 
    94         for ( ; steps > 0; steps--) {
     94       
     95        for (; steps > 0; steps--) {
    9596                /* shift one bit to remainder */
    96                 *remainder = ( (*remainder) << 1) | ((a >> 63) & 0x1);
     97                *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1);
    9798                result <<= 1;
    9899               
    99100                if (*remainder >= b) {
    100                                 *remainder -= b;
    101                                 result |= 0x1;
     101                        *remainder -= b;
     102                        result |= 0x1;
    102103                }
    103104                a <<= 1;
    104105        }
    105 
     106       
    106107        return result;
    107108}
    108109
    109110/* 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 
    117         if ( SGN(a) == SGN(b)) return result;
     111int __divsi3(int a, int b)
     112{
     113        unsigned int rem;
     114        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
     115       
     116        if (SGN(a) == SGN(b))
     117                return result;
     118       
    118119        return -result;
    119120}
    120121
    121122/* 64bit integer division */
    122 long long __divdi3(long long a, long long b) 
    123 {
    124         unsigned long long rem;
    125         long long result;
    126        
    127         result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    128 
    129         if ( SGN(a) == SGN(b)) return result;
     123long long __divdi3(long long a, long long b)
     124{
     125        unsigned long long rem;
     126        long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
     127       
     128        if (SGN(a) == SGN(b))
     129                return result;
     130       
    130131        return -result;
    131132}
     
    141142unsigned long long __udivdi3(unsigned long long a, unsigned long long b)
    142143{
    143         unsigned long long  rem;
     144        unsigned long long rem;
    144145        return divandmod64(a, b, &rem);
    145146}
     
    152153       
    153154        /* if divident is negative, remainder must be too */
    154         if (!(SGN(a))) {
    155                 return -((int)rem);
    156         }
    157        
    158         return (int)rem;
     155        if (!(SGN(a)))
     156                return -((int) rem);
     157       
     158        return (int) rem;
    159159}
    160160
    161161/* 64bit remainder of the signed division */
    162 long long __moddi3(long long a,long long b)
     162long long __moddi3(long long a, long long b)
    163163{
    164164        unsigned long long rem;
     
    166166       
    167167        /* if divident is negative, remainder must be too */
    168         if (!(SGN(a))) {
    169                 return -((long long)rem);
    170         }
    171        
    172         return (long long)rem;
     168        if (!(SGN(a)))
     169                return -((long long) rem);
     170       
     171        return (long long) rem;
    173172}
    174173
     
    189188}
    190189
    191 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c)
     190unsigned int __udivmodsi3(unsigned int a, unsigned int b,
     191    unsigned int *c)
     192{
     193        return divandmod32(a, b, c);
     194}
     195
     196unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
     197    unsigned long long *c)
    192198{
    193199        return divandmod64(a, b, c);
  • uspace/lib/softint/include/division.h

    rdf955955 r5a6a42f  
    3737#define __SOFTINT_DIVISION_H__
    3838
     39extern int __divsi3(int, int);
     40extern long long __divdi3(long long, long long);
    3941
    40 /* 32bit integer division */
    41 int __divsi3(int a, int b);
     42extern unsigned int __udivsi3(unsigned int, unsigned int);
     43extern unsigned long long __udivdi3(unsigned long long, unsigned long long);
    4244
    43 /* 64bit integer division */
    44 long long __divdi3(long long a, long long b);
     45extern int __modsi3(int, int);
     46extern long long __moddi3(long long, long long);
    4547
    46 /* 32bit unsigned integer division */
    47 unsigned int __udivsi3(unsigned int a, unsigned int b);
     48extern unsigned int __umodsi3(unsigned int, unsigned int);
     49extern unsigned long long __umoddi3(unsigned long long, unsigned long long);
    4850
    49 /* 64bit unsigned integer division */
    50 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);
    51 
    52 /* 32bit remainder of the signed division */
    53 int __modsi3(int a, int b);
    54 
    55 /* 64bit remainder of the signed division */
    56 long long __moddi3(long long a, long long b);
    57 
    58 /* 32bit remainder of the unsigned division */
    59 unsigned int __umodsi3(unsigned int a, unsigned int b);
    60 
    61 /* 64bit remainder of the unsigned division */
    62 unsigned long long __umoddi3(unsigned long long a, unsigned long long b);
    63 
    64 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c);
     51extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *);
     52extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long,
     53    unsigned long long *);
    6554
    6655#endif
     
    6857/** @}
    6958 */
    70 
Note: See TracChangeset for help on using the changeset viewer.