Changeset bd48f4c in mainline for boot/genarch/src/multiplication.c


Ignore:
Timestamp:
2010-07-12T10:53:30Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bd11d3e
Parents:
c40e6ef (diff), bee2d4c (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 mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • boot/genarch/src/multiplication.c

    rc40e6ef rbd48f4c  
    3333
    3434#include <genarch/multiplication.h>
     35#include <typedefs.h>
    3536
    36 /** Set 1 to return MAX_INT64 or MIN_INT64 on overflow */
     37/** Set 1 to return INT64_MAX or INT64_MIN on overflow */
    3738#ifndef SOFTINT_CHECK_OF
    38         #define SOFTINT_CHECK_OF 0
     39        #define SOFTINT_CHECK_OF  0
    3940#endif
    40 
    41 #define MAX_UINT16  (0xFFFFu)
    42 #define MAX_UINT32  (0xFFFFFFFFu)
    43 #define MAX_INT64   (0x7FFFFFFFFFFFFFFFll)
    44 #define MIN_INT64   (0x8000000000000000ll)
    4541
    4642/** Multiply two integers and return long long as result.
     
    5147static unsigned long long mul(unsigned int a, unsigned int b) {
    5248        unsigned int a1 = a >> 16;
    53         unsigned int a2 = a & MAX_UINT16;
     49        unsigned int a2 = a & UINT16_MAX;
    5450        unsigned int b1 = b >> 16;
    55         unsigned int b2 = b & MAX_UINT16;
     51        unsigned int b2 = b & UINT16_MAX;
    5652       
    5753        unsigned long long t1 = a1 * b1;
     
    8581        unsigned long long b1 = b >> 32;
    8682       
    87         unsigned long long a2 = a & (MAX_UINT32);
    88         unsigned long long b2 = b & (MAX_UINT32);
     83        unsigned long long a2 = a & (UINT32_MAX);
     84        unsigned long long b2 = b & (UINT32_MAX);
    8985       
    9086        if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) {
    9187                /* Error (overflow) */
    92                 return (neg ? MIN_INT64 : MAX_INT64);
     88                return (neg ? INT64_MIN : INT64_MAX);
    9389        }
    9490       
     
    9894        unsigned long long t1 = mul(a1, b2) + mul(b1, a2);
    9995       
    100         if ((SOFTINT_CHECK_OF) && (t1 > MAX_UINT32)) {
     96        if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) {
    10197                /* Error (overflow) */
    102                 return (neg ? MIN_INT64 : MAX_INT64);
     98                return (neg ? INT64_MIN : INT64_MAX);
    10399        }
    104100       
     
    112108        if ((SOFTINT_CHECK_OF) && ((t2 < t1) || (t2 & (1ull << 63)))) {
    113109                /* Error (overflow) */
    114                 return (neg ? MIN_INT64 : MAX_INT64);
     110                return (neg ? INT64_MIN : INT64_MAX);
    115111        }
    116112       
Note: See TracChangeset for help on using the changeset viewer.