News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

pmaddwd

Started by jj2007, March 02, 2024, 11:28:13 PM

Previous topic - Next topic

jj2007

Anybody familiar with this instruction?

include \masm32\include\masm32rt.inc
.code
.686p
.xmm


StringToDwordSimd_s:
psMask OWORD 80808003808080028080800180808000h
psMaskW OWORD 80078006800580048003800280018000h
s2Mult OWORD 000003E8000000640000000A00000001h
s2MultW OWORD 000000000000000003E80064000A0001h ; xmm3=1, 10, 100, 1000, 10000=2710h
s2Sub dq 3030303030303030h
OPTION PROLOGUE:NONE ; 1000
OPTION EPILOGUE:NONE
StringToDwordSimd proc arg
  pop eax ; get ret address
  pop edx ; get string pointer
  push eax ; save ret address
  movups xmm0, [edx]
  movlps xmm1, s2Sub
  psubb xmm0, xmm1 ; xmm0=08070605 04030201 
  movups xmm3, s2MultW
  movups xmm2, psMaskW
  pshufb xmm0, xmm2 ; xmm0=00080007 00060005 00040003 00020001, xmm3=00000000 00000000 03E80064 000A0001
  int 3
  pmaddwd xmm0, xmm3 ; xmm3=00000000 00000000 03E80064 000A0001 ->21, 4300 instead of 1200+34
  movd eax, xmm0 ; xmm0=00000000 00000000 000010CCh 00000015h
  retn
StringToDwordSimd endp
StringToDwordSimd_endp:
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
start:
  push chr$("12345678")
  call StringToDwordSimd
  inkey str$(eax), " is the result"
end start