The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: liamo1 on August 30, 2010, 01:23:23 AM

Title: macro for loop unrolling?
Post by: liamo1 on August 30, 2010, 01:23:23 AM
I was just wondering if anyone had a macro for loop unrolling. I was thinking that a new command such as foru could be developed in a macro. I'm a newbie to assembly and macros and just thought I'd ask :bg
Title: Re: macro for loop unrolling?
Post by: jj2007 on August 30, 2010, 01:47:41 AM
There is no specific macro, but REPEAT is often being used:
align 16
repct = 16 ; unrolling helps, but make sure that the count is divisible by the rep count!!
@@:
REPEAT repct
movaps xmm0, [eax+edx]
mulps xmm0, [edx]
lea edx, [edx+16]
addps xmm7, xmm0
ENDM
cmp edx, ecx
jb @B
Title: Re: macro for loop unrolling?
Post by: MichaelW on August 30, 2010, 04:19:32 AM
It's not packaged as a macro (and ATM I don't see any good way it could be), but in masm32\examples\exampl10\timer_demos\unroll there is something similar.
Title: Re: macro for loop unrolling?
Post by: hutch-- on August 30, 2010, 04:30:05 AM
The built in REPEAT macro does the job when the contents need to be duplicated (simple unroll) but some algos have different offsets for data in each iteration. I have seen this done with a macro but it can get a bit complicated. You always have the option to just manually code an unroll if its too complicated to automate with REPEAT.
Title: Re: macro for loop unrolling?
Post by: bomz on August 30, 2010, 06:20:13 AM
Quote
@@:
cmp eax, edx
jz @B:
    please explain me this part of code (http://smiles.kolobok.us/light_skin/unknw.gif)

@ replaced by assembler with index number????

Title: Re: macro for loop unrolling?
Post by: jj2007 on August 30, 2010, 09:13:55 AM
Quote from: bomz on August 30, 2010, 06:20:13 AM
Quote
@@:
cmp eax, edx
jz @B:
    please explain me this part of code (http://smiles.kolobok.us/light_skin/unknw.gif)

@ replaced by assembler with index number????


Go to Greg's post (http://www.masm32.com/board/index.php?topic=5433.msg40530#msg40530), download the Masm Programmer's Guide, and search inside for "Anonymous".
Title: Re: macro for loop unrolling?
Post by: bomz on August 30, 2010, 09:26:01 AM
удобненько comfortably (http://smiles.kolobok.us/light_skin/girl_in_love.gif)
Quote
Anonymous Labels
When you code jumps in assembly language, you must invent many label names. One alternative to continually thinking up new label names is to use anonymous labels, which you can use anywhere in your program. But because anonymous labels do not provide meaningful names, they are best used for jumping over only a few lines of code. You should mark major divisions of a program with actual named labels.
Use two at signs (@@) followed by a colon (:) as an anonymous label. To jump to the nearest preceding anonymous label, use @B (back) in the jump instruction's operand field; to jump to the nearest following anonymous label, use @F (forward) in the operand field.
The jump in the following example targets an anonymous label:
        jge     @F

        .

@@:

The items @B and @F always refer to the nearest occurrences of @@:, so there is never any conflict between different anonymous labels.
Title: Re: macro for loop unrolling?
Post by: liamo1 on August 30, 2010, 07:37:21 PM
Thank you all for the answers. I am trying to find out the optimal unroll depth for a dot product routine on my machine. I just tought I could be lazy and use a macro! :bg