JDK-6452568 : i486 use SQRTSS instead of SQRTSD for (float)Math.sqrt()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-07-25
  • Updated: 2010-04-03
  • Resolved: 2006-11-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u4Fixed 7Fixed hs10Fixed
Description
A DESCRIPTION OF THE REQUEST :
A common code sequence in 3d code is this:
float value = ....;
float result = (float)Math.sqrt(value);


Disabled code obtained from 1.6.0-rc-fastdebug-b90-debug
with the following options:
-XX:+PrintCompilation -XX:+PrintInlining -XX:+PrintOptoAssembly


JUSTIFICATION :
unneccessary float point format conversion.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
SQRTSS XMM1a,XMM0a

ACTUAL -
CVTSS2SD XMM0a,XMM1a	# D-round
SQRTSD XMM0a,XMM0a
CVTSD2SS XMM1a,XMM0a	# F-round

---------- BEGIN SOURCE ----------
public class Vector3f {
    
    public float x, y, z;

    public Vector3f normalize() {
        float x = this.x;
        float y = this.y;
        float z = this.z;
        float l = (float)Math.sqrt(x*x + y*y + z*z);
        this.x = x / l;
        this.y = y / l;
        this.z = z / l;
        return this;
    }

}

---------- END SOURCE ----------

Comments
SUGGESTED FIX Webrev: http://analemma.sfbay.sun.com/net/prt-archiver.sfbay/data/archived_workspaces/main/c2_baseline/2006/20060913084920.kvn.6452568/workspace/webrevs/webrev-2006.09.13/index.html
13-09-2006

SUGGESTED FIX Add the next optimization for SSE >= 1: replace CVTSS2SD XMM0a,XMM1a # D-round SQRTSD XMM0a,XMM0a CVTSD2SS XMM1a,XMM0a # F-round with: SQRTSS XMM0a,XMM1a
28-07-2006

EVALUATION Missed optimization.
28-07-2006