qt5base-lts/tests/auto/corelib/global
Thiago Macieira 29bc68cf16 Add code to perform overflow-checking additions and multiplication
Most processors have carry flags which they set on addition overflow, so
it's a good idea to access them whenever possible. Most of them also
have widening multiply instructions that can be used to detect overflow
of the non-widening version.

Tested to compile on:
 Architecture     Compiler
  x86             GCC 4.9, GCC 5*, Clang 3.6*, ICC 16 beta
  x86-64          GCC 4.9, GCC 5*, Clang 3.6*, ICC 16 beta
  x86-64 ILP32    GCC 4.9, GCC 5*, Clang 3.6*
  IA-64 LP64      GCC 4.8
  ARMv7-A         GCC 4.9, Clang 3.6*
  AArch64         Clang 3.6*
  MIPS            GCC 4.9, Clang 3.6*
  MIPS64          GCC 4.9, Clang 3.6*
  PowerPC         GCC 4.9, Clang 3.6*
  PowerPC 64      GCC 4.9, Clang 3.6*
  SPARC           Clang 3.6*
  SPARCv9         Clang 3.6*

[*] supports the intrinsics

If the compiler does not offer a way to detect an overflow, we do it by
hand. For unsigned additions, that's easy, since the C++ language
specifies the behavior of the overflow. That's also the reason why this
code is implemented only for unsigned integers.

For the multiplication, if the compiler does not support widening
multiplications, we do it with a division instead. This is necessary for
GCC < 4.5 and compilers not compatible with GCC or MSVC.

Change-Id: I049a653beeb5454c9539ffff13e637de0f1338c1
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-23 16:19:45 +00:00
..
q_func_info Update copyright headers 2015-02-11 06:49:51 +00:00
qflags Update copyright headers 2015-02-11 06:49:51 +00:00
qgetputenv QtCore: assorted migrations to QString::asprintf 2015-02-12 19:40:04 +00:00
qglobal Tests: Replace Q[TRY]_VERIFY(v == true|false) by QVERIFY(v)|QVERIFY(!v). 2015-07-27 12:09:19 +00:00
qglobalstatic Merge remote-tracking branch 'origin/5.5' into HEAD 2015-07-17 16:35:42 +02:00
qhooks Update copyright headers 2015-02-11 06:49:51 +00:00
qlogging Update copyright headers 2015-02-11 06:49:51 +00:00
qnumeric Add code to perform overflow-checking additions and multiplication 2015-09-23 16:19:45 +00:00
qrand Update copyright headers 2015-02-11 06:49:51 +00:00
qtendian Update copyright headers 2015-02-11 06:49:51 +00:00
global.pro Add a more reliable replacement for qt_add/removeObject(). 2014-04-15 17:50:20 +02:00