Click here to Skip to main content
16,016,076 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: eliminate 50Hz noise in ECG.. Pin
Russell'10-Sep-07 23:25
Russell'10-Sep-07 23:25 
AnswerRe: eliminate 50Hz noise in ECG.. Pin
cp987611-Sep-07 0:36
cp987611-Sep-07 0:36 
QuestionFixed Point vs. Floating Point Pin
Leslie Sanford9-Sep-07 20:29
Leslie Sanford9-Sep-07 20:29 
AnswerRe: Fixed Point vs. Floating Point Pin
Russell'9-Sep-07 23:21
Russell'9-Sep-07 23:21 
GeneralRe: Fixed Point vs. Floating Point Pin
cp987610-Sep-07 1:06
cp987610-Sep-07 1:06 
AnswerRe: Fixed Point vs. Floating Point Pin
cp987610-Sep-07 0:53
cp987610-Sep-07 0:53 
AnswerRe: Fixed Point vs. Floating Point Pin
Luc Pattyn10-Sep-07 1:16
sitebuilderLuc Pattyn10-Sep-07 1:16 
GeneralRe: Fixed Point vs. Floating Point Pin
Leslie Sanford10-Sep-07 13:14
Leslie Sanford10-Sep-07 13:14 
Luc Pattyn wrote:
If you need to add code to prevent integers from overflowing, you should consider floats,
since unpredictable conditional branches are very bad for performance.


This is a bit off-topic, but I've been curious about how the compiler treats predictable branches. For example, say I have a function that is passed a boolean value. Within this method is a loop in which the boolean is tested:

void Function(bool condition)
{
    for(int i = 0; i < 1000; i++)
    {
        if(condition)
        {
            // Do stuff.
        }
        else
        {
            // Do other stuff.
        }
    }
}


The obvious cure for getting the branch out of the loop would be to nest the loop inside the if and else blocks; you'd wind up with two version of the loop. I've done this in some situations, but in others, it can lead to exceedingly verbose code.

So my question is that in the above situation, we have a condition that will not change for the duration of the function call, i.e. a predictable branch. Can the compiler help us out here to keep things efficient?

Luc Pattyn wrote:
If your inputs and outputs are integers, using floats will cost conversion times; most modern
CPUs have different register sets for ints and floats, and can pass data between them only
through "memory" (i.e. the data cache), adding to latency, and probably taking away some
performance.
If you need transcendental functions, floats are the obvious choice.
If you have streaming data the CPU might be optimized more for one or the other.
The Intel processor line has a long tradition of favoring integers over floats when spending
the transistor budget.
If your CPU is general-purpose (as opposed to DSP) and your algorithm needs a lot of
address calculations and indexing, you should consider float data, so the integer ALUs
are available for sequencing and addressing, the float ALU(s) for data operations.


Based on this criteria, I think I'll stick with floats. I seem to have the denormal problem under control, which was my main motivation for switching. I'm working on a VST synth plugin; the input and output to and from the plugin respectively are in floats, so it probably doesn't make sense to change to integers.

Thanks again for your insightful answers.
GeneralRe: Fixed Point vs. Floating Point Pin
Luc Pattyn10-Sep-07 13:30
sitebuilderLuc Pattyn10-Sep-07 13:30 
GeneralRe: Fixed Point vs. Floating Point Pin
cp987610-Sep-07 14:00
cp987610-Sep-07 14:00 
AnswerRe: Fixed Point vs. Floating Point Pin
Stuart Dootson11-Sep-07 22:56
professionalStuart Dootson11-Sep-07 22:56 
Questionalgorithm help!?! Pin
marvc17-Sep-07 6:11
marvc17-Sep-07 6:11 
AnswerRe: algorithm help!?! Pin
Luc Pattyn7-Sep-07 6:56
sitebuilderLuc Pattyn7-Sep-07 6:56 
GeneralRe: algorithm help!?! Pin
Dan Neely7-Sep-07 10:17
Dan Neely7-Sep-07 10:17 
GeneralRe: algorithm help!?! Pin
Luc Pattyn7-Sep-07 10:50
sitebuilderLuc Pattyn7-Sep-07 10:50 
GeneralRe: algorithm help!?! Pin
Daniel Grunwald7-Sep-07 11:42
Daniel Grunwald7-Sep-07 11:42 
GeneralRe: algorithm help!?! Pin
Luc Pattyn7-Sep-07 12:15
sitebuilderLuc Pattyn7-Sep-07 12:15 
AnswerRe: algorithm help!?! Pin
Russell'8-Sep-07 0:22
Russell'8-Sep-07 0:22 
QuestionMagic squares in matlab Pin
Rami Y.5-Sep-07 17:19
Rami Y.5-Sep-07 17:19 
AnswerRe: Magic squares in matlab Pin
Russell'5-Sep-07 22:26
Russell'5-Sep-07 22:26 
QuestionFRACTAL FORMULAS Pin
cyndy_northrup4-Sep-07 21:50
cyndy_northrup4-Sep-07 21:50 
AnswerRe: FRACTAL FORMULAS Pin
Russell'4-Sep-07 22:57
Russell'4-Sep-07 22:57 
GeneralRe: FRACTAL FORMULAS Pin
cyndy_northrup5-Sep-07 15:10
cyndy_northrup5-Sep-07 15:10 
GeneralRe: FRACTAL FORMULAS Pin
Russell'5-Sep-07 22:09
Russell'5-Sep-07 22:09 
AnswerRe: FRACTAL FORMULAS Pin
Luc Pattyn4-Sep-07 23:06
sitebuilderLuc Pattyn4-Sep-07 23:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.