src/nint128/nint128_cint128

Search:
Group by:
Source   Edit  

This module allows, when possible, to use the C extension of the GCC and CLANG compilers for 128-bit integers (__int128 and unsigned __int128), or to use VCC compiler intrinsics. Therefore, there are possibilities to optimize the generated code, since, by default, the nint128 package only uses pure Nim. It doesn't need to be imported.

Usage

To enable its use it is necessary to compile with: -d:useCInt128=SYMBOL,SYMBOL,...,SYMBOL.

Symbols for GCC and CLANG:

  • Comparisons: cunotequal, cnotequal, cuequal, cequal, cugreaterthanorequal, cgreaterthanorequal, cugreaterthan, cgreaterthan, culessthan, clessthan, culessthanorequal, clessthanorequal.
  • Bitwise: cubitand, cbitand, cubitor, cbitor, cubitnot, cbitnot, cubitxor, cbitxor, cushl, cshl, cushr, cshr.
  • Arithmetic: cuplus, cplus, cuminus, cminus, cuminusunary, cminusunary, cumul64by64To128, cumul, cmul, cudivmod, cdivmod, cudiv, cdiv, cumod, cmod.

Symbols for VCC:

  • Comparisons: none.
  • Bitwise: cushl, cushr.
  • Arithmetic: cuplus, cuminus, cumul64by64To128, cumul.

Symbols prefixed with c are for operators of type Int128 and symbols prefixed with cu are for operators of type UInt128.

Important notes

  • Only available for C and C++ backend.
  • The GCC and CLANG compiler do not provide further details on when the C extension for 128-bit integers is available. However, it is believed to be only available for targets that natively support 64-bit integers.
  • The intrinsics used with the VCC compiler are only supported on amd64 architecture.
  • The GCC compiler supports __int128 and unsigned __int128 types from version 4.6; The CLANG compiler supports it from version 3.1 onwards.
  • To use legacy type for 128-bit integers (__int128_t and __uint128_t), compile with -d:useLegacyCInt128. These types are present in GCC from version 4.1 and CLANG from version 3.0.

Types

CInt128 = object
  a, b: uint64
For internal use of the package. Source   Edit  
CUInt128 = object
  a, b: uint64
For internal use of the package. Source   Edit  

Procs

proc shouldUseCInt128(cproc: string): bool {.compileTime, ...raises: [], tags: [],
    forbids: [].}
For internal use of the package. Source   Edit