Re: Alignment question
From: Aslan Kral (spamtrap_at_crayne.org)
Date: 02/27/05
- Previous message: Alan Illeman: "Re: I'm a bit rusty"
- In reply to: kingzog: "Re: Alignment question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 19:40:54 +0000 (UTC)
"kingzog" <spamtrap@crayne.org>, haber iletisinde sunlari
yazdi:1109454150.697734.259800@o13g2000cwo.googlegroups.com...
> Aslan Kral wrote:
> > The following C++ class is used to jump to the first pointer in the
> > vtable.
> > class KWndProc
> > {
> > uint32 jmp_buf[3];
> > protected:
> > virtual LRESULT WndProc(HWND hWnd,UINT nMessage,WPARAM
> > wParam,LPARAM lParam)=0;
> >
> >
> > public:
> > #if 1
> > KWndProc()
> > {
> > jmp_buf[0] = 0xB9909090; // mov ecx,
> > jmp_buf[1] = (uint32)this;// this
>
>
> In Visual C++, the default for non vararg functions is thiscall, so
> ecx=this at all times, so you could skip these two lines.
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/ht
ml/_core_results_of_calling_example.asp
>
> I think you should have a pure C++ version too, so it will build for
> Win64 - just put in a regular function call, e.g.
>
> #ifdef _M_X86
> // asm version
> #else
> // c++ version
> func();
> #end
>
> Have you checked the ATL source code? It has a nice technique for
> generating some thunk code for a WndProc that changes the first
> parameter from a HWND to this.
>
No. But I have now. Basically it is the same logic (Jumping and registering
classes, but they use different instructions). My class is defined a little
bit different. I simply derive a class from it and implement the windows
procedure (virtual function) in it.
> (snip version where this is aligned)
>
> >
> > Which one is better for alignment? The first pointer in the vtable
> > is a window procedure so it will be called many times by windows
> > through this thunk data.
>
> I don't know to be honest - I'd try testuing them, or counting cycles.
> I'd guess that the CPU doesn't care if the immediate data after the mov
> is aligned or not, so the version with the NOPs will be slower.
>
> Zog.
>
- Previous message: Alan Illeman: "Re: I'm a bit rusty"
- In reply to: kingzog: "Re: Alignment question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]