[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [f-cpu] Conditionnal Load and Store

On Fri, Jul 26, 2002 at 03:18:15PM +0200, Cedric BAIL wrote:
> Why didn't we have conditionnal load and store. I mean somtehing like storez,
> storenz, loadz, loadnz, ... It can be really usefull and we can do with that
> all what we can do with predicate I think.

Conditional load/store makes less sense than you may think. When an
address is loaded into a register, the prefetch cycle begins, whether
or not memory is actually accessed. Thus, there will be no increase in
memory bandwidth due to the use of conditional load/store.

The only positive effect ist that CL/S will avoid some jumps. That is,
in the rare case that you have code like

	if (condition) {
		*pointer = expression;

with no preset and no else clause (or a volatile memory location),
and with a trivial expression (something that is already present in a
register, or can be computed with few additional instructions).  If the
computation of the expression becomes more complex, a jump is the better
choice. As soon as other statements precede or follow the assignment
(inside the if clause), it is a must anyway.

BTW: Good programmers avoid code like this anyway. Remember that the
contents of `*pointer' remain undefined if `condition' evaluates to
`false'. It's much better to write:

	if (condition) {
		*pointer = expression;
	else {
		*pointer = default_value;


	*pointer = condition ? expression : default_value;

which can be transformed to a conditional move.

 Michael "Tired" Riepe <Michael.Riepe@stud.uni-hannover.de>
 "All I wanna do is have a little fun before I die"
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/