summaryrefslogtreecommitdiff
path: root/internal/bits.h
AgeCommit message (Collapse)Author
2020-04-13add #include guard hack卜部昌平
According to MSVC manual (*1), cl.exe can skip including a header file when that: - contains #pragma once, or - starts with #ifndef, or - starts with #if ! defined. GCC has a similar trick (*2), but it acts more stricter (e. g. there must be _no tokens_ outside of #ifndef...#endif). Sun C lacked #pragma once for a looong time. Oracle Developer Studio 12.5 finally implemented it, but we cannot assume such recent version. This changeset modifies header files so that each of them include strictly one #ifndef...#endif. I believe this is the most portable way to trigger compiler optimizations. [Bug #16770] *1: https://docs.microsoft.com/en-us/cpp/preprocessor/once *2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html Notes: Merged: https://github.com/ruby/ruby/pull/3023
2020-04-09internal/bits.h: Suppress "uninitialized variable"Yusuke Endoh
Coverity Scan says "Using uninitialized value c.fixnum when calling __builtin_mul_overflow_p."
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-11Fix typos (#2958)K.Takata
* Fix a typo * Fix typos in st.[ch] Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-01-10avoid undefined behaviour when n==0卜部昌平
ISO/IEC 9899:1999 section 6.5.7 states that "If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined". So we have to take care of such situations. This has not been a problem because contemporary C compilers are extraordinary smart to compile the series of shifts into a single ROTLQ/ROTRQ machine instruction. In contrast to what C says those instructions have fully defined behaviour for all possible inputs. Hence it has been quite difficult to observe the undefined-ness of such situations. But undefined is undefined. We should not rely on such target-specific assumptions. We are fixing the situation by carefully avoiding shifts with out-of- range values. At least GCC since 4.6.3 and Clang since 8.0 can issue the exact same instructions like before the changeset. Also in case of Intel processors, there supposedly be intrinsics named _rotr/_rotl that do exactly what we need. They, in practice, are absent on Clang before 9.x so we cannot blindly use. But we can at least save MSVC. See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57157 https://bugs.llvm.org/show_bug.cgi?id=17332 Notes: Merged: https://github.com/ruby/ruby/pull/2824
2020-01-10more use of MSC_VERSION_SINCE卜部昌平
Replaces `#ifdef _MSC_VER` with more accurate version checks. Also, `defined(_WIN64) && defined(__AVX2__)` is redundant because there is no such tihng like a 32bit AVX2 machine. Notes: Merged: https://github.com/ruby/ruby/pull/2824
2020-01-10fix Windows breakage卜部昌平
Fixing typo revealed that _BitScanReverse is BSR, which behaves differently than LZCNT. What we want here is LZCNT so we have to emulate. Notes: Merged: https://github.com/ruby/ruby/pull/2824
2020-01-10fix typos卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/2824
2019-12-27reroute macro conflicts on OpenBSD卜部昌平
OpenBSD's <sys/endian.h> has its own swap32() etc. We have to avoid name conflicts. See also https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20191226T210011Z.log.html.gz#miniruby
2019-12-26internal/bits.h rework卜部昌平
Improving readability by converting some macros into inline functions. Also improved support for recent x86_64 processors, which have better instructions for the purposes. Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26split internal.h into files卜部昌平
One day, I could not resist the way it was written. I finally started to make the code clean. This changeset is the beginning of a series of housekeeping commits. It is a simple refactoring; split internal.h into files, so that we can divide and concur in the upcoming commits. No lines of codes are either added or removed, except the obvious file headers/footers. The generated binary is identical to the one before. Notes: Merged: https://github.com/ruby/ruby/pull/2711