Git Product home page Git Product logo

Comments (6)

nemequ avatar nemequ commented on April 28, 2024

Probably related (warnings from clang):

/home/nemequ/local/src/squash/plugins/brotli/brotli/dec/./bit_reader.h:151:8: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint64_t *'
      (aka 'unsigned long *') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
      *(uint64_t*)(dst + bytes_read) = 0;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nemequ/local/src/squash/plugins/brotli/brotli/dec/./bit_reader.h:152:8: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint64_t *'
      (aka 'unsigned long *') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
      *(uint64_t*)(dst + bytes_read + 8) = 0;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nemequ/local/src/squash/plugins/brotli/brotli/dec/./bit_reader.h:153:8: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint64_t *'
      (aka 'unsigned long *') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
      *(uint64_t*)(dst + bytes_read + 16) = 0;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nemequ/local/src/squash/plugins/brotli/brotli/dec/./bit_reader.h:154:8: error: cast from 'uint8_t *' (aka 'unsigned char *') to 'uint64_t *'
      (aka 'unsigned long *') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
      *(uint64_t*)(dst + bytes_read + 24) = 0;
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/nemequ/local/src/squash/plugins/brotli/brotli/dec/./bit_reader.h:189:30: error: cast from 'uint8_t *' (aka 'unsigned char *') to
      'const uint32_t *' (aka 'const unsigned int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align]
    br->val_ |= ((uint64_t)(*(const uint32_t*)(
                             ^~~~~~~~~~~~~~~~~~

from brotli.

eustas avatar eustas commented on April 28, 2024

Unaligned loads/stores in bit_reader are intentional. We carefully profiled and decided to use them for better performance.

I'm going to take a look at overflow/shifting issues soon.

from brotli.

nemequ avatar nemequ commented on April 28, 2024

FWIW at least clang and, to a lesser extent, gcc are pretty good about generating fast code for memcpy with fixed sizes. Newer versions of GCC are better, but still not optimal. It might be worth it to keep an eye on that GCC bug and revisit the issue once it is resolved… unaligned accesses can cause problems down the road when the CC starts optimizing things better (this happened to LZ4 recently).

from brotli.

rygorous avatar rygorous commented on April 28, 2024

Unaligned loads/stores: the "official"/safe way to do an unaligned 32-bit load from "p" is:

uint32_t tmp;
memcpy(&tmp, p, sizeof(uint32_t));
// use tmp

Store likewise via memcpy. I know this is really gross, but I've run into several compilers that get really aggressive about assuming that loads/stores are aligned, and all major C/C++ compilers actually detect this type of use of memcpy and turn it into the unaligned loads/stores you want. I would prefer not to have to do this kind of thing, but compilers tend to get more pedantic about spec-lawyering all the time, and especially ARM compilers like to combine adjacent LDRs (which do not require alignment on ARMv6+) into LDRDs (which do), which has caused "fun" portability problems for me in the past.

from brotli.

eustas avatar eustas commented on April 28, 2024

We're going to make unaligned safer and more portable soon. So, stay tuned.

from brotli.

eustas avatar eustas commented on April 28, 2024

Fixed with PR 183.
Compiling with -DBROTLI_BUILD_PORTABLE avoids overlapping memcpy and unaligned reads.

from brotli.

Related Issues (20)

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.