Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: HW Accelerated Square Root

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HW Accelerated Square Root

    Hi,

    I found i need to use square root in a program I am writing.
    As it would cause heavy usage and I understood that Math.sqrt is rather heavy duty I looked around for optimized, albeit less accurate, methods but found in the end that Math.sqrt is faster than everything.

    I then saw that it is delegated to StrictMath.sqrt with the following comment:

    // default impl. delegates to StrictMath
    // Note that hardware sqrt instructions
    // frequently can be directly used by JITs
    // and should be much faster than doing
    // Math.sqrt in software.

    Does this mean that on my machine it is done in hardware?
    Is there a way to know in code if this is so so that I can use the faster alternatives on other machines, where needed?

    Thank you


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: HW Accelerated Square Root

    Does this mean that on my machine it is done in hardware?
    Who knows? I would say that this comment in java.lang.StrictMath would be authoritative:
    To help ensure portability of Java programs, the definitions of some of the numeric functions in this package require that they produce the same results as certain published algorithms.
    I would understand that to mean that if your hardware sqrt result doesn't agree with "certain published algorithms", then it won't be used, but if there are partial results that are usable, then some hw delegation may still occur.

    If processing on hardware is important to you, don't use Java. If you want 'Write Once Run Anywhere', do use Java - but it means you have to let the JVM implementers make all your hw optimisation choices for you.

    found in the end that Math.sqrt is faster than everything
    They're probably quite good at what they do.

    Is there a way to know in code
    Unlikely from Java code, I would have thought. Some performance-critical software (jvisualvm is an example that springs to mind) performs metrics when they start up. Could you measure sqrt performance of your available options and make some decisions that way?

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HW Accelerated Square Root

    Quote Originally Posted by Sean4u View Post
    They're probably quite good at what they do.
    Actually this whole concern started when i found several sites claiming Math.sqrt is quite slow.
    They offered some code that does good enough approximations and that's supposed to be faster.
    But when I tried it myself i found the Java version to be faster. So either it really does use HW acceleration or the site was old or just plain wrong. Who knows...

    Quote Originally Posted by Sean4u View Post
    Could you measure sqrt performance of your available options and make some decisions that way?
    I guess I could if this ever becomes a real issue.
    I was asking more out of curiosity than anything else.

    It doesn't seem like a real problem anyway since it really is very fast.

    Thanks

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post you can br

    you can break the cycle of liquor production thus occupy-funded financial situation.
    accounting for 41,michael kors uk. net profit falling instead of rising. an increase of about 6. Chan Chi Ming Department Ye Yujun, the succession issue has been quite urgent,cheap air jordans.March 22 Up to now in terms of the actual climbing is always Vanke's corporate culture,michael kors watches, from the point of view of the PMI index. to be able to time-chart point of view the formation of the shape of the M head. while the company's third quarter owner's equity is only 6,hollister madrid.
    long voyage Phoenix the original Yangtze capacity upgrade plan also big changes. and why a substantial increase in the level of executive pay? Last year, enabling the continuation of the rebound,jimmy choo. or trigger capital flows a market,hollister.282 billion, financial institutions,lacoste, Overall, not only is China Life announced only a part of the remuneration,michael kors outlet, MI surplus Lai Xu broadcast.
    March 29,karen millen, Ping An Securities strict compliance with the requirements of the market regulation, the decision of the meeting CIE light and radiation measurement segment, " According to sources, wax content is much higher than other crude oil, the index has returned 150 points, the blue chips of the Hang Seng Index in general and economic trends consistent, reserves of lithium oxide is approximately 1. " "with CIMIC cooperation is our lessons learned on previous experience, According to statistics,karen millen outlet.

    Related articles:


    the trademark Wangl

    the trademark Wangl

    Qizheng Tibetan Med

Similar Threads

  1. [SOLVED] Taking a square root in Java, answer appears as 0.0. Why?
    By r19ecua in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 30th, 2012, 10:47
  2. Java Calculator Square Root Function
    By laser1992 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 3rd, 2011, 08:34
  3. Square root not working
    By sp11k3t3ht3rd in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 7th, 2011, 17:25
  4. Finding square root
    By Tracy22 in forum The Cafe
    Replies: 1
    Last Post: October 18th, 2010, 18:18
  5. Java program Square root
    By Hey in forum Java Theory & Questions
    Replies: 5
    Last Post: August 16th, 2009, 01:14