Code Monkey home page Code Monkey logo

arith64's Introduction

32- and 64-bit arithmetic functions for use with 32-bit GCC.

Some versions of 32-bit GCC may emit calls to external helper functions to
perform certain 32- and 64-bit operations. Normally these functions are
resolved by libgcc.a which is statically linked to the program.

But libgcc may not be usable in some applications, e.g. embedded systems and
linux kernel drivers. In those cases you'll get an linker error such as:

    undefined reference to `__divdi3'

The solution is to link arith64.c to your code, or just copy the required
functions.

Also see https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html.

Note not all operations have been implemented, just the ones I've required to
date.

====

'make' performs Monte-Carlo validation testing. Two test executables are
created, one linked to arith64.c and one to libgcc. test.py launches these into
the background and then passes identical sets of random numbers to each,
comparing their outputs. On mismatch it reports error and exits, otherwise it
will run forever, printing the total number of test performed every 5 seconds.

'make bench' starts the test executables in benchmark mode, they perform each
operation one million times and print the average elapsed time in nanoseconds.
test.py then collates the returned information and prints a running average
every 5 seconds, e.g.:

1,772 cases
          arith64      gcc
   abs :   3.85nS   6.15nS
  ashl :   4.22nS   5.00nS
  ashr :   4.31nS   4.04nS
  clzd :   6.51nS   3.62nS
  clzs :   5.14nS   2.98nS
  ctsz :   4.63nS   2.66nS
  ctzd :   6.01nS   2.98nS
   div :  15.41nS   8.12nS
   ffs :   6.19nS   2.80nS
   mod :  17.84nS   8.99nS
  popd :   8.72nS   5.55nS
  pops :   3.94nS   4.40nS
   shr :   4.50nS   4.45nS
  udiv :  11.47nS   5.64nS
  umod :  11.56nS   6.74nS

This shows that the gcc native functions, presumably written in assembly
language and leveraging CPU-specific arithmetic operators, are generally twice
as fast as arith64 equivalents.

NOTE: the test code is built in 32-bit mode. If your development system is
64-bit you'll need to install 32-bit compatible headers and libraries. On
debian this can be done with "sudo apt install gcc-multilib".

arith64's People

Contributors

glitchub 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.