POD
bearophile
bearophileHUGS at lycos.com
Fri Dec 28 18:41:20 PST 2012
David Nadlinger:
> - More or less another way of stating the last point, it is
> not at all obvious from the x86-64 ABI specification: I
> re-implemented the x86-64 ABI for D from scratch for LDC
> recently, and this was just about the only difference between
> your implementation and mine (the other, as far as I remember,
> being that DMD mistakenly never enregisters 3-byte structs).
I have done a small experiment. This is C99 code:
#include "stdint.h"
typedef uint8_t ubyte;
typedef struct { ubyte r, g, b; } RGB;
RGB bar(RGB c1, RGB c2) {
return (RGB){ (ubyte)(c1.r + c2.r),
(ubyte)(c1.g + c2.g),
(ubyte)(c1.g + c2.b) };
}
Compiled with Clang 3.0 gives:
bar:
pushl %esi
movl 8(%esp), %ecx
movl 12(%esp), %eax
leal (%eax,%ecx), %edx
movzbl %dl, %esi
andl $16776960, %ecx # imm = 0xFFFF00
shrl $8, %ecx
andl $16777215, %eax # imm = 0xFFFFFF
movl %eax, %edx
shrl $16, %edx
addl %ecx, %edx
shll $16, %edx
orl %esi, %edx
shrl $8, %eax
addl %ecx, %eax
shll $8, %eax
movzwl %ax, %eax
orl %edx, %eax
popl %esi
ret
This is D code:
struct RGB { ubyte r, g, b; }
RGB bar(RGB c1, RGB c2) {
return RGB(cast(ubyte)(c1.r + c2.r),
cast(ubyte)(c1.g + c2.g),
cast(ubyte)(c1.g + c2.b));
}
DMD 2.061alpha gives (-O -release -inline):
_D4test3barFS4test3RGBS4test3RGBZS4test3RGB:
push EAX
push EBX
mov EBX,EAX
push ESI
push EDI
movzx ECX,byte ptr 018h[ESP]
movzx EDX,byte ptr 014h[ESP]
add CL,DL
mov [EBX],CL
movzx ESI,byte ptr 019h[ESP]
mov ECX,ESI
movzx EDI,byte ptr 015h[ESP]
mov EDX,EDI
mov 0Ch[ESP],ECX
add CL,DL
mov 1[EBX],CL
mov ECX,0Ch[ESP]
movzx ESI,byte ptr 016h[ESP]
mov EDX,ESI
add CL,DL
mov 2[EBX],CL
pop EDI
pop ESI
pop EBX
pop ECX
ret 8
Bye,
bearophile
More information about the Digitalmars-d
mailing list