When I type __int128
in a C++ project in Visual Studio, the editor changes color of __int128
to blue (like keyword).
But when I compile the source, the folowing error appears:
error C4235:
nonstandard extension used : '__int128' keyword not supported on this architecture
How can I enable __int128
on Visual Studio?
And the rest is here. (conversion functions to/from string)
MSDN doesn't list it as being available, and this recent response agrees, so officially, no, there is no type called
__int128
and it can't be enabled.Additionally, never trust the syntax hilighter; it is user editable, and thus likely to either have bogus or 'future' types in it. (it is probably a reserved word however, due to the error, thus you should avoid naming any types
__int128
, this follows the convention that anything prefixed with a double underscore should reserved for compiler use).One would think the
__int128
might be available on x64/IPF machines via register spanning, like__in64
is on 32bit targets, but right now the only 128 bit types stem from SIMD types (__m128
and its various typed forms).Your conversions to/from string could use some improvement.
For saftey, the interface for converting to a string should include the allocated length of the user provided string, so you can return an error if they didn't provide enough memory.
Also, try to process strings in chunks: for example, suppose the user wants to convert a 128 bit number into base 10. Instead of repeatedly doing modulo 10, you could be doing modulo
1000000000ul
, and usingsprintf(s, "%09u", c)
.Converting from a string could be similarly optimized.
It would not be a bad idea to include a
divrem
method, with a return type ofstd::pair<_uint128, _uint128>
.It would be absolutely awesome if you had a integer class where the type used for
hi
andlo
was a template parameter. Then, with a small handful of typedefs, you could create an int256, an int512, etc..I've found a treasure in my old Visual Studio 6.0 C++ from 1996 (32-bit) making use of MS's own assembler routines that enabled 64-bit math on a 32-bit CPU(__int64). Source-code unfortunately not available). However, doing a debug-session that calls these functions, copy/paste the disassembler-list, search-replace "dword ptr" -> "qword ptr", eax,ebx,... -> rax,rbx,... and a Little adjustment of registers used for parameter-passing (and a lot of coffee), I succeeded to make this code, that makes it possible to do _int128-math in x64-mode just as it is possible to do __int64-math with 32-bit. It's essential the same code, with a doubleup in bits/cycle. For the matter of copyrights, I've seen no licenses in the disassembler-list, and perhaps it's time for Microsoft to integrate this into their x64 C++ compiler (vers. 2015) The code goes here
There will be 3 more files. not enough Space here...
There is a new version of _int128 which solves some of the problems mentioned. It includes a natvis addin, so you can view int128 in the debugger. To do this it was nessecary to write an x86 version of int128, because natvis-dll's need to be win32. The idea of using af template for the members lo,hi is ok, but I think it's a little to optimistic, because the routines that do the real job have to use the CPU's registers which, at least at the moment, are only 64 bit. But ok when Intel releases a 128-bit CPU. in/out in c++ std stream are added A lot of inline operators have been added too, so the compiler will do
without ambiguities.
The code is too big to fit in this answer so it's put in github with links to the files listet below
New header Int128.h
Int128x64.asm Assembler code for x64
Int128x86.cpp
Int128Str.cpp Common for x86 and x64
Int128IO.cpp Common for x86 and x64
AddIn-dll called by debugger to convert _int128/_uint128 to char*(radix 10)
Header for all natvis addin dll's