News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Working WndProc with no stack frame.

Started by ThoughtCriminal, January 30, 2006, 09:43:01 AM

Previous topic - Next topic

Ratch

EduardoS,
Quote
using ESP as base register you need 1 byte more for each time you need a local variable or parameters, 5 of them takes more space then the stack frame,
creating a stack frame may be a good ideia when you don't need 7 registers,

     You are correct about ESP references needing one more byte, but no matter how you cut it, you are tying up an often needed extra register if you use it for a stackframe.

Quote
Now another question, some routines save the esp in a global variable and use all 8 registers to the proc, what happen if windows interrupt the execution and esp have a random value?

     What is the purpose of the routines doing that?  A Windows OS interrupt is supposed to restore the environment, including the previous value of ESP to the user.  Ratch

EduardoS

Ratch, that rotine is a SHA1 algo, and need 8 registers
windows really restore the evirenmont, but to do that it dont need the stack?

hutch--

EduardoS,

If you are using a late enough processor, there is a trick where you use MOVD to preserve as many of the normal 32 bit registers as you like in the XMM registers. Sure solves the problem if you need 8 registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Gustav

> Now another question, some routines save the esp in a global variable and use all 8 registers to the proc, what
> happen if windows interrupt the execution and esp have a random value?

that should be no problem because the interrupt will also cause a switch to ring 0, which has it's own ESP, so the ring 3 ESP isn't used at all to save anything.

lingo

 :lol
“…there is a trick where you use MOVD to preserve as many of the normal 32 bit registers”


25112 Rev. 3.06 Software Optimization Guide for AMD64 Processors September 2005

9.6 Avoid Moving Data Directly Between General-Purpose and MMX™ Registers

Optimization
Avoid moving data directly between general-purpose registers and MMX™ registers;
this operation requires the use of the MOVD instruction. If it is absolutely necessary to move data
between these two types of registers, use separate store and load instructions to move the data
from the source register to a temporary location in memory and then from memory into the
destination register, separating the store and the load by at least 10 instructions.

Application
This optimization applies to:
• 32-bit software
• 64-bit software

Rationale
The register-to-register forms of the MOVD instruction are either VectorPath or DirectPath Double
instructions. When compared with DirectPath Single instructions, VectorPath and DirectPath Double
instructions have comparatively longer execution latencies. In addition, VectorPath instructions prevent
the processor from simultaneously decoding other insructions.

Example
Avoid code like this, which copies a value directly from an MMX register to a general-purpose register:
movd eax, mm2
If it is absolutely necessary to copy a value from an MMX register to a general-purpose register (or
vice versa), use separate store and load instructions, separating them by at least 10 instructions:

movd DWORD PTR temp, mm2 ; Store the value in memory.
...
; At least 10 other instructions appear here.
...
mov eax, DWORD PTR temp ; Load the value from memory.


Regards,
Lingo

hutch--

Lingo,

This makes sense but they forgot to tell Intel who created the XMM registers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

zcoder

No lets tell intel to make an instruction
thats swaps ALL registers
in other word there is really 2 FULL sets
of the same registers with same names
like a mem bank you swap to the other set

Z80 had this build in to it.


Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names