int128

Divide 64-bit integers as though the dividend is shifted left 64 bits, without having 128-bit types

試著忘記壹切 提交于 2019-12-24 04:43:22
问题 Apologies for the confusing title. I'm not sure how to better describe what I'm trying to accomplish. I'm essentially trying to do the reverse of getting the high half of a 64-bit multiplication in C for platforms where int64_t divHi64(int64_t dividend, int64_t divisor) { return ((__int128)dividend << 64) / (__int128)divisor; } isn't possible due to lacking support for __int128 . 回答1: This can be done without a multi-word division Suppose we want to do ⌊2 64 × x ⁄ y ⌋ then we can transform

Is there hardware support for 128bit integers in modern processors?

廉价感情. 提交于 2019-12-18 05:42:54
问题 Do we still need to emulate 128bit integers in software, or is there hardware support for them in your average desktop processor these days? 回答1: The x86-64 instruction set can do 64-bit*64-bit to 128-bit using one instruction ( mul for unsigned imul for signed each with one operand) so I would argue that to some degree that the x86 instruction set does include some support for 128-bit integers. If your instruction set does not have an instruction to do 64-bit*64-bit to 128-bit then you need

How to enable __int128 on Visual Studio?

点点圈 提交于 2019-12-17 06:49:09
问题 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? 回答1: 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

GCC alternative for Linux supporting OpenMP and 128-bit integers with +, -, *, /, and %

旧城冷巷雨未停 提交于 2019-12-14 02:08:01
问题 I have a C code that uses OpenMP and 128-bit integers. For the 128-bit integers, I'm using the __int128_t and __uint128_t extensions provided by GCC. I'm looking for any other compiler that can also compile this kind of code. Clang supports __uint128_t, but not OpenMP. ICC supports OpenMP, but not 128-bit integers (at least not ones that you can use built-in operators like +, -, *, /, and % with). The Portland Group C Compiler doesn't natively support 128-bit arithmetic. Just to be clear, I'm

Handling 128-bit integers with ctypes

若如初见. 提交于 2019-12-12 08:39:34
问题 What is the best way of supporting 128-bit integers (currently __uint128_t) with Python ctypes? A user-defined struct of two uint64_t's perhaps, but this will create alignment issues where that is required. Any thoughts on why ctypes has not been extended to support 128-bit integers? 回答1: If you really want to work with 128-bit integers then you don't need to worry about alignment. No current architecture, no machine that Python runs on, supports 128-bit native integer arithmetic. So no

redis store 128 bit number

半腔热情 提交于 2019-12-12 04:19:09
问题 I want to efficiently search IPv6 subnet range using redis . i thought of storing the IPv6 numeric addresses in redis and search them by range. those are 128-bit ints , e.g: import ipaddress int(ipaddress.ip_address(u'113f:a:2:3:4:1::77')) > 22923991422715307029586104612626104439L and query by range: ZRANGEBYSCORE numerics <subnet-S-start> <subnet-S-end> HOWEVER , redis sorted-sets can hold score of up to 2^53, so all my large ints are being trimmed and I'm losing precision. Is there a way to

How to properly add/subtract a 128-bit number (as two uint64_t)?

戏子无情 提交于 2019-12-11 07:30:48
问题 I'm working in C and need to add and subtract a 64-bit number and a 128-bit number. The result will be held in the 128-bit number. I am using an integer array to store the upper and lower halves of the 128-bit number (i.e. uint64_t bigNum[2] , where bigNum[0] is the least significant). Can anybody help with an addition and subtraction function that can take in bigNum and add/subtract a uint64_t to it? I have seen many incorrect examples on the web, so consider this: bigNum[0] = 0; bigNum[1] =

How can I use a custom type for keys in a boost::unordered_map?

荒凉一梦 提交于 2019-12-10 11:17:16
问题 I'm using Boost's implementation of a hash map in a project right now, and I'm trying to implement a custom type for keys. I have four unsigned integers which I'd like to combine into a single 128-bit datatype to use as a key. I've created a struct with a 32-bit integer array of four elements, which serves as my storage. To be honest, I'm not sure how Boost's hash map works, so I'm not sure what I'm doing here, but I followed the Boost documentation (http://www.boost.org/doc/libs/1_37_0/doc

128-bit integers supporting +, -, *, /, and % in the Intel C Compiler?

旧时模样 提交于 2019-12-10 01:02:59
问题 GCC and Clang have the __int128_t and __uint128_t extensions for 128-bit integer arithmetic. I was hopeful that __m128i would give something similar for the Intel C Compiler, but (if it's even possible) it looks to me like I'd have to write explicit SSE2 function calls in order to use __m128i , instead of using "built-in" operators like + , - , * , / , and % . I was hoping to do something like this (this doesn't work): #if defined(__INTEL_COMPILER) && defined(__SSE2__) #include "xmmintrin.h"

Fastest way to multiply two 64-bit ints to 128-bit then >> to 64-bit? [duplicate]

江枫思渺然 提交于 2019-12-06 07:34:47
问题 This question already has answers here : Computing high 64 bits of a 64x64 int product in C (5 answers) Closed 2 years ago . I need to multiply two signed 64-bit integers a and b together, then shift the (128-bit) result to a signed 64-bit integer. What's the fastest way to do that? My 64-bit integers actually represent fixed-point numbers with fmt fractional bits. fmt is chosen so that a * b >> fmt should not overflow, for instance abs(a) < 64<<fmt and abs(b) < 2<<fmt with fmt==56 would