These are chat archives for symengine/symengine
fmpz_tis claimed to be more efficient than GMP's
mpz_tin that it is faster for 1-limb numbers, that it only allocates limbs when needed, and other things. Has anyone compared?
fmpz_tis either a (64bit) pointer to an allocated
mpz_tor a (64bit) machine integer itself. Since a pointer has to be at least power of 2 aligned (typically it is aligned on 64bit or even up to 256bit boundary), so the highest bit is never used in the pointer (i.e. it must be 0), and so you use it to determine if the 64bits is a pointer or a machine integer. It's a nice trick. However, it has a double indirection if it is not a machine integer.
piranha::integeris using an alternative approach, I think it's size is at least 128bit or more, and it is just a union. So the
mpz_ttype is directly in the memory, so it has only one indirection, but the price is that the
piranha::integertype is larger than 64bit. Another difference is that
fmpz_tis using a 64bit integer, while
piranha::integeris using 128bit integer --- this choice has pros and cons: if your integers fit into 64bits, then 64bit is faster. If they fit into 128bit, then 128bit is a lot faster than
mpz_t. If they are larger than 128bit, then it doesn't matter. @bluescarni did some benchmarking and concluded that for the applications that he needed, the 128bit version was faster overall. Either way, I think we can (or perhaps should) have more than just 1 type for integer, and the user would choose which one to use for the given application.