Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cdcl and floats and doubles

19 views
Skip to first unread message

fir

unread,
May 24, 2022, 4:17:14 PM5/24/22
to
i find cdcl as not so stupid becouse it allows
to pass any number of arguments (as te first,
leftiside argument is closest to call when being push)
it also allows in fact to return variable arguments
when used like

void foo int x int y int z -> int a int b

which goes like

add esp 4
add esp 4
push (z)
push (y)
push (x)
call foo
sub esp 4
sub esp 4
sub esp 4
pop a
pop b

(in fact as stack is reversed it should be sub above and add down below)

i used word stupid as generally i find those stack using as stupid and in my compiler i think i implement my own fully static convention when x y z a b would be 5 static ints belonging to foo and 5 pops/pushes would be replaced by 5 more clear movs (and in case this is only one caller could be reduced to zero movs)

hovever using cdcl for floats and doubles im not sure is not even worse

i compiled
float foo(float x) { return x*2; } and find such code (im not sure if this is for
thia function but probably

sub esp 4
movss xmm0 (esp+8)
adds xmm0 xmm0
movss (esp) xmm0
fld (esp)
add esp 4
ret

which is probably idiotic for such simple task... (it is even compiled woth -O2 i guess)
it also mixes sse code iwth old and rather unused fpu code i mean fld
which probably cdcls says how floats (and doubles?) should be returned
(??)

when when pasing as i remember when one pases float to function it gies just simple push eax (with eax loaded by this float) and when passing double
it goes to 2 pushes with two halfs of double

i need to implement at least cdecl and my ovn conventions so i need
to learn details of this (govever i presently lost the momentum in writing the compiler and probably i will back to it in some future, im not sure yet)


in my ovn convention such float foo(float x) { return x*2; }
would probably be

foo:
movss xmm0 (foo.x) //or movd i dont remember
mulss xmm0 2
movss (foo.y) xmm0
ret

in fact those fastcall conventions are like even better but this static one is for now good enough as it simple


fir

unread,
May 24, 2022, 4:57:27 PM5/24/22
to
i checked how it looks like in case of doubles
double xxx(float x)
{
return x*333;
}

sub esp 0xc
pxor xmm1 xmm1
movss xmm0 (0x406044)] ; .rdata: 0x00 0x80 0xa6 0x43
mulss xmm0 (esp+0x10)
cvtss2sd xmm1 xmm0
movsdd mmword ptr (esp) xmm1
fld qword prt (esp)
add esp 0xc
0 new messages