Assembly code snippets

Back to the snippets overview

Details

TitleInline MMX Constants
AuthorbitRAKE
Submitted by:bitRAKE
Date added:2002-02-24 03:40:33
Date modified:2002-02-24 03:40:33

Comments

This macro creates global labels for the MMX constants and uses them apon repeated access to the same constant values. The MMX constants are also stored in their own sub-segment of the CONST segment.

Snippet

mxc MACRO val:REQ
    LOCAL w,y,z

    z SIZESTR <&val>

    ;; Attempt to compact data
    WHILE (z LT 17) AND (z GT 2)
        z = z/2
        IFDIF @SubStr(<&val>,1,z),@SubStr(<&val>,1+z,z)
            z = z + z + 16
        ENDIF
    ENDM

    IF z GT 16
        z = z - 16
    ENDIF

    w TEXTEQU @SubStr(<&val>,1,z)

    ;; figure out global name for constant
    y CATSTR <__MMX_>,w

    IF (OPATTR(y)) EQ 0 ;; not defined
        CONST$mmx SEGMENT
            y LABEL QWORD
            w CATSTR <0>,w,<h>
            IF z EQ 16
                dq w
            ELSEIF z EQ 8
                dd w,w
            ELSEIF z EQ 4
                dw w,w,w,w
            ELSEIF z EQ 2
                db w,w,w,w,w,w,w,w
            ENDIF
        CONST$mmx ENDS
    ENDIF
    EXITM y
ENDM

...and you would use it like this:

movq mm7,mxc(<01>) ; eight bytes
movq mm7,mxc(<0101>) ; four words, but same data
movq mm7,mxc(<01234567>) ; two dwords