SPO600 - Project Stage 2/3
Published: 2021-12-15 08:29:12

##Hello!
Hello everyone, my name is Brian and I'm going to be describing and explaining the process I used to complete the second stage of my project in the SPO600 course. If you haven't read the first stage yet, be sure to check it out!

##What does the second stage consist of?

The second stage of this project now involves looking into open source packages and dissecting them. Specifically, going through the code and identifying the SIMD code and related information. For this project I have chosen FFmpeg because it was the first package I recognized that stood out to me. I noticed VLC later but after doing a little bit of research I figured the former would be easier to work with.

##What is FFmpeg?

FFmpeg is an extension within your command line which can convert audio or video formats. It can be used to edit or stream them as well. The project first began over 2 decades ago in the year 2000 and has been going strong since, with regular activity on the [GitHub](https://github.com/FFmpeg/FFmpeg) page. We can see here that this folder was last modified 18 hours ago.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ueh8yfnqniksx49dn8fk.png)
 

##SIMD Code

What is an SIMD code? It stands for Single Instruction/Multiple Data. SIMD performs processing of more than one piece of data with just one instruction, boosting efficiency by a ton. It's very useful in modern technology as things get more demanding and speed and efficiency is required.

I was able to find an example of some SIMD code in FFmpeg's source.
For example, in the AArch64 directory, we can find [this](https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/aarch64/output.S).
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkqjb5yx39qk6qr7tcxh.png)

Here we are able to see some assembly code. It's a function which is being exported, but I'm not 100% sure what it's doing here. It seems like it's preparing some information to be written in another function or file. Either that, or it's outputting something to the screen, hence the file name. Luckily for me this file was commented unlike many others I stumbled across, so it wasn't completely unknown what the code is doing. This code is specifically for the ARM64 architecture. 

Looking at the other side, there are a lot of files involving x86 architecture as well. The first file is an example of it, which is shown [here](https://github.com/FFmpeg/FFmpeg/blob/master/libswscale/x86/hscale_fast_bilinear_simd.c). 

Unlike the other file, this one has no comments. It's really hard to understand what it is doing here exactly however a few things are pointed out. It is firstly nested in the `__asm__` keyword which indicates that it utilizes an inline assembler. We can also determine that it runs at compile-time. The reason for this is because #if is a compile time specific keyword, and there is one present in the code.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xssrf9h3tef30i45chh9.png)
Lastly, it does use macros at some point in the code.

##Conclusion

There's a lot more files but I only covered those two (one from each architecture). FFmpeg does many intensive things at once, which is why it is useful to be able to process many operations from a single instruction. It clearly utilizes SIMD well, knowing that fact, and considering it's been around for so long. From what I've seen, it seems to be well structured and easy to read, just hard to understand because I'm not too experienced in the languages. I think an improvement would be to comment more lines or files of code so people getting into it (like me) will be able to understand how things work and have an easier time. 

Overall, a research intensive lab but actually somewhat fun.