g+
g+ Communities
Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  Index 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
<== Date ==> <== Thread ==>

Subject: RE: optimization to epicsTime
From: "Hill, Jeff" <johill@lanl.gov>
To: "core-talk@aps.anl.gov" <core-talk@aps.anl.gov>
Date: Wed, 14 Nov 2012 20:13:25 +0000
I also changed this function to not be inline, since it is larger now,
after being optimized.

> -----Original Message-----
> From: Hill, Jeff
> Sent: Wednesday, November 14, 2012 1:05 PM
> To: core-talk@aps.anl.gov
> Subject: optimization to epicsTime
> 
> Dear All,
> 
> I inadvertently committed the attached change to the main trunk on a
> checkout instead of a branch and therefore bypassed the normal review
> process. If there is (any) opposition I will back out the change and make
> a branch. I did run the epicsTime regression test, which didn't detect any
> issues, before making this commit.
> 
> Jeff
> 
> Commit message:
> 
> After optimizing the epicsTime::addNanoSec function we now have a larger
> code which uses only unsigned integer arithmetic. This is for the benefit
> of embedded cpu's lacking a hardware floating point coprocessor at the
> expense of some additional code to maintain. I measured the cpu load
> improving from 40% free to 80% free after making this change, on a nios2
> soft core processor.
> 
> Change:
> 
> == modified file src/libCom/osi/epicsTime.cpp
> --- src/libCom/osi/epicsTime.cpp	2012-05-03 17:19:34 +0000
> +++ src/libCom/osi/epicsTime.cpp	2012-11-14 19:51:30 +0000
> @@ -113,8 +113,48 @@
>  //
>  inline void epicsTime::addNanoSec (long nSecAdj)
>  {
> -    double secAdj = static_cast <double> (nSecAdj) / nSecPerSec;
> -    *this += secAdj;
> +    // After optimizing this function we now have a larger
> +    // code which uses only unsigned integer arithmetic.
> +    // This is for the benefit of embedded cpu's lacking
> +    // a hardware floating point coprocessor at the
> +    // expense of some additional code to maintain.
> +    // joh 14-11-2012
> +    if ( nSecAdj >= 0 ) {
> +        unsigned long nSecOffsetLong =
> +              static_cast < unsigned long > ( nSecAdj );
> +        while ( nSecOffsetLong >= nSecPerSec ) {
> +            this->secPastEpoch++; // overflow expected
> +            nSecOffsetLong -= nSecPerSec;
> +        }
> +        const epicsUInt32 nSecOffset =
> +            static_cast < epicsUInt32 > ( nSecOffsetLong );
> +        epicsUInt32 nSecPerSecRemaining = nSecPerSec - nSecOffset;
> +        if ( this->nSec >= nSecPerSecRemaining ) {
> +            this->secPastEpoch++; // overflow expected
> +            this->nSec -= nSecPerSecRemaining;
> +        }
> +        else {
> +            this->nSec += nSecOffset;
> +        }
> +    }
> +    else {
> +        unsigned long nSecOffsetLong =
> +            static_cast <unsigned long> ( -nSecAdj );
> +        while ( nSecOffsetLong >= nSecPerSec ) {
> +            this->secPastEpoch--; // underflow expected
> +            nSecOffsetLong -= nSecPerSec;
> +        }
> +        const epicsUInt32 nSecOffset =
> +            static_cast < epicsUInt32 > ( nSecOffsetLong );
> +        if ( this->nSec >= nSecOffset ) {
> +            this->nSec -= nSecOffset;
> +        }
> +        else {
> +            // borrow
> +            this->secPastEpoch--; // underflow expected
> +            this->nSec += nSecPerSec - nSecOffset;
> +        }
> +    }
>  }
> 
>  //
> 
> 
> Jeff
> ______________________________________________________
> Jeffrey O. Hill           Email        johill@lanl.gov
> LANL MS H820              Voice        505 665 1831
> Los Alamos NM 87545 USA   FAX          505 665 5107
> 
> Message content: TSPA
> 
> 



Navigate by Date:
Prev: optimization to epicsTime Hill, Jeff
Next: Re: optimization to epicsTime Andrew Johnson
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
Navigate by Thread:
Prev: Re: optimization to epicsTime Andrew Johnson
Next: catch in ubuntu gcc 4.6.1 Hill, Jeff
Index: 2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
ANJ, 26 Nov 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICSv4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·