Re: [OT] On `ad hominem' - OS X users



On 2008-09-25 20:57, John W Kennedy <jwkenne@xxxxxxxxxxxxx> wrote:
Sherm Pendley wrote:
It's a fact that modern compilers *usually* generate faster code than
hand-coded assembler. If this library is an exception to that general
rule, why can't you just say so without being a condescending ass
about it?

While this is true, it applies only to things that the language can
express. Most processors have special tricks for multi-word arithmetic
(such as the Intel ADC instruction or the new z/Architecture ALC family
of instructions) that cannot be expressed at all in, say, C. (That is, C
has no way of saying, "Add X to Y, and add an additional 1 if the last
addition set the CPU carry flag.")

The CPU may not have a carry flag.

However, you can express "Add X to Y, and add an additional 1 if the last
addition produced an unsigned overflow" (which is functionally the same
thing):

struct twowords {
unsigned low;
unsigned high;
};

struct twowords add (struct twowords a, struct twowords b) {
struct twowords result;
result.low = a.low + b.low; /* 1 */
result.high = a.high + b.high + (result.low < a.low); /* 2 */
return result;
}

The compiler may or may not be smart enough to figure out that line
/* 2 */ can be optimized into a single ADC instruction. Interestingly
gcc 4.3.1 on i386 does figure out that (result.low < a.low) corresponds
to the carry flag, but doesn't use it in an ADC instruction. Instead it
uses SETB to set a register to 0 or 1, and then ADDs it normally. I
wonder if this is an oversight or if that is actually faster than an
ADC.

hp
.