News:

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

Main Menu

Is there a better way to update any one particular DWORD in a YMM register?

Started by Rav, September 24, 2022, 12:18:36 PM

Previous topic - Next topic

Rav

Greetings.  I need to be able to update (replace) any one of the eight DWORDs in a YMM register with the contents of a GP register.  But unlike updating any one of the four DWORDs in a XMM register (using PINSRD), there is no corresponding assembly instruction that can also get to the upper four DWORDs in a YMM register.  I wrote some sample code below which is hard-wired to update the second most significant DWORD of a YMM register.  I'm looking for (1) something less complicated than what I'm doing below even when it's hard-wired to update a particular DWORD as the code below is, and (2) something that is also more generalized, that can update any one of the eight DWORDs.  I'm using MASM version 17.3.4.  Thanks for any insight.

===================================

; Test moving a DWORD GP register into one DWORD of a YMM register.
; In this PARTICULAR example, I'm updating the second most significant DWORD of the YMM register.
; But I'm hoping for something less complicated, and that is generalized to be able to update ANY one of the 8 DWORDs in the YMM register.

.686
.XMM
.model flat,stdcall

.DATA

; I don't know how to declare a YMMWORD without using two OWORDS -- I tried YWORD, YMMWORD, DY, nothing worked.
; Is there a way to do this more directly?
myYMM   OWORD   0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFH,000000000FFFFFFFFFFFFFFFFFFFFFFFFH

.CODE

MyAsm   proc   near

vmovdqu   ymm0,ymmword ptr [myYMM]   ; Move YMMWORD in memory to YMM0.
; YMM0 now = 00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

vextracti128 xmm1,ymm0,1         ; Hard-coded to extract upper 128 bits of YMM0 register to XMM1 (imm8 would be 0 for lower 128).
; XMM1 now = 00000000FFFFFFFFFFFFFFFFFFFFFFFF

mov eax,06AFFFFFH               ; The value that I want to insert for one particular DWORD.

vpinsrd xmm1,xmm1,eax,2            ; Move DWORD into the appropriate DWORD of XMM1 (here hard-coded to move into 2nd most significant DWORD of the XMM register).
; XMM1 now = 0000000006AFFFFFFFFFFFFFFFFFFFFF

vinserti128 ymm0,ymm0,xmm1,1      ; Move XMM1 back into the upper 128 bits of YMM0 (again, hard-coded which half of YMM to update).
; YMM0 now = 0000000006AFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

ret

MyAsm   endp
end      MyAsm

zedd151

If it not time critical, try getting the ymm register into memory. Change whatever you need to there (in memory), then put it back into a ymm register. Once the code works as expected make a macro from it; it should work 'like' an instruction if coded properly. In theory should be possible.



Rav

Quote from: swordfish on September 24, 2022, 02:57:22 PM
If it not time critical, try getting the ymm register into memory. Change whatever you need to there (in memory), then put it back into a ymm register. Once the code works as expected make a macro from it; it should work 'like' an instruction if coded properly. In theory should be possible.

Thanks.  Much easier than the limited instructions for directly addressing parts of a vector register.

jj2007

Quote from: Rav on September 24, 2022, 12:18:36 PMI need to be able to update (replace) any one of the eight DWORDs in a YMM register with the contents of a GP register.

IMHO vpshufd is the way to go, but don't trust your assembler. Especially some older variants may produce invalid code.

Something like this?
vmovdqu ymm0, ymmword ptr myYMM ; load from mem
movd xmm0, eax ; load a reg32
vpshufd ymm0, ymm1, someimmediate ; decide where to put the dwords from ymm1 and xmm0/eax


I can't test it with my current machine, though, it's too old :sad:

hutch--


jj2007

Quote from: hutch-- on September 25, 2022, 09:06:59 AM
What happened to your new one ?

It's lying around somewhere. I can't get used to the touchpad's mouse buttons, and I don't like the keyboard.

zedd151

Quote from: jj2007 on September 25, 2022, 09:31:49 AM
It's lying around somewhere. I can't get used to the touchpad's mouse buttons, and I don't like the keyboard.
I had a notebook at one point, had a decent size screen, but the touchpad, and buttons. yuk.
USB mouse took care of that. For what you describe, maybe a USB keyboard/mouse combo?