21 ms·
Putting the “You” in CPU
- n6h6 3y ago>The bottom of every page is padded so readers can maintain a consistent eyeline. Very considerate!
- dwrodri 3y agoLove resources like this. I’m getting my feet wet in the RISC-V world, and it’s clear that people who want to push FOSS forward are going to need knowledge like this to get software working well on all of the SBCs that are coming out.
- mgaunard 3y agowouldn't any programmer already know this, assuming you studied for a bachelor's degree or more? At least if you didn't skip the computer architecture and operating systems classes. For me it was a common thing to define an ISA, implement a simulator and assembler, and hand-write some assembly as part of learning how computers work. A dedicated man might go the extra mile and implement it in FPGA, or write a LLVM backend. Then there is all the operating system aspect. It's quite common to implement your own kernel there to learn, or at least to modify an existing one.
- Claude_Shannon 3y agoFor you it was common thing, at mine classes best we did was adding numbers in assembly. Don't assume everyone had the same uni experience.
- __bjoernd 3y agoConfirmation Bias. How many "programmers" went through a traditional university CS course?
- mgaunard 3y agoHow can you call yourself a programmer if you don't know the basics? If you're gonna skip education, you better make up for it by going above and beyond what they teach with your self-learning.
- xeonmc 3y agoHow many people who call themselves "programmers" went through the basics?
- zerodensity 3y agoIf only this was how it worked :( From my experience a substantial fraction of programmers learn the absolute minimum to get a job. Then they either learn on the job or ask the same questions over and over again, never learning. The latter being the really annoying people to work with.
- j33zusjuice 3y agoOTOH, thank goodness for them or you wouldn’t find jobs so easily, nor would you command the salary you command.
- cyclotron3k 3y agoSome types of low level programming require you to know about CPU architectures and op codes, but certainly not all types of programming. You can be an excellent web dev without knowing how a CPU works, for example.
- kunley 3y agoFPGA sounds like the very old days, while LLVM is relatively new. Are you referring to a curriculum of specific university which makes students do both mentioned things?
- mgaunard 3y agoLLVM is 20 years old.
- kunley 3y agoLLVM as a project might be old, but to make its way to university's curriculum takes years or decades. So I guess you are avoiding answering my question: can you give an example of university's curriculum, when they make students work on both FPGA and LLVM? Because that's what you were suggesting in your statement.
- mgaunard 3y agoI didn't say there was a course that did both; in practice these things would depend on what the professor/assistants are personally researching. The school I went to definitely did the FPGA bit as there was a research team looking into FPUs at the time. I don't think we did any LLVM, though one of the teaching assistants I was friends with was excited about it as he was specifically researching SSA transformations, but most of my exposure to that must have been outside of class. That school specializes in theoretical computer science so I wouldn't really recommend it to anyone willing to do practical things, nor can I vouch for the quality of any remaining practical bits today. In practice I don't really know where to get a good computer science education. It seems computer architecture has become optional in quite a few top-ranking institutions as well. And they tend to follow trends like the whole AI fad. Your best bet is to research what kind of research the associated people do.
- Semaphor 3y agoNot everyone studied at the same university as you. And after having worked full time for over 10 years now, I never needed any of those skills.
- mgaunard 3y agoMany jobs wouldn't hire you if you couldn't demonstrate solid understanding of how computers and operating systems work. Myself I don't understand how one could write any code without understanding how the code gets run.
- intelVISA 3y ago> Myself I don't understand how one could write any code without understanding how the code gets run. I've got bad news if you work anywhere that is web or web adjacent then :)
- imdsm 3y ago> Myself I don't understand how one could write any code without understanding how the code gets run. I think this perhaps says more about you then it does the people to whom you're referring. If you can't understand how someone can write code to perform tasks and extrapolate from that ways that programming can be used to perform tasks, without any underlying knowledge of the architecture that it runs on, then I would suggest your education is currently incomplete. How far down does the full stack go? Hardware? Digital electronics? Analogue electronics? Physics? Further?
- mgaunard 3y agoCode is not just to perform tasks, at least not if we're talking about software engineering, rather than mere scripting. Code is typically used to run a service running for a potentially long time leveraging hardware resources which are made accessible and shared with other processes through an operating system. To ensure that the service runs well and doesn't hamper other services sharing those resources, you need at least high-level understanding of how the hardware and operating systems work.
- hgsgm 3y agoI went to a university, not a trade school. It taught me how to learn effectively, so I can learn technical details on my own for decades outside of school. I'm sorry that you wasted your money on an educational investment that doesn't pay dividends.
- mgaunard 3y agoIf you have good grades, you can be paid to study.
- CogitoCogito 3y ago> I'm sorry that you wasted your money on an educational investment that doesn't pay dividends. Which part of the grandparent's post led you to the conclusion that his/her education wasn’t good?
- metabagel 3y agoSarcastic response to a humble brag.
- skepticATX 3y agoNothing wrong with a refresher. The details can get fuzzy after a decade or two if you don't think about it regularly.
- metabagel 3y agoMost people have at least some gaps in their knowledge. A lot of people come to computer programming by way of other degree programs, such as EE, physics, math, even astronomy.
- still_grokking 3y agoWell, the voting on this question and the other replays could explain why most code in the wild looks like it was written by people who don't know how computers work… Sad, but this here is quite telling imho. I don't say that you need to be an expert on low level programming to write good code (sometimes this is even a hindrance as quite some of these people are prone to the premature optimization anti-pattern) but one should imho know at least the basics and have a high level overview of the low level stuff. But frankly the reality is that even people who struggle with mere syntax, people who have no clue whatsoever what's going actually on, "contribute" code way to often to the corpus that you need to deal with in professional settings. </rant> Edith thinks I should at least praise the great article we're commenting on here! Very nice write up. The only thing that I miss a little bit is a kind of "disclaimer" that what gets presented is "just" the result of a market race, and not how computers need necessary to work like. Not going into the details of possible hardware architectures and implementation, but even on the "user facing" level (the operating system and application layer) things can look very, very differently. Just as an example: https://en.wikipedia.org/wiki/Genera_(operating_system) https://en.wikipedia.org/wiki/Genera_(operating_system)
- archmaster 3y agoNot gonna get involved in the Hacker Newsmare occurring in the comments here, but still_grokking: great point about the disclaimer and I was definitely intending to put something similar in. Article is still in WIP status!
- bazoom42 3y agoSurely there was a point even in your life when you didnt know everything worth knowing about how computers work?
- bazoom42 3y ago“Anyone should already know this” is a very weird and illogic criticism towards learning material. Nobody is born knowing this, so surely such material is useful for everybody at some point.
- mananaysiempre 3y agoJust FYI, the RISC-V instruction encoding is considerably freakier than just about anything else you could be exploring except perhaps Thumb-2. They had good reasons to make it like that, but still, if you’re planning on reading hexdumps RISC-V is not going to go easy on you, even if it’s simple from most other angles.
- klelatti 3y agoI’m intrigued why you say this as my impression was that RISC-V coding was very straightforward.
- mananaysiempre 3y agoIt’s mostly the immediates, I mean, how could I not mention the immediates. The other parts are indeed arranged fairly straightforwardly, but trying to read off a 5-bit register field crossing a byte boundary when the instruction is written in little endian—or even just a three-bit field somewhere in the middle to figure out what the instruction even is—is less than pleasant. Again, I recognize this makes things simpler, not more difficult, for the hardware, and even a compiler’s emitter will spend very little code dealing with it. But it’s not easy on the eyes.
- klelatti 3y agoMakes sense - thanks!
- deleted 3y ago[deleted]
- amelius 3y agoReading the title I thought this was about owning your hardware (as opposed to the Apple approach where they effectively own your hardware).
- hgsgm 3y ago"The bottom of every page is padded so readers can maintain a consistent eyeline." What does this mean?
- chamik 3y agoIt means that you don't have to move your eyes horizontally very much. Some people (including me) like to just scroll.
- yakubin 3y agoIf you press page down to scroll, at the end of the page you’ll typically scroll by a smaller amount than prior to that, which changes the level at which your eyeline should be after hitting page down to continue reading uninterrupted. In Emacs and Vim hitting page down works nicely, because they just scroll “past end”. Other programs, like web browsers, often stop at the end, causing this issue and making the reader look for the point where they stopped reading for maybe even 30-45 seconds. This seems to be a workaround for that.
- imdsm 3y agoThe page will continue to scroll until the last line can fit to the top of the page. Nobody likes it when you can't scroll past the end, and have to then start moving your eyes/head to look at the bottom of the screen. Same with IDEs.
- kunley 3y agoBtw, Chapter 6 contains wrong explanation of fork() return values. It should be opposite than stated: in the parent, child's pid is returned and in the child it's zero; just created a pull request for that.
- archmaster 3y agoOh, thank you so much, and whoops :) Fixed the code example and merged!
- tromp 3y ago> For example, add eax, 512 translates to 05 00 02 00 00. > The first byte (05) is an opcode specifically representing adding the EAX register to a 16-bit number. The remaining bytes are 512 (0x200) in little-endian byte order. That explains only the first 3 of the 5 bytes in the instruction. What are the remaining 00s for? Did he perhaps mean that the opcode is for adding EAX to a 32-bit number?
- cormacrelf 3y agoIf it’s talking about x86, then yes the eax register is 32 bits wide. The low 16 bits of the same register are called “ax”.
- archmaster 3y ago*she and whoops, yep, I think that's supposed to say 32-bit. Good catch.
- nateguchi 3y agoFor anyone looking to find out more about how computers work at a very basic level, I really recommend the book "Code" by Charles Petzold. Goes from first principles all the way up.
- bazoom42 3y agoAnd Nandgame https://nandgame.com https://nandgame.com if you prefer to learn by building.
- bryancoxwell 3y agoThis is amazing, thank you!
- jayGlow 3y agothere is also Turing complete which is pretty similar. https://store.steampowered.com/app/1444480/Turing_Complete/ https://store.steampowered.com/app/1444480/Turing_Complete/
- nickpsecurity 3y agoThese projects are really fun. On the other hand, you might want to learn in a way that lets you build hardware (esp for FPGA's). For that, I suggest a few types of books with examples: - Computer architecture or CPU design book covering modern designs with their tradeoffs https://www.amazon.com/Computer-Architecture-Quantitative-Approach-Kaufmann/dp/0128119055/ref=d_m_crc_dp_lf_d_t1_sccl_3_1/139-2849439-8399939?pd_rd_w=b3QVg&content-id=amzn1.sym.5d471845-5073-424b-b27b-c0676f48a016&pf_rd_p=5d471845-5073-424b-b27b-c0676f48a016&pf_rd_r=JDREN15KEBVWZZ35RBPP&pd_rd_wg=TPBwg&pd_rd_r=41f7d839-8893-4910-b730-0a6b6c2f9fda&pd_rd_i=0128119055&psc=1 https://www.amazon.com/Computer-Architecture-Quantitative-Ap... - Introduction to Verilog or VHDL (languages for hardware) maybe on FPGA's or well-known boards https://www.amazon.com/Programming-FPGAs-Getting-Started-Verilog/dp/125964376X/ref=sr_1_1?keywords=Programming+FPGAs%3A+Getting+Started+with+Verilog+by+Monk&qid=1690028736&sr=8-1 https://www.amazon.com/Programming-FPGAs-Getting-Started-Ver... - High Speed Digital Design (many recommended it) https://www.amazon.com/High-Speed-Digital-Design-Handbook/dp/0133957241 https://www.amazon.com/High-Speed-Digital-Design-Handbook/dp... - Cookbook with many examples for FPGA's I don't have one. Most with these titles are expensive. One that looked promising had bad reviews. I'll leave it to HN to fill in the blanks. - High-level synthesis Most exciting one I remember when I stopped researching this stuff was Synflow. I don't know if they're still around. https://www.synflow.com/ https://www.synflow.com/ Before that, I had saved Baranov's work which showed how to turn Abstract, State Machines into actual hardware. It was like a how-to on high-level synthesis that he used commercially at Synthezza. I still share them periodically in case someone wants to build an OSS version. I also saw ASM's used in verifying compilers and hardware in separate work. There's a good chance someone can turn many things into a unified, field theory of sorts using ASM's. https://www.amazon.com/Finite-State-Machines-Algorithmic-Complex-ebook/dp/B078RYYBCJ/ref=sr_1_1?ie=UTF8&qid=1515915758&sr=8-1&keywords=samary+baranov https://www.amazon.com/Finite-State-Machines-Algorithmic-Com... https://www.linkedin.com/pulse/second-ebook-samary-baranov-high-level-synthesis-digital-baranov https://www.linkedin.com/pulse/second-ebook-samary-baranov-h...
- quickthrower2 3y agoThis looks like a good resource, and gets into the meat very quickly, and is sort of entertaining. It is less "monad tutorial"-esque than I expected. Look forward to reading more of it.
- archmaster 3y agoThanks! Glad you liked it — let me know if you have any feedback later on.
- quickthrower2 3y agoWill do, thanks for publishing it.
- TheBigRoomXXL 3y agoGreat article! As a self-taught web developer I find that kind of resources very valuable. It help me to move away from all the abstractions and towards a more concrete understanding of how thing work. Thank you.
- colejohnson66 3y agoGreat resource! However, one thing left me with a question about the kernel: From [0]: > Since shebangs are handled by the kernel, and pull from buf instead of loading the whole file, they’re always truncated to the length of buf. Apparently, 4 years ago, someone got annoyed by the kernel truncating their >128-character paths, and their solution was to double the truncation point by doubling the buffer size! Today, on your very own Linux machine, if you have a shebang line more than 256 characters long, everything past 256 characters will be completely lost. What is the reason for silently truncating someone's filepath? The kernel, of all places, should not be doing such things. Granted, 256-byte long file paths don't make sense, but 256-byte long path+argument strings will almost certainly happen sometimes. To just silently break someone's script is wrong. [0]: https://cpu.land/how-to-run-a-program https://cpu.land/how-to-run-a-program
- knome 3y agoyou shouldn't be putting complex arguments in a shebang. it's there to tell where the interpreter for the current file is. shebang can't even handle more than a single argument on its own. if you have `#!/bin/program -args somescript`, it will divide it into ['/bin/program','-args somescript'], which is almost never what you actually wanted. ( this is linux specific, shebangs aren't necessarily universally portable between all unices ) if you want to do something complex, make it `#!/bin/sh` and then `exec` from the current file with whatever arguments you need. one thing that link doesn't mention is that you can use env to lookup an interpreter via the current path. `#!/usr/bin/env python3` for example, will find whatever `python3` the users is using, without having to know where it is. this can be useful for scripts that you will be running from virtual environments, for example, which work by overriding the PATH to the python interpreter. you wouldn't want to do this with anything installed, however, since you wouldn't want installed programs to let the user control what interpreter to use. instead, you should just use an absolute path. there is an option in env, -S, that can be used to parse a command line from a single string specifically to handle this limitation. after years of avoiding much trickery in shebang lines, it seems like a questionable practice at best.
- fbdab103 3y ago
- mattfrommars 3y agoCurious, are material such as this targeted for folks who did not do undergrad in CS? Don't typical CS grads know about this?
- moribvndvs 3y ago> Chapter 4: Becoming an Elf Lord Clearly this is targets only people with multiple PhDs in electrical engineering and computer science.
- archmaster 3y agoMy article is, indeed, targeted towards folks who did not do undergrad in CS! Self-taught people need better resources to understand more low level things. I have never taken a CS class, undergrad, high school, middle school, or otherwise.
- archmaster 3y agoHi! I'm the person who made this thing! Thanks for reading and thanks for all the corrections, in glorious Hacker News fashion. It's definitely a pleasant surprise to see my project here. Putting the "You" in CPU is still very much a work in progress — I was hoping to polish it a lot more and even add some more content before posting on HN later next week :) Some backstory on me: I'm 17 and left high school a year ago to work full-time at Hack Club (https://hackclub.com/ https://hackclub.com/). I've been programming for as long as I can remember, and started homeschooling about 6 years ago to focus more on that (and my other interests). Since I'm entirely self-taught, I haven't taken any college systems classes — and while I had picked up a lot, I wasn't happy with my answer to "what happens when you run a thing." So I let myself spend a shit ton of time actually learning as much as possible. What I found was that: 1. Operating systems and hardware are really fun to learn about! 2. Wow, online resources on this stuff are terrible. A decent portion of my research ended up at PDFs of lecture slides from 2014, or StackOverflow answers that were, in fact, incorrect or vastly oversimplified. So, I wrote Putting the "You" in CPU to hopefully provide a better resource to people who wanted to start teaching themselves all this stuff! While I don't provide perfect coverage (still need to write a couple paragraphs on SMP), it's a lot better than most of what I've seen. I also had fun drawing and making diagrams for the first time, I think I definitely got progressively better and I'm really proud of some of the drawings in the latter few chapters. P.S. The whole thing is open source on GitHub if you want to look under the hood: https://github.com/hackclub/putting-the-you-in-cpu https://github.com/hackclub/putting-the-you-in-cpu
- uneekname 3y ago> I was hoping to polish it a lot more and even add some more content before posting on HN later next week :) That's on me, I'm a fan of your work and saw this pop up on my GitHub feed. I probably should have considered if you were ready for it to be shared. I hope the attention was mostly positive!
- still_grokking 3y agoWow! I'm impressed! Have you actually gone down already the rabbit hole that is the history of computing and alternative approaches to what we have today?
- ComputerGuru 3y agoAwesome work - I like the balance between the details and the high-level overview. How do you get it all on one page? That gives you the ability to ctrl+f stuff, skip past things you know by skimming their contents, scroll back up to things you need to re-read, and way more.
- archmaster 3y agoThis is still a WIP and I kinda wasn't expecting HN-level attention yet! I was definitely gonna make a 1-pager version, especially for offline reading (ie. public transit). Also had some people asking for PDF/EPUB.
- bhasi 3y agoCommenting to get back to reading this later. Thank you for this resource#
- archmaster 3y agoLMK what you think!
- bhasi 3y ago1. Loved discovering that shebangs are handled by the kernel in Chapter 3 - I did not know that. 2. Enjoyed reading the `execve` walkthrough. 3. I also like that you make it a point to include what the Mac OS and Windows equivalents for Linux terms are. If you could enable opening of the graphics such as the one illustrating the hierarchical page table concept to their original high resolution, that would be nice for readability.
- dmvdoug 3y agoOne of the things this does well is it remarks on expectations versus what was learned in the process of compiling the information. “I expected x because y but actually it’s a because b!” Clearing up misconceptions is often one of the key steps in new knowledge formation, and it’s helpful for writers to acknowledge that people often need to overcome their misconceptions as they process the information in the writing. It’s a much more reader-friendly approach than just being like, “Well, this is correct, and if you thought something else you’re a dummy.”
- deleted 3y ago[deleted]