diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-08-05 21:29:02 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2019-08-08 20:29:32 -0700 |
commit | 48b3ec6e8e4be23e0d4620fb32b8c7faf082569d (patch) | |
tree | d3a1c5f1e2b6949460a1694d89ddce6fea34c4f6 /src/corelib | |
parent | c76b86aec64c4098434340ec17a26d7b2a32338e (diff) |
QBitArray: change modulo 8 with bitwise-AND 7
They're the same only for unsigned values. Modulo of negative numbers
since C++11 has an expected behavior and generates more code:
%rax = %rax & 7:
andl $7, %eax
%rax = %rax % 8 with GCC:
cqto
shrq $61, %rdx
addq %rdx, %rax
andl $7, %eax
subq %rdx, %rax
[read as ((%rax + (%rax < 0 ? 7 : 0)) & 7) - (%rax < 0 ? 7 : 0))]
With Clang:
movq %rax, %rcx
sarq $63, %rcx
shrq $61, %rcx
addq %rax, %rcx
andq $-8, %rcx
subq %rcx, %rax
Change-Id: Ife213d861bb14c1787e1fffd15b83b004be7eba0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qbitarray.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp index 4e8e3c241e..4952090620 100644 --- a/src/corelib/tools/qbitarray.cpp +++ b/src/corelib/tools/qbitarray.cpp @@ -154,8 +154,8 @@ QBitArray::QBitArray(int size, bool value) uchar* c = reinterpret_cast<uchar*>(d.data()); memset(c + 1, value ? 0xff : 0, d.size() - 1); *c = d.size()*8 - size; - if (value && size && size % 8) - *(c+1+size/8) &= (1 << (size%8)) - 1; + if (value && size && size & 7) + *(c+1+size/8) &= (1 << (size & 7)) - 1; } /*! \fn int QBitArray::size() const @@ -227,8 +227,8 @@ void QBitArray::resize(int size) uchar* c = reinterpret_cast<uchar*>(d.data()); if (size > (s << 3)) memset(c + s, 0, d.size() - s); - else if ( size % 8) - *(c+1+size/8) &= (1 << (size%8)) - 1; + else if (size & 7) + *(c+1+size/8) &= (1 << (size & 7)) - 1; *c = d.size()*8 - size; } } |