THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES. IT IS ONLY SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES. IN FACT, IT IS ALMOST GUARANTEED THAT THEY'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
or
* the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received copies of the GNU General Public License and the GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
/* Table quotients. We extract the NBITS most significant bits of the numerator limb, and the corresponding bits from the divisor limb, and use these to form an index into the table. This method is probably only useful for short pipelines with slow multiplication.
Possible improvements:
* Perhaps extract the highest NBITS of the divisor instead of the same bits as from the numerator. That would require another count_leading_zeros, and a post-multiply shift of the quotient.
* Compress tables? Their values are tiny, and there are lots of zero entries (which are never used).
/* Doing tabp with a #define makes compiler warnings about pointing outside an object go away. We used to define this as a variable. It is not clear if e.g. (vector[100] - 10) + 10 is well- defined as per the C standard; (vector[100] + 10) - 10 surely is and there is no sequence point so the expressions should be equivalent. To make this safe, we might want to define tabp as a macro with the index as an argument. Depending on the platform, relocs might allow for assembly-time or linker-time resolution to
take place. */ #define tabp (tab - (1 << (NBITS - 1) << NBITS))
/* Table inverses of divisors. We don't bother with suppressing the msb from the tables. We index with the NBITS most significant divisor bits, including the always-set highest bit, but use addressing trickery via tabp to suppress it.
Possible improvements:
* Do first multiply using 32-bit operations on 64-bit computers. At least on most Arm64 cores, that uses 3 times less resources. It also saves on many x86-64 processors.
*/
#ifndef NBITS #define NBITS 7 #endif
#if NBITS == 5 /* This needs full division about 1.63% of the time. */ staticconstunsignedchar tab[16] = { 63, 59, 55, 52, 50, 47, 45, 43, 41, 39, 38, 36, 35, 34, 33, 32
}; #elif NBITS == 6 /* This needs full division about 0.93% of the time. */ staticconstunsignedchar tab[32] = { 127,123,119,116,112,109,106,104,101, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80, 79, 77, 76, 74, 73, 72, 70, 69, 68, 67, 66, 65, 64
}; #elif NBITS == 7 /* This needs full division about 0.49% of the time. */ staticconstunsignedchar tab[64] = { 255,251,247,243,239,236,233,229,226,223,220,217,214,211,209,206, 203,201,198,196,194,191,189,187,185,183,181,179,177,175,173,171, 169,167,166,164,162,161,159,158,156,155,153,152,150,149,147,146, 145,143,142,141,140,139,137,136,135,134,133,132,131,130,129,128
}; #elif NBITS == 8 /* This needs full division about 0.26% of the time. */ staticconstunsignedshort tab[128] = { 511,507,503,499,495,491,488,484,480,477,473,470,467,463,460,457, 454,450,447,444,441,438,435,433,430,427,424,421,419,416,413,411, 408,406,403,401,398,396,393,391,389,386,384,382,380,377,375,373, 371,369,367,365,363,361,359,357,355,353,351,349,347,345,343,342, 340,338,336,335,333,331,329,328,326,325,323,321,320,318,317,315, 314,312,311,309,308,306,305,303,302,301,299,298,296,295,294,292, 291,290,288,287,286,285,283,282,281,280,279,277,276,275,274,273, 272,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256
}; #else #error No table for provided NBITS #endif
/* Doing tabp with a #define makes compiler warnings about pointing outside an object go away. We used to define this as a variable. It is not clear if e.g. (vector[100] - 10) + 10 is well- defined as per the C standard; (vector[100] + 10) - 10 surely is and there is no sequence point so the expressions should be equivalent. To make this safe, we might want to define tabp as a macro with the index as an argument. Depending on the platform, relocs might allow for assembly-time or linker-time resolution to
take place. */ #define tabp (tab - (1 << (NBITS - 1)))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.