Thread: Differents results x86 and ARM

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    2

    Differents results x86 and ARM

    Hi guys,

    I am a newbie in C and I am having some problems about the numeric format, My code in C is:

    Code:
    inline long compute_delta(struct timeval* t2, struct timeval* t1) {
            return ((long)(t2->tv_sec - t1->tv_sec)) * 1000000 +
                   (t2->tv_usec - t1->tv_usec);
    }
    #define LOG_EVERY_USEC 1000000
    //printf("DELTA %ld\n", compute_delta(&t2, &tlast));
            if(compute_delta(&t2, &tlast) > LOG_EVERY_USEC) {
    
                    fprintf(stdout, "received = %ld, throughput (b/s) = %ld\n",
                            totreceived,
                            ((8 * totreceived * 1000000L) / compute_delta(&t2, &tstart)));
                    fflush(stdout);
                    tlast = t2;
    
            }
    in x86 Architecture I have the results:

    received = 107321084, throughput (b/s) = 855028001
    received = 222587106, throughput (b/s) = 875168194
    received = 337852114, throughput (b/s) = 881820801
    received = 453118704, throughput (b/s) = 884694650

    in ARM architecture is different:
    received = 7954626, throughput (b/s) = -1323
    received = 19879344, throughput (b/s) = 310
    received = 31802412, throughput (b/s) = -502
    received = 43726706, throughput (b/s) = 329
    received = 55651424, throughput (b/s) = -114
    received = 67574492, throughput (b/s) = 198

    The code is the same in both architectures.

    Thanks Guys.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,880
    I suggest learning about inttypes.h and stdint.h std headers I think added in C99.

    The size of long and int likely differs between the two CPUs.

    Edit: Likely you should also use signed and unsigned prefixes in case the signness differs.

    Edit2: The literal constant 1000000 should have a suffix; likely L or UL.

    Tim S.
    Last edited by stahta01; 01-21-2015 at 12:45 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    2
    Thanks Tim,

    I've put the literal constant like 1000000LL and this did work.

    BR

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Code:
    ((8 * totreceived * 1000000L) / compute_delta(&t2, &tstart)
    The multiplication expression (8 * totreceived * 1000000L) is overflowing. If the size of long is 32 bits, this will overflow after about 267 bytes (!!)

    Apparently, whatever compiler you are using on x86 treats longs as 64 bits and there is no overflow.

    BTW, measing the time interval in microseconds will also be a problem if the timescale gets bigger (it'll overflow after 2147 seconds). It seems like way too much precision for what you are trying to do. Going down to milliseconds would alleviate both the multiplication overflow and the possible overflow in computing the time delta. Choose your scales carefully!
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. copying differents maps
    By l2u in forum C++ Programming
    Replies: 20
    Last Post: 10-14-2008, 04:59 AM
  2. Odd results.. help?
    By MCyborg in forum C Programming
    Replies: 15
    Last Post: 11-14-2005, 07:24 PM
  3. First results
    By RoD in forum Tech Board
    Replies: 19
    Last Post: 03-31-2004, 03:47 PM
  4. ADC #4 Results
    By Prelude in forum Contests Board
    Replies: 9
    Last Post: 08-28-2003, 01:38 PM
  5. Using differents API in a program
    By gustavosserra in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2003, 07:30 PM