# HLSL Assembly Question

This topic is 1995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,
I'm trying to learn HLSL assembly, using MSDN as a guide and a book or two. Most swizzle examples given are kind of simple and I saw some code that looked like this and wondered what the equivalent statements were.
[source]mova a0.w, r4.x
mul r4.yzw, v0.y, c0[a0.w].xxyz
[/source]
is the equivalent expression
[source]a0.w = r4.x
r4.y = v0.y * c0[a0.w].x
r4.z = v0.y * c0[a0.w].x
r4.w = v0.y * c0[a0.w].y[/source]
or this?
[source]a0.w = r4.x
r4.y = v0.y * c0[a0.w].x
r4.z = v0.y * c0[a0.w].x
r4.w = v0.y * c0[a0.w].y
r4.w = v0.y * c0[a0.w].z[/source]
Thanks!

##### Share on other sites
The first. the z in c0[a0.w].xxyz would get dropped as it doesn't have a corresponding output in r4.yzw

##### Share on other sites
Cool, thanks, makes sense now! The repeat rule only applies to the source register and not the dest.

##### Share on other sites
I'm not sure.. but I would guess neither.. and that r4.yzw = v0.y * c0[a0.w].xyz
The docs http://msdn.microsoft.com/en-us/library/windows/desktop/hh447193(v=vs.85).aspx says the destination register has a writemask.. which is not the same as a swizzle. I interpret it as that the calculation is done on 4 components and the components of the result is written to the destination register or skipped depending on the mask..
That is, xxyz * v0.y is calculated to a temporary result xyzw, and the x is skipped on write to destination since it's not in the mask.

##### Share on other sites
so maybe something like this? that's why the mask has to be in order...

[source lang="cpp"]// mova a0.w, r4.x
temp.x = r4.x
temp.y = r4.x
temp.z = r4.x
temp.w = r4.x
a0.x = unchanged
a0.y = unchanged
a0.z = unchanged
a0.w = temp.w

// mul r4.yzw, v0.y, c0[a0.w].xxyz
temp1.x = v0.y
temp1.y = v0.y
temp1.z = v0.y
temp1.w = v0.y
temp2.x = c0[a0.w].x
temp2.y = c0[a0.w].x
temp2.z = c0[a0.w].y
temp2.w = c0[a0.w].z
r4.x = unchanged
r4.y = temp1.y * temp2.y
r4.z = temp1.z * temp2.z
r4.w = temp1.w * temp2.w[/source] Edited by yadango

##### Share on other sites
The internal steps will differ from platform to platform, HLSL ASM is an intermediate format, but the end result is most likely like that.