HNHacker News
TopNewBestAskShowJobs

mnurzia

237 karma · joined July 5, 2021

23

I love coding in old versions of C on my own time but I have extensive experience in Python and C++.

I play the bass guitar, and I run a lot. If you're in the Boston area and want to go on a run let me know.

contact me: max[U+0040]mmn[U+002E]sh

submissionscomments
mnurzia··on Sixel: A terminal bitmap graphics format from the 80s
Whenever Sixel comes up, I always think about this guy who wrote terminal patches that allowed for Sixel support, as well as a library (libsixel) that generates them: https://github.com/saitoha

A couple years ago, it seemed like he was on a mission to patch every terminal in existence so that Sixel support was widespread. Seriously, half of his repositories have something to do with Sixel. Back then I was still on Windows, and when he patched mintty it was kind of crazy seeing bitmap graphics in my terminal for the first time.

It seems as though he hasn't made any commits in years, though. I wonder what happened to him. I always admired his interest in pushing these graphics, however old and arcane the protocol may be.

mnurzia··on Shiki Syntax Highlighter
This is really cool. I've been looking for a high quality (Textmate-based) syntax highlighter for rendering source code on a poster. It would be great to integrate this library with ctags or something in order to perform accurate semantic highlighting for C/C++ (distinguishing between macros and functions, etc.).
mnurzia··on How to check if any word is zero (2021)
You're right about it being up to the compiler if the conditions don't have side-effects.

The C++ standard's "as-if" rule[1] allows these kinds of transformations if they do not effect the "observable behavior" of the program. Interestingly, if the values are marked volatile the compiler outputs the "correct" short-circuiting code, even with optimizations[2]

[1] https://en.cppreference.com/w/cpp/language/as_if

[2] https://cpp.godbolt.org/z/dzTh1vPW9

mnurzia··on Improving Firefox Responsiveness on macOS
Musl libc also does this for threads, spinning 100 times by default before switching to a heavier system wait (see line 71): https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_...
mnurzia··on RacketCon 2022
I took Fundies 1 at NEU last year, but I came in with a good amount of programming experience. I appreciated it because it forced me to think in a new programming paradigm (functional) but for a lot of my classmates who were beginners it was tough because of the much more puzzle-like nature of the problems. I also didn't think it was very fair to these students for the curriculum to immediately abandon Racket after the first semester and go right into Java for the second. The Fundies classes can at times be very discouraging because of the intensity.
mnurzia··on Cowgod's Chip-8 Technical Reference
I used this reference to write a CHIP-8 emulator in Z80 assembly a couple years back: https://github.com/mnurzia/chip8-ce
mnurzia··on Ange Yaghi: Simulating an entire car engine
This reminds me a lot of the engine simulators people would make in the sandbox gamemode for Garry's Mod. When I was first getting into coding I used the Expression 2 programming language (basically a scripting language implemented in the Lua sandbox for GMod) and this kind of thing was somewhat common. Here's an example of an engine that someone else made (the code is in the video description): https://www.youtube.com/watch?v=Ktbu4gomOjA
mnurzia··on Holley Carburetor Operating Principles
SmarterEveryDay recently made a video[1] touring Holley's factory. Pretty interesting stuff. The manufacturing process is fairly complex and elaborate.

[1] https://www.youtube.com/watch?v=1_hFKRDDP_o

mnurzia··on Ask HN: What do you use VMs for regularly?
I recently brought up a Windows 10 VM and a couple Debian, FreeBSD, and OpenBSD VMs to test building C software on multiple platforms and toolchains. It's notoriously hard to run MSVC on non-Windows platforms, especially my M1 Mac, so having a dedicated build VM is a must for me. I use QEMU on the command line to virtualize everything. Although it was incredibly hard to get both x86_64 and aarch64 Windows reliably working (3+ days of waiting for installers and trial and error, in case you're wondering) it's worth it as now I can use a shell script to boot each VM, rsync a folder full of source files, and then run cmake to check for build errors, all from the host machine. It's kind of close to some form of CI at this point.
mnurzia··on Current Causes of Death in Children and Adolescents in the United States
I go to college in Boston and was housed around Berklee, and I also agree that the billboard (recently removed, IIRC) was in pretty bad taste. I agree that we're missing the point here, but more so because messaging like that only seems to be counterintuitive and provocative and probably does more harm than good.

The billboard in question, when I saw it: https://www.stophandgunviolence.org/wp-content/uploads/2020/...

mnurzia··on TreeFlat: Building a (possible) faster tree for Rust, inspired by APL
The arena design pattern is something I'm using a lot for a project in C. Like Rust, the primary reason it's attractive to use is because of how it plays well with memory safety. Although I'm no Rust expert, I suspect that its ownership model makes designing tree data structures difficult and unwieldy. In C, it is similarly unwieldy to design traditional tree structures because of how hard it is to manage pointers everywhere. If each Tree is a pointer to a dynamically-allocated block of data, it's really hard to remember when to call free(), especially if you have a function that modifies a Node in place by rearranging (or possibly deleting) its children, which is often the case for ASTs. In contrast, the arena pattern uses one flat memory allocation, and allows a couple optimizations:

- References between nodes can be whatever type you want. In most cases, I don't need a full size_t or the width of a pointer to represent a reference to another node, and a uint32_t or the likes will do. (This is faster on some platforms.)

- The whole arena is a single memory allocation (usually a vector.) Rather than allocating on every node, you can allocate memory for a few nodes and then use it until it runs out, at which point you can allocate memory for a few more.

- Since it's a single allocation, destroying the entire tree is trivial: just free the block of memory. Importantly, this doesn't require the recursive algorithm that a pointer-based tree might use to free itself, so you run no risk of blowing out your stack if some user creates a really deep tree.

- You can do repeated node removal/insertion in a really efficient way using a neat trick. It's possible to maintain an "empty list" by using the memory reclaimed from removed nodes in the arena to represent a linked list of empty positions. Then, if you want to add a new node later, you can use the last element of the empty list as the position for your next node, without resizing the arena. For an AST, this can be crucial because some algorithms will thrash the tree by doing lots of insertions and removals. (This technique is not type-safe in C, however, and can be UB if you do it wrong, so you have to be really careful, and it's a bit of a code smell.)

- Since the tree is stored in contiguous memory, it's a little more cache-friendly than a bunch of pointers that are potentially scattered throughout the heap. This is a nice bonus.

- The structure generalizes to any type of graph, like a linked list. If you need a structure that can represent any kind of link between objects without pointers, the arena will do.

There are a few cons, however:

- Like a pointer-based structure, you still have to remember to update edges in the tree when you update its nodes. Instead of updating a Node*, however, you're updating a NodeID, and sometimes less obvious when to do this.

- Since the array is a large contiguous allocation, its effect on your heap is very different than the pointer strategy that uses tons of small allocations. This gives different heap fragmentation characteristics, which might be better or worse depending on what allocator you use.

- Because a NodeID is just a position in an array, you likely won't get segfaults when you access a node that was freed, or a NULL Node*. This is actually a bad thing because you don't catch certain bugs until way later, when the corrupted tree is used. In C, I've found that a healthy amount of assert()s helps a lot but it requires a lot of abstraction and makes the code significantly more verbose.

All in all it's just another example of balancing performance, complexity, and ease of development. Like any programming tool, it's worth considering, but not really necessary unless you really need the speed (C) or unless it actually makes your code easier to use (Rust).*

mnurzia··on PortableGL: An implementation of OpenGL 3.x-ish in clean C
Just because I was curious, I did a little digging: A cursory look at Sean Barrett's website on the Internet Archive lists Dec. 2006 as the first date where stb_image was published (but looking at the file, versions go back much further than that)

https://web.archive.org/web/20061205030342/http://nothings.o...

That means for 15+ years, he's been iterating on the same file. It certainly works as a development style, but I personally feel that it's easier to edit a set of smaller files.

mnurzia··on PortableGL: An implementation of OpenGL 3.x-ish in clean C
Not entirely related to the subject of OpenGL, but I really like how the author has decided to lay out this project. It's pretty hard to beat the convenience of a single header (or single header/single source) distribution for C libraries, but library development gets progressively harder as the project gets bigger as more code is added to the (usually hard to navigate) header file. Here, the author does their development with multiple files as one normally would, but when a new version is released they run the generate_gl_h[1] script that concatenates everything into a .h file for distribution. Simple yet flexible! This is also how SQLite[2] distributes its builds. It's a pattern that I'm using myself in some unreleased projects.

[1] https://github.com/rswinkle/PortableGL/blob/master/src/gener... [2] https://www.sqlite.org/amalgamation.html

mnurzia··on The ultimate SMD marking codes database
How was this data compiled? There is very little information on the site.
mnurzia··on XiangShan open-source 64-bit RISC-V processor to rival Arm Cortex-A76
It's worth noting that Micro Magic's design tools are likely what allowed them to claim these numbers. Some of the claims they make about their software are pretty impressive, but it mainly boils down to intelligent placing/routing techniques that mirror fully custom hand-made silicon designs but are actually designed by the computer: http://www.micromagic.com/datasheets/PDFs/DPC_3page_Layout.p...

It seems like their design workflow is ahead of the rest of the field.

← PreviousPage 2 of 2