Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-04-2009
Member
 
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:

Quote:
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?
Reply With Quote
  #2  
Old 24-04-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #3  
Old 24-04-2009
Member
 
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.
Reply With Quote
  #4  
Old 24-04-2009
Member
 
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:

Quote:
1>.\sq.cpp(1) : warning C4164: 'sqrt' : intrinsic function not declared
Reply With Quote
  #5  
Old 25-04-2009
XSI XSI is offline
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Square root and Visual C++ compiler"
Thread Thread Starter Forum Replies Last Post
fatal error C1060: compiler is out of heap space in visual studio Dannai7 Software Development 5 15-06-2011 07:10 AM
DCDiag Test - DNS Root hints list has invalid root hint server Sean Windows Server Help 5 07-06-2010 10:47 PM
Square Root Symbol In Java Sheenas Software Development 5 27-01-2010 10:27 AM
How can I find square root using c program? ScarFace 01 Software Development 5 06-01-2010 02:16 PM
Compiler Error in Visual Studio 6,while adding OpenGL as header files. Santanio Software Development 2 12-01-2009 08:40 PM


All times are GMT +5.5. The time now is 01:36 PM.