Changeset 8565a42 in mainline for uspace/lib/math


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (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.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
uspace/lib/math
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/math/arch/amd64/src/cos.S

    r3061bc1 r8565a42  
    3535        pushq %rbp
    3636        movq %rsp, %rbp
    37        
     37
    3838        # compute cosine (using red zone)
    39        
     39
    4040        movsd %xmm0, -8(%rbp)
    4141        fldl -8(%rbp)
    42        
     42
    4343        fcos
    44        
     44
    4545        # detect if source operand is out of range
    46        
     46
    4747        fnstsw %ax
    4848        andw $X87_STATUS_WORD_C2_MASK, %ax
    4949        jnz fix_range
    50        
     50
    5151                fstpl -8(%rbp)
    5252                movsd -8(%rbp), %xmm0
    53                
     53
    5454                leave
    5555                retq
    56        
     56
    5757        # argument reduction
    58        
     58
    5959        fix_range:
    6060                fldpi
    6161                fadd %st(0)
    6262                fxch %st(1)
    63        
     63
    6464        reduce:
    6565                fprem1
     
    6767                andw $X87_STATUS_WORD_C2_MASK, %ax
    6868                jnz reduce
    69        
     69
    7070        fstp %st(1)
    7171        fcos
    72        
     72
    7373        fstpl -8(%rbp)
    7474        movsd -8(%rbp), %xmm0
    75        
     75
    7676        leave
    7777        retq
  • uspace/lib/math/arch/amd64/src/sin.S

    r3061bc1 r8565a42  
    3535        pushq %rbp
    3636        movq %rsp, %rbp
    37        
     37
    3838        # compute sine (using red zone)
    39        
     39
    4040        movsd %xmm0, -8(%rbp)
    4141        fldl -8(%rbp)
    42        
     42
    4343        fsin
    44        
     44
    4545        # detect if source operand is out of range
    46        
     46
    4747        fnstsw %ax
    4848        andw $X87_STATUS_WORD_C2_MASK, %ax
    4949        jnz fix_range
    50        
     50
    5151                fstpl -8(%rbp)
    5252                movsd -8(%rbp), %xmm0
    53                
     53
    5454                leave
    5555                retq
    56        
     56
    5757        # argument reduction
    58        
     58
    5959        fix_range:
    6060                fldpi
    6161                fadd %st(0)
    6262                fxch %st(1)
    63        
     63
    6464        reduce:
    6565                fprem1
     
    6767                andw $X87_STATUS_WORD_C2_MASK, %ax
    6868                jnz reduce
    69        
     69
    7070        fstp %st(1)
    7171        fsin
    72        
     72
    7373        fstpl -8(%rbp)
    7474        movsd -8(%rbp), %xmm0
    75        
     75
    7676        leave
    7777        retq
  • uspace/lib/math/arch/amd64/src/trunc.S

    r3061bc1 r8565a42  
    3535        pushq %rbp
    3636        movq %rsp, %rbp
    37        
     37
    3838        # store x87 control word in the red zone
    39        
     39
    4040        fnstcw -8(%rbp)
    4141        movw -8(%rbp), %ax
    42        
     42
    4343        # set rounding control to truncate
    4444        # (no masking necessary for this flag)
    45        
     45
    4646        orw $X87_CONTROL_WORD_RC_TRUNCATE, %ax
    4747        movw %ax, -16(%rbp)
    4848        fldcw -16(%rbp)
    49        
     49
    5050        # truncate
    51        
     51
    5252        movsd %xmm0, -16(%rbp)
    5353        fldl -16(%rbp)
     
    5555        fstpl -16(%rbp)
    5656        movsd -16(%rbp), %xmm0
    57        
     57
    5858        # restore original control word
    59        
     59
    6060        fldcw -8(%rbp)
    61        
     61
    6262        leave
    6363        retq
  • uspace/lib/math/arch/ia32/src/cos.S

    r3061bc1 r8565a42  
    3434FUNCTION_BEGIN(cos_f64)
    3535        # compute cosine (no stack frame)
    36        
     36
    3737        fldl 4(%esp)
    3838        fcos
    39        
     39
    4040        # detect if source operand is out of range
    41        
     41
    4242        fnstsw %ax
    4343        andw $X87_STATUS_WORD_C2_MASK, %ax
    4444        jnz fix_range
    45        
     45
    4646                ret
    47        
     47
    4848        # argument reduction
    49        
     49
    5050        fix_range:
    5151                fldpi
    5252                fadd %st(0)
    5353                fxch %st(1)
    54        
     54
    5555        reduce:
    5656                fprem1
     
    5858                andw $X87_STATUS_WORD_C2_MASK, %ax
    5959                jnz reduce
    60        
     60
    6161        fstp %st(1)
    6262        fcos
    63        
     63
    6464        ret
    6565FUNCTION_END(cos_f64)
  • uspace/lib/math/arch/ia32/src/sin.S

    r3061bc1 r8565a42  
    3434FUNCTION_BEGIN(sin_f64)
    3535        # compute sine (no stack frame)
    36        
     36
    3737        fldl 4(%esp)
    3838        fsin
    39        
     39
    4040        # detect if source operand is out of range
    41        
     41
    4242        fnstsw %ax
    4343        andw $X87_STATUS_WORD_C2_MASK, %ax
    4444        jnz fix_range
    45        
     45
    4646                ret
    47        
     47
    4848        # argument reduction
    49        
     49
    5050        fix_range:
    5151                fldpi
    5252                fadd %st(0)
    5353                fxch %st(1)
    54        
     54
    5555        reduce:
    5656                fprem1
     
    5858                andw $X87_STATUS_WORD_C2_MASK, %ax
    5959                jnz reduce
    60        
     60
    6161        fstp %st(1)
    6262        fsin
    63        
     63
    6464        ret
    6565FUNCTION_END(sin_f64)
  • uspace/lib/math/arch/ia32/src/trunc.S

    r3061bc1 r8565a42  
    3636        movl %esp, %ebp
    3737        subl $8, %esp
    38        
     38
    3939        # store x87 control word
    40        
     40
    4141        fnstcw -4(%ebp)
    4242        movw -4(%ebp), %ax
    43        
     43
    4444        # set rounding control to truncate
    4545        # (no masking necessary for this flag)
    46        
     46
    4747        orw $X87_CONTROL_WORD_RC_TRUNCATE, %ax
    4848        movw %ax, -8(%ebp)
    4949        fldcw -8(%ebp)
    50        
     50
    5151        # truncate
    52        
     52
    5353        fldl 8(%ebp)
    5454        frndint
    55        
     55
    5656        # restore original control word
    57        
     57
    5858        fldcw -4(%ebp)
    59        
     59
    6060        leave
    6161        ret
  • uspace/lib/math/generic/asin.c

    r3061bc1 r8565a42  
    4949{
    5050        float32_t aval;
    51        
     51
    5252        if (arg < -1.0 || arg > 1.0) {
    5353                errno = EDOM;
    5454                return FLOAT32_NAN;
    5555        }
    56        
     56
    5757        aval = 2.0 * atan_f32(arg / (1.0 + sqrt_f32(1.0 - arg*arg)));
    5858        if (arg > 0.0)
     
    7474{
    7575        float64_t aval;
    76        
     76
    7777        if (arg < -1.0 || arg > 1.0) {
    7878                errno = EDOM;
    7979                return FLOAT64_NAN;
    8080        }
    81        
     81
    8282        aval = 2.0 * atan_f64(arg / (1.0 + sqrt_f64(1.0 - arg*arg)));
    8383        if (arg > 0.0)
  • uspace/lib/math/generic/atan.c

    r3061bc1 r8565a42  
    5454        float32_t sum = 0;
    5555        float32_t a = arg / (1.0 + arg * arg);
    56        
     56
    5757        /*
    5858         * atan(z) = sum(n=0, +inf) [ (2^2n) * (n!)^2 / (2n + 1)! *
    5959         *    z^(2n+1) / (1 + z^2)^(n+1) ]
    6060         */
    61        
     61
    6262        for (unsigned int n = 0; n < SERIES_DEGREE_32; n++) {
    6363                if (n > 0) {
     
    6868                a = a * 4.0 * arg * arg / (1.0 + arg * arg);
    6969        }
    70        
     70
    7171        return sum;
    7272}
     
    8686        float64_t sum = 0;
    8787        float64_t a = arg / (1.0 + arg * arg);
    88        
     88
    8989        /*
    9090         * atan(z) = sum(n=0, +inf) [ (2^2n) * (n!)^2 / (2n + 1)! *
    9191         *    z^(2n+1) / (1 + z^2)^(n+1) ]
    9292         */
    93        
     93
    9494        for (unsigned int n = 0; n < SERIES_DEGREE_64; n++) {
    9595                if (n > 0) {
     
    100100                a = a * 4.0 * arg * arg / (1.0 + arg * arg);
    101101        }
    102        
     102
    103103        return sum;
    104104}
  • uspace/lib/math/generic/ceil.c

    r3061bc1 r8565a42  
    4848        float32_u v;
    4949        float32_u r;
    50        
     50
    5151        v.val = val;
    5252        t.val = trunc_f32(val);
    53        
     53
    5454        if (v.data.parts.sign == 1 || val == t.val) {
    5555                r = t;
     
    5757                r.val = t.val + 1.0;
    5858        }
    59        
     59
    6060        return r.val;
    6161}
     
    7272        float64_u v;
    7373        float64_u r;
    74        
     74
    7575        v.val = val;
    7676        t.val = trunc_f64(val);
    77        
     77
    7878        if (v.data.parts.sign == 1 || val == t.val) {
    7979                r = t;
     
    8181                r.val = t.val + 1.0;
    8282        }
    83        
     83
    8484        return r.val;
    8585}
  • uspace/lib/math/generic/exp.c

    r3061bc1 r8565a42  
    6464        float32_t ret = 1;
    6565        float32_t nom = 1;
    66        
     66
    6767        for (unsigned int i = 0; i < TAYLOR_DEGREE_32; i++) {
    6868                nom *= arg;
    6969                ret += nom / factorials[i];
    7070        }
    71        
     71
    7272        return ret;
    7373}
     
    8989        float64_t ret = 1;
    9090        float64_t nom = 1;
    91        
     91
    9292        for (unsigned int i = 0; i < TAYLOR_DEGREE_64; i++) {
    9393                nom *= arg;
    9494                ret += nom / factorials[i];
    9595        }
    96        
     96
    9797        return ret;
    9898}
  • uspace/lib/math/generic/floor.c

    r3061bc1 r8565a42  
    4848        float32_t t;
    4949        float32_u v;
    50        
     50
    5151        v.val = val;
    5252        t = trunc_f32(val);
    53        
     53
    5454        if (v.data.parts.sign == 0 || val == t)
    5555                return t;
     
    6969        float64_t t;
    7070        float64_u v;
    71        
     71
    7272        v.val = val;
    7373        t = trunc_f64(val);
    74        
     74
    7575        if (v.data.parts.sign == 0 || val == t)
    7676                return t;
  • uspace/lib/math/generic/fmod.c

    r3061bc1 r8565a42  
    5555{
    5656        // FIXME: replace with exact arithmetics
    57        
     57
    5858        float32_t quotient = trunc_f32(dividend / divisor);
    59        
     59
    6060        return (dividend - quotient * divisor);
    6161}
     
    8080{
    8181        // FIXME: replace with exact arithmetics
    82        
     82
    8383        float64_t quotient = trunc_f64(dividend / divisor);
    84        
     84
    8585        return (dividend - quotient * divisor);
    8686}
  • uspace/lib/math/generic/log.c

    r3061bc1 r8565a42  
    5555        float32_t ret = 0;
    5656        float32_t num = 1;
    57        
     57
    5858        for (unsigned int i = 1; i <= TAYLOR_DEGREE_32; i++) {
    5959                num *= arg;
    60                
     60
    6161                if ((i % 2) == 0)
    6262                        ret += num / i;
     
    6464                        ret -= num / i;
    6565        }
    66        
     66
    6767        return ret;
    6868}
     
    8383        float64_t ret = 0;
    8484        float64_t num = 1;
    85        
     85
    8686        for (unsigned int i = 1; i <= TAYLOR_DEGREE_64; i++) {
    8787                num *= arg;
    88                
     88
    8989                if ((i % 2) == 0)
    9090                        ret += num / i;
     
    9292                        ret -= num / i;
    9393        }
    94        
     94
    9595        return ret;
    9696}
     
    107107        float32_u m;
    108108        int e;
    109        
     109
    110110        m.val = arg;
    111111        /*
     
    118118        e = m.data.parts.exp - (FLOAT32_BIAS - 1);
    119119        m.data.parts.exp = FLOAT32_BIAS - 1;
    120        
     120
    121121        /*
    122122         * arg = m * 2^e ; log(arg) = log(m) + log(2^e) =
     
    137137        float64_u m;
    138138        int e;
    139        
     139
    140140        m.val = arg;
    141        
     141
    142142        /*
    143143         * Factor arg into m * 2^e where m has exponent -1,
     
    149149        e = m.data.parts.exp - (FLOAT64_BIAS - 1);
    150150        m.data.parts.exp = FLOAT64_BIAS - 1;
    151        
     151
    152152        /*
    153153         * arg = m * 2^e ; log(arg) = log(m) + log(2^e) =
  • uspace/lib/math/generic/trig.c

    r3061bc1 r8565a42  
    6464        float32_t ret = 0;
    6565        float32_t nom = 1;
    66        
     66
    6767        for (unsigned int i = 0; i < TAYLOR_DEGREE_32; i++) {
    6868                nom *= arg;
    69                
     69
    7070                if ((i % 4) == 0)
    7171                        ret += nom / factorials[i];
     
    7373                        ret -= nom / factorials[i];
    7474        }
    75        
     75
    7676        return ret;
    7777}
     
    9393        float64_t ret = 0;
    9494        float64_t nom = 1;
    95        
     95
    9696        for (unsigned int i = 0; i < TAYLOR_DEGREE_64; i++) {
    9797                nom *= arg;
    98                
     98
    9999                if ((i % 4) == 0)
    100100                        ret += nom / factorials[i];
     
    102102                        ret -= nom / factorials[i];
    103103        }
    104        
     104
    105105        return ret;
    106106}
     
    122122        float32_t ret = 1;
    123123        float32_t nom = 1;
    124        
     124
    125125        for (unsigned int i = 0; i < TAYLOR_DEGREE_32; i++) {
    126126                nom *= arg;
    127                
     127
    128128                if ((i % 4) == 1)
    129129                        ret -= nom / factorials[i];
     
    131131                        ret += nom / factorials[i];
    132132        }
    133        
     133
    134134        return ret;
    135135}
     
    151151        float64_t ret = 1;
    152152        float64_t nom = 1;
    153        
     153
    154154        for (unsigned int i = 0; i < TAYLOR_DEGREE_64; i++) {
    155155                nom *= arg;
    156                
     156
    157157                if ((i % 4) == 1)
    158158                        ret -= nom / factorials[i];
     
    160160                        ret += nom / factorials[i];
    161161        }
    162        
     162
    163163        return ret;
    164164}
     
    179179{
    180180        unsigned int period = arg / (M_PI / 4);
    181        
     181
    182182        switch (period) {
    183183        case 0:
     
    212212{
    213213        unsigned int period = arg / (M_PI / 4);
    214        
     214
    215215        switch (period) {
    216216        case 0:
     
    245245{
    246246        unsigned int period = arg / (M_PI / 4);
    247        
     247
    248248        switch (period) {
    249249        case 0:
     
    278278{
    279279        unsigned int period = arg / (M_PI / 4);
    280        
     280
    281281        switch (period) {
    282282        case 0:
     
    308308{
    309309        float32_t base_arg = fmod_f32(arg, 2 * M_PI);
    310        
     310
    311311        if (base_arg < 0)
    312312                return -base_sin_32(-base_arg);
    313        
     313
    314314        return base_sin_32(base_arg);
    315315}
     
    327327{
    328328        float64_t base_arg = fmod_f64(arg, 2 * M_PI);
    329        
     329
    330330        if (base_arg < 0)
    331331                return -base_sin_64(-base_arg);
    332        
     332
    333333        return base_sin_64(base_arg);
    334334}
     
    346346{
    347347        float32_t base_arg = fmod_f32(arg, 2 * M_PI);
    348        
     348
    349349        if (base_arg < 0)
    350350                return base_cos_32(-base_arg);
    351        
     351
    352352        return base_cos_32(base_arg);
    353353}
     
    365365{
    366366        float64_t base_arg = fmod_f64(arg, 2 * M_PI);
    367        
     367
    368368        if (base_arg < 0)
    369369                return base_cos_64(-base_arg);
    370        
     370
    371371        return base_cos_64(base_arg);
    372372}
  • uspace/lib/math/generic/trunc.c

    r3061bc1 r8565a42  
    5656        float32_u v;
    5757        int32_t exp;
    58        
     58
    5959        v.val = val;
    6060        exp = v.data.parts.exp - FLOAT32_BIAS;
    61        
     61
    6262        if (exp < 0) {
    6363                /* -1 < val < 1 => result is +0 or -0 */
     
    6969                        // FIXME TODO
    7070                }
    71                
     71
    7272                /* All bits in val are relevant for the result */
    7373        } else {
     
    7575                v.data.parts.fraction &= ~(UINT32_C(0x007fffff) >> exp);
    7676        }
    77        
     77
    7878        return v.val;
    7979}
     
    9898        float64_u v;
    9999        int32_t exp;
    100        
     100
    101101        v.val = val;
    102102        exp = v.data.parts.exp - FLOAT64_BIAS;
    103        
     103
    104104        if (exp < 0) {
    105105                /* -1 < val < 1 => result is +0 or -0 */
     
    111111                        // FIXME TODO
    112112                }
    113                
     113
    114114                /* All bits in val are relevant for the result */
    115115        } else {
     
    117117                v.data.parts.fraction &= ~(UINT64_C(0x000fffffffffffff) >> exp);
    118118        }
    119        
     119
    120120        return v.val;
    121121}
  • uspace/lib/math/include/mathtypes.h

    r3061bc1 r8565a42  
    9191typedef union {
    9292        uint32_t bin;
    93        
     93
    9494        struct {
    9595                uint32_t sign : 1;
     
    101101typedef union {
    102102        uint64_t bin;
    103        
     103
    104104        struct {
    105105                uint64_t sign : 1;
     
    114114                uint32_t lo;
    115115        } bin __attribute__((packed));
    116        
     116
    117117        struct {
    118118                uint64_t padding : 16;
     
    128128                uint64_t lo;
    129129        } bin __attribute__((packed));
    130        
     130
    131131        struct {
    132132                uint64_t sign : 1;
     
    141141typedef union {
    142142        uint32_t bin;
    143        
     143
    144144        struct {
    145145                uint32_t fraction : 23;
     
    151151typedef union {
    152152        uint64_t bin;
    153        
     153
    154154        struct {
    155155                uint64_t fraction : 52;
     
    164164                uint64_t hi;
    165165        } bin __attribute__((packed));
    166        
     166
    167167        struct {
    168168                uint64_t fraction : 64;
     
    178178                uint64_t hi;
    179179        } bin __attribute__((packed));
    180        
     180
    181181        struct {
    182182                uint64_t frac_lo : 64;
Note: See TracChangeset for help on using the changeset viewer.