I've been interested in (relatively) low-level programming for quite some time. I know C, I can read assembly (write - not so much) and I have basic understanding of CPU (registers, cache, stack and whatnot). What should I read or learn next to be able to reason about things like cache usage of a C program or possible low-level microoptimizations?
It's still just a hobby for me for the most part, so it's not that I'm trying to prematurely optimize some production code. I'm just interested in how it all works under the hood.
sshine|1 year ago
https://sysprog21.github.io/lkmpg/
https://blog.sourcerer.io/writing-a-simple-linux-kernel-modu...
If you want to "go low" in the way hardware works, you could try and write an interrupt handler on an embedded device.
If you want to "go low" in how optimizations work in application development, you could try and implement microbenchmarks and look at flamegraphs.
https://github.com/brendangregg/FlameGraph
https://bheisler.github.io/criterion.rs/book/index.html
kjuulh|1 year ago
I've recently enjoyed Game Engine Architecture, mostly because there is an interesting mix using low level techniques to solve problems a normal application wouldn't be required to fix.
Game development in general is case for tuning yourself to when you should utilize high level programming techniques, and when required dropping into low level optimization to solve local problems.
boffinAudio|1 year ago
Some simple things you can do:
* Get yourself a suitable embedded development system - I would recommend anything ESP32'ish that suits your fancy such as a Liligo or Watchy ESP32-based watch, or PineTime if thats more up your alley - and then write some little apps for it.
* Get to know Godbolt with a great deal of intimacy, just as a general approach to understanding what is going on:
https://godbolt.org/
* Invest a little workbench time in some of the various embedded frameworks out there - platformio, FreeRTOS, etc. and, very important: learn the Tooling And Methodology techniques that these frameworks manifest.
* Invest some workbench time in the RETRO Computing Scene. Seriously, you can still learn extremely valuable principles of tooling and methodology from an 8-bit retro system from the 80's. Get your favourite platform, get all its tools onboard, engage with its community - you will learn a lot of things that are still entirely relevant, in spite of the changes over the decades.
* Get into the F/OSS tooling/methdology flow - find software projects that are interesting to you, find their repositories, learn to clone and build and test locally, and so on. There are so many fantastic projects out there for which low-level skills can be developed/fostered. Get onboard with something that interests you.
Good luck!
mandliya|1 year ago
GPU race is getting really hot and there is a lot of work being done to squeeze every ounce of performance especially for LLM training and inference.
One resource I would recommend is “Programming massively parallel processors” [1]
I am also learning it as my hobby project and uploading my notes here [2]
[1] https://shop.elsevier.com/books/programming-massively-parall...
[2] https://github.com/mandliya/PMPP_notes
abnercoimbre|1 year ago
[0] https://handmade.network
[1] https://handmadecities.com
visil|1 year ago
makz|1 year ago
mikewarot|1 year ago
[1] https://www.nand2tetris.org/
* - Lower levels include transistor logic, analog electronics, electromagnetism, chemistry and the equilibrium equation (how transistors work), quantum mechanics (how atoms and chemistry works).
lelanthran|1 year ago
1. The best source of low-level information on things like operating systems (writing your own) etc is https://wiki.osdev.org/Expanded_Main_Page
2. Compiler related low-level should include a read through Crafting Interpreters (https://craftinginterpreters.com/), even if all you're going to do is create compiled languages.
3. Hardware type low-level (where you build your own logic) is a long and ultimately non-rewarding path. I would suggest https://eater.net/8bit/
All those links are only starting points; use them to find a direction in which to head.
[EDIT: I also recommend writing a eBPF module for linux - easier than writing a kernel module, with just as much low-level hooks as you might need].
motherfsck|1 year ago
eBPF is great for some things and is "easier" for some things but kernel modules are able to do _way_ more by design.
junon|1 year ago
Also, learn Rust.
koliber|1 year ago
This comes to mind: https://www.morling.dev/blog/one-billion-row-challenge/
Read how others have done it. Here's an example in Java that goes relatively low-level to squeeze out performance: https://questdb.io/blog/billion-row-challenge-step-by-step/
sph|1 year ago
https://wiki.osdev.org/Main_Page
It will give you a much more holistic view of computers-as-hardware and the low-level intricacies, that are in my opinion more useful and more foundational than just being good at optimising a hot-loop.
I did it in my teenage years, and it's my first true and only love. Now almost 20 years later I'm back at it, this time with all the accumulated experience in software engineering. There is nothing quite like it. Any basic, trite design (i.e. the usual POSIX clone) will teach you a great deal about the entire stack.
marckerbiquet|1 year ago
cladopa|1 year ago
I learned assembly so I could disassemble and understand programs.
I learned C so I could use all the libraries that people had made and their frameworks than later because C++, Objective C, C#, java, python and other derivatives.
I wanted to manipulate images, speech and video and using high level programming language was so inefficient so I continued using C.
I learned FPFGAs again because I needed efficiency or the things I wanted to do like controlling robots did not work at all(they moved so sluggishly).
I love learning things, but that was never enough for me to learn something deeply when problems appear.
slyfox125|1 year ago
My suggestion would be to find something that can be improved on in daily life and then learn the skills necessary to make that improvement, to include the trades more physical in nature, such as woodworking, 3D printing, etc. Then, combine those skills with, say, programming embedded devices, etc. or whatever else is needed to accomplish the task.
This ultimately provides a diverse skill-set, feeds the desire to learn, and provides legitimate improvements to quality of life - both tangible and intangible.
afr0ck|1 year ago
zamalek|1 year ago
aetimmes|1 year ago
He discusses exactly what you're describing (L1/2/3 cache hit rates, their performance implications, how compiler optimizations can fool us into thinking we have a good hit rate, etc).
Also take a look into Intel VTune and Processor Tracing to understand how performance counters like Instructions per Cycle are calculated.
muzani|1 year ago
Here's a doc you can dig around with https://source.android.com/docs/core
You get a high level overview, then it explains how everything connects right down to the hardware. It's open source too, so you can go in there and poke around.
If you want something that can make money, I'd say look at camera and Bluetooth, because these are the things that need the most customization. Neural network API could see a lot of use in the future too.
But there's plenty of fascinating stuff, like how it renders fonts, how it handles hearing aids, and so on.
Edit: TIL Android has a category of 'rich haptics', where it gives tiny haptic feedback when you swipe your finger across a surface or to the beat of music. Very few app devs know this, so it's not integrates well into apps.
Brightwise|1 year ago
https://wiki.osdev.org/ is a good source for getting a hold in OS development
jiggawatts|1 year ago
Not only will it show you how C/C++/Rust, etc... language statements map to CPU instructions, but it can also show you how CPUs execute those instructions! There are advanced views that show the various pipeline stages, execution ports, etc...
E.g.: https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename...
The right-most tab should show you the CPU execution pipeline
1ark|1 year ago
http://asmirvine.com/index.htm
azubinski|1 year ago
And the hardest things are in peripheral.
Any modern microcontroller it will give you the opportunity to learn a lot of useful things about peripheral devices. You can start with any really good modern 8-bits micro like Microchip's 2nd generation of ATTiny, so you'll have in your hands a lot of very powerful interesting smart peripherals: hardware event system, small programmable logic, different timers, good ADC etc.
The only rational additional consideration here is that your target platform should be popular, well documented and supported by the manufacturer.
Then will be time for some Cortex-M0 device with DMA.
Then you'll decide where to go further :)
rwmj|1 year ago
Learn how it works, try adding a new instruction or implementing an extension.
jeffrallen|1 year ago
Then write your own OS.
pietmichal|1 year ago
https://www.computerenhance.com/p/table-of-contents
pabs3|1 year ago
https://bootstrappable.org/ https://github.com/fosslinux/live-bootstrap/ https://bootstrapping.miraheze.org/wiki/Stage0
dprophecyguy|1 year ago
Start with this - https://bottomupcs.com/
Then do this - https://www.youtube.com/playlist?list=PLhy9gU5W1fvUND_5mdpbN...
and finally this https://diveintosystems.org/book/introduction.html
4pkjai|1 year ago
camgunz|1 year ago
visil|1 year ago
unknown|1 year ago
[deleted]
kfreds|1 year ago
Learn everything there is to learn about the Tillitis TKey. It's the most open-source software and hardware USB security token there is. It is FPGA-based, and contains a tiny RISC-V core.
Full disclosure: I'm involved in the project.
ReleaseCandidat|1 year ago
Learn how to use a profiler like Linux' perf, VTune or Apple's Instruments. Which means interpreting the results of it to optimise your code.
greytape|1 year ago
gauravkumar37|1 year ago
petabyt|1 year ago
ydnaclementine|1 year ago
moeadham|1 year ago
alexdowad|1 year ago
sakex|1 year ago
shivc|1 year ago
unknown|1 year ago
[deleted]
exe34|1 year ago
keyle|1 year ago
DoingIsLearning|1 year ago
zabzonk|1 year ago
gravescale|1 year ago
It doesn't really matter what it is, it could be porting FeeeRTOS to your toaster, writing a kernel driver for something, reversing some device protocol, implementing something on an FPGA or building some embedded device or hacking another one into something else. Just get stuck into something and feel the gravity of your open interests.
Nothing you learn along the way will be a waste.
anonymoushn|1 year ago
blankx32|1 year ago
082349872349872|1 year ago
latenightcoding|1 year ago
boffinAudio|1 year ago
Learning Lua is a great way to get introduced to a lot of low-level concepts, from bytecode to VM's to language design and beyond.
hnaccountme|1 year ago