Results 1 to 5 of 5

Thread: Square root and Visual C++ compiler

  1. #1
    Join Date
    May 2008
    Posts
    962

    Square root and Visual C++ compiler

    Suppose that:
    1) you create a new C++ (Empty C++) in Visual Studio 2008 Express.
    2) you have a Core 2 Duo 6400@2.13GHz like mine or something
    3) we write, compile and execute this code:

    Code:
    # include <math.h> 
    int main (void) 
    {
    sqrt (71634.4174f); 
    return 0; 
    }
    The implementation of sqrt (71634.4174f); going to map a (or a set of) instruction (s) Math (s) established (s) in the processor, or are we going to use an implementation of calculating the square root of this issue found in the library by pointing math.h. And if so, are there ways to ensure that the program should make use of mathematical instructions located in the CPU, without diving into the writing of microcode assembler?

    For info, I found this, about the Core 2 Duos:

    Sqrt is an intrinsic on the SSE-platform, and thus reduces to a single instruction. The implementation for ppu/spu is based on the inverse-square-root estimate intrinsic of these platforms. This instruction is combined with one iteration of the Newton-Raphson algorithm to provide the final result.
    I wonder in passing (and admiration) that their implementation is able to obtain a sufficiently accurate with a single iteration of the Newton algo. Their basic approximation must be devilishly good. Reminds me of 0x5f3759df

    I ask this because I have tested the execution time of 10 million once a sqrt () and 10 million times a root obtained by the Newton algo precisely, and I was surprised to get a time 2/3 or 3/4 lower with a code made by hand.

    So, what is VC++ compiler will do with a code like that?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Square root and Visual C++ compiler

    sqrt drew implementation lib by sellers who will be optimized or not. Under VC, it should be used after implementation IEE SUN MATH 754 or approaching.

    1 from Newton-Raphson enough time or your proxy is to be near 10-4 lead to 10-8. It's the same trick in Altivec. And in fact, we wrote more assembler to pr ESS kind since 10 years, should see to keep up

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: Square root and Visual C++ compiler

    Under visual there is a pragma to enable intrinsic, including sqrt. You can also use an optional compiler, I know that. It depends on your compiler and its configuration, not your processor.

    If in doubt, compile in release + debug info (possible) and look at the assembly.

  4. #4
    Join Date
    May 2008
    Posts
    962

    Re: Square root and Visual C++ compiler

    OK, I try to use #pragma intrinsic (sqrt) but strangely it is not recognized by the compiler:

    1>.\sq.cpp(1) : warning C4164: 'sqrt' : intrinsic function not declared

  5. #5
    Join Date
    May 2008
    Posts
    271

    Re: Square root and Visual C++ compiler

    Quote Originally Posted by kelfro View Post
    And in fact, we wrote more assembler to pr ESS kind since 10 years, should see to keep up
    I do not know or its seen that, but there are people who write the assembler SSE every day and working for large hi-tech companies.

    Of course, not necessarily for general public applications, but it exists. VC in the compilation of SSE intrinsics does all the time not the same as the inline assembler.

Similar Threads

  1. Replies: 5
    Last Post: 15-06-2011, 07:10 AM
  2. Replies: 5
    Last Post: 07-06-2010, 10:47 PM
  3. Square Root Symbol In Java
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 10:27 AM
  4. How can I find square root using c program?
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 06-01-2010, 02:16 PM
  5. Replies: 2
    Last Post: 12-01-2009, 08:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,674,540.93444 seconds with 17 queries