"Timothy Baldwin" <spamtrap@[EMAIL PROTECTED]
> wrote in message
news:nsednUryuaSrUZTVRVnyuQA@[EMAIL PROTECTED]
> 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:
>
[...]
> Also you
> can store a constant into memory.
>
[...]
>
> Or on Pentium 4 or later:
> MOV ECX, [ESP + 4]
> MFENCE
> MOV [ECX], 0
> RET
Don't you mean:
MOV DWORD PTR [ECX], 0
?
Try running this program, which compiles on VC++:
________________________________________________________________
typedef int atomicword_i686;
typedef char atomicword_i686_static_assert[
(sizeof(atomicword_i686) == 4) ? 1 : -1
];
__declspec(****d) void
null_i686(
atomicword_i686* const _this
) {
_asm {
MOV EAX, [ESP + 4]
MOV [EAX], 0
RET
}
}
__declspec(****d) void
nullword_i686(
atomicword_i686* const _this
) {
_asm {
MOV EAX, [ESP + 4]
MOV DWORD PTR [EAX], 0
RET
}
}
#include <stdio.h>
int main() {
atomicword_i686 word = 0x12345678;
nullword_i686(&word);
if (word) {
puts("CRAP 1!");
}
word = 0x12345678;
null_i686(&word);
if (word) {
puts("CRAP 2!");
}
return 0;
}
________________________________________________________________
You should get an output of 'CRAP 2!'. The 'null_i686()' function does not
set the whole word to NULL. However, the 'nullword_i686()' does because it
uses 'MOV DWORD PTR [EAX], 0'. If you exchange the call to 'null_i686()'
with 'nullword_i686()', then the output will be nothing.
[...]


|