Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: optimizatio...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 13 Topic 4621 of 4729
Post > Topic >>

Re: optimization possibilities...

by Timothy Baldwin <spamtrap@[EMAIL PROTECTED] > Apr 19, 2008 at 11:40 AM

In message <oc6dnTLn9pEyoZTVnZ2dnUVZ_gmdnZ2d@[EMAIL PROTECTED]
>, Chris Thomasson
<spamtrap@[EMAIL PROTECTED]
> wrote:

> Before I convert this code into AT&T syntax for GAS to assemble, and to
> MASM I was wondering if there are any possible optimizations I can
perform
> on the following code, I will show the C header first:

Use inline functions with inline assembler to avoid the function call
overhead; ensure that your inline assembler is an optimisation barrier.

> __declspec(****d) void
> spinlock_i686_release(
>  atomicword_i686* const _this
> ) {
>   _asm {
>     MOV ECX, [ESP + 4]
>     MOV EAX, 0
>     MOV [ECX], EAX
>     RET
>   }
> }

There is no memory barrier here, therefore reads from the structure
protected by the lock can be performed after the lock is released. Also
you
can store a constant into memory.

Replace that with:
MOV ECX, [ESP + 4]
LOCK SUB [ECX], 1
RET

Or on Pentium 4 or later:
MOV ECX, [ESP + 4]
MFENCE
MOV [ECX], 0
RET

You may also consider using CPUID on older processors, however I suspect
that it would be slower due to the need to preserve the contents of the
registers that CPUID changes.

> AFAICT, everything seems to look okay. However, I am not an expert x86
> programmer! Any comments/suggestions would be highly appreciated.

Don't use spinlocks in a preemptive multitasking environment without
disabling preemption.

Consider disabling interrupts whilst the locks are held.
 




 13 Posts in Topic:
optimization possibilities...
"Chris Thomasson&quo  2008-04-18 17:30:10 
Re: optimization possibilities...
Terje Mathisen <spamt  2008-04-19 07:30:55 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-19 14:06:11 
Re: optimization possibilities...
Timothy Baldwin <spam  2008-04-19 11:40:51 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-19 12:27:17 
Re: optimization possibilities...
Timothy Baldwin <spam  2008-04-22 20:36:39 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-22 16:58:52 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-19 16:53:01 
Re: optimization possibilities...
"Alexei A. Frounze&q  2008-04-19 00:15:30 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-19 12:41:01 
Re: optimization possibilities...
"Alexei A. Frounze&q  2008-04-20 02:12:38 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-04-20 11:33:37 
Re: optimization possibilities...
"Chris Thomasson&quo  2008-06-10 23:30:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:02:44 CDT 2008.