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

?

1 view
Skip to first unread message

Frank

unread,
Oct 7, 2009, 10:40:35 PM10/7/09
to

#if __LCCOPTIMLEVEL > 0
inline div_t __declspec(naked) div(int a,int b)
{
_asm("\tmovl\t(%esp),%eax");
_asm("\tmovl\t4(%esp),%ecx");
_asm("\tcdq");
_asm("\tidivl\t%ecx");
}
#else
div_t div(int _numer, int _denom);
#endif

I like being away from the anal-retentive topic guards in clc. This comes
from stdlib.h. What does it do?
--
Frank

I do personal attacks only on people who specialize in personal attacks..
~~ Al Franken, Playboy interview

Tim E. Sneddon

unread,
Oct 7, 2009, 11:17:12 PM10/7/09
to
Frank wrote:
> #if __LCCOPTIMLEVEL > 0
> inline div_t __declspec(naked) div(int a,int b)
> {
> _asm("\tmovl\t(%esp),%eax");
> _asm("\tmovl\t4(%esp),%ecx");
> _asm("\tcdq");
> _asm("\tidivl\t%ecx");
> }
> #else
> div_t div(int _numer, int _denom);
> #endif
>
> I like being away from the anal-retentive topic guards in clc. This comes
> from stdlib.h. What does it do?

This code snippet provides optimisation for the C run-time
library function, div(). If optimisation is disabled then the
div() function is defined as a reference to an external function.

In the event that the compiler has been run with optimisation
enabled then the div() function is defined as an inline assembly
function. This would improve performance by removing call over-
head and any other cruft related to the execution of div().

Tim.

Frank

unread,
Oct 11, 2009, 2:04:22 PM10/11/09
to
In Dread Ink, the Grave Hand of Tim E. Sneddon Did Inscribe:

Thanks Tim. Can you tell what the assembly is doing specifically?
--
Frank

...it's obviously how his disease manifests itself, any kind of substance
dependency is very deep, issues of self esteem, you can just tell that he's
a really insecure and vulnerable person -- and I love him. You know,
sometimes I listen to him on the radio, and he's very judgmental, he's a
very angry person, and I just want to remind him that anytime you have a
finger pointing at someone else, there's three pointing back at you.
~~ Al Franken

jacob navia

unread,
Oct 11, 2009, 3:45:22 PM10/11/09
to
Frank a �crit :

> In Dread Ink, the Grave Hand of Tim E. Sneddon Did Inscribe:
>
>> Frank wrote:
>>> #if __LCCOPTIMLEVEL > 0
>>> inline div_t __declspec(naked) div(int a,int b)
>>> {
>>> _asm("\tmovl\t(%esp),%eax");
>>> _asm("\tmovl\t4(%esp),%ecx");
>>> _asm("\tcdq");
>>> _asm("\tidivl\t%ecx");
>>> }
>>> #else
>>> div_t div(int _numer, int _denom);
>>> #endif
>>>
>>> I like being away from the anal-retentive topic guards in clc. This comes
>>> from stdlib.h. What does it do?
>> This code snippet provides optimisation for the C run-time
>> library function, div(). If optimisation is disabled then the
>> div() function is defined as a reference to an external function.
>>
>> In the event that the compiler has been run with optimisation
>> enabled then the div() function is defined as an inline assembly
>> function. This would improve performance by removing call over-
>> head and any other cruft related to the execution of div().
>>
>> Tim.
>
> Thanks Tim. Can you tell what the assembly is doing specifically?

Divides the first argument by the second and returning the divisor and
the remainder in a 64 bit result with the lower part (result of division)
and the upper part (edx) remainder. All in a single operation.
You can follow it in the debugger and you will see how it works.
Compile with debug info ON, then step by step the assembly code (request in
the debuggeer to see the machine instructions) and open the CPU
window. You will see how registers change

0 new messages