GithubHelp home page GithubHelp logo

batonius / uuz Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 32 KB

Fast and small unzip written in x86-64 asm

License: MIT License

Makefile 1.90% Assembly 38.21% Pawn 0.82% C++ 5.81% C 53.26%

uuz's Introduction

uuz (µ-unzip)

A minimal viable unzip clone written in x86-64 assembler for Linux, and then ported to C.

What

The repo contains two implementations of the same algorithm both in x86-64 asm and C. The asm version was written first and is a 5kb libc-free static x86-64 ELF binary calling Linux syscalls directly. The C version is a straightforward port using libc, tested on both x86-64 and aarch64.

Performance

Using UnZip 6.0 as a yardstick, the performance is as follows:

  • On x86-64 machine (Ryzen 3700X):
    1. uuz-asm is 1.3x faster than unzip.
    2. uuz-c is 1.4x faster than unzip, with both gcc and clang.
  • On aarch64 machine (Cortex-A76, Raspberry Pi 5):
    1. uuz-c is 1.3 faster than unzip, with both gcc and clang, if I ignore the bizarre Micro-SD performance lags.

Note: the comparison with unzip is just for scale, in no way the functionality is comparable.

Limitations

Both versions unpack only the first file in the archive. Neither version has bound checks, malformed archives will result in memory corruption.

How

Clang knows how to assemble .S files, so no external assembler like nasm is required. The asm version is completely inlined and heavily unrolled, resulting in measurable performance benefits at the cost of an unnecessarily large disk size. By replacing often-used macros with function calls and limiting loop unrolling I think it's possible to reduce the size of the binary to ~3kb. The DEFLATE implementation is based on the description in RFC1951, to simplify the code both versions just mmap input and output files, which is somewhat suboptimal.

Why

20 years ago I attempted to implement an unzipper in MASM32 but got lost in the process. 20 years later I thought it is a good little project to dust off my assembly skills.

Conclusion

The compilers are better at writing an efficient asm code than me. Duh.

uuz's People

Contributors

batonius avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.