Hi,
I'm working on an implementation of the CORDIC
algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you
can implement it with simple additions of numbers and
division of (doubles) by powers of two. However, there
doesn't seem to be any mechanism in the C/C++ language
to direct the compiler to do this efficient form of division,
any ideas, experiences out there please?
dave 11 4831
Dave Townsend wrote: I'm working on an implementation of the CORDIC algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you can implement it with simple additions of numbers and division of (doubles) by powers of two. However, there doesn't seem to be any mechanism in the C/C++ language to direct the compiler to do this efficient form of division, any ideas, experiences out there please?
I am curious about how you've arrived to the [apparent] conclusion
that whatever the compiler does (without your direction) is somehow
inefficient.
V
--
Please remove capital As from my address when replying by mail
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:Xs******** *************** *******@comcast .com... Dave Townsend wrote: I'm working on an implementation of the CORDIC algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you can implement it with simple additions of numbers and division of (doubles) by powers of two. However, there doesn't seem to be any mechanism in the C/C++ language to direct the compiler to do this efficient form of division, any ideas, experiences out there please?
I am curious about how you've arrived to the [apparent] conclusion that whatever the compiler does (without your direction) is somehow inefficient.
V -- Please remove capital As from my address when replying by mail
I happend to have looked at the assembly code generated - albeit in Debug
mode on VC6.
9: double d = 100.00;
00401028 mov dword ptr [ebp-8],0
0040102F mov dword ptr [ebp-4],40590000h
10: double e = d / 2 ;
00401036 fld qword ptr [ebp-8]
00401039 fdiv qword ptr [__real@8@400080 00000000000000 (00423ff0)]
0040103F fstp qword ptr [ebp-10h]
11: double f = d / 2.5;
00401042 fld qword ptr [ebp-8]
00401045 fdiv qword ptr [__real@8@400080 00000000000000 (00423030)]
0040104B fstp qword ptr [ebp-18h]
Dave Townsend skrev: "Victor Bazarov" <v.********@com Acast.net> wrote in message news:Xs******** *************** *******@comcast .com... Dave Townsend wrote: I'm working on an implementation of the CORDIC algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you can implement it with simple additions of numbers and division of (doubles) by powers of two. However, there doesn't seem to be any mechanism in the C/C++ language to direct the compiler to do this efficient form of division, any ideas, experiences out there please? I am curious about how you've arrived to the [apparent] conclusion that whatever the compiler does (without your direction) is somehow inefficient.
V -- Please remove capital As from my address when replying by mail
I happend to have looked at the assembly code generated - albeit in Debug mode on VC6.
Are you trashing a compiler as inefficient based on the debug code? 9: double d = 100.00; 00401028 mov dword ptr [ebp-8],0 0040102F mov dword ptr [ebp-4],40590000h 10: double e = d / 2 ; 00401036 fld qword ptr [ebp-8] 00401039 fdiv qword ptr [__real@8@400080 00000000000000 (00423ff0)] 0040103F fstp qword ptr [ebp-10h] 11: double f = d / 2.5; 00401042 fld qword ptr [ebp-8] 00401045 fdiv qword ptr [__real@8@400080 00000000000000 (00423030)] 0040104B fstp qword ptr [ebp-18h]
And what do you deem as a more efficient substitute?
--
TB @ SWEDEN
"TB" <TB@SWEDEN> wrote in message
news:44******** **************@ taz.nntpserver. com... Dave Townsend skrev: "Victor Bazarov" <v.********@com Acast.net> wrote in message news:Xs******** *************** *******@comcast .com... Dave Townsend wrote: I'm working on an implementation of the CORDIC algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you can implement it with simple additions of numbers and division of (doubles) by powers of two. However, there doesn't seem to be any mechanism in the C/C++ language to direct the compiler to do this efficient form of division, any ideas, experiences out there please? I am curious about how you've arrived to the [apparent] conclusion that whatever the compiler does (without your direction) is somehow inefficient.
V -- Please remove capital As from my address when replying by mail
I happend to have looked at the assembly code generated - albeit in
Debug mode on VC6.
Are you trashing a compiler as inefficient based on the debug code?
9: double d = 100.00; 00401028 mov dword ptr [ebp-8],0 0040102F mov dword ptr [ebp-4],40590000h 10: double e = d / 2 ; 00401036 fld qword ptr [ebp-8] 00401039 fdiv qword ptr [__real@8@400080 00000000000000
(00423ff0)] 0040103F fstp qword ptr [ebp-10h] 11: double f = d / 2.5; 00401042 fld qword ptr [ebp-8] 00401045 fdiv qword ptr [__real@8@400080 00000000000000
(00423030)] 0040104B fstp qword ptr [ebp-18h]
And what do you deem as a more efficient substitute?
-- TB @ SWEDEN
Did everybody get out of bed on the wrong side this morning?
I'm not trashing anybody or any compiler, I'm just trying to investigate the
benefits of using a CORDIC algorithm. I was looking for a "shift" type
operation which would divide a double by a power of two which presumably
would be more efficient than a general purpose division algorithm. If people
have some useful comments, please post.
Dave Townsend wrote: [..] Did everybody get out of bed on the wrong side this morning?
Not me. You sound like that, however. I was just asking where you
get your information about the alleged inefficiency.
I'm not trashing anybody or any compiler, I'm just trying to investigate the benefits of using a CORDIC algorithm.
I have no idea what that is. C++ Standard doesn't define one, so
you might actually mention some source of information (besides the
obvious Google) about your subject.
I was looking for a "shift" type operation which would divide a double by a power of two which presumably would be more efficient than a general purpose division algorithm. If people have some useful comments, please post.
Dividing by a power of two the most efficiently would be subtracting
from the exponent stored in some bits of the FP number. Is that what
you're trying to do? Essentially you need to extract the exponent
(see 'frexp' function), subtract and then recombine the new exponent
with the mantissa (see 'ldexp' function).
V
--
Please remove capital As from my address when replying by mail Did everybody get out of bed on the wrong side this morning? I'm not trashing anybody or any compiler, I'm just trying to investigate the benefits of using a CORDIC algorithm. I was looking for a "shift" type operation which would divide a double by a power of two which presumably would be more efficient than a general purpose division algorithm. If people have some useful comments, please post.
Assuming that floating point values are stored in a certain format (ie. IEEE
floats) you can implement your own shift operations that would modify the
mantisa fields of the binary representations directly. This would obviously
be non-portable and certainly not guaranteed to be faster than the
corresponding multiplications/division performed on the FPU.
-- Marek
Dave Townsend wrote:
[snipped] Did everybody get out of bed on the wrong side this morning? I'm not trashing anybody or any compiler, I'm just trying to investigate the benefits of using a CORDIC algorithm. I was looking for a "shift" type operation which would divide a double by a power of two which presumably would be more efficient than a general purpose division algorithm. If people have some useful comments, please post.
Dave,
For start of the discourse, why in the Earth you think it is possible to do
'efficient' division with floats using shifts?
--
Cesar Rabak
GNU/Linux User 52247.
Get counted: http://counter.li.org/
"Cesar Rabak" <cs*****@hotmai l.com> wrote in message
news:dt******** **@emma.aioe.or g... Dave Townsend wrote:
[snipped] Did everybody get out of bed on the wrong side this morning? I'm not trashing anybody or any compiler, I'm just trying to investigate the benefits of using a CORDIC algorithm. I was looking for a "shift"
type operation which would divide a double by a power of two which presumably would be more efficient than a general purpose division algorithm. If people have some useful comments, please post.
Dave,
For start of the discourse, why in the Earth you think it is possible to
do 'efficient' division with floats using shifts?
-- Cesar Rabak GNU/Linux User 52247. Get counted: http://counter.li.org/
Why not? I never did computer science at school, so I only have a limited
knowledge of how floating point numbers are manipulated in the hardware.
From what I do know, it doesn't seem a stretch to shift the mantissa part of
the number by 2 and then deal with the possible change in mantissa? That
would appear to be less effort than a general double precision divide. What
am I missing here?
I thought there might be a special instruction on many CPU architectures
which could do divide by a power of two. Notice that I did put "shift" in
quotes, not to imply that it was literally possible that the operation could
be done in shifts. The idea is not so unreasonable, the CORDIC algorithm
is used extensively in chip design where the "divide-by-power-of-two" can
be performed by relatively simple digital logic. For that matter, I
understand that a lot of early portable calculators computed trig functions
this way.
Oh, dear, perhaps this is getting a little too far off-topic?
Dave Townsend wrote: "Cesar Rabak" <cs*****@hotmai l.com> wrote in message news:dt******** **@emma.aioe.or g... Dave Townsend wrote:
> [snipped] > Did everybody get out of bed on the wrong side this morning? > I'm not trashing anybody or any compiler, I'm just trying to > investigate the benefits of using a CORDIC algorithm. I was looking for > a "shift" type > operation which would divide a double by a power of two which > presumably would be more efficient than a general purpose division > algorithm. If people have some useful comments, please post.
Dave,
For start of the discourse, why in the Earth you think it is possible to do 'efficient' division with floats using shifts? Why not? I never did computer science at school, so I only have a limited knowledge of how floating point numbers are manipulated in the hardware.
OK. This explains certain things.
From what I do know, it doesn't seem a stretch to shift the mantissa part of the number by 2 and then deal with the possible change in mantissa? That would appear to be less effort than a general double precision divide. What am I missing here?
The first thing I think you should consider is that in most hosted
environments the floating point operation will done in a specific silicon
real state in the machine generally called "Floating Point Processor" or
something along this name.
Caveat: YMMV if you're coding for free standing environments like SBCs or
some other exotic hardware.
Second thing is the representation of the mantissa can not be in a format
that shifting bits may be not enough to do a division by two.
Last but not the least. It remains that the platform gives you access to
manipulating the mantissa bits themselves and then (obviously that would be
not portable from this point on) a means to expose this to the compiler
you're using. I thought there might be a special instruction on many CPU architectures which could do divide by a power of two. Notice that I did put "shift" in quotes, not to imply that it was literally possible that the operation could be done in shifts.
OK. I see you put '"shift" in quotes'. I think we can now settle this
special instruction, even if it exists for some exotic architecture, is not
part of the C++ standard.
You would need to check the targed CPU of your project and then see if it is
worhtwhile to expend time to call it via an embedded assembly instruction. The idea is not so unreasonable, the CORDIC algorithm is used extensively in chip design where the "divide-by-power-of-two" can be performed by relatively simple digital logic. For that matter, I understand that a lot of early portable calculators computed trig functions this way.
The CORDIC algorithm and specially the trick you mention is intended for use
when all the math is done with integer arithmetic. I also was exposed to
the CORDIC routine with this information the early hand calculator used it.
HTH
--
Cesar Rabak
GNU/Linux User 52247.
Get counted: http://counter.li.org/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: OcelotIguana |
last post by:
Hello,
Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?
Thanks,
OcelotIguana@yahoo.com
|
by: Davidlohr Bueso |
last post by:
Hi,
I've been trying to write some trigonometric functions of the math library
(sin, cos, tan, etc, etc.) in C and I've learned that instead of using
series, the best way to go is by using the CORDIC algorithm. The problem
is that I haven't been able to find the algorithm itself, just brief
descriptions of it. Does anyone have any experience with this? Thanks!
Dave
|
by: Hans |
last post by:
Hi All,
In the stripped down code example below Visual C++ 2005 issues the following
error:
error LNK2019: unresolved external symbol "public: void __thiscall
Addsub<24>::do_process123(void)"
This is a SystemC example, however I believe this is a basic C++ syntax
error since if I move the Addsub function inside the Addsub class (that is
|
by: astri |
last post by:
#include "Unit1.h"
#include "math.h"
#include "fixed_math.hpp"
#include "algorithm.h"
#define MBIT 0x4000
#define CBIT 16
long constbl;
void __fastcall TForm1::Button1Click(TObject *Sender)
|
by: astri |
last post by:
i`m doing thesis about comparing calculation of arctan by polynomial and CORDIC. I`ve read a lot of journal and books about CORDIC and this is what i understand.
1. make x and y
2. make iterations
3. process with cordic calculation
4. the arctan result is calculating by arctan(y/x).
what i m confused that in cordic equation there`s
Zi=Zo-arctan(2^-i)
| |
by: astri |
last post by:
i`m doing my thesis comparing CORDIC with polynomial in counting arctan with fixed point. I`m using Q15 format now. I`m using this site CORDIC arctan as a referenced when making with floating point. The problem there`s a lot of error when i try to make it with fixed point.
this is my program
#include "Unit1.h"
#include "math.h"
#include "fixed_math.hpp"
#define MAXBITS 15
static float invGain1;
|
by: Roman Mashak |
last post by:
Hello,
I'd like to make a simple replacement of 'pow()' function for the embedded
platform I'm working on. What is the better way, probably bit shifting?
Thanks.
Best regards, Roman Mashak.
|
by: manish2008 |
last post by:
Assignment statement
Background theory
Consider a phasor at an angle of Ø (0 <= Ø <= 90°) with projections on the x and y axes as x0 and y0, respectively.
Let it be rotated by an angle of Ø0 (0 <= Ø0 < 90°) so that it is now at an angle of Ø'0 (0 <= Ø'0 <= 90°) with projections on the x and y axes as x1 and y1, respectively.
It can be easily shown that x1 and y1 are related to x0 and y0 as follows:
x1 = x0 * cos(Ø0) - y0 *...
|
by: kadghar |
last post by:
Hello Experts:
I was wondering if anyone knows how does a computer do exponents operations (powers).
I know its simple when the exponent is a positive integer.
a^b can be easily done with:
c = 1
while b > 1 {
c = c * a
b = b - 1
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |