-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Porting from boost multiprecision #234
Comments
Thank you for your queries @illera88
There is a bunch to say on this. I'm also co-author/co-maintainer of Boost.Multiprecision so that also has lots of strengths I see. One thing in the oven is when Boost 1.79 rolls out this spring, Multiprecision will/is-expected-to-be standalone and essentially dependency-free (except for config and possibly math, which are also standalone). So the dependencies of boost 1.79's version of Multiprecision and following versions will become a lot more dependency-free.
Yes. This is an area that I have done quite a bit of work on recently, so i'm not sure it is entirely correct. This also means if problems are found, we can discuss these. At the moment, cast to built-in integral type is explicit (as considered to be a narrowing cast. These should run through the operator here.
Good question. At the moment, you do, in fact, have to string-stream it. There is, however #153 which purposes to implement
Oddly enough, wide-integer started as a project for bare-metal microcontrollers. No-weight was the first mandate. Nowdays folks use it for high-performance all over so it's not such a thing. But a relic of this origin is the fact that there is not a constructor from
This is a weakness of wide-integer. At the moment, there is no support for fractional limbs. There is an issue (#7, which I see is a very old issue) that is expected to handle this. At ehe moment, you need to fill up the limbs. So you could synthesize theoretically, we could clear up all this stuff this spring/summer, as I've opted out of one project in particular that usually keeps me busy at the time. If you like, try the branch, see how it goes and if you hit any road blocks, please contact me any time. Thanks for your interest. |
tl;dr it might be best to avoid in-class conversion to/from other types such as Firstly, if you mean representation of a number in human-readable form, that's not a cast, it's a conversion. Certainly, it may not be appropriate to supply conversion via constructors or conversion operators. There are many reasons why. E.g., the choice of Secondly - and as Chris mentions - it would be great if wide-integer remained embedded-friendly. Drawing in a type like Finally, it would be ideal to reduce coupling between types. If you think of all the different types that can be converted between, you quickly get a combinatorial explosion. For this reason, a free function (like Does that sound like an OK way to use |
Hey guys! First of all, thank you for your responses. I've already adapted most of my questions but there are still two things left. Here is the branch where I'm working on migrating Triton from using Boost to wide-integers. The two things left:
//! unsigned 80-bits
typedef math::wide_integer::uintwide_t<static_cast<size_t>(UINT32_C(80)), std::uint32_t> uint80; You mentioned:
triton::sint512 modularSignExtend(AbstractNode* node) {
triton::sint512 value = 0;
if ((node->evaluate() >> (node->getBitvectorSize()-1)) & 1) {
value = -1;
value = ((value << node->getBitvectorSize()) | node->evaluate()); // node->evaluate() returns a math::wide_integer::uint512_t type
}
else {
value = node->evaluate();
}
return value;
} Thank you!! |
Simply replace the so-called limb type (the second template parameter) with In your exact cast, then (using a
A lot of mixed operators are not specialized for intermixing wide-integers having different limb types. So you might find other conversions needing to be explicit when you use the synthesized type |
OK. Well, it's moving right along. But a few things are not yet quite resolved... I need to understand the use case a bit more clearly. Could you please describe more clearly what the types are in lines around here? The subroutine seems to use a signed integer. Also, it would really help diagnosing this issue if I know exactly what the types of the results of Also |
I've tried to change:
Any thoughts? |
Yes. I have numerous thoughts on this phenomenon. Consider what I had written in a previous thread entry above:
This, combined with your empirical observations, means we have reached a point where wide-integer is not at the moment a one-to-one seamless drop in replacement for what you have or need in your project. There are several ways to proceed.
I realize that none of these solutions is a perfect fit. But I fear that either 4 or 5 might really take a while. Wide-integer has settled down quite a bit recently after a big year of change last year. In fact, last year, we handled |
I guess there is a final option. You could walk every integer type down to 16-bit internal limb type. But that hits performance rather hard. |
Is the requirement that storage is alignment 10bytes only? If so, that's
quite a specific ask for a 32-bit of 64-bit type due to alignment. Would a
12-byte type with 80-bit semantics suffice?
…On Sat 26 Feb 2022, 16:25 Christopher Kormanyos, ***@***.***> wrote:
I guess there is a final option. You could walk every integer type down to
16-bit internal limb type. But that hits performance rather hard.
—
Reply to this email directly, view it on GitHub
<#234 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFTGN7EOQ4JKEKCBM43GO3U5D5GFANCNFSM5PHQOMWQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Exactly! Indeed, I was thinking a 96-bit (12-byte) type composed of 3 internal |
If that's the case, I'm working on a type that might wrap uintwide, might
be more efficient if uintwide can support 3 x .uint32
…On Sat 26 Feb 2022, 17:04 Christopher Kormanyos, ***@***.***> wrote:
Would a 12-byte type with 80-bit semantics suffice?
Exactly! Indeed, I was thinking a 96-bit (12-byte) type composed of 3
internal uint32_t would be a rather close fit. But I am not exactly sure
how the OP is using the 80-bit type.
—
Reply to this email directly, view it on GitHub
<#234 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFTGN2RV3AC3J34B7AZ3L3U5EBYBANCNFSM5PHQOMWQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Maybe I'm missing the point of this comment, but yes, of course. This might not be quite clear, but |
Maybe the docs are unclear (and I should clear them up). But as long as the bits fit entirely within the limbs, then you can instantiate
gives the above-mentioned 96-bit unsigned integer composed of three 32-bit limbs, where the default limb type of |
A clearer description would be appreciated, but understood, efficient 96-bit type is supported. However, a type named |
Hi guys Thank you for your explanation. It makes more sense now to me. Out of the 5 or 6 options you proposed giving that I can't for now count with the 4th and 5th option, I think the more straightforward one is the 1st one ( To do so I would need to write:
Thankfully those are the only two types that I need to convert between. Do you have some code I can inspire from to fill those functions or can you help me out? Regarding the thank you guys |
I will add some lines of clarification near the top of the MD.
We discussed this previously, though I do not exactly remember where. In fact, the use of the @johnmcfarlane now that we discuss this yet again, and I'm not really sure of the exact syntax in the standard, but is the use-of/reserved-nature-of the |
Hi @illera88 you need to use the I will be happy to draft out some code for those two conversions. Please give me a day or two for that. OK? |
Sure thing. I'll wait to check your code. Thank you |
Specifically, I'm making a suggestion WRT Triton. Admittedly I have very little knowledge of that library so please don't feel the need to act on it. :) However, yes, we already discussed this WRT wide-integer. To recap/update my thoughts... The template<class T, int Digits>
using set_digits_t = typename set_digits<T, Digits>::type; I was going to add that aliases in the form std::[u]intn_t tend to be for aliases of fundamental types only. However, looking at P1889R1, that doesn't appear to be the case! There are still aliases to wide integers in there. Personally, I'd advocate to revise that paper and and reserve those aliases for fundamentals. They already mean 'fundamental' to users and while wide-integer is a great way to break the width barrier, that doesn't mean the user should be unaware/unsure what kind of type is used to do that. They may depend on qualities of the type (e.g. trivially-copyable), which we're not sure we want wide-integer to grant. In particular, what do you do about I personally believe it should be an opt-in for the user to decide: I want a machine-efficient integer and I'm OK if that requires a library feature. E.g.: namespace acme { // could be std some day, who knows?!
template<int Width, unsigned_integer Limb = unsigned, bool IsSigned = true>
fixed_int_t = ?;
} But what wide-integer library chooses to do already is completely fine, and backward-compatibility is an important quality.#236 HTH, thanks, John |
Hi @illera88 the draft of the conversion routines can be found here. I decided after a bit of deliberation to make the In the conversion subroutines, I also did some modernization via aliases and trailing return type. This is mostly because i have a bunch of syntax checkers running for these checks. Traditional style backport will, of course, also work fine if you prefer These conversions are very specific and apply solely and to exactly to the conversions we mentioned above (80/512). They are not generic, and they are not flexible. If you have any problems adapting them or other roadbloks, please get back to me. Those drafts are very new code and might need more testing. Please see how it goes with them... For the final issue of the 32-bit mixed-OR operations, we need to see what's exactly going on... |
Hey @ckormanyos thank for the conversion. I've already added it to the code and now there is just the OR operation problem remaining. I've reduced the problem to these few lines so you can debug it easily: math::wide_integer::int512_t value = 0;
std::uint32_t to_shift = 11111;
math::wide_integer::uint512_t value2 = 31337; // node->evaluate()
math::wide_integer::int512_t shift = (value << to_shift);
value = shift | value2; // math::wide_integer::int512_t | math::wide_integer::uint512_t This is the error I get" Do you have any idea why this is not working? |
Yes. Wide-integer's casting/conversion philosophy differs slightly from that of Boost's. Although admittedly I actually think Boost's philosophy might be better (or more right, or less wrong) than that of wide-integer. On the other hand, neither of them can actually be considered right or wrong because the behavior of user-defined types is not yet specified in the standard. In this particular case, you need an explicit cast to either You would need to explicitly tell the compiler which of the available wide-integer operators to take via explicit cast or construct. For instance.
Also note that I changed a few values in your sample. The value of |
Again, if Boost is more right or less wrong than wide-integer regarding some casts/conversions, that may be one result of these kinds of porting efforts. Yet even if this is the case (and it might not be), I probably won't be able to (in a stable, error-free fashion) change wide-integer's behavior very quickly. So you might ultimately need to consider the cast. |
Hi @illera88 what is the status of this issue? Open? Or can I close this issue? Thx. |
You can close it. It was successfully integrated in Triton JonathanSalwan/Triton#1105 |
Great! Glad it works. Thank you @illera88 for pushing forward on this. |
Hi,
I'm thinking on creating a branch to move away from boost in Triton. I have multiple questions:
static_cast<T>(value)
right? i.e.std::string
to amath::wide_integer::uint512_t
?but I get:
because of:
Thank you so much for your help
The text was updated successfully, but these errors were encountered: