Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16673

qRound do double to float conversions

XMLWordPrintable

    • 0f9cbfc6124b331d006b396d56ad5ae0e6d548e0

      Purra Joel (TCS) 2011-01-10 15:37:23 EET

      STEPS LEADING TO PROBLEM:
      --------------------------
      floating point compiler optimization has been enabled but the effect was less
      than expected

      It is caused by the function int qRound(qreal d) , defined in qglobal.h

      Reason is as follows :
      ------------------------
      Code like below line cause conversion to double
      qreal b = 3.0;
      qreal a = 2.0* b;
      double calculations are not optimized

      It should be
      qreal b = 3.0f;
      qreal a = 2.0f* b;

      For more on double conversion analysis, refer
      https://projects.maemo.org/mediawiki/index.php/SystemAnalysis/DoubleConversion

      Comment 1 Liimatainen Jari Juhani (Nokia) error_managers 2011-01-10 15:50:45 EET

      Joel sent me the actual code of qRound via e-mail:

      inline int qRound(qreal d) // here, qreal can be though of as float for ARM.

      { return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }

      If this is called all over our code, it would be nice to get this fixed indeed,
      as it causes unnecessary double conversions, and results into not using
      run-fast mode (i.e. NEON), as it does not support doubles, but only floats.

      Comment 2 Mannisto Tatu (Nokia) 2011-01-10 16:07:58 EET

      You may also look at
      https://projects.maemo.org/mediawiki/index.php?title=SystemAnalysis/NEON%2Bfloats
      for other potential ways to handle these small Qt math related functions.

      As stated there the 0.5 constant should be used as qreal(0.5) in the qRound.

      Comment 3 Pakarinen Juuso (Tieto) 2011-01-13 09:40:24 EET

      (In reply to comment #2)
      > You may also look at
      > https://projects.maemo.org/mediawiki/index.php?title=SystemAnalysis/NEON%2Bfloats
      > for other potential ways to handle these small Qt math related functions.
      >
      > As stated there the 0.5 constant should be used as qreal(0.5) in the qRound.

      So just to make sure, is your fix proposal following:
      inline int qRound(qreal d) // here, qreal can be though of as float for ARM.

      { return d >= 0.0 ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1); }

      Comment 4 Liimatainen Jari Juhani (Nokia) error_managers 2011-01-13 10:17:17 EET

      (In reply to comment #3)
      > (In reply to comment #2)
      > > You may also look at
      > > https://projects.maemo.org/mediawiki/index.php?title=SystemAnalysis/NEON%2Bfloats
      > > for other potential ways to handle these small Qt math related functions.
      > >
      > > As stated there the 0.5 constant should be used as qreal(0.5) in the qRound.
      > So just to make sure, is your fix proposal following:
      > inline int qRound(qreal d) // here, qreal can be though of as float for ARM.
      >

      { return d >= 0.0 ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + > int(d-1); }

      Yes, but it's good to verify with objdump still, is that enough, or should you
      do explicit conversion also of 0.0.

      I believe d-1 parts do not cause implicit double conversions, but that's also
      good to veryfy with objdump so that the fix will be flawless.

      For exact instructions how to verify it, please check the link provided in the
      description!

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            jupakari Juuso Pakarinen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes