Changeset 123be4f in mainline


Ignore:
Timestamp:
2012-11-25T18:56:39Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ce60be1
Parents:
ab52a3e (diff), 7462674 (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:

Mainline changes.

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/float/softfloat1.c

    rab52a3e r123be4f  
    3535#include <div.h>
    3636#include <comparison.h>
     37#include <conversion.h>
    3738#include <bool.h>
    3839#include "../tester.h"
    3940
    40 #define OPERANDS  6
     41#define OPERANDS  10
    4142#define PRECISION  10000
    4243
     
    4445
    4546typedef int32_t cmptype_t;
    46 typedef void (* float_op_t)(float, float, float *, float_t *);
    47 typedef void (* double_op_t)(double, double, double *, double_t *);
     47
     48typedef void (* uint_to_double_op_t)(unsigned int, double *, double_t *);
     49typedef void (* double_to_uint_op_t)(double, unsigned int *, unsigned int *);
     50typedef void (* float_binary_op_t)(float, float, float *, float_t *);
     51typedef void (* double_binary_op_t)(double, double, double *, double_t *);
    4852typedef void (* double_cmp_op_t)(double, double, cmptype_t *, cmptype_t *);
    49 typedef void (* template_t)(void *, unsigned, unsigned, cmptype_t *,
     53
     54typedef void (* template_unary_t)(void *, unsigned, cmptype_t *, cmptype_t *);
     55typedef void (* template_binary_t)(void *, unsigned, unsigned, cmptype_t *,
    5056    cmptype_t *);
    5157
    52 static float fop_a[OPERANDS] =
    53         {3.5, -2.1, 100.0, 50.0, -1024.0, 0.0};
    54 
    55 static float fop_b[OPERANDS] =
    56         {-2.1, 100.0, 50.0, -1024.0, 3.5, 0.0};
    57 
    58 static double dop_a[OPERANDS] =
    59         {3.5, -2.1, 100.0, 50.0, -1024.0, 0.0};
    60 
    61 static double dop_b[OPERANDS] =
    62         {-2.1, 100.0, 50.0, -1024.0, 3.5, 0.0};
     58#define NUMBERS \
     59        3.5, -2.1, 100.0, 50.0, -1024.0, 0.0, 768.3156, 1080.499999, -600.0, 1.0
     60
     61static float fop_a[OPERANDS] = {
     62        NUMBERS
     63};
     64
     65static double dop_a[OPERANDS] = {
     66        NUMBERS
     67};
     68
     69static unsigned int uop_a[OPERANDS] = {
     70        4, -100, 100, 50, 1024, 0, 1000000, -1U, 0x80000000U, 500
     71};
    6372
    6473static cmptype_t cmpabs(cmptype_t a)
     
    8190
    8291static void
    83 float_template(void *f, unsigned i, unsigned j, cmptype_t *pic,
     92uint_to_double_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc)
     93{
     94        double c;
     95        double_t sc;
     96
     97        uint_to_double_op_t op = (uint_to_double_op_t) f;
     98       
     99        op(uop_a[i], &c, &sc);
     100
     101        *pic = (cmptype_t) (c * PRECISION);
     102        *pisc = (cmptype_t) (sc.val * PRECISION);
     103}
     104
     105static void
     106double_to_uint_template(void *f, unsigned i, cmptype_t *pic, cmptype_t *pisc)
     107{
     108        unsigned int c;
     109        unsigned int sc;
     110
     111        double_to_uint_op_t op = (double_to_uint_op_t) f;
     112       
     113        op(dop_a[i], &c, &sc);
     114
     115        *pic = (cmptype_t) c;
     116        *pisc = (cmptype_t) sc;
     117}
     118
     119
     120static void
     121float_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic,
    84122    cmptype_t *pisc)
    85123{
     
    87125        float_t sc;
    88126
    89         float_op_t op = (float_op_t) f;
    90        
    91         op(fop_a[i], fop_b[j], &c, &sc);
     127        float_binary_op_t op = (float_binary_op_t) f;
     128       
     129        op(fop_a[i], fop_a[j], &c, &sc);
    92130
    93131        *pic = (cmptype_t) (c * PRECISION);
     
    96134
    97135static void
    98 double_template(void *f, unsigned i, unsigned j, cmptype_t *pic,
     136double_template_binary(void *f, unsigned i, unsigned j, cmptype_t *pic,
    99137    cmptype_t *pisc)
    100138{
     
    102140        double_t sc;
    103141
    104         double_op_t op = (double_op_t) f;
    105        
    106         op(dop_a[i], dop_b[j], &c, &sc);
     142        double_binary_op_t op = (double_binary_op_t) f;
     143       
     144        op(dop_a[i], dop_a[j], &c, &sc);
    107145
    108146        *pic = (cmptype_t) (c * PRECISION);
     
    116154        double_cmp_op_t op = (double_cmp_op_t) f;
    117155       
    118         op(dop_a[i], dop_b[j], pis, piss);
    119 }
    120 
    121 static bool test_template(template_t template, void *f)
     156        op(dop_a[i], dop_a[j], pis, piss);
     157}
     158
     159static bool test_template_unary(template_unary_t template, void *f)
     160{
     161        bool correct = true;
     162       
     163        for (unsigned int i = 0; i < OPERANDS; i++) {
     164                cmptype_t ic;
     165                cmptype_t isc;
     166
     167                template(f, i, &ic, &isc);     
     168                cmptype_t diff = cmpabs(ic - isc);
     169                       
     170                if (diff != 0) {
     171                        TPRINTF("i=%u diff=%" PRIdCMPTYPE "\n", i, diff);
     172                        correct = false;
     173                }
     174        }
     175       
     176        return correct;
     177}
     178
     179static bool test_template_binary(template_binary_t template, void *f)
    122180{
    123181        bool correct = true;
     
    142200}
    143201
     202static void uint_to_double_operator(unsigned int a, double *pc, double_t *psc)
     203{
     204        *pc = (double) a;
     205        psc->data = uint_to_double(a);
     206}
     207
     208static void
     209double_to_uint_operator(double a, unsigned int *pc, unsigned int *psc)
     210{
     211        double_t sa;
     212
     213        sa.val = a;
     214
     215        *pc = (unsigned int) a;
     216        *psc = double_to_uint(sa.data);
     217}
     218
     219static void
     220double_to_int_operator(double a, unsigned int *pc, unsigned int *psc)
     221{
     222        double_t sa;
     223
     224        sa.val = a;
     225
     226        *pc = (int) a;
     227        *psc = double_to_int(sa.data);
     228}
     229
    144230static void float_add_operator(float a, float b, float *pc, float_t *psc)
    145231{
     
    267353        const char *err = NULL;
    268354
    269         if (!test_template(float_template, float_add_operator)) {
     355        if (!test_template_binary(float_template_binary, float_add_operator)) {
    270356                err = "Float addition failed";
    271357                TPRINTF("%s\n", err);
    272358        }
    273         if (!test_template(float_template, float_mul_operator)) {
     359        if (!test_template_binary(float_template_binary, float_mul_operator)) {
    274360                err = "Float multiplication failed";
    275361                TPRINTF("%s\n", err);
    276362        }
    277         if (!test_template(float_template, float_div_operator)) {
     363        if (!test_template_binary(float_template_binary, float_div_operator)) {
    278364                err = "Float division failed";
    279365                TPRINTF("%s\n", err);
    280366        }
    281         if (!test_template(double_template, double_add_operator)) {
     367        if (!test_template_binary(double_template_binary, double_add_operator)) {
    282368                err = "Double addition failed";
    283369                TPRINTF("%s\n", err);
    284370        }
    285         if (!test_template(double_template, double_mul_operator)) {
     371        if (!test_template_binary(double_template_binary, double_mul_operator)) {
    286372                err = "Double multiplication failed";
    287373                TPRINTF("%s\n", err);
    288374        }
    289         if (!test_template(double_template, double_div_operator)) {
     375        if (!test_template_binary(double_template_binary, double_div_operator)) {
    290376                err = "Double division failed";
    291377                TPRINTF("%s\n", err);
    292378        }
    293         if (!test_template(double_compare_template, double_cmp_operator)) {
     379        if (!test_template_binary(double_compare_template, double_cmp_operator)) {
    294380                err = "Double comparison failed";
    295381                TPRINTF("%s\n", err);
    296382        }
     383        if (!test_template_unary(uint_to_double_template,
     384            uint_to_double_operator)) {
     385                err = "Conversion from unsigned int to double failed";
     386                TPRINTF("%s\n", err);
     387        }
     388        if (!test_template_unary(double_to_uint_template,
     389            double_to_uint_operator)) {
     390                err = "Conversion from double to unsigned int failed";
     391                TPRINTF("%s\n", err);
     392        }
     393        if (!test_template_unary(double_to_uint_template,
     394            double_to_int_operator)) {
     395                err = "Conversion from double to signed int failed";
     396                TPRINTF("%s\n", err);
     397        }
    297398       
    298399        return err;
  • uspace/lib/softfloat/common.c

    rab52a3e r123be4f  
    3939/* Table for fast leading zeroes counting. */
    4040char zeroTable[256] = {
    41         8, 7, 7, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, \
     41        8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, \
    4242        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    4343        2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \
     
    307307/**
    308308 * Round and normalize number expressed by exponent and fraction with
    309  * first bit (equal to hidden bit) at 62nd bit.
     309 * first bit (equal to hidden bit) at bit 62.
    310310 *
    311311 * @param exp Exponent part.
    312  * @param fraction Fraction with hidden bit shifted to 62nd bit.
     312 * @param fraction Fraction with hidden bit shifted to bit 62.
    313313 */
    314314void round_float64(int32_t *exp, uint64_t *fraction)
    315315{
    316         /* rounding - if first bit after fraction is set then round up */
     316        /*
     317         * Rounding - if first bit after fraction is set then round up.
     318         */
     319
     320        /*
     321         * Add 1 to the least significant bit of the fraction respecting the
     322         * current shift to bit 62 and see if there will be a carry to bit 63.
     323         */
    317324        (*fraction) += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3));
    318325       
     326        /* See if there was a carry to bit 63. */
    319327        if ((*fraction) &
    320             (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 3))) {
     328            (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1))) {
    321329                /* rounding overflow */
    322330                ++(*exp);
Note: See TracChangeset for help on using the changeset viewer.