I guess, what I may be asking is, if CPU's accumA has value1 and accumB
has value2, is there one instruction that will compare the two values
and set accumA to either 0 or leave accumA with original value1?
Yes, on at least one CPU there is such an instruction (clear
accumulator, and any instruction can be conditional). However, whether
you use such a CPU I don't know, and whether any C compiler would
optimise any particular construct to use it I don't know either, and it
is irrelevant to the C language which don't have a specific construct to
do it. I would use a = (a == b ? a : 0) and let the compiler determine
the optimal code for whatever processor it is targetting. Or if you
want to be tricky (and probably slower):
a *= (a == b);
would do the same (a relational operator returns 1 if true and 0 if
false).
But premature optimisation is almost always a bad idea, and it can
result in worse code on some platforms (hence the 'register' keyword
being deprecated, it says to the compiler "I want this variable in a
register" but that may well not be the best one to optimise). Better to
write your code in a clear fashion, and only if you find it taking too
long run a profiler and find which parts are actually taking the time
(and be prepared to be very surprised, in the (uhm!) years I've been
programming I've seen lots of people very surprised that the
inefficiencies weren't where they expected and that some code they
thought was bound to be inefficient was optimised well by that
particular compiler).
Chris C