Git Product home page Git Product logo

crc32c's Introduction

leptonyu's github stats

crc32c's People

Contributors

dcoutts avatar dynamicboid avatar istathar avatar leptonyu avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

tloncorp dcoutts

crc32c's Issues

The C++ code does not build on Windows or OSX

With the current .cabal file, the bundled C++ code does not build on OSX or Windows with default versions of the toolchain on those platforms.

There are two independent problems:

OSX

The -std=c++11 flag is not getting passed to the C++ compiler (on any platform). Apparently on OSX the default C++ language standard for clang is not C++11 and so the compilation fails, complaining about the use of some C++11 features (constexpr). This is despite the crc32c.cabal file saying:

  if arch(x86_64)
    cc-options: -std=c++11 -D__HAVE_SSE42=1 -D__HAVE_ARM64_CRC32C=0 -msse4.2

The problem is that the crc32c.cabal file specifies cc-sources and cc-options which are for C code, not C++ code. It should use cxx-sources and cxx-options. Then the options do get passed to the C++ compiler.

The reason it sort-of works when one uses cc-sources is that Cabal guesses that .cc files are probably C++, but still it doesn't pass C++ options to those compilations. But the fix it simple: use cxx-sources and cxx-options and then it works.

Note also that this means that all of the cc flags that the .cabal tries to specify are being ignored, and thus presumably this means the generic implementation is being used rather than the arm or msse42 optimised versions.

Windows

Both FFI imports involve an argument of type size_t:

uint32_t crc32c_extend(uint32_t crc, const uint8_t* data, size_t count);
uint32_t crc32c_value(const uint8_t* data, size_t count);

Windows uses C type unsigned long long for a 64bit unsigned int, while most other platforms use C type unsigned long for the same. The significance of this is that c2hs will look through the size_t type alias and bind the function with either the Haskell type CULong or CULLong. Given that the binding code assumes CULong then this fails with a type error when c2hs (correctly) discovers that the C type is actually CULLong.

lib_crc32c_extend :: CUInt -> Ptr CUChar -> CULong -> CUInt
lib_crc32c_extend = {#call pure crc32c_extend #}

lib_crc32c_value :: Ptr CUChar -> CULong -> CUInt
lib_crc32c_value  = {#call pure crc32c_value  #}

The simple solution is to use the Haskell type CSize instead, and not to bother with using c2hs at all.

foreign import ccall unsafe "crc32c/crc32c.h crc32c_extend"
  lib_crc32c_extend :: CUInt -> Ptr CUChar -> CSize -> IO CUInt

foreign import ccall unsafe "crc32c/crc32c.h crc32c_value"
  lib_crc32c_value :: Ptr CUChar -> CSize -> IO CUInt

Note also the use of unsafe since these are usually short-running calls so the overhead of a safe call is rather high.

Wrong defines

In addition, -D__HAVE_SSE42=1 -D__HAVE_ARM64_CRC32C=0 is using the wrong CPP define names. The names as used in the C++ code are AVE_SSE42 and HAVE_ARM64_CRC32C without the __ prefix.

Fixes

I have been testing fixes for these issues here IntersectMBO/lsm-tree#75

I plan to tidy this up and provide PRs here soonish.

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.