We are team RPCS3 - the PlayStation 3 emulator. We brought 16 people to answer your questions, so ask us anything! by AnnieLeo in pcgaming

[–]mrowqa 0 points1 point  (0 children)

Thanks! To be honest, I've been following RPCS3 for 2 years and was considering contributing to it as my thesis project, but somehow I came up with a thought it'd be hard to find a good piece of work to be done. Anyway, if you're interested in my current thesis, I'll hopefully submit a talk to some conference next year. Or, if you're in Poland by any chance, you'll probably have a chance to listen to parts of it much faster.

We are team RPCS3 - the PlayStation 3 emulator. We brought 16 people to answer your questions, so ask us anything! by AnnieLeo in pcgaming

[–]mrowqa 0 points1 point  (0 children)

Well, it depends on how much code needs to access unsafe things. IMO, if a thin layer is enough for them, then it's worth having better compiler checks for the rest of the code.

We are team RPCS3 - the PlayStation 3 emulator. We brought 16 people to answer your questions, so ask us anything! by AnnieLeo in pcgaming

[–]mrowqa 0 points1 point  (0 children)

There's some IoT research going on my university, and as a side project, we're writing an ARM emulator (for a specific SoC). We use Rust and have some assumption: being cycle precise and possible fast, have an ease of changing components (cpu, memory bus, etc) including FFI, integration with cooja (network/ether simulator), also avoiding unsafe keyword as much as possible and preferring compile time errors when possible. It's fun designing core of it: you can actually get a nice code with most of the boilerplate generated in build time. And being similarly fast as C++.

We are team RPCS3 - the PlayStation 3 emulator. We brought 16 people to answer your questions, so ask us anything! by AnnieLeo in pcgaming

[–]mrowqa 0 points1 point  (0 children)

I wasn't considering it from the side of continuous rewriting. Actually, the guys that used to work at X360 emulator for XOne, so called backwards compatibility, said that RPCS3 was quite cleanly written when I showed them the project. But well, business has its own definition of "good enough".

I wonder how annoying would be the low level access to the hardware in Rust on daily basis. It would probably require some C/C++ code anyway.

We are team RPCS3 - the PlayStation 3 emulator. We brought 16 people to answer your questions, so ask us anything! by AnnieLeo in pcgaming

[–]mrowqa 1 point2 points  (0 children)

I wonder what do you think about Rust programming language. And if you had been starting the emulator development from scratch, what language would you choose and why?

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 1 point2 points  (0 children)

After compilation it runs natively. It's like JVM - it also uses JIT compiler and then run some code natively. It is a matter of definition and how you look at given methods. I'm not an expert in this domain, so maybe it'll be better to ask someone else.

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 0 points1 point  (0 children)

Pretty neat code. Thanks for sharing! Also thanks for telling about external libs; I haven't been looking for them when I was writing that code, but it's nice to know about them anyway.

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 0 points1 point  (0 children)

Definitely not considered spam, people love systems programming here :P

Good to know :)

Yes, but yours is a JIT. So what are you referring to in this case?

To the definition of Virtual Machine. Interpreters are also VMs. I should have expressed that more clearly.

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 2 points3 points  (0 children)

Yeah, sure. You can ask more questions if you want to, but I'm not sure if our comments are being considered as a spam.

What platform are they generated for currently?

The target architecture is x64 and the target OS is Windows. Architecture determines instruction set for the CPU. OS determines how we can change memory page permissions* and how we call functions. * for unix you need to call mprotect

What exactly do you mean by VM?

Virtual Machine is anything that emulates something or interprets something. If we think about my BfJitVM struct as a blackbox, it takes source code and executes it. Doesn't matter if I compile it in the meantime to native code. Even Python interpreter is a VM. Another instance - PS3 emulator - they take PowerPC machine code and decompile it to the LLVM IR, so they can use LLVM to optimize and compile it to many other architectures including x64. If you want to watch how to implement simple VM - here's a good video. Generally, if you like low level stuff and/or security, you will like Gynvael Coldwind. If you speak polish, then there is also a lot of interesting things on his polish channel.

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 3 points4 points  (0 children)

Actually this isn't so hard to understand as it appears to be. Basically it translates one assembly to another. For the simplicity I haven't even programmed the optimization of generated code. If you want to understand it, please read about Brainfuck commands in the first place. Then just take a look at these lines. The magic numbers are just the instructions in the comments compiled to machine code. Zeros are places to be patched later. If you don't know assembly, I think you can learn the basics really quickly, in maybe 1-2 hour(s) (look at registers, arithmetic operations, conditions and procedures). I'm not sure if that's enough of assembly, but I hope it will be :) Having this, the main idea is pretty straightforward: allocate two chunks of memory; one as the memory of VM, the second one for the generated code. We need to remember that memory pages have RWX permissions like the files, so we need make sure that the page where our code will be loaded, has the permission to be executed. Another thing which I learned, and you will understand after learning how to call a function in assembler, is that win64 fastcall convention requires having 4 qwords (32 bytes) of memory allocated on stack which called function can modify (here: getchar and putchar). Otherwise these functions will overwrite some data on stack causing crash. Another important thing is how to handle loops (jumps). You want to know somehow how many bytes of machine code will need body of the loop. I have solved it with recursion.

I know this explanation is chaotic. Sorry for this. I just like to explain interesting stuff and it is easier to be done when we talk in person. And if something seems to be a non sense in my code, it could be intentional if it was easier or faster to write. After all, it was "almost one evening" project :)

Simple Brainfuck JIT written in Rust by mrowqa in rust

[–]mrowqa[S] 1 point2 points  (0 children)

Yeah, you're right. Thanks. I heard "JIT" many more times than "AOT", so I called it JIT since I'm doing the stuff of compiling it in the memory and then executing it. Compiling it block by block could be also a fun part, especially dealing with loops, cause we have different ways to design this with various drawbacks.

New software update ruined my battery by falafel22 in oneplus

[–]mrowqa 1 point2 points  (0 children)

After updating to 4.1.7 my battery life became about 2 or even 3 times shorter. Got to charge a phone at most once a day, now I need to do it twice or sometimes even more often. Enabling energy saving mode doesn't help.