SIMD Load and Store Data
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
Already have an account? Sign In »
13 hours 15 minutes
Hello. This is Dr Miller, and this is Episode 12.5 of Assembly.
Today, we're gonna talk about S I M. D or single instruction, multiple data and loading data and storing data
as I am d
so single instruction, multiple data as I am d allows processes toe operate more efficiently, so multiple pieces of data can be loaded. And it's more efficient than reading data one word at a time.
So some examples that you might use it for would include images, movies and encryption.
And for example, in X 86 we had the MX, sse, and SSE to.
And so, with the popularity of the MX instructions, Arm added this functionality to theirs.
So s I m. D loading data
so we can load data using and store data using two different
primitives will look at each one of these. So the l, d and V S T. So one will load another little store data
and allows for the different inter leave patterns so we can do 1234 depending on
on what our data looks like.
So here's the VLT are extension register load.
So we've got DLD are we've got the size. So 64 then we can either loaded a label or loaded a register. So are in.
We always have our conditional operations that we can have,
and then we can have a particular offset or a label that we want to use to load the data.
So here we're going to have an example. So we have a bunch of a raise of different words
and you can see that these are 123123 And these
and then this one is cafe fief and
or is our cab a fief for each of those and then just going down the order so we can see some of the differences?
So let's look at how this runs.
So if we execute this first instruction and we print d zero,
we can see that the VLT 1.8 will load them sort of exactly as they were defined in here. So we get cafe feet, Cabaye fief and Cabaye fief.
I'm loaded when we look here at the 32 bit sized loading of that
to go to the next one.
So we're gonna use the load, the inner leave for two and so basically, it will load.
Um, every other one.
And so you can see that
it got the,
We got beef and cafe in these, right? And so we got C A and then we skip to and then Effie and then b E and then skip to and then e f.
And in the 2nd 1
Well, yeah, that's how we loaded the data in the 2nd 2 Here, we're loading every other. So you get 2468
and in the 3rd 1 to get 135 and seven. Right. So those get loaded, every other one gets loaded.
And then when we do the 3rd 1 so VLT three So we're loading every 3rd 1
We'll see here are alternated. 123123 And so when you load every 3rd 1 into the different registers using this instruction here,
we can see that we get an entire set of
one's an entire set of twos, an entire set of threes
and your typical example for this one would be so. For example, if you're loading pixels, we have
three different colors red, green and blue, and so those might be in the data Red, green, blue, red, green, blue, red, green, blue.
And so when you goto load them it will go ahead and load all of the red pixels in one area, the green and another and the blue and another.
And so that way, if you wanted to
maybe just increase the red in the picture where you could just increase those red pixels by loading it in. And then
during one operation on all of that data at once
So storing data
So we got the VSD are so weaken store a particular register and then at the location pointed to by RN. Right. So this is the register that we want to save, and then this is the register holding the base that we want to transfer to, and then you could additionally, at an offset that you could
specify inside of there.
So here's an example. So we go ahead and load the values ABC
de, except for his A a B b, C, C D d. We load that into our zero, and then we use the V Duke Command.
The basically copied that from here into Q zero Q zero is gonna have
a, B, C, C d, um, all throughout. And so
then you know, part of Q zero is D zero until I can save the store 64
d zero and then are one. And so that'll store I'm 64
bits worth in each, right, so we can get to 32 bits that we store in there.
Here. I just went ahead and printed it off. So are one when we're done with here. When I print the value of our one, I get a, B, B, C, C, D, d and R one plus four. So that's going four bites in. Because this took up four bites, we get a B, B, C, C D d.
And then beyond that, they're zeros. So I put a post eight and there's nothing stored beyond that.
So leave it to you. You could take this program in and see if you could save all of Q zero using two V store commands.
That would be an interesting example for you to try.
And then we got V S, t n and where n is, ah, number that we can use in order to store it.
And so again, we can dio inter leavings using the and inside of there and so we can
save data. We have our condition. That's
we have our data type. And so the different data types would say there's a whole listing of them. I didn't include them all in the slide.
Um, different alignments. And so we'll just look at an example here of storing a single end element structure. Toe one lean.
So here again, I got you know, a a three D a one b one C one.
So I loaded All those into these registers are one through our four. And then I did a V move of for S zero s one s two in history, right? So these all make up,
um, que zero or D zero d one.
And so I can store every other so, too, And we're going to do every other bite.
And so it's actually pretty easy to see
what happens here. So
if I look at Q zero before we go ahead and store the data, we got D c B a. D C.
D four c three B two a one and then d 80 70 65.
So when we look in the output, we can see that it basically takes every other one. Right? So we got D. D is the 1st 1 and then D eight
and then CC
and then C seven
and then BB
and then be six. Right? So it's kept copying. Here, here, here, here, here, here, right going down the line.
I de four d 43333
So, again, the the two means every other so copies every other one. So it's a nen are leaving or reenter, leaving the data
from what it's stored in in D zero and D one. So if used the inter leave toe, load it, then you can use the inter leave to save it back.
I'm in the example.
So today we talked about the S I m. D loading of data and then the storing of data
looking forward, we're gonna use S I m. D to process data, and then we'll do s, um I d s I m d. Example.
We'll also talk about some mode and conditional execution.
So how do you load data into a D sized register with no inner leave?
So we got V l. D one means no Inter leave. Um, we're going to each bite and then are zero points to our memory. And D one is the register that we want to do. So you could pick any register from Z 02 d 31.
If you have questions, you can email me, Miller, MJ at you and Katie to you, and you can find me on Twitter at Milhouse 30.