5 ms·
Why do people use NASM? Faster binaries? When is it needed? Where do the binaries run?
by tarkin2 5y ago
Why do people use NASM? Faster binaries? When is it needed? Where do the binaries run?
- sharikous 5y agoMore control on the machine. For example you may want to use certain CPU instructions, or as you mentioned you can eliminate a lot of overhead in certain cases. Look at it like melting your own metal piece. Sometimes the screws that you find in the shop are not the exact shape you need and it's better to build your own. I bet most of the things you code with Nasm are not entire binaries. You can write functions entirely in assembly and link the compiled outputs to any binary file once you know the calling convention
- sigjuice 5y agoPortions of a program or library might be written in assembly for performance. This list should give an idea of the type of software that does this $ cd /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula $ grep depends_on.*nasm * | sed 's,:.*,,' | xargs grep desc dav1d.rb: desc "AV1 decoder targeted to be small and fast" dssim.rb: desc "RGBA Structural Similarity Rust implementation" ffmpeg.rb: desc "Play, record, convert, and stream audio and video" handbrake.rb: desc "Open-source video transcoder available for Linux, Mac, and Windows" isa-l.rb: desc "Intelligent Storage Acceleration Library" jpeg-turbo.rb: desc "JPEG image codec that aids compression and decompression" libass.rb: desc "Subtitle renderer for the ASS/SSA subtitle format" libavif.rb: desc "Library for encoding and decoding .avif files" libvmaf.rb: desc "Perceptual video quality assessment based on multi-method fusion" lrzip.rb: desc "Compression program with a very high compression ratio" mozjpeg.rb: desc "Improved JPEG encoder" mvtools.rb: desc "Filters for motion estimation and compensation" openh264.rb: desc "H.264 codec from Cisco" openj9.rb: desc "High performance, scalable, Java virtual machine" pce.rb: desc "PC emulator" ppsspp.rb: desc "PlayStation Portable emulator" rav1e.rb: desc "Fastest and safest AV1 video encoder" vapoursynth.rb: desc "Video processing framework with simplicity in mind" x264.rb: desc "H.264/AVC encoder" x265.rb: desc "H.265/HEVC encoder
- totorovirus 5y agoI am truly impressed by your command line skills. Awesome
- the_only_law 5y agoInteresting how many of these are related to video encoding. While I can understand wanting to micro optimize performance for this sort of work when done in the CPU, I would think that if you truly wanted maximum performance, you’d offload this to something like a GPU or other hardware offering this feature. Emulators make sense I suppose. I’ve only ever seen modern assembly in the wild in small parts, in say a kernel or something like coreboot. I’ve been told by graphics programmers and game devs that’s its not uncommon to hand roll assembly code in those domains, which was suprising to me
- yjftsjthsd-h 5y agoI'm about to use it for really early OS development. You kind of need assembly for some bits in early boot / setup, and nasm seems friendlier to me than the alternatives.
- chrisseaton 5y ago> Why do people use NASM? Faster binaries? There's nothing NASM can do to produce faster binaries than any other assembler - as it doesn't control which instructions to generate - they're specified entirely by the user.
- glandium 5y agoActually, nasm does have optimization passes. https://nasm.us/doc/nasmdoc2.html#section-2.1.24 https://nasm.us/doc/nasmdoc2.html#section-2.1.24 That's not full of details, but one thing that it does on x86_64, for example is replace instructions that set 64-bits registers to immediate values smaller than 2^32 with instructions that set the equivalent 32-bits register (because that's a shorter equivalent, because those instructions zero-extend the value).
- pjmlp 5y agoThat is common in most Assemblers, RISC ones like MIPS even go further with pseudo instructions to work around how low level RISC opcodes tend to be.
- Koshkin 5y agoGo to Java for the climate, NASM for the company. (Or was it the other way around?) In any case, even Windows programming in NASM is easy! https://news.ycombinator.com/item?id=28790747 https://news.ycombinator.com/item?id=28790747
- sebow 5y agoBetter documentation (I'm pretty sure the latest official documentation from gnu/as is from like 2009), packages on all distros & *nix flavors: linux, deb/rpm-based, freebsd, etc. And also why not a lot of people use it.I think gnu/as has a bit better tooling,more flags, etc., but that's quickly changing.