News:

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

macro for loop unrolling?

Started by liamo1, August 30, 2010, 01:23:23 AM

Previous topic - Next topic

liamo1

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

jj2007

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

MichaelW

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.
eschew obfuscation

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bomz

Quote
@@:
cmp eax, edx
jz @B:
    please explain me this part of code

@ replaced by assembler with index number????


jj2007

Quote from: bomz on August 30, 2010, 06:20:13 AM
Quote
@@:
cmp eax, edx
jz @B:
    please explain me this part of code

@ replaced by assembler with index number????


Go to Greg's post, download the Masm Programmer's Guide, and search inside for "Anonymous".

bomz

удобненько comfortably
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.

liamo1

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