Git Product home page Git Product logo

libdivide's Introduction

libdivide is a "library" for optimizing integer division.  See http://libdivide.com for more information on libdivide.

This is summary of how to use libdivide's testing tools to develop on libdivide itself.  

libdivide proper consists of a single header file, libdivide.h, which compiles as both C and C++.

libdivide has two test tools: a verification utility "tester", and a benchmarking utility "benchmark".  The verification utility is used to help ensure that the division algorithm is correct, and the benchmarking utility is used to measure the speed increase.  On Mac OS X, Linux, and other Unix-like systems, you can build both with the Makefile.  On Windows, there is a Visual C++ 2010 project that can build both, in windows/libdivide_Win32

To build the tester via the Makefile, build one of the following targets:

   debug:   builds the tester without optimization
   release: builds the tester with optimization  
   
Both build an executable "tester".  You can pass it one or more of the following arguments: u32, s32, u64, s64, to test the four cases (signed, unsigned, 32 bit, or 64 bit), or run it with no arguments to test all four.   The tester is multithreaded so it can test multiple cases simultaneously.  The tester will verify the correctness of libdivide via a set of randomly chosen denominators, by comparing the result of libdivide's division to hardware division.  It may take a long time to run, but it will output as soon as it finds a discrepancy.
  
The benchmarking utility is built with target "benchmark."  You may pass it one of the same arguments (u32, s32, u64, s64) to compare libdivide's speed against hardware division.

"benchmark" tests a simple function that inputs an array of random numerators and a single divisor, and returns the sum of their quotients.  It tests this using both hardware division, and the various division approaches supported by libdivide, including vector division.

It will output data like this:

     #  system  scalar  scl_us  vector  vec_us   gener  algo
     1   5.733   0.849   0.580   0.431   0.431   1.663     0
     2   6.716   0.847   0.580   0.431   0.431   1.663     0
     3   6.687   1.425   1.427   1.862   1.444  22.156     1
     4   6.668   0.851   0.580   0.431   0.431   1.663     0
     5   6.697   1.425   1.425   1.837   1.425  22.156     1
     ...

It will keep going as long as you let it, so it's best to stop it when you are happy with the denominators tested.  These columns have the following significance.  All times are in nanoseconds, and lower is better.

        #:  The divisor that is tested
   system:  Hardware divide time
   scalar:  libdivide time, using scalar functions
   scl_us:  libdivide time, using scalar unswitching functions
   vector:  libdivide time, using vector functions
   vec_us:  libdivide time, using vector unswitching
     algo:  The algorithm used.  See libdivide_*_get_algorithm
     
The benchmarking utility will also verify that each function returns the same value, so "benchmark" is valuable for its verification as well.

Before sending in patches to libdivide, please run the tester to completion with all four types, and the benchmark utility for a reasonable period, to ensure that you have not introduced a regression.  Happy hacking!

libdivide's People

Contributors

charlienewey avatar dtzwill avatar kasper93 avatar kimwalisch avatar ridiculousfish avatar

Watchers

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