Experimental Physics and Industrial Control System
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: [email protected]
> 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 [email protected]
> 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
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- 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
<2012>
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024