On Jan 9, 2008 5:05 PM, Darx Kies <[EMAIL PROTECTED]> wrote:
> I removed that patch as it was wrong assuming that the eax can be marked
> as dirty.
> eax, ecx, edx can be used and changed in every IL instructions.
> ebx, esi, edi are reserved for the use by the register allocator.

But I didn't mark it dirty for any other instructions - just for
initializations that are put together anyway. It happens only at the
beginning of a block and only eax is used for cleaning the memory.
Anyways, later I've realized, that you can go even further, since .net
does variable initialization explicitly in IL. Example code:

// b is rewritten later (0 is not used, initialization can be skipped)
public unsafe static uint testinit(uint a) {
        uint b=0;
...
// b is either rewritten, or 0 is used (initialization is needed)
public unsafe static uint testneededinit(uint a) {
        uint b=0;
...
// b is initialized later
public unsafe static uint testnoinit(uint a) {
        uint b;
...

Those three generated previously this IL to initialize b in testinit
and testneededinit:
--->8---
IL_0000:  ldc.i4.0
IL_0001:  stloc.0
--->8---
The only place where b is not initialized is testnoinit, but b is not
used for reading before first write (compiler enforces that one).

But that code has the following effect in AOT (asm-dump):
--->8---
; Initialize(Loc0_0__U4)
XOR EAX, EAX
MOV [EBP - 0x10], EAX  ; <- here it's initialized

; Ldc(Reg0_1__I4 <= 0)
MOV [EBP - 0x14], 0x0

; Stloc(Loc0_0__U4 <= Reg0_1__I4)
MOV EAX, [EBP - 0x14]
MOV [EBP - 0x10], EAX  ; <- here it's overwritten by 0 (or any value from code)
--->8---

Since compiler will not allow to compile code where I try to use
uninitialized 'b' anyway, AOT can just skip the xor&mov cleaning of
stack. I've removed those and did a quick scan - can't see any place
where uninitialized variable is used. And my kernel still runs without
problems :) Couldn't find any text in ecma that would require to
initialize those either - maybe someone will correct me, but I think
it's not needed to clean the stack. Can someone check is ngen does it
in windows?

I don't know what happens in (identifier.IsRegisterSet) branch though
- couldn't find a place where it was used.

I hope I've described that properly :)

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
SharpOS-Developers mailing list
SharpOS-Developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sharpos-developers

Reply via email to