, ? mingw gcc 4.3 (x86). "gcc test.c -O2 -S -c -Wall"
:
float calc_mean(unsigned char r, unsigned char g, unsigned char b)
{
return (r+b+g)/3/255.0f;
}( . , , , ):
movzbl 12(%ebp), %edx ; edx = g
movzbl 8(%ebp), %eax ; eax = r
addl %eax, %edx ; edx = eax + edx
movzbl 16(%ebp), %eax ; eax = b
addl %eax, %edx ; edx = eax + edx
movl $1431655766, %eax ;
imull %edx ; edx *= a const
flds LC0 ; put a const in the floating point reg
pushl %edx ; put edx on the stack
fidivrl (%esp) ; float reg /= top of stack
:
float calc_mean2(unsigned char r, unsigned char g, unsigned char b)
{
const float AVERAGE_SCALE_FACTOR = 1.f / (3.f * 255.f);
return (r+b+g) * AVERAGE_SCALE_FACTOR;
}
:
movzbl 12(%ebp), %eax
movzbl 8(%ebp), %edx
addl %edx, %eax
movzbl 16(%ebp), %edx
addl %edx, %eax
flds LC2
pushl %eax
fimull (%esp)
, . -freciprocal-math fidivrl fimull, . .
, , - 18- , , - . , .
. , . !