int128

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

北城以北 提交于 2019-12-06 04:12:44
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/html/hash/custom.html ) for extending boost::hash, and I created a hash function, as well as a custom

Arithmetic with IPv6 addresses (large integers)

不羁的心 提交于 2019-12-05 01:18:29
问题 I'm working with IPv6 addresses in the form: FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF Internally, I store them in an array: TIp6Bytes = array [0..15] of Byte; I need to manipulate the IPv6 addresses in a number of ways including adding, dividing, multiplying etc. Can anyone suggest a good way to do this? I guess I should have mentioned that I'm working with Delphi 2009 回答1: Jes Klinke wrote a bignum unit for Pascal here. Disclaimer : I have not used this library personally. 回答2: After trying

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

无人久伴 提交于 2019-12-04 23:41:39
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" typedef __u128 uint128_t; #elif defined (__GNUC__) typedef __uint128_t uint128_t; #else #error For 128

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

六眼飞鱼酱① 提交于 2019-12-04 11:55:01
This question already has an answer here: Computing high 64 bits of a 64x64 int product in C 5 answers 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 never overflow in 64-bits as the final result would be < 128<<fmt and therefore fit in an int64. The reason I want to do that is

Bug with __int128_t in Clang?

99封情书 提交于 2019-12-04 00:59:31
问题 This little code compiles with both GCC and Clang, but gives different results: #include <stdio.h> int main(){ __int128_t test=10; while(test>0){ int myTest=(int)test; printf("? %d\n", myTest); test--; } } With GCC this counts from 10 down to 1, the intended behaviour, while for Clang it keeps on counting into negative numbers. With Clang, if I replace test-- with test-=1 then it gives the expected behaviour as well. __int128_t is a GCC extension, so the above results only apply to non

Arithmetic with IPv6 addresses (large integers)

风格不统一 提交于 2019-12-03 20:21:43
I'm working with IPv6 addresses in the form: FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF Internally, I store them in an array: TIp6Bytes = array [0..15] of Byte; I need to manipulate the IPv6 addresses in a number of ways including adding, dividing, multiplying etc. Can anyone suggest a good way to do this? I guess I should have mentioned that I'm working with Delphi 2009 Jes Klinke wrote a bignum unit for Pascal here . Disclaimer : I have not used this library personally. After trying many of the suggestions I could not find a library that fulfilled all my needs and were bug free. I searched a

Efficient way to store IPv4/IPv6 addresses

↘锁芯ラ 提交于 2019-12-01 17:00:06
问题 I am working on a C/C++ networking project that it should be able to both use the IPv4 and IPv6 networking stacks. The project works only on Linux. So, I tried to find an efficient way to store the IP addresses and differentiate between the protocol families. The first approach was to have a union: struct ip_addr { uint8_t fam; // socket family type union { struct in_addr ipv4_sin_addr; struct in6_addr ipv6_sin_addr; }addr; }; The second approach was to define a typedef std::vector<unsigned

Efficient way to store IPv4/IPv6 addresses

北慕城南 提交于 2019-12-01 16:54:12
I am working on a C/C++ networking project that it should be able to both use the IPv4 and IPv6 networking stacks. The project works only on Linux. So, I tried to find an efficient way to store the IP addresses and differentiate between the protocol families. The first approach was to have a union: struct ip_addr { uint8_t fam; // socket family type union { struct in_addr ipv4_sin_addr; struct in6_addr ipv6_sin_addr; }addr; }; The second approach was to define a typedef std::vector<unsigned char> IPAddressNumber and make the difference after the number of bytes from the vector. The third

An efficient way to do basic 128 bit integer calculations in C++?

ε祈祈猫儿з 提交于 2019-12-01 11:45:56
Some years ago I needed a way to do some basic 128 bit integer math with Cuda: 128 bit integer on cuda? . Now I am having the same problem, but this time I need to run some basic 128 bit arithmetics (sums, bitshifts and multiplications) on a 32 bit embedded system (Intel Edison) that does not support 128 bits of any kind. There are, however, 64 bit integers supported directly (unsigned long long int). I tried naively to use the asm code that was answered to me last time on the CPU, but I got a bunch of errors. I am really not experienced with asm, so: what is the most efficient way, having 64

An efficient way to do basic 128 bit integer calculations in C++?

旧城冷巷雨未停 提交于 2019-12-01 08:54:32
问题 Some years ago I needed a way to do some basic 128 bit integer math with Cuda: 128 bit integer on cuda?. Now I am having the same problem, but this time I need to run some basic 128 bit arithmetics (sums, bitshifts and multiplications) on a 32 bit embedded system (Intel Edison) that does not support 128 bits of any kind. There are, however, 64 bit integers supported directly (unsigned long long int). I tried naively to use the asm code that was answered to me last time on the CPU, but I got a