tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] sinf/sin problems


From: Lee Duhem
Subject: Re: [Tinycc-devel] sinf/sin problems
Date: Fri, 26 Dec 2014 18:06:32 +0800

On Wed, Dec 24, 2014 at 8:53 PM, Daniel Glöckner <address@hidden> wrote:
>
> The return value of a function returning an int is not passed in the
> register where a double would be returned, so you might get garbage
> that is in no way related to the input.

You are correct. Assembly code generated by tcc reveals the difference caused
by the properly prototype of `sin'. For example, on x86-64, int type
return value
will be in rax, but double type return value in xmm0. Without properly
prototype of
`sin', tcc will
1. read return value from rax instead of xmm0 after sin call
2. pass the second argument of printf in rdi instead of xmm0

This is all wrong...

>
> On top of that the int is not cast to double in
> printf("\n%f", sin(1.0));
> The bytes on the stack are simply reinterpreted as double, so
> printf("%f\n", 1);
> will not print 1.000000.  That's because of the ellipsis in the
> declaration of printf.

Exactly.

lee

>
> Best regards,
>
>   Daniel
>
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]