Nov 10 13:44
BTW if there is no 128-bit integer type there may still be 64-bit multiply-high, so it does not mean that you're necessarily stuck with 32-bit. Of course that's a whole extra code path.. but given that at least one popular platform (MSVC targeting x64) is in that situation it may be worth it.
 
Apr 16 00:16
I just mean, let's say you have two books on a shelf, and I say "pick the middle one" .. which book is in the middle?
Apr 16 00:14
idk but basically anyone could have, it's basic arithmetic after all
Apr 16 00:13
you get 2 because the division rounds down but it's an edge case
Apr 16 00:13
the middle between the indices 2 and 3? there's not a lot of middle there, seeing as they're right next to each other
Apr 16 00:09
well it's accidentally equivalent for that example, but not in general
Apr 16 00:09
no, but we don't need to average N numbers
 
Feb 13 16:27
@tansy the difference between when I compiled the code and when you did it is that I compiled for ARM64 and you compiled for ARM but not 64-bit, so native 64-bit operations were not available
Feb 13 16:27
I know, I acknowledged that already.
Feb 13 16:27
@tansy "{U|S}MULH" means both "UMULH" and "SMULH" it's just a shortened notation, idk what you mean by standard C compiler but if you don't like the clang example well here's gcc using umulh as well
Feb 13 16:27
@tansy you didn't target 64-bit ARM, that list does have umulh in it (but as {U|S}MULH so ctrl+F is defeated) and here's the official page E: and here's umulh being used by clang
Feb 13 16:27
@tansy Arm® A64 Instruction Set Architecture (Armv8-A architecture profile), lists umulh and smulh. But since you're looking at something else, maybe that's not available on the kind of ARM processor that you meant.
Feb 13 16:27
BTW arm64 can construct both the lower 64 bits and upper 64 bits of the product of two 64-bit integers trivially (each in one instruction)
 
Jun 16, 2023 21:54
start with [0, 0], we add 1 to it, and we get [0, 1] (because `mag` is oddly reversed, that's the effect of it being big-endian)
Then multiply it by 3 (the base) and add 2, so we get [0, 5]
Multiply by 3, add 0: [1, 5]
Multiply by 3, add 0: [4, 5]
Jun 16, 2023 21:51
well it doesn't convert to base 10, but we can pretend, right?
Jun 16, 2023 21:23
the base of the input that is, not the base in which the result is represented
Jun 16, 2023 21:22
right that's what happens, the advantage I suppose is that the multiplication is always just by the base (working the other way, we'd have to multiply by successive powers of the base)
Jun 16, 2023 21:10
sorry I got that reversed for a moment, numbers in strings being conventionally big-endian gets me every time
Jun 16, 2023 21:09
the way BigInteger(String val, int radix) does the base conversion is essentially the opposite: it starts by extracting the most significant digits from the input (which is easy with a string, the linked algorithm isn't so string focused). It's like this, but with a larger base: for (int i = 0; i < str.length; i++) number = number * 10 + (str[i] - '0');
Jun 16, 2023 19:57
It just looks that way. If you look at the final result, or at how the arithmetic works, you will see that it's not so. The number in the int[] is iteratively changed by multiplying it by 10^9 and adding a chunk from the string. The first part of the string that gets added to it, starts at the least significant end of the int[] indeed, but then it gets multiplied by 10^9 the most times so it ends up in the most significant part eventually. Try parsing "340282367079394788547243514857164636165"
Jun 16, 2023 19:57
For the purposes of eg addition and multiplication: if you use base 2^32 you never have to use annoying operations such as modulo by 10^9 or divide by 10^9, just truncation and shift. Even worse, for the purposes of eg bitCount, shiftRight, xor, having a non-power-of-two base would be very annoying. By "lowest index" I just mean zero.
Jun 16, 2023 19:57
The most significant part of the number is stored at the lowest index, which is similar to big-endian although I normally only use that terminology for a byte order. That's why the loops for multiplication and addition are "backwards".
Jun 16, 2023 19:57
Absolutely, that would be much easier - for conversion to and from a (decimal) string. It would be less efficient to implement arithmetic on that representation, but it's possible and sometimes done that way. Java's BigInteger doesn't do it that way.
Jun 16, 2023 19:57
The base of the number in the int[] is 2^32, the base of the number being parsed is effectively 10^9 (by pulling out 9 digits and parsing them to an int first). We multiply the number in the int[] by 10^9, because that's the base of the number being parsed (effectively), but that multiplication happens in a representation that is base 2^32.
Jun 16, 2023 19:57
Just as 123 means 3 * 10^0 + 2 * 10^1 + 1 * 10^2, here int[] { 1, 2, 3 } would mean 3 * (2^32)^0 + 2 * (2^32)^1 + 1 * (2^32)^2. Limbs with their highest bit set will be presented as being negative, but you're supposed to interpret them as unsigned values, which the code does by bitwise-ANDing them with LONG_MASK
Jun 16, 2023 19:57
This is an algorithm that you learned in elementary school, maybe you are confusing yourself with the implementation details but the algorithm itself is trivial. How do you multiply 123456 by 8? With this algorithm, probably. Multiply 6 by 8, write down an 8, carry the 4.. that's what's happening here but with a higher base.
 
Nov 26, 2022 01:10
IDK about that crash, but does for example result.context->dictionary_size give you any reasonable value? Even if it does though, dictionary is a void pointer so you can't really do much with it. The actual contents of the dictionary aren't directly usable.
Nov 26, 2022 01:10
No, IntPtr is a C# thing so you wouldn't be able to do that anyway. You could change the parameter to den_context *context on the C# side, then you can pass the pointer directly without casting it to IntPtr, doesn't really matter though.
Nov 26, 2022 01:10
enum1.ALGO1 is not part of the struct, it's just one of members of that enum. It doesn't make sense to pass that to free_context either, it expects a pointer (as IntPtr) to a context, so (IntPtr)Result.den_context
Nov 26, 2022 01:10
@DarkKnight -> is an operator in C# too, you can use it in unsafe contexts
Nov 26, 2022 01:10
You should be able to use _result.den_context->algorithm for example (in unsafe code)
Nov 26, 2022 01:10
@DarkKnight what do you mean by "get the values" exactly? You have some pointer _result.den_context and you can use it, right? Does the address look plausible?
Nov 26, 2022 01:10
The structs on the C# side make some assumptions about the sizes and layout of the fields which I think won't be true, but it depends on how exactly the C++ side struct works, which is not clear: most of those types are non-standard. Normally fields are aligned to their natural alignment (which your C# struct assumes they aren't), and long (in C++, unlike in C#) is 4 bytes on windows. E: you're usually better off with sequential layout (typically does the right thing), unless you really need explicit layout and you know what you're doing
 
Mar 10, 2022 16:17
Instruction-level profiling often misattributes the time an instruction takes to the next instruction after the real offender. Either way the lack of SIMD is a bad sign.
 
Sep 7, 2019 17:12
@JacekZabrzowski if you need more confirmation you can cite from this
Sep 7, 2019 17:12
Using lots of delete when closing the process is not just unnecessary but a big waste of time, as you have already found. You probably won't be receiving practical answers here, people in the C++ tag concentrate on anything but that.
 
Jun 7, 2019 01:47
Can single "run" in the mask be redundantly selected by several 1s in IN?
 
Oct 9, 2018 15:24
ok
Oct 9, 2018 15:22
this is the same output: https://ideone.com/YKBjop
so it seems good
Oct 9, 2018 15:20
ok
Oct 9, 2018 15:14
isn't this a sneaky comma operator, so it only puts (byte)HEX in the array?
Oct 9, 2018 15:13
what about CK[0] = (CheckSum1 , HEX); what does this really do
Oct 9, 2018 15:13
it looks more C++ish
Oct 9, 2018 15:13
is this still C#?
Oct 9, 2018 15:12
I don't know, it got more confusing now
Oct 9, 2018 15:01
155+49+146+105+253 & 0xff == 0xc4
Oct 9, 2018 15:00
but -(-a + -b) = a + b so we can in fact sum the individual checksums
Oct 9, 2018 15:00
ok yes, a slightly different rule applies here though since there is negation too
Oct 9, 2018 14:59
well what do you want to do? combine them?
Oct 9, 2018 14:58
no problems here