News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Help for a MACRO

Started by frktons, November 30, 2012, 06:01:50 AM

Previous topic - Next topic

frktons

nidud, your code on my pc:


Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz (SSE4)
---------------------------------------------------------
9054    cycles for XMM/pcmpeqd
9071    cycles for XMM/pcmpeqb
---------------------------------------------------------
9260    cycles for XMM/pcmpeqd
9047    cycles for XMM/pcmpeqb
---------------------------------------------------------
9046    cycles for XMM/pcmpeqd
9067    cycles for XMM/pcmpeqb
---------------------------------------------------------

There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

nidud

#16
deleted

frktons

Quote from: nidud on November 30, 2012, 11:51:45 AM
I will assume they are more or less the same, but since the mask returned from pmovmskb is from the 16 bytes, you may as well use the byte-cmp version.

Also, I used pcmpeqb and pcmpeqd in the test, and not pcmpgtb and pcmpgtd, so maybe that gives other results.


The road to Greater than or Less than should be
longer, so I forecast the performance will be Less than
PCMPEQD/B. 
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

frktons

The new partial ISGTLT16A MACRO with new syntax error
I'm unable to see.

;-------------------------------------------------------------------------------
; Macro_ISGTLT16A.asm
; http://masm32.com/board/index.php?topic=983.0
;-------------------------------------------------------------------------------
; Test the difference between two 16 bytes long strings and display the result.
; The strings have to be 16 bytes boundaries aligned.
;
; 30/Nov/2012 - MASM FORUM - frktons
;-------------------------------------------------------------------------------

.nolist
include \masm32\include\masm32rt.inc
.686
.xmm

;-------------------------------------------------------------------------------
; MACRO to verify the greater of two 16 bytes long aligned strings
;-------------------------------------------------------------------------------
ISGTLT16A MACRO PtrValue1, PtrValue2   ;; 2 PTR value to the strings

   LOCAL   RetCode, ISNOTGT2, EndCheck

   YesEQU   EQU 1
   NotEQU   EQU 0
   
   .data?
       RetCode dd ?
   .code
       push eax
       
       mov  eax, PtrValue1
       movdqa xmm1, [eax]

       mov  eax, PtrValue2
       movdqa xmm2, [eax]

       pcmpgtd xmm1, xmm2
       pmovmskb  eax, xmm1
       
       .if  ((bit ax, 15) == 0)

          jmp  short ISNOTGT2

       .endif
       
       mov  eax, YesEQU   
       mov  RetCode, eax
       jmp  short EndCheck

   ISNOTGT2:

       mov  eax, NotEQU 
       mov  RetCode, eax
       
   EndCheck:

       pop eax
 
   EXITM <RetCode>

ENDM


.data


align 16
Str1        db  "Prima stringa da",0,0,0,0
PtrStr1     dd  Str1
align 16
Str2        db  "Prima stringa di",0,0,0,0
PtrStr2     dd  Str2

.code

start:

print "---------------------------------------------------------", 13, 10
      print " Testing two strings for GT / LT through two", 13, 10
      print " xmm registers", 13, 10
print "---------------------------------------------------------", 13, 10     
      print " Test with PCMPGTD in a macro - ISGTLT16A -", 13, 10, 13, 10
      print " The two strings are ", 13, 10, 13, 10
      print " 1. "
      print PtrStr1, 13, 10
      print " 2. "
      print PtrStr2, 13, 10, 13, 10
      print " and the first is "
     
      .if   ISGTLT16A(PtrStr1, PtrStr2)
     
            print "Greater than the second one", 13, 10, 13, 10
           
      .else
     
            print "Less than the second one", 13, 10, 13, 10
                 
      .endif
           
print "---------------------------------------------------------", 13, 10


      inkey

      exit
     
end start


Quote
Microsoft (R) Macro Assembler Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: F:\Esempi_PGM\Assembly\Macro_ISGTLT16A.asm

***********
ASCII build
***********

F:\Esempi_PGM\Assembly\Macro_ISGTLT16A.asm(90) : error A2008:syntax error : ,
ISGTLT16A(21): Macro Called From
  F:\Esempi_PGM\Assembly\Macro_ISGTLT16A.asm(90): Main Line Code
F:\Esempi_PGM\Assembly\Macro_ISGTLT16A.asm(90) : fatal error A1011:directive mus
t be in control block
ISGTLT16A(25): Macro Called From
  F:\Esempi_PGM\Assembly\Macro_ISGTLT16A.asm(90): Main Line Code
_
Assembly Error

Someone who sees better than me could please let me know where
I mispelled something.

Thanks
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

.if  ((bit ax, 15) == 0)

Doesn't look like assembler. Do you mean this?
bt ax, 15
.if  Zero?


frktons

Quote from: jj2007 on November 30, 2012, 11:19:53 PM
.if  ((bit ax, 15) == 0)

Doesn't look like assembler. Do you mean this?
bt ax, 15
.if  Zero?



Yes JJ, that's what I meant. This mean I can't use
.if with the bt opcode test?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

You can use almost everything, provided you defined it before and it does not clash with defined keywords.

include \masm32\include\masm32rt.inc
btx MACRO Reg, Bit
  bt Reg, Bit
  EXITM <Carry?>
ENDM
.code
start:
mov ebx, -1
bt ebx, 15
.if  Carry?
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
.if btx(ebx, 15)
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
inc ebx
bt ebx, 15
.if  Carry?
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
.if btx(ebx, 15)
inkey "Set"
.else
inkey "Not Set"
.endif
exit
end start

frktons

Quote from: jj2007 on December 01, 2012, 12:26:33 AM
You can use almost everything, provided you defined it before and it does not clash with defined keywords.

include \masm32\include\masm32rt.inc
btx MACRO Reg, Bit
  bt Reg, Bit
  EXITM <Carry?>
ENDM
.code
start:
mov ebx, -1
bt ebx, 15
.if  Carry?
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
.if btx(ebx, 15)
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
inc ebx
bt ebx, 15
.if  Carry?
print "Set", 13, 10
.else
print "Not set", 13, 10
.endif
.if btx(ebx, 15)
inkey "Set"
.else
inkey "Not Set"
.endif
exit
end start


Thanks Jochen. A little bit every day, in a couple of months
I hope I'll get what I need to write properly written MACROS.
:-)

By the way I finished ISGTLT16A, to compare two 16 bytes aligned strings
or two chunks of bigger strings/files/whatever with the alignement required.
The ISGTLT16U does the same with unaligned chunks.

Quote
---------------------------------------------------------
Testing two strings for GT / LT using two
xmm registers
---------------------------------------------------------
Test with PCMPGTD in a macro - ISGTLT16A -

The two strings are

1. Prima stringa da
2. Prima stringa di

and the first is Less than the second one

---------------------------------------------------------
Press any key to continue ...
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

you can still do things like
bt ebx, 15
.if  Carry? || x==21 || eax==3

frktons

Quote from: dedndave on December 01, 2012, 06:37:18 AM
you can still do things like
bt ebx, 15
.if  Carry? || x==21 || eax==3


Thanks Dave. I've been 2 years out of assembly or
computer languages whatsoever, so I've to relearn the few
things I learned here at the time.
Being a hobby now, I just do it when I've time, and
assembly needs a lot of it.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

Quote from: dedndave on December 01, 2012, 06:37:18 AM
you can still do things like
bt ebx, 15
.if  Carry? || x==21 || eax==3


Same effect:
.if  btx(ebx, 15) || x==21 || eax==3

frktons

Quote from: jj2007 on December 01, 2012, 07:07:57 AM
Quote from: dedndave on December 01, 2012, 06:37:18 AM
you can still do things like
bt ebx, 15
.if  Carry? || x==21 || eax==3


Same effect:
.if  btx(ebx, 15) || x==21 || eax==3

That's cool.

Thanks
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

qWord

MREAL macros - when you need floating point arithmetic while assembling!

jj2007


dedndave