Learn x86-64 Assembly by Writing a GUI from Scratch

2025-09-16

This article details the author's journey of learning x86-64 assembly language by creating a simple GUI program. Starting with a basic exit program, the author progressively explains system calls, stack operations, the X11 protocol, and more, ultimately achieving a window displaying "Hello, world!" in a binary under 1KB. The article is well-structured and suitable for readers with some programming experience.

Read more
Development GUI programming

Making My Debug Build 100x Faster: SIMD and Dedicated Silicon to the Rescue

2025-02-18

While developing a C-based torrent application, the author encountered a slow debug build startup time (20-30 seconds). This was mainly due to the program's startup verification of SHA1 hash values for each downloaded file piece, significantly slowed by Address Sanitizer in debug mode. The article explores several optimization techniques, including using SIMD instructions and the CPU's dedicated SHA acceleration hardware. Ultimately, using Intel's SHA extension instruction set reduced startup time to 866.9 milliseconds, achieving a 100x performance improvement. The article details the implementation and performance comparison of various optimization approaches, discussing compiler optimization and the impact of disk I/O.

Read more
Development

The Elusive Cross-Platform Timer API: A Journey Through OS APIs

2025-02-06

This article explores the challenges of cross-platform timer APIs in C programming. The author discovers that different Unix systems (including Linux, FreeBSD, NetBSD, etc.) handle timers very differently. The POSIX timer_create function, based on signals, presents numerous problems, such as poor interoperability with other OS primitives and signal mask interference. The article delves into the pros and cons of various solutions, including timerfd_create, kqueue, port_create, and io_uring, ultimately concluding that for cross-platform applications, implementing timers in userspace, as libuv does, is a more efficient and reliable approach. Libuv uses a min-heap data structure to manage timers and uses system calls like poll/epoll/kqueue for multiplexing.

Read more