Remove the old libgmp. Version 2.0.2 is about to hit prime time.

This commit is contained in:
Mark Murray 1996-10-20 09:11:57 +00:00
parent a0f91beb39
commit 504fa96f30
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19050
145 changed files with 0 additions and 32146 deletions

View File

@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of 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.
This program 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 a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -1,481 +0,0 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load Diff

View File

@ -1,154 +0,0 @@
INSTALLING GMP
==============
These instructions are only for the impatient. Others should read the install
instructions in the manual, gmp.info. Use "info -f gmp.info", or, if you
don't have info, use type "C-h i g (gmp.info)Top" in emacs.
Here are short instructions how to install MP, and some examples that help you
get started using MP.
First, you need to compile, and optionally install, MP. Since you're
impatient, try this:
./configure; make
If that fails, or you care about the performance of MP, you need to read the
full instructions in the chapter "Installing MP", in the manual.
Next, you need to try some small test programs, for example the ones below.
In MP programs, all variables need to be initialized before they are assigned,
and cleared out before program flow leaves the scope in which it was declared.
Here is an example of a program that reads two numbers from the command line,
multiplies them, and prints the result to stdout.
#include <stdio.h>
#include <gmp.h> /* All MP programs need to include gmp.h */
main (int argc, char **argv)
{
mpz_t a, b, p;
/* Initialize variables */
mpz_init (a);
mpz_init (b);
mpz_init (p);
/* Assign a and b from base 10 strings in argv */
mpz_set_str (a, argv[1], 10);
mpz_set_str (b, argv[2], 10);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Clear out variables */
mpz_clear (a);
mpz_clear (b);
mpz_clear (p);
exit (0);
}
In practice, that example would be written like this instead:
#include <stdio.h>
#include <gmp.h>
main (int argc, char **argv)
{
mpz_t a, b, p;
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
/* Initialize p */
mpz_init (p);
/* Multiply a and b and put the result in p */
mpz_mul (p, a, b);
/* Print p in base 10 */
mpz_out_str (stdout, 10, p);
fputc ('\n', stdout);
/* Since we're about to exit, no need to clear out variables */
exit (0);
}
Finally, you have to compile your test program, and link it with the MP
library. Assuming your working directory is still the gmp source directory,
type:
gcc -g -I. example.c libgmp.a
Now try to run the example:
a.out 98365871231256752134 319378318340103345227
31415926535897932384618573336104570964418
The functions used here all operate on the domain of signed integers.
Functions operating on that domain have names starting with "mpz_". There are
many more such functions than used in these examples. See the chapter
"Integer Functions" in the manual, for a complete list.
There are two other main classes of functions in MP. They operate on rational
numbers and floating-point numbers, respectively. The chapters "Rational
Number Functions", and "Floating-point Functions" documents these classes.
To run a set of tests, do "make check". This will take a while.
To create the printable documentation from the texinfo source, type "make
dvi". This requires the "tex" command to be available in your search path.
To install the library, do "make install".
If you decide to use MP, It is a good idea you read at least the chapter "MP
Basics" in the manual.
Known Build Problems
--------------------
Note that GCC 2.7.2 (as well as 2.6.3) for the RS/6000 and PowerPC can not
be used to compile GMP, due to a bug in GCC. If you want to use GCC, you
need to apply the patch at the end of this file, or use a later version of
the compiler.
If you are on a Sequent Symmetry, use GAS instead of the system's assembler
due to the latter's serious bugs.
The system compiler on NeXT is a massacred and old gcc, even if the
compiler calls itself cc. This compiler cannot be used to build GMP. You
need to get a real gcc, and install that before you compile GMP. (NeXT
might have fixed this in newer releases of their system.)
Please report other problems to bug-gmp@prep.ai.mit.edu.
Patch to apply to GCC 2.6.3 and 2.7.2:
*** config/rs6000/rs6000.md Sun Feb 11 08:22:11 1996
--- config/rs6000/rs6000.md.new Sun Feb 18 03:33:37 1996
***************
*** 920,926 ****
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%2,%1"
[(set_attr "type" "compare")])
(define_insn ""
--- 920,926 ----
(set (match_operand:SI 0 "gpc_reg_operand" "=r")
(not:SI (match_dup 1)))]
""
! "nor. %0,%1,%1"
[(set_attr "type" "compare")])
(define_insn ""

View File

@ -1,62 +0,0 @@
# Makefile for libgmp
# $Id: Makefile,v 1.4 1996/05/07 23:14:38 wosch Exp $
LIB= gmp
SRCS= $(GMP_SRCS)
CLEANFILES+= cre-mparam cre-conv-tab gmp-mparam.h mp_bases.c
GMP_SRCS= mp_bases.c $(MPZ_SRCS) $(MPQ_SRCS) $(MPN_SRCS) $(IMPL_SRCS)
CFLAGS+= -I${.CURDIR} -I${.OBJDIR} -Wall -Wstrict-prototypes -DLOCALE
MPN_SRCS= mpn_add.c mpn_sub.c mpn_cmp.c mpn_mul.c mpn_div.c mpn_dm_1.c \
mpn_mod_1.c mpn_lshift.c mpn_rshift.c mpn_rshiftci.c mpn_sqrt.c
IMPL_SRCS= memory.c mp_set_fns.c _mpz_set_str.c _mpz_get_str.c \
mpz_realloc.c mp_clz_tab.c
MPZ_SRCS= mpz_init.c mpz_set.c mpz_set_ui.c mpz_set_si.c mpz_set_str.c \
mpz_iset.c mpz_iset_ui.c mpz_iset_si.c mpz_iset_str.c \
mpz_clear.c mpz_get_ui.c mpz_get_si.c mpz_get_str.c \
mpz_size.c mpz_sizeinb.c mpz_add.c mpz_add_ui.c mpz_sub.c \
mpz_sub_ui.c mpz_mul.c mpz_mul_ui.c mpz_div.c mpz_div_ui.c \
mpz_mod.c mpz_mod_ui.c mpz_dm.c mpz_dm_ui.c mpz_mdiv.c \
mpz_mmod.c mpz_mdm.c mpz_mdiv_ui.c mpz_mmod_ui.c mpz_mdm_ui.c \
mpz_gcd.c mpz_gcdext.c mpz_sqrt.c mpz_sqrtrem.c mpz_powm.c \
mpz_powm_ui.c mpz_cmp.c mpz_cmp_ui.c mpz_cmp_si.c \
mpz_mul_2exp.c mpz_div_2exp.c mpz_mod_2exp.c mpz_abs.c \
mpz_neg.c mpz_com.c mpz_and.c mpz_ior.c mpz_inp_raw.c \
mpz_inp_str.c mpz_out_raw.c mpz_out_str.c mpz_perfsqr.c \
mpz_random.c mpz_random2.c mpz_pow_ui.c mpz_clrbit.c \
mpz_fac_ui.c mpz_pprime_p.c
MPQ_SRCS= mpq_init.c mpq_set.c mpq_set_ui.c mpq_set_si.c \
mpq_set_num.c mpq_set_den.c mpq_get_num.c mpq_get_den.c \
mpq_add.c mpq_sub.c mpq_mul.c mpq_div.c mpq_clear.c \
mpq_cmp.c mpq_inv.c mpq_neg.c
SUBDIR+= doc
beforedepend: gmp-mparam.h mp_bases.c
beforeinstall:
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/gmp.h \
${DESTDIR}/usr/include
cre-mparam: cre-mparam.c
$(CC) $(CFLAGS) ${.CURDIR}/cre-mparam.c -o ${.TARGET}
cre-conv-tab: cre-conv-tab.c gmp-mparam.h
$(CC) $(CFLAGS) -lm ${.CURDIR}/cre-conv-tab.c -o ${.TARGET}
cre-conv-tab: gmp-mparam.h
gmp-mparam.h: cre-mparam
./cre-mparam > tmp-${.TARGET}
mv -f tmp-${.TARGET} ${.TARGET}
mp_bases.c: cre-conv-tab
./cre-conv-tab > tmp-${.TARGET}
mv -f tmp-${.TARGET} ${.TARGET}
.include <bsd.lib.mk>

View File

@ -1,289 +0,0 @@
# Makefile for GNU MP (a.k.a. biGNUm)
# Copyright (C) 1991, 1993 Free Software Foundation, Inc.
# This file is part of the GNU MP Library.
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 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 a copy of the GNU General Public License
# along with the GNU MP Library; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
CC = gcc
# If you cross compile on a machine with the same sizes of the integral
# types ("int", "long int", "short int", and "char") define this as the
# local compiler. Otherwise, you need look for the uses of LOCAL_CC below,
# and handle those cases manually.
LOCAL_CC = $(CC)
OPT = -O -g
CFLAGS = -I. $(OPT)
AR = ar
RANLIB=`if [ -r /bin/ranlib -o -r /usr/bin/ranlib ]; \
then echo ranlib; else echo true; fi`
SHELL = /bin/sh
SRCS = $(MPZ_SRCS) $(MPQ_SRCS) $(BSDMP_SRCS) $(MPN_SRCS) $(IMPL_SRCS)
OBJS = $(MPZ_OBJS) $(MPQ_OBJS) $(BSDMP_OBJS) $(MPN_OBJS) $(IMPL_OBJS)
MP_OBJS = $(BSDMP_OBJS) $(MPN_OBJS) $(IMPL_OBJS) mp_bases.o mpz_sizeinb.o
GMP_OBJS = $(MPZ_OBJS) $(MPQ_OBJS) $(MPN_OBJS) $(IMPL_OBJS) mp_bases.o
IMPL_SRCS = memory.c mp_set_fns.c _mpz_set_str.c _mpz_get_str.c \
mpz_realloc.c mp_clz_tab.c alloca.c
IMPL_OBJS = memory.o mp_set_fns.o _mpz_set_str.o _mpz_get_str.o \
mpz_realloc.o mp_clz_tab.o alloca.o
MPZ_SRCS = mpz_init.c mpz_set.c mpz_set_ui.c mpz_set_si.c mpz_set_str.c \
mpz_iset.c mpz_iset_ui.c mpz_iset_si.c mpz_iset_str.c mpz_clear.c \
mpz_get_ui.c mpz_get_si.c mpz_get_str.c mpz_size.c mpz_sizeinb.c \
mpz_add.c mpz_add_ui.c mpz_sub.c mpz_sub_ui.c mpz_mul.c mpz_mul_ui.c \
mpz_div.c mpz_div_ui.c mpz_mod.c mpz_mod_ui.c mpz_dm.c mpz_dm_ui.c \
mpz_mdiv.c mpz_mmod.c mpz_mdm.c mpz_mdiv_ui.c mpz_mmod_ui.c mpz_mdm_ui.c \
mpz_gcd.c mpz_gcdext.c mpz_sqrt.c mpz_sqrtrem.c mpz_powm.c mpz_powm_ui.c \
mpz_cmp.c mpz_cmp_ui.c mpz_cmp_si.c mpz_mul_2exp.c mpz_div_2exp.c \
mpz_mod_2exp.c mpz_abs.c mpz_neg.c mpz_com.c mpz_and.c mpz_ior.c \
mpz_inp_raw.c mpz_inp_str.c mpz_out_raw.c mpz_out_str.c \
mpz_perfsqr.c mpz_random.c mpz_random2.c mpz_pow_ui.c \
mpz_clrbit.c mpz_fac_ui.c mpz_pprime_p.c
MPZ_OBJS = mpz_init.o mpz_set.o mpz_set_ui.o mpz_set_si.o mpz_set_str.o \
mpz_iset.o mpz_iset_ui.o mpz_iset_si.o mpz_iset_str.o mpz_clear.o \
mpz_get_ui.o mpz_get_si.o mpz_get_str.o mpz_size.o mpz_sizeinb.o \
mpz_add.o mpz_add_ui.o mpz_sub.o mpz_sub_ui.o mpz_mul.o mpz_mul_ui.o \
mpz_div.o mpz_div_ui.o mpz_mod.o mpz_mod_ui.o mpz_dm.o mpz_dm_ui.o \
mpz_mdiv.o mpz_mmod.o mpz_mdm.o mpz_mdiv_ui.o mpz_mmod_ui.o mpz_mdm_ui.o \
mpz_gcd.o mpz_gcdext.o mpz_sqrt.o mpz_sqrtrem.o mpz_powm.o mpz_powm_ui.o \
mpz_cmp.o mpz_cmp_ui.o mpz_cmp_si.o mpz_mul_2exp.o mpz_div_2exp.o \
mpz_mod_2exp.o mpz_abs.o mpz_neg.o mpz_com.o mpz_and.o mpz_ior.o \
mpz_inp_raw.o mpz_inp_str.o mpz_out_raw.o mpz_out_str.o \
mpz_perfsqr.o mpz_random.o mpz_random2.o mpz_pow_ui.o \
mpz_clrbit.o mpz_fac_ui.o mpz_pprime_p.o
MPQ_SRCS = mpq_init.c mpq_set.c mpq_set_ui.c mpq_set_si.c \
mpq_set_num.c mpq_set_den.c mpq_get_num.c mpq_get_den.c \
mpq_add.c mpq_sub.c mpq_mul.c mpq_div.c \
mpq_clear.c mpq_cmp.c mpq_inv.c mpq_neg.c
MPQ_OBJS = mpq_init.o mpq_set.o mpq_set_ui.o mpq_set_si.o \
mpq_set_num.o mpq_set_den.o mpq_get_num.o mpq_get_den.o \
mpq_add.o mpq_sub.o mpq_mul.o mpq_div.o \
mpq_clear.o mpq_cmp.o mpq_inv.o mpq_neg.o
MPN_SRCS = mpn_add.c mpn_sub.c mpn_cmp.c mpn_mul.c mpn_div.c mpn_dm_1.c \
mpn_mod_1.c mpn_lshift.c mpn_rshift.c mpn_rshiftci.c mpn_sqrt.c
MPN_OBJS = mpn_add.o mpn_sub.o mpn_cmp.o mpn_mul.o mpn_div.o mpn_dm_1.o \
mpn_mod_1.o mpn_lshift.o mpn_rshift.o mpn_rshiftci.o mpn_sqrt.o
# There are fewer members in the BSDMP_SRCS list that in the BSDMP_OBJS
# list because some of the .c files are created by this Makefile.
BSDMP_SRCS = itom.c mdiv.c move.c mtox.c xtom.c sdiv.c mout.c min.c mfree.c
BSDMP_OBJS = gcd.o itom.o madd.o mcmp.o mdiv.o move.o msub.o mtox.o mult.o \
pow.o rpow.o xtom.o msqrt.o sdiv.o mout.o min.o mfree.o
all: libgmp.a libmp.a
check: libgmp.a
cd tests; $(MAKE) CC="$(CC)" SHELL="$(SHELL)" OPT="$(OPT)"
libgmp.a: stamp-stddefh $(GMP_OBJS)
rm -f $@
$(AR) cr $@ $(GMP_OBJS)
$(RANLIB) $@
# libmp.a depend on libgmp.a, to get around Unix(tm) ar/ranlib concurrency bug.
libmp.a: stamp-stddefh $(MP_OBJS) libgmp.a
rm -f $@
$(AR) cr $@ $(MP_OBJS)
$(RANLIB) $@
stamp-stddefh:
rm -f stddef.h
rm -f test-stddefh.c
( echo '#include <stddef.h>' ;\
echo 'main(){size_t foo=sizeof(size_t);exit(0);}' ;\
) > test-stddefh.c
@if $(LOCAL_CC) $(CFLAGS) test-stddefh.c -c 2> /dev/null ;\
then true ;\
else \
echo 'This machine has no "stddef.h". Creating a minimal in ./';\
$(LOCAL_CC) $(CFLAGS) cre-stddefh.c -o cre-stddefh ;\
./cre-stddefh > stddef.h ;\
fi
rm -f test-stddefh.o
touch stamp-stddefh
mp_bases.c: cre-conv-tab
./cre-conv-tab > tmp-$@
mv tmp-$@ $@
cre-conv-tab: cre-conv-tab.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
$(LOCAL_CC) $(CFLAGS) `if [ x$(firstword $^) = x ]; \
then echo cre-conv-tab.c; \
else echo $(firstword $^); fi` -o $@ -lm
gmp-mparam.h: cre-mparam
./cre-mparam > tmp-$@
mv tmp-$@ $@
cre-mparam: cre-mparam.c stamp-stddefh gmp.h
$(LOCAL_CC) $(CFLAGS) cre-mparam.c -o $@
gcd.c : mpz_gcd.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h longlong.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_gcd.c \
| grep -v '^#' > $@
pow.c : mpz_powm.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h longlong.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_powm.c\
| grep -v '^#' > $@
rpow.c: mpz_pow_ui.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h longlong.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_pow_ui.c\
| grep -v '^#' > $@
madd.c : mpz_add.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_add.c\
| grep -v '^#' > $@
msub.c : mpz_sub.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_sub.c\
| grep -v '^#' > $@
mult.c : mpz_mul.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_mul.c\
| grep -v '^#' > $@
mcmp.c : mpz_cmp.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_cmp.c\
| grep -v '^#' > $@
msqrt.c : mpz_sqrtrem.c stamp-stddefh mp.h gmp.h gmp-impl.h gmp-mparam.h
$(CC) $(CFLAGS) -E -DBERKELEY_MP mpz_sqrtrem.c\
| grep -v '^#' > $@
doc: gmp.dvi gmp.info
LN = ln -s
gmp.dvi: gmp.texi
rm -f tmp.texi
$(LN) gmp.texi tmp.texi
tex tmp.texi < /dev/null
texindex tmp.cp tmp.fn
tex tmp.texi < /dev/null 2> /dev/null
mv tmp.dvi gmp.dvi
gmp.info: gmp.texi
makeinfo gmp.texi
clean:
rm -f *.o libgmp.a libmp.a cre-conv-tab cre-mparam cre-stddefh \
gmp.dvi gmp.info mp_bases.c gmp-mparam.h stamp-stddefh test-stddefh.c \
stddef.h gcd.c pow.c rpow.c madd.c msub.c mult.c mcmp.c msqrt.c \
tmp.* tmp-* gmp.ps core
-cd tests; $(MAKE) clean
realclean: clean
# Automatically generated dependencies
_mpz_get_str.o : _mpz_get_str.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
_mpz_set_str.o : _mpz_set_str.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
cre-conv-tab.o : cre-conv-tab.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
cre-mparam.o : cre-mparam.c gmp.h
cre-stddefh.o : cre-stddefh.c
itom.o : itom.c mp.h gmp.h gmp-impl.h gmp-mparam.h
mdiv.o : mdiv.c mp.h gmp.h gmp-impl.h gmp-mparam.h longlong.h mpz_dmincl.c
memory.o : memory.c gmp.h gmp-impl.h gmp-mparam.h
mfree.o : mfree.c mp.h gmp.h gmp-impl.h gmp-mparam.h
min.o : min.c mp.h gmp.h gmp-impl.h gmp-mparam.h
mout.o : mout.c mp.h gmp.h gmp-impl.h gmp-mparam.h
move.o : move.c mp.h gmp.h gmp-impl.h gmp-mparam.h
mp_bases.o : mp_bases.c gmp.h gmp-impl.h gmp-mparam.h
mp_clz_tab.o : mp_clz_tab.c gmp.h gmp-impl.h gmp-mparam.h
mp_set_fns.o : mp_set_fns.c gmp.h gmp-impl.h gmp-mparam.h
mpn_add.o : mpn_add.c gmp.h gmp-impl.h gmp-mparam.h
mpn_cmp.o : mpn_cmp.c gmp.h gmp-impl.h gmp-mparam.h
mpn_div.o : mpn_div.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpn_dm_1.o : mpn_dm_1.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpn_lshift.o : mpn_lshift.c gmp.h gmp-impl.h gmp-mparam.h
mpn_mod_1.o : mpn_mod_1.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpn_mul.o : mpn_mul.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpn_rshift.o : mpn_rshift.c gmp.h gmp-impl.h gmp-mparam.h
mpn_rshiftci.o : mpn_rshiftci.c gmp.h gmp-impl.h gmp-mparam.h
mpn_sqrt.o : mpn_sqrt.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpn_sub.o : mpn_sub.c gmp.h gmp-impl.h gmp-mparam.h
mpq_add.o : mpq_add.c gmp.h gmp-impl.h gmp-mparam.h
mpq_clear.o : mpq_clear.c gmp.h gmp-impl.h gmp-mparam.h
mpq_cmp.o : mpq_cmp.c gmp.h gmp-impl.h gmp-mparam.h
mpq_div.o : mpq_div.c gmp.h gmp-impl.h gmp-mparam.h
mpq_get_den.o : mpq_get_den.c gmp.h gmp-impl.h gmp-mparam.h
mpq_get_num.o : mpq_get_num.c gmp.h gmp-impl.h gmp-mparam.h
mpq_init.o : mpq_init.c gmp.h gmp-impl.h gmp-mparam.h
mpq_inv.o : mpq_inv.c gmp.h gmp-impl.h gmp-mparam.h
mpq_mul.o : mpq_mul.c gmp.h gmp-impl.h gmp-mparam.h
mpq_neg.o : mpq_neg.c gmp.h gmp-impl.h gmp-mparam.h
mpq_set.o : mpq_set.c gmp.h gmp-impl.h gmp-mparam.h
mpq_set_den.o : mpq_set_den.c gmp.h gmp-impl.h gmp-mparam.h
mpq_set_num.o : mpq_set_num.c gmp.h gmp-impl.h gmp-mparam.h
mpq_set_si.o : mpq_set_si.c gmp.h gmp-impl.h gmp-mparam.h
mpq_set_ui.o : mpq_set_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpq_sub.o : mpq_sub.c gmp.h gmp-impl.h gmp-mparam.h
mpz_abs.o : mpz_abs.c gmp.h gmp-impl.h gmp-mparam.h
mpz_add.o : mpz_add.c gmp.h gmp-impl.h gmp-mparam.h
mpz_add_ui.o : mpz_add_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_and.o : mpz_and.c gmp.h gmp-impl.h gmp-mparam.h
mpz_clear.o : mpz_clear.c gmp.h gmp-impl.h gmp-mparam.h
mpz_clrbit.o : mpz_clrbit.c gmp.h gmp-impl.h gmp-mparam.h
mpz_cmp.o : mpz_cmp.c gmp.h gmp-impl.h gmp-mparam.h
mpz_cmp_si.o : mpz_cmp_si.c gmp.h gmp-impl.h gmp-mparam.h
mpz_cmp_ui.o : mpz_cmp_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_com.o : mpz_com.c gmp.h gmp-impl.h gmp-mparam.h
mpz_div.o : mpz_div.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_div_2exp.o : mpz_div_2exp.c gmp.h gmp-impl.h gmp-mparam.h
mpz_div_ui.o : mpz_div_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_dm.o : mpz_dm.c gmp.h gmp-impl.h gmp-mparam.h longlong.h mpz_dmincl.c
mpz_dm_ui.o : mpz_dm_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_fac_ui.o : mpz_fac_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_gcd.o : mpz_gcd.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_gcdext.o : mpz_gcdext.c gmp.h gmp-impl.h gmp-mparam.h
mpz_get_si.o : mpz_get_si.c gmp.h gmp-impl.h gmp-mparam.h
mpz_get_str.o : mpz_get_str.c gmp.h gmp-impl.h gmp-mparam.h
mpz_get_ui.o : mpz_get_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_init.o : mpz_init.c gmp.h gmp-impl.h gmp-mparam.h
mpz_inp_raw.o : mpz_inp_raw.c gmp.h gmp-impl.h gmp-mparam.h
mpz_inp_str.o : mpz_inp_str.c gmp.h gmp-impl.h gmp-mparam.h
mpz_ior.o : mpz_ior.c gmp.h gmp-impl.h gmp-mparam.h
mpz_iset.o : mpz_iset.c gmp.h gmp-impl.h gmp-mparam.h
mpz_iset_si.o : mpz_iset_si.c gmp.h gmp-impl.h gmp-mparam.h
mpz_iset_str.o : mpz_iset_str.c gmp.h gmp-impl.h gmp-mparam.h
mpz_iset_ui.o : mpz_iset_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mdiv.o : mpz_mdiv.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mdiv_ui.o : mpz_mdiv_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mdm.o : mpz_mdm.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mdm_ui.o : mpz_mdm_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mmod.o : mpz_mmod.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mmod_ui.o : mpz_mmod_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mod.o : mpz_mod.c gmp.h gmp-impl.h gmp-mparam.h longlong.h mpz_dmincl.c
mpz_mod_2exp.o : mpz_mod_2exp.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mod_ui.o : mpz_mod_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_mul.o : mpz_mul.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mul_2exp.o : mpz_mul_2exp.c gmp.h gmp-impl.h gmp-mparam.h
mpz_mul_ui.o : mpz_mul_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_neg.o : mpz_neg.c gmp.h gmp-impl.h gmp-mparam.h
mpz_out_raw.o : mpz_out_raw.c gmp.h gmp-impl.h gmp-mparam.h
mpz_out_str.o : mpz_out_str.c gmp.h gmp-impl.h gmp-mparam.h
mpz_perfsqr.o : mpz_perfsqr.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_pow_ui.o : mpz_pow_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_powm.o : mpz_powm.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_powm_ui.o : mpz_powm_ui.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_pprime_p.o : mpz_pprime_p.c gmp.h gmp-impl.h gmp-mparam.h
mpz_random.o : mpz_random.c gmp.h gmp-impl.h gmp-mparam.h
mpz_random2.o : mpz_random2.c gmp.h gmp-impl.h gmp-mparam.h
mpz_realloc.o : mpz_realloc.c gmp.h gmp-impl.h gmp-mparam.h
mpz_set.o : mpz_set.c gmp.h gmp-impl.h gmp-mparam.h
mpz_set_si.o : mpz_set_si.c gmp.h gmp-impl.h gmp-mparam.h
mpz_set_str.o : mpz_set_str.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_set_ui.o : mpz_set_ui.c gmp.h gmp-impl.h gmp-mparam.h
mpz_size.o : mpz_size.c gmp.h gmp-impl.h gmp-mparam.h
mpz_sizeinb.o : mpz_sizeinb.c gmp.h gmp-impl.h gmp-mparam.h longlong.h
mpz_sqrt.o : mpz_sqrt.c gmp.h gmp-impl.h gmp-mparam.h
mpz_sqrtrem.o : mpz_sqrtrem.c gmp.h gmp-impl.h gmp-mparam.h
mpz_sub.o : mpz_sub.c gmp.h gmp-impl.h gmp-mparam.h
mpz_sub_ui.o : mpz_sub_ui.c gmp.h gmp-impl.h gmp-mparam.h
mtox.o : mtox.c mp.h gmp.h gmp-impl.h gmp-mparam.h
sdiv.o : sdiv.c mp.h gmp.h gmp-impl.h gmp-mparam.h longlong.h
xtom.o : xtom.c mp.h gmp.h gmp-impl.h gmp-mparam.h

View File

@ -1,210 +0,0 @@
# Top Makefile for GNU MP
# Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
# This file is part of the GNU MP Library.
# The GNU MP Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 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 Library General Public
# License for more details.
# You should have received a copy of the GNU Library General Public License
# along with the GNU MP Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
srcdir = .
prefix = /usr/local
exec_prefix = $(prefix)
libdir = $(exec_prefix)/lib
infodir = $(prefix)/info
includedir = $(prefix)/include
CC = gcc
LOCAL_CC = $(CC)
CFLAGS = -g -O
XCFLAGS =
AR = ar
AR_FLAGS = rc
RANLIB_TEST = [ -f /usr/bin/ranlib -o -f /bin/ranlib ]
RANLIB = ranlib
SHELL = /bin/sh
INSTALL = $(srcdir)/install.sh -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)
MAKEINFO = makeinfo
MAKEINFOFLAGS =
TEXI2DVI = texi2dvi
LN = ln -s
#### host and target specific makefile fragments come in here.
###
SRCS = memory.c mp_set_fns.c mp_clz_tab.c version.c stack-alloc.c mp_bpl.c \
extract-double.c insert-double.c
OBJS = memory.o mp_set_fns.o mp_clz_tab.o version.o stack-alloc.o mp_bpl.o \
extract-double.o insert-double.o
FILES = gmp.h mp.h gmp-impl.h longlong.h urandom.h move-if-change \
mkinstalldirs INSTALL COPYING.LIB ChangeLog Makefile.in \
NEWS README SPEED TODO config.guess config.sub configure configure.in \
gmp.info* gmp.texi texinfo.tex $(SRCS)
INCLUDES = -I. -Impn -I$(srcdir)
FLAGS_TO_PASS = "CC=$(CC)" "CFLAGS=$(CFLAGS)" "XCFLAGS=$(XCFLAGS)"
all: libgmp.a
.c.o:
$(CC) -c $(INCLUDES) $(CFLAGS) $(XCFLAGS) $<
libgmp.a: mpn/libmpn.a mpz/libmpz.a mpf/libmpf.a mpq/libmpq.a $(OBJS)
rm -rf tmpdir
mkdir tmpdir
for i in mpn mpz mpf mpq; \
do \
mkdir tmpdir/$$i; \
( cd tmpdir/$$i; $(AR) x ../../$$i/lib$$i.a ); \
done
cp $(OBJS) tmpdir
cd tmpdir; $(AR) $(AR_FLAGS) $@ *.o */*.o
if $(RANLIB_TEST) ; then $(RANLIB) tmpdir/$@; else true; fi
mv tmpdir/$@ .
rm -rf tmpdir
libmp.a: mpn/libmpn.a mpbsd/libmpbsd.a $(OBJS)
rm -rf tmpdir
mkdir tmpdir
for i in mpn mpbsd; \
do \
mkdir tmpdir/$$i; \
( cd tmpdir/$$i; $(AR) x ../../$$i/lib$$i.a ); \
done
cp $(OBJS) tmpdir
cd tmpdir; $(AR) $(AR_FLAGS) $@ *.o */*.o
if $(RANLIB_TEST) ; then $(RANLIB) tmpdir/$@; else true; fi
mv tmpdir/$@ .
rm -rf tmpdir
mpn/libmpn.a: force
cd mpn; $(MAKE) $(FLAGS_TO_PASS) libmpn.a
mpz/libmpz.a: force
cd mpz; $(MAKE) $(FLAGS_TO_PASS) libmpz.a
mpf/libmpf.a: force
cd mpf; $(MAKE) $(FLAGS_TO_PASS) libmpf.a
mpq/libmpq.a: force
cd mpq; $(MAKE) $(FLAGS_TO_PASS) libmpq.a
mpbsd/libmpbsd.a: force
cd mpbsd; $(MAKE) $(FLAGS_TO_PASS) libmpbsd.a
check: libgmp.a
cd mpz/tests; $(MAKE) $(FLAGS_TO_PASS) check
cd mpq/tests; $(MAKE) $(FLAGS_TO_PASS) check
cd mpf/tests; $(MAKE) $(FLAGS_TO_PASS) check
doc: gmp.dvi gmp.info
info: $(srcdir)/gmp.info
$(srcdir)/gmp.info: $(srcdir)/gmp.texi
cd $(srcdir); $(MAKEINFO) gmp.texi
dvi: gmp.dvi
gmp.dvi: $(srcdir)/gmp.texi
rm -f tmp.texi
$(LN) $(srcdir)/gmp.texi tmp.texi
TEXINPUTS=.:$(srcdir) $(TEXI2DVI) tmp.texi
rm -f tmp.texi
mv tmp.dvi gmp.dvi
rm -f tmp.*
ps: gmp.ps
gmp.ps: gmp.dvi
dvips gmp.dvi -o gmp.ps
html: gmp_toc.html
gmp_toc.html: $(srcdir)/gmp.texi
texi2html -acc -split_chapter $(srcdir)/gmp.texi
# The semicolon is to prevent the install.sh -> install default rule
# from doing anything. Having it run true helps avoid problems and
# noise from versions of make which don't like to have null commands.
install: install-normal ; @true
install-strip: install-normal
install-normal: installdirs libgmp.a gmp.info install-info-files
$(INSTALL_DATA) libgmp.a $(libdir)/libgmp.a
-chmod a-x $(libdir)/libgmp.a
$(INSTALL_DATA) $(srcdir)/gmp.h $(includedir)/gmp.h
-chmod a-x $(includedir)/gmp.h
install-bsdmp: installdirs libmp.a gmp.info install-info-files
$(INSTALL_DATA) libmp.a $(libdir)/libmp.a
-chmod a-x $(libdir)/libmp.a
$(INSTALL_DATA) $(srcdir)/mp.h $(includedir)/mp.h
-chmod a-x $(includedir)/mp.h
install-info-files: installdirs $(srcdir)/gmp.info
cd $(srcdir); for f in gmp.info*; \
do $(INSTALL_DATA) $$f $(infodir)/$$f; done
-chmod a-x $(infodir)/gmp.info*
# Attempt to edit the info directory node
if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
install-info --dir-file=$(infodir)/dir $(infodir)/gmp.info; \
else true; fi
installdirs: $(srcdir)/mkinstalldirs
$(srcdir)/mkinstalldirs $(includedir) $(libdir) $(infodir)
uninstall:
rm -f $(libdir)/libgmp.a
rm -f $(includedir)/gmp.h
rm -f $(libdir)/libmp.a
rm -f $(includedir)/mp.h
rm -f $(infodir)/gmp.info*
clean mostlyclean:
rm -f *.o libgmp.a libmp.a gmp.dvi gmp.ps tmp.* tmp-*
rm -f gmp.?? gmp.??s gmp.log gmp.toc gmp.*aux gmp*.html
-cd mpn; $(MAKE) $@
-cd mpz; $(MAKE) $@
-cd mpf; $(MAKE) $@
-cd mpq; $(MAKE) $@
-cd mpbsd; $(MAKE) $@
distclean: clean
rm -f Makefile config.status
-cd mpn; $(MAKE) $@
-cd mpz; $(MAKE) $@
-cd mpf; $(MAKE) $@
-cd mpq; $(MAKE) $@
-cd mpbsd; $(MAKE) $@
maintainer-clean: distclean
rm -f $(srcdir)/gmp.info*
TAGS: force
cd $(srcdir); etags *.[ch] mp*/*.c mpn/generic/*.c >TAGS
dist:
@echo "sorry, not supported target"
@exit 1
Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag)
$(SHELL) ./config.status
H = $(srcdir)/gmp.h $(srcdir)/gmp-impl.h mpn/gmp-mparam.h
extract-double.o: $(srcdir)/extract-double.c $(H)
insert-double.o: $(srcdir)/insert-double.c $(H)
memory.o: $(srcdir)/memory.c $(H)
mp_bpl.o: $(srcdir)/mp_bpl.c
mp_clz_tab.o: $(srcdir)/mp_clz_tab.c
mp_set_fns.o: $(srcdir)/mp_set_fns.c $(H)
stack-alloc.o: $(srcdir)/stack-alloc.c $(srcdir)/stack-alloc.h
version.o: $(srcdir)/version.c
force:
.PNONY: check install install-bsdmp install-info-files install-strip uninstall
.PHONY: doc clean distclean maintainer-clean force info dvi

View File

@ -1,56 +0,0 @@
NOTEWORTHY CHANGES IN GNU MP IN VERSION 2
* Division routines in the mpz class have changed. There are three classes of
functions, that rounds the quotient to -infinity, 0, and +infinity,
respectively. The first class of functions have names that begin with
mpz_fdiv (f is short for floor), the second class' names begin with mpz_tdiv
(t is short for trunc), and the third class' names begin with mpz_cdiv (c is
short for ceil).
The old division routines beginning with mpz_m are similar to the new
mpz_fdiv, with the exception that some of the new functions return useful
values.
The old function names can still be used. All the old functions names will
now do floor division, not trunc division as some of them used to. This was
changed to make the functions more compatible with common mathematical
practice.
The mpz_mod and mpz_mod_ui functions now compute the mathematical mod
function. I.e., the sign of the 2nd argument is ignored.
* The mpq assignment functions do not canonicalize their results. A new
function, mpq_canonicalize must be called by the user if the result is not
known to be canonical.
* The mpn functions are now documented. These functions are intended for
very time critical applications, or applications that need full control over
memory allocation. Note that the mpn interface is irregular and hard to
use.
* New functions for arbitrary precision floating point arithmetic. Names
begin with `mpf_'. Associated type mpf_t.
* New and improved mpz functions, including much faster GCD, fast exact
division (mpz_divexact), bit scan (mpz_scan0 and mpz_scan1), and number
theoretical functions like Jacobi (mpz_jacobi) and multiplicative inverse
(mpz_invert).
* New variable types (mpz_t and mpq_t) are available that makes syntax of
mpz and mpq calls nicer (no need for & before variables). The MP_INT and
MP_RAT types are still available for compatibility.
* Uses GNU configure. This makes it possible to choose target architecture
and CPU variant, and to compile into a separate object directory.
* Carefully optimized assembly for important inner loops. Support for DEC
Alpha, Amd 29000, HPPA 1.0 and 1.1, Intel pentium and generic x86, Intel
i960, Motorola MC68000, MC68020, MC88100, and MC88110, Motorola/IBM
PowerPC, National NS32000, IBM POWER, MIPS R3000, R4000, SPARCv7,
SuperSPARC, generic SPARCv8, and DEC VAX. Some support also for ARM,
Clipper, IBM ROMP (RT), and Pyramid AP/XP.
* Faster. Thanks to the assembler code, new algorithms, and general tuning.
In particular, the speed on machines without GCC is improved.
* Support for machines without alloca.
* Now under the LGPL.
INCOMPATIBILITIES BETWEEN GMP 1 AND GMP 2
* mpq assignment functions do not canonicalize their results.
* mpz division functions round differently.
* mpz mod functions now really compute mod.
* mpz_powm and mpz_powm_ui now really use mod for reduction.

View File

@ -1,270 +0,0 @@
IDEAS ABOUT THINGS TO WORK ON
* mpq_cmp: Maybe the most sensible thing to do would be to multiply the, say,
4 most significant limbs of each operand and compare them. If that is not
sufficient, do the same for 8 limbs, etc.
* Write mpi, the Multiple Precision Interval Arithmetic layer.
* Write `mpX_eval' that take lambda-like expressions and a list of operands.
* As a general rule, recognize special operand values in mpz and mpf, and
use shortcuts for speed. Examples: Recognize (small or all) 2^n in
multiplication and division. Recognize small bases in mpz_pow_ui.
* Implement lazy allocation? mpz->d == 0 would mean no allocation made yet.
* Maybe store one-limb numbers according to Per Bothner's idea:
struct {
mp_ptr d;
union {
mp_limb val; /* if (d == NULL). */
mp_size size; /* Length of data array, if (d != NULL). */
} u;
};
Problem: We can't normalize to that format unless we free the space
pointed to by d, and therefore small values will not be stored in a
canonical way.
* Document complexity of all functions.
* Add predicate functions mpz_fits_signedlong_p, mpz_fits_unsignedlong_p,
mpz_fits_signedint_p, etc.
mpz_floor (mpz, mpq), mpz_trunc (mpz, mpq), mpz_round (mpz, mpq).
* Better random number generators. There should be fast (like mpz_random),
very good (mpz_veryrandom), and special purpose (like mpz_random2). Sizes
in *bits*, not in limbs.
* It'd be possible to have an interface "s = add(a,b)" with automatic GC.
If the mpz_xinit routine remembers the address of the variable we could
walk-and-mark the list of remembered variables, and free the space
occupied by the remembered variables that didn't get marked. Fairly
standard.
* Improve speed for non-gcc compilers by defining umul_ppmm, udiv_qrnnd,
etc, to call __umul_ppmm, __udiv_qrnnd. A typical definition for
umul_ppmm would be
#define umul_ppmm(ph,pl,m0,m1) \
{unsigned long __ph; (pl) = __umul_ppmm (&__ph, (m0), (m1)); (ph) = __ph;}
In order to maintain just one version of longlong.h (gmp and gcc), this
has to be done outside of longlong.h.
Bennet Yee at CMU proposes:
* mpz_{put,get}_raw for memory oriented I/O like other *_raw functions.
* A function mpfatal that is called for exceptions. Let the user override
a default definition.
* Make all computation mpz_* functions return a signed int indicating if the
result was zero, positive, or negative?
* Implement mpz_cmpabs, mpz_xor, mpz_to_double, mpz_to_si, mpz_lcm, mpz_dpb,
mpz_ldb, various bit string operations. Also mpz_@_si for most @??
* Add macros for looping efficiently over a number's limbs:
MPZ_LOOP_OVER_LIMBS_INCREASING(num,limb)
{ user code manipulating limb}
MPZ_LOOP_OVER_LIMBS_DECREASING(num,limb)
{ user code manipulating limb}
Brian Beuning proposes:
1. An array of small primes
3. A function to factor a mpz_t. [How do we return the factors? Maybe
we just return one arbitrary factor? In the latter case, we have to
use a data structure that records the state of the factoring routine.]
4. A routine to look for "small" divisors of an mpz_t
5. A 'multiply mod n' routine based on Montgomery's algorithm.
Dough Lea proposes:
1. A way to find out if an integer fits into a signed int, and if so, a
way to convert it out.
2. Similarly for double precision float conversion.
3. A function to convert the ratio of two integers to a double. This
can be useful for mixed mode operations with integers, rationals, and
doubles.
Elliptic curve method description in the Chapter `Algorithms in Number
Theory' in the Handbook of Theoretical Computer Science, Elsevier,
Amsterdam, 1990. Also in Carl Pomerance's lecture notes on Cryptology and
Computational Number Theory, 1990.
* Harald Kirsh suggests:
mpq_set_str (MP_RAT *r, char *numerator, char *denominator).
* New function: mpq_get_ifstr (int_str, frac_str, base,
precision_in_som_way, rational_number). Convert RATIONAL_NUMBER to a
string in BASE and put the integer part in INT_STR and the fraction part
in FRAC_STR. (This function would do a division of the numerator and the
denominator.)
* Should mpz_powm* handle negative exponents?
* udiv_qrnnd: If the denominator is normalized, the n0 argument has very
little effect on the quotient. Maybe we can assume it is 0, and
compensate at a later stage?
* Better sqrt: First calculate the reciprocal square root, then multiply by
the operand to get the square root. The reciprocal square root can be
obtained through Newton-Raphson without division. To compute sqrt(A), the
iteration is,
2
x = x (3 - A x )/2.
i+1 i i
The final result can be computed without division using,
sqrt(A) = A x .
n
* Newton-Raphson using multiplication: We get twice as many correct digits
in each iteration. So if we square x(k) as part of the iteration, the
result will have the leading digits in common with the entire result from
iteration k-1. A _mpn_mul_lowpart could help us take advantage of this.
* Peter Montgomery: If 0 <= a, b < p < 2^31 and I want a modular product
a*b modulo p and the long long type is unavailable, then I can write
typedef signed long slong;
typedef unsigned long ulong;
slong a, b, p, quot, rem;
quot = (slong) (0.5 + (double)a * (double)b / (double)p);
rem = (slong)((ulong)a * (ulong)b - (ulong)p * (ulong)quot);
if (rem < 0} {rem += p; quot--;}
* Speed modulo arithmetic, using Montgomery's method or my pre-inversion
method. In either case, special arithmetic calls would be needed,
mpz_mmmul, mpz_mmadd, mpz_mmsub, plus some kind of initialization
functions. Better yet: Write a new mpr layer.
* mpz_powm* should not use division to reduce the result in the loop, but
instead pre-compute the reciprocal of the MOD argument and do reduced_val
= val-val*reciprocal(MOD)*MOD, or use Montgomery's method.
* mpz_mod_2expplussi -- to reduce a bignum modulo (2**n)+s
* It would be a quite important feature never to allocate more memory than
really necessary for a result. Sometimes we can achieve this cheaply, by
deferring reallocation until the result size is known.
* New macro in longlong.h: shift_rhl that extracts a word by shifting two
words as a unit. (Supported by i386, i860, HP-PA, POWER, 29k.) Useful
for shifting multiple precision numbers.
* The installation procedure should make a test run of multiplication to
decide the threshold values for algorithm switching between the available
methods.
* Fast output conversion of x to base B:
1. Find n, such that (B^n > x).
2. Set y to (x*2^m)/(B^n), where m large enough to make 2^n ~~ B^n
3. Multiply the low half of y by B^(n/2), and recursively convert the
result. Truncate the low half of y and convert that recursively.
Complexity: O(M(n)log(n))+O(D(n))!
* Improve division using Newton-Raphson. Check out "Newton Iteration and
Integer Division" by Stephen Tate in "Synthesis of Parallel Algorithms",
Morgan Kaufmann, 1993 ("beware of some errors"...)
* Improve implementation of Karatsuba's algorithm. For most operand sizes,
we can reduce the number of operations by splitting differently.
* Faster multiplication: The best approach is to first implement Toom-Cook.
People report that it beats Karatsuba's algorithm already at about 100
limbs. FFT would probably never beat a well-written Toom-Cook (not even for
millions of bits).
FFT:
{
* Multiplication could be done with Montgomery's method combined with
the "three primes" method described in Lipson. Maybe this would be
faster than to Nussbaumer's method with 3 (simple) moduli?
* Maybe the modular tricks below are not needed: We are using very
special numbers, Fermat numbers with a small base and a large exponent,
and maybe it's possible to just subtract and add?
* Modify Nussbaumer's convolution algorithm, to use 3 words for each
coefficient, calculating in 3 relatively prime moduli (e.g.
0xffffffff, 0x100000000, and 0x7fff on a 32-bit computer). Both all
operations and CRR would be very fast with such numbers.
* Optimize the Schoenhage-Stassen multiplication algorithm. Take advantage
of the real valued input to save half of the operations and half of the
memory. Use recursive FFT with large base cases, since recursive FFT has
better memory locality. A normal FFT get 100% cache misses for large
enough operands.
* In the 3-prime convolution method, it might sometimes be a win to use 2,
3, or 5 primes. Imagine that using 3 primes would require a transform
length of 2^n. But 2 primes might still sometimes give us correct
results with that same transform length, or 5 primes might allow us to
decrease the transform size to 2^(n-1).
To optimize floating-point based complex FFT we have to think of:
1. The normal implementation accesses all input exactly once for each of
the log(n) passes. This means that we will get 0% cache hit when n >
our cache. Remedy: Reorganize computation to compute partial passes,
maybe similar to a standard recursive FFT implementation. Use a large
`base case' to make any extra overhead of this organization negligible.
2. Use base-4, base-8 and base-16 FFT instead of just radix-2. This can
reduce the number of operations by 2x.
3. Inputs are real-valued. According to Knuth's "Seminumerical
Algorithms", exercise 4.6.4-14, we can save half the memory and half
the operations if we take advantage of that.
4. Maybe make it possible to write the innermost loop in assembly, since
that could win us another 2x speedup. (If we write our FFT to avoid
cache-miss (see #1 above) it might be logical to write the `base case'
in assembly.)
5. Avoid multiplication by 1, i, -1, -i. Similarly, optimize
multiplication by (+-\/2 +- i\/2).
6. Put as many bits as possible in each double (but don't waste time if
that doesn't make the transform size become smaller).
7. For n > some large number, we will get accuracy problems because of the
limited precision of our floating point arithmetic. This can easily be
solved by using the Karatsuba trick a few times until our operands
become small enough.
8. Precompute the roots-of-unity and store them in a vector.
}
* When a division result is going to be just one limb, (i.e. nsize-dsize is
small) normalization could be done in the division loop.
* Never allocate temporary space for a source param that overlaps with a
destination param needing reallocation. Instead malloc a new block for
the destination (and free the source before returning to the caller).
* Parallel addition. Since each processors have to tell it is ready to the
next processor, we can use simplified synchronization, and actually write
it in C: For each processor (apart from the least significant):
while (*svar != my_number)
;
*svar = my_number + 1;
The least significant processor does this:
*svar = my_number + 1; /* i.e., *svar = 1 */
Before starting the addition, one processor has to store 0 in *svar.
Other things to think about for parallel addition: To avoid false
(cache-line) sharing, allocate blocks on cache-line boundaries.
Local Variables:
mode: text
fill-column: 77
fill-prefix: " "
version-control: never
End:

View File

@ -1,137 +0,0 @@
THE GNU MP LIBRARY
GNU MP is a library for arbitrary precision arithmetic, operating on signed
integers, rational numbers, and floating point numbers. It has a rich set
of functions, and the functions have a regular interface.
GNU MP is designed to be as fast as possible, both for small operands and for
huge operands. The speed is achieved by using fullwords as the basic
arithmetic type, by using fast algorithms, by carefully optimized assembly
code for the most common inner loops for a lots of CPUs, and by a general
emphasis on speed (instead of simplicity or elegance).
The speed of GNU MP is believed to be faster than any other similar library.
The advantage for GNU MP increases with the operand sizes for certain
operations, since GNU MP in many cases has asymptotically faster algorithms.
GETTING STARTED
First, you have to configure and compiler GNU MP. Simply typing
./configure; make
will normally do a reasonable job, but will not give optimal library
execution speed. So unless you're very unpatient, please read the detailed
instructions in the file INSTALL or in gmp.texi.
Once you have compiled the library, you should write some small example, and
make sure you can compile them. A typical compilation command is this:
gcc -g your-file.c -I<gmp-source-dir> <gmp-bin-dir>libgmp.a -lm
If you have installed the library, you can simply do:
gcc -g your-file.c -lgmp -lm
The -lm is normally not needed, since only a few functions in GNU MP use the
math library.
Here is a sample program that declares 2 variables, initializes them as
required, and sets one of them from a signed integer, and the other from a
string of digits. It then prints the product of the two numbers in base 10.
#include <stdio.h>
#include "gmp.h"
main ()
{
mpz_t a, b, p;
mpz_init (a); /* initialize variables */
mpz_init (b);
mpz_init (p);
mpz_set_si (a, 756839); /* assign variables */
mpz_set_str (b, "314159265358979323846", 0);
mpz_mul (p, a, b); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
mpz_clear (a); /* clear out variables */
mpz_clear (b);
mpz_clear (p);
exit (0);
}
This might look tedious, with all initializing and clearing. Fortunately
some of these operations can be combined, and other operations can often be
avoided. The example above would be written differently by an experienced
GNU MP user:
#include <stdio.h>
#include "gmp.h"
main ()
{
mpz_t b, p;
mpz_init (p);
mpz_init_set_str (b, "314159265358979323846", 0);
mpz_mul_ui (p, b, 756839); /* generate product */
mpz_out_str (stdout, 10, p); /* print number without newline */
puts (""); /* print newline */
exit (0);
}
OVERVIEW OF GNU MP
There are five classes of functions in GNU MP.
1. Signed integer arithmetic functions, mpz_*. These functions are intended
to be easy to use, with their regular interface. The associated type is
`mpz_t'.
2. Rational arithmetic functions, mpq_*. For now, just a small set of
functions necessary for basic rational arithmetics. The associated type
is `mpq_t'.
3. Floating-point arithmetic functions, mpf_*. If the C type `double'
doesn't give enough precision for your application, declare your
variables as `mpf_t' instead, set the precision to any number desired,
and call the functions in the mpf class for the arithmetic operations.
4. Positive-integer, hard-to-use, very low overhead functions are in the
mpn_* class. No memory management is performed. The caller must ensure
enough space is available for the results. The set of functions is not
regular, nor is the calling interface. These functions accept input
arguments in the form of pairs consisting of a pointer to the least
significant word, and a integral size telling how many limbs (= words)
the pointer points to.
Almost all calculations, in the entire package, are made by calling these
low-level functions.
5. Berkeley MP compatible functions.
To use these functions, include the file "mp.h". You can test if you are
using the GNU version by testing if the symbol __GNU_MP__ is defined.
For more information on how to use GNU MP, please refer to the documentation.
It is composed from the file gmp.texi, and can be displayed on the screen or
printed. How to do that, as well how to build the library, is described in
the INSTALL file in this directory.
REPORTING BUGS
If you find a bug in the library, please make sure to tell us about it!
Report bugs and propose modifications and enhancements to
bug-gmp@prep.ai.mit.edu. What information is needed in a good bug report is
described in the manual.

View File

@ -1,156 +0,0 @@
==============================================================================
Cycle counts and throughput for low-level routines in GNU MP as currently
implemented.
A range means that the timing is data-dependent. The slower number of such
an interval is usually the best performance estimate.
The throughput value, measured in Gb/s (gigabits per second) has a meaning
only for comparison between CPUs.
A star before a line means that all values on that line are estimates. A
star before a number means that that number is an estimate. A `p' before a
number means that the code is not complete, but the timing is believed to be
accurate.
| mpn_lshift mpn_add_n mpn_mul_1 mpn_addmul_1
| mpn_rshift mpn_sub_n mpn_submul_1
------------+-----------------------------------------------------------------
DEC/Alpha |
EV4 | 4.75 cycles/64b 7.75 cycles/64b 42 cycles/64b 42 cycles/64b
200MHz | 2.7 Gb/s 1.65 Gb/s 20 Gb/s 20 Gb/s
EV5 old code| 4.0 cycles/64b 5.5 cycles/64b 18 cycles/64b 18 cycles/64b
267MHz | 4.27 Gb/s 3.10 Gb/s 61 Gb/s 61 Gb/s
417MHz | 6.67 Gb/s 4.85 Gb/s 95 Gb/s 95 Gb/s
EV5 tuned | 3.25 cycles/64b 4.75 cycles/64b
267MHz | 5.25 Gb/s 3.59 Gb/s as above
417MHz | 8.21 Gb/s 5.61 Gb/s
------------+-----------------------------------------------------------------
Sun/SPARC |
SPARC v7 | 14.0 cycles/32b 8.5 cycles/32b 37-54 cycl/32b 37-54 cycl/32b
SuperSPARC | 3 cycles/32b 2.5 cycles/32b 8.2 cycles/32b 10.8 cycles/32b
50MHz | 0.53 Gb/s 0.64 Gb/s 6.2 Gb/s 4.7 Gb/s
**SuperSPARC| tuned addmul and submul will take: 9.25 cycles/32b
MicroSPARC2 | ? 6.65 cycles/32b 30 cycles/32b 31.5 cycles/32b
110MHz | ? 0.53 Gb/s 3.75 Gb/s 3.58 Gb/s
SuperSPARC2 | ? ? ? ?
Ultra/32 (4)| 2.5 cycles/32b 6.5 cycles/32b 13-27 cyc/32b 16-30 cyc/32b
182MHz | 2.33 Gb/s 0.896 Gb/s 14.3-6.9 Gb/s
Ultra/64 (5)| 2.5 cycles/64b 10 cycles/64b 40-70 cyc/64b 46-76 cyc/64b
182MHz | 4.66 Gb/s 1.16 Gb/s 18.6-11 Gb/s
HalSPARC64 | ? ? ? ?
------------+-----------------------------------------------------------------
SGI/MIPS |
R3000 | 6 cycles/32b 9.25 cycles/32b 16 cycles/32b 16 cycles/32b
40MHz | 0.21 Gb/s 0.14 Gb/s 2.56 Gb/s 2.56 Gb/s
R4400/32 | 8.6 cycles/32b 10 cycles/32b 16-18 19-21
200MHz | 0.74 Gb/s 0.64 Gb/s 13-11 Gb/s 11-9.6 Gb/s
*R4400/64 | 8.6 cycles/64b 10 cycles/64b 22 cycles/64b 22 cycles/64b
*200MHz | 1.48 Gb/s 1.28 Gb/s 37 Gb/s 37 Gb/s
R4600/32 | 6 cycles/64b 9.25 cycles/32b 15 cycles/32b 19 cycles/32b
134MHz | 0.71 Gb/s 0.46 Gb/s 9.1 Gb/s 7.2 Gb/s
R4600/64 | 6 cycles/64b 9.25 cycles/64b ? ?
134MHz | 1.4 Gb/s 0.93 Gb/s ? ?
R8000/64 | 3 cycles/64b 4.6 cycles/64b 8 cycles/64b 8 cycles/64b
75MHz | 1.6 Gb/s 1.0 Gb/s 38 Gb/s 38 Gb/s
*R10000/64 | 2 cycles/64b 3 cycles/64b 11 cycles/64b 11 cycles/64b
*200MHz | 6.4 Gb/s 4.27 Gb/s 74 Gb/s 74 Gb/s
*250MHz | 8.0 Gb/s 5.33 Gb/s 93 Gb/s 93 Gb/s
------------+-----------------------------------------------------------------
Motorola |
MC68020 | ? 24 cycles/32b 62 cycles/32b 70 cycles/32b
MC68040 | ? 6 cycles/32b 24 cycles/32b 25 cycles/32b
MC88100 | >5 cycles/32b 4.6 cycles/32b 16/21 cyc/32b p 18/23 cyc/32b
MC88110 wt | ? 3.75 cycles/32b 6 cycles/32b 8.5 cyc/32b
*MC88110 wb | ? 2.25 cycles/32b 4 cycles/32b 5 cycles/32b
------------+-----------------------------------------------------------------
HP/PA-RISC |
PA7000 | 4 cycles/32b 5 cycles/32b 9 cycles/32b 11 cycles/32b
67MHz | 0.53 Gb/s 0.43 Gb/s 7.6 Gb/s 6.2 Gb/s
PA7100 | 3.25 cycles/32b 4.25 cycles/32b 7 cycles/32b 8 cycles/32b
99MHz | 0.97 Gb/s 0.75 Gb/s 14 Gb/s 12.8 Gb/s
PA7100LC | ? ? ? ?
PA7200 (3) | 3 cycles/32b 4 cycles/32b 7 cycles/32b 6.5 cycles/32b
100MHz | 1.07 Gb/s 0.80 14 Gb/s 15.8 Gb/s
PA7300LC | ? ? ? ?
*PA8000 | 3 cycles/64b 4 cycles/64b 7 cycles/64b 6.5 cycles/64b
180MHz | 3.84 Gb/s 2.88 Gb/s 105 Gb/s 113 Gb/s
------------+-----------------------------------------------------------------
Intel/x86 |
386DX | 20 cycles/32b 17 cycles/32b 41-70 cycl/32b 50-79 cycl/32b
16.7MHz | 0.027 Gb/s 0.031 Gb/s 0.42-0.24 Gb/s 0.34-0.22 Gb/s
486DX | ? ? ? ?
486DX4 | 9.5 cycles/32b 9.25 cycles/32b 17-23 cycl/32b 20-26 cycl/32b
100MHz | 0.34 Gb/s 0.35 Gb/s 6.0-4.5 Gb/s 5.1-3.9 Gb/s
Pentium | 2/6 cycles/32b 2.5 cycles/32b 13 cycles/32b 14 cycles/32b
167MHz | 2.7/0.89 Gb/s 2.1 Gb/s 13.1 Gb/s 12.2 Gb/s
Pentium Pro | 2.5 cycles/32b 3.5 cycles/32b 6 cycles/32b 9 cycles/32b
200MHz | 2.6 Gb/s 1.8 Gb/s 34 Gb/s 23 Gb/s
------------+-----------------------------------------------------------------
IBM/POWER |
RIOS 1 | 3 cycles/32b 4 cycles/32b 11.5-12.5 c/32b 14.5/15.5 c/32b
RIOS 2 | 2 cycles/32b 2 cycles/32b 7 cycles/32b 8.5 cycles/32b
------------+-----------------------------------------------------------------
PowerPC |
PPC601 (1) | 3 cycles/32b 6 cycles/32b 11-16 cycl/32b 14-19 cycl/32b
PPC601 (2) | 5 cycles/32b 6 cycles/32b 13-22 cycl/32b 16-25 cycl/32b
67MHz (2) | 0.43 Gb/s 0.36 Gb/s 5.3-3.0 Gb/s 4.3-2.7 Gb/s
PPC603 | ? ? ? ?
*PPC604 | 2 3 2 3
*167MHz | 57 Gb/s
PPC620 | ? ? ? ?
------------+-----------------------------------------------------------------
Tege |
Model 1 | 2 cycles/64b 3 cycles/64b 2 cycles/64b 3 cycles/64b
250MHz | 8 Gb/s 5.3 Gb/s 500 Gb/s 340 Gb/s
500MHz | 16 Gb/s 11 Gb/s 1000 Gb/s 680 Gb/s
____________|_________________________________________________________________
(1) Using POWER and PowerPC instructions
(2) Using only PowerPC instructions
(3) Actual timing for shift/add/sub depends on code alignment. PA7000 code
is smaller and therefore often faster on this CPU.
(4) Multiplication routines modified for bogus UltraSPARC early-out
optimization. Smaller operand is put in rs1, not rs2 as it should
according to the SPARC architecture manuals.
(5) Preliminary timings, since there is no stable 64-bit environment.
(6) Use mulu.d at least for mpn_lshift. With mak/extu/or, we can only get
to 2 cycles/32b.
=============================================================================
Estimated theoretical asymptotic cycle counts for low-level routines:
| mpn_lshift mpn_add_n mpn_mul_1 mpn_addmul_1
| mpn_rshift mpn_sub_n mpn_submul_1
------------+-----------------------------------------------------------------
DEC/Alpha |
EV4 | 3 cycles/64b 5 cycles/64b 42 cycles/64b 42 cycles/64b
EV5 | 3 cycles/64b 4 cycles/64b 18 cycles/64b 18 cycles/64b
------------+-----------------------------------------------------------------
Sun/SPARC |
SuperSPARC | 2.5 cycles/32b 2 cycles/32b 8 cycles/32b 9 cycles/32b
------------+-----------------------------------------------------------------
SGI/MIPS |
R4400/32 | 5 cycles/64b 8 cycles/64b 16 cycles/64b 16 cycles/64b
R4400/64 | 5 cycles/64b 8 cycles/64b 22 cycles/64b 22 cycles/64b
R4600 |
------------+-----------------------------------------------------------------
HP/PA-RISC |
PA7100 | 3 cycles/32b 4 cycles/32b 6.5 cycles/32b 7.5 cycles/32b
PA7100LC |
------------+-----------------------------------------------------------------
Motorola |
MC88110 | 1.5 cyc/32b (6) 1.5 cycle/32b 1.5 cycles/32b 2.25 cycles/32b
------------+-----------------------------------------------------------------
Intel/x86 |
486DX4 |
Pentium P5x | 5 cycles/32b 2 cycles/32b 11.5 cycles/32b 13 cycles/32b
Pentium Pro | 2 cycles/32b 3 cycles/32b 4 cycles/32b 6 cycles/32b
------------+-----------------------------------------------------------------
IBM/POWER |
RIOS 1 | 3 cycles/32b 4 cycles/32b
RIOS 2 | 1.5 cycles/32b 2 cycles/32b 4.5 cycles/32b 5.5 cycles/32b
------------+-----------------------------------------------------------------
PowerPC |
PPC601 (1) | 3 cycles/32b ?4 cycles/32b
PPC601 (2) | 4 cycles/32b ?4 cycles/32b
____________|_________________________________________________________________

View File

@ -1,184 +0,0 @@
THINGS TO WORK ON
Note that many of these things mentioned here are already fixed in GMP 2.0.
* Improve speed for non-gcc compilers by defining umul_ppmm, udiv_qrnnd,
etc, to call __umul_ppmm, __udiv_qrnnd. A typical definition for
umul_ppmm would be
#define umul_ppmm(ph,pl,m0,m1) \
{unsigned long __ph; (pl) = __umul_ppmm (&__ph, (m0), (m1)); (ph) = __ph;}
In order to maintain just one version of longlong.h (gmp and gcc), this
has to be done outside of longlong.h.
* Change mpn-routines to not deal with normalisation?
mpn_add: Unchanged.
mpn_sub: Remove normalization loop. Does it assume normalised input?
mpn_mul: Make it return most sign limb, to simplify normalisation.
Karatsubas algorith will be greatly simplified if mpn_add and
mpn_sub doesn't normalise their results.
mpn_div: Still requires strict normalisation.
Beware of problems with mpn_cmp (and similar), a larger size does not
ensure that an operand is larger, since it may be "less normalised".
Normalization has to be moved into mpz-functions.
Bennet Yee at CMU proposes:
* mpz_{put,get}_raw for memory oriented I/O like other *_raw functions.
* A function mpfatal that is called for exceptions. The user may override
the default definition.
* mout should group in 10-digit groups.
* ASCII dependence?
* Error reporting from I/O functions (linkoping)?
* Make all computation mpz_* functions return a signed int indicating if
the result was zero, positive, or negative?
* Implement mpz_cmpabs, mpz_xor, mpz_to_double, mpz_to_si, mpz_lcm,
mpz_dpb, mpz_ldb, various bit string operations like mpz_cntbits. Also
mpz_@_si for most @??
Brian Beuning proposes:
1. An array of small primes
3. A function to factor an MINT
4. A routine to look for "small" divisors of an MINT
5. A 'multiply mod n' routine based on Montgomery's algorithm.
Doug Lea proposes:
1. A way to find out if an integer fits into a signed int, and if so, a
way to convert it out.
2. Similarly for double precision float conversion.
3. A function to convert the ratio of two integers to a double. This
can be useful for mixed mode operations with integers, rationals, and
doubles.
5. Bit-setting, clearing, and testing operations, as in
mpz_setbit(MP_INT* dest, MP_INT* src, unsigned long bit_number),
and used, for example in
mpz_setbit(x, x, 123)
to directly set the 123rd bit of x.
If these are supported, you don't first have to set up
an otherwise unnecessary mpz holding a shifted value, then
do an "or" operation.
Elliptic curve method descrition in the Chapter `Algorithms in Number
Theory' in the Handbook of Theoretical Computer Science, Elsevier,
Amsterdam, 1990. Also in Carl Pomerance's lecture notes on Cryptology and
Computational Number Theory, 1990.
* New function: mpq_get_ifstr (int_str, frac_str, base,
precision_in_som_way, rational_number). Convert RATIONAL_NUMBER to a
string in BASE and put the integer part in INT_STR and the fraction part
in FRAC_STR. (This function would do a division of the numerator and the
denominator.)
* Should mpz_powm* handle negative exponents?
* udiv_qrnnd: If the denominator is normalized, the n0 argument has very
little effect on the quotient. Maybe we can assume it is 0, and
compensate at a later stage?
* Better sqrt: First calculate the reciprocal square root, then multiply by
the operand to get the square root. The reciprocal square root can be
obtained through Newton-Raphson without division. The iteration is x :=
x*(3-a*x^2)/2, where a is the operand.
* Newton-Raphson using multiplication: We get twice as many correct digits
in each iteration. So if we square x(k) as part of the iteration, the
result will have the leading digits in common with the entire result from
iteration k-1. A _mpn_mul_lowpart could implement this.
* Peter Montgomery: If 0 <= a, b < p < 2^31 and I want a modular product
a*b modulo p and the long long type is unavailable, then I can write
typedef signed long slong;
typedef unsigned long ulong;
slong a, b, p, quot, rem;
quot = (slong) (0.5 + (double)a * (double)b / (double)p);
rem = (slong)((ulong)a * (ulong)b - (ulong)p * (ulong)q);
if (rem < 0} {rem += p; quot--;}
FFT:
{
* Multiplication could be done with Montgomery's method combined with
the "three primes" method described in Lipson. Maybe this would be
faster than to Nussbaumer's method with 3 (simple) moduli?
* Maybe the modular tricks below are not needed: We are using very
special numbers, Fermat numbers with a small base and a large exponent,
and maybe it's possible to just subtract and add?
* Modify Nussbaumer's convolution algorithm, to use 3 words for each
coefficient, calculating in 3 relatively prime moduli (e.g.
0xffffffff, 0x100000000, and 0x7fff on a 32-bit computer). Both all
operations and CRR would be very fast with such numbers.
* Optimize the Shoenhage-Stassen multiplication algorithm. Take
advantage of the real valued input to save half of the operations and
half of the memory. Try recursive variants with large, optimized base
cases. Use recursive FFT with large base cases, since recursive FFT
has better memory locality. A normal FFT get 100% cache miss.
}
* Speed modulo arithmetic, using Montgomery's method or my pre-invertion
method. In either case, special arithmetic calls would be needed,
mpz_mmmul, mpz_mmadd, mpz_mmsub, plus some kind of initialization
functions.
* mpz_powm* should not use division to reduce the result in the loop, but
instead pre-compute the reciprocal of the MOD argument and do reduced_val
= val-val*reciprocal(MOD)*MOD, or use Montgomery's method.
* mpz_mod_2expplussi -- to reduce a bignum modulo (2**n)+s
* It would be a quite important feature never to allocate more memory than
really necessary for a result. Sometimes we can achieve this cheaply, by
deferring reallocation until the result size is known.
* New macro in longlong.h: shift_rhl that extracts a word by shifting two
words as a unit. (Supported by i386, i860, HP-PA, RS6000, 29k.) Useful
for shifting multiple precision numbers.
* The installation procedure should make a test run of multiplication to
decide the threshold values for algorithm switching between the available
methods.
* The gcd algorithm could probably be improved with a divide-and-conquer
(DAC) approach. At least the bulk of the operations should be done with
single precision.
* Fast output conversion of x to base B:
1. Find n, such that (B^n > x).
2. Set y to (x*2^m)/(B^n), where m large enough to make 2^n ~~ B^n
3. Multiply the low half of y by B^(n/2), and recursively convert the
result. Truncate the low half of y and convert that recursively.
Complexity: O(M(n)log(n))+O(D(n))!
* Extensions for floating-point arithmetic.
* Improve special cases for division.
1. When the divisor is just one word, normalization is not needed for
most CPUs, and can be done in the division loop for CPUs that need
normalization.
2. Even when the result is going to be very small, (i.e. nsize-dsize is
small) normalization should also be done in the division loop.
To fix this, a new routine mpn_div_unnormalized is needed.
* Never allocate temporary space for a source param that overlaps with a
destination param needing reallocation. Instead malloc a new block for
the destination (and free the source before returning to the caller).
* When any of the source operands overlap with the destination, mult (and
other routines) slow down. This is so because the need of temporary
allocation (with alloca) and copying. If a new destination were
malloc'ed instead (and the overlapping source free'd before return) no
copying would be needed. Is GNU malloc quick enough to make this faster
even for reasonably small operands?
Local Variables:
mode: text
fill-column: 75
version-control: never
End:

View File

@ -1 +0,0 @@
GNU MP version 1.3.2

View File

@ -1,309 +0,0 @@
/* _mpz_get_str (string, base, mp_src) -- Convert the multiple precision
number MP_SRC to a string STRING of base BASE. If STRING is NULL
allocate space for the result. In any case, return a pointer to the
result. If STRING is not NULL, the caller must ensure enough space is
available to store the result.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#ifndef UMUL_TIME
#define UMUL_TIME 1
#endif
#ifndef UDIV_TIME
#define UDIV_TIME UMUL_TIME
#endif
#define udiv_qrnndx(q, r, nh, nl, d, di) \
do { \
unsigned long int _q, _ql, _r; \
unsigned long int _xh, _xl; \
umul_ppmm (_q, _ql, (nh), (di)); \
_q += (nh); /* DI is 2**32 too small. Compensate */\
if (_q < (nh)) \
{ \
/* Got carry. Propagate it in the multiplication. */ \
umul_ppmm (_xh, _xl, (d), _q); \
_xh += (d); \
} \
else \
umul_ppmm (_xh, _xl, (d), _q); \
sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
} \
} \
if (_r >= (d)) \
{ \
_r -= (d); \
_q += 1; \
} \
(r) = _r; \
(q) = _q; \
} while (0)
char *
#ifdef __STDC__
_mpz_get_str (char *str, int base, const MP_INT *m)
#else
_mpz_get_str (str, base, m)
char *str;
int base;
const MP_INT *m;
#endif
{
mp_ptr tp;
mp_size msize;
mp_limb big_base;
#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME
int normalization_steps;
#if UDIV_TIME > 2 * UMUL_TIME
mp_limb big_base_inverted;
#endif
#endif
unsigned int dig_per_u;
mp_size out_len;
char *s;
char *num_to_ascii;
if (base >= 0)
{
if (base == 0)
base = 10;
num_to_ascii = "0123456789abcdefghijklmnopqrstuvwxyz";
}
else
{
base = -base;
num_to_ascii = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
dig_per_u = __mp_bases[base].chars_per_limb;
out_len = mpz_sizeinbase (m, base) + 1;
big_base = __mp_bases[base].big_base;
msize = m->size;
if (str == NULL)
str = (char *) (*_mp_allocate_func) (out_len + (msize < 0));
if (msize < 0)
*str++ = '-';
s = str;
msize = ABS (msize);
/* Special case zero, as the code below doesn't handle it. */
if (msize == 0)
{
s[0] = '0';
s[1] = 0;
return str;
}
if ((base & (base - 1)) == 0)
{
/* The base is a power of 2. Make conversion from most
significant side. */
mp_limb n1, n0;
int bits_per_digit = big_base;
int x;
int bit_pos;
int i;
unsigned mask = (1 << bits_per_digit) - 1;
tp = m->d;
n1 = tp[msize - 1];
count_leading_zeros (x, n1);
/* BIT_POS should be R when input ends in least sign. nibble,
R + bits_per_digit * n when input ends in n:th least significant
nibble. */
{
int bits;
bits = BITS_PER_MP_LIMB * msize - x;
x = bits % bits_per_digit;
if (x != 0)
bits += bits_per_digit - x;
bit_pos = bits - (msize - 1) * BITS_PER_MP_LIMB;
}
/* Fast loop for bit output. */
i = msize - 1;
for (;;)
{
bit_pos -= bits_per_digit;
while (bit_pos >= 0)
{
*s++ = num_to_ascii[(n1 >> bit_pos) & mask];
bit_pos -= bits_per_digit;
}
i--;
if (i < 0)
break;
n0 = (n1 << -bit_pos) & mask;
n1 = tp[i];
bit_pos += BITS_PER_MP_LIMB;
*s++ = num_to_ascii[n0 | (n1 >> bit_pos)];
}
*s = 0;
}
else
{
/* General case. The base is not a power of 2. Make conversion
from least significant end. */
/* If udiv_qrnnd only handles divisors with the most significant bit
set, prepare BIG_BASE for being a divisor by shifting it to the
left exactly enough to set the most significant bit. */
#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME
count_leading_zeros (normalization_steps, big_base);
big_base <<= normalization_steps;
#if UDIV_TIME > 2 * UMUL_TIME
/* Get the fixed-point approximation to 1/BIG_BASE. */
big_base_inverted = __mp_bases[base].big_base_inverted;
#endif
#endif
out_len--; /* now not include terminating \0 */
s += out_len;
/* Allocate temporary space and move the multi prec number to
convert there, as we need to overwrite it below, while
computing the successive remainders. */
tp = (mp_ptr) alloca ((msize + 1) * BYTES_PER_MP_LIMB);
MPN_COPY (tp, m->d, msize);
while (msize != 0)
{
int i;
mp_limb n0, n1;
#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME
/* If we shifted BIG_BASE above, shift the dividend too, to get
the right quotient. We need to do this every loop,
as the intermediate quotients are OK, but the quotient from
one turn in the loop is going to be the dividend in the
next turn, and the dividend needs to be up-shifted. */
if (normalization_steps != 0)
{
n0 = mpn_lshift (tp, tp, msize, normalization_steps);
/* If the shifting gave a carry out limb, store it and
increase the length. */
if (n0 != 0)
{
tp[msize] = n0;
msize++;
}
}
#endif
/* Divide the number at TP with BIG_BASE to get a quotient and a
remainder. The remainder is our new digit in base BIG_BASE. */
i = msize - 1;
n1 = tp[i];
if (n1 >= big_base)
n1 = 0;
else
{
msize--;
i--;
}
for (; i >= 0; i--)
{
n0 = tp[i];
#if UDIV_TIME > 2 * UMUL_TIME
udiv_qrnndx (tp[i], n1, n1, n0, big_base, big_base_inverted);
#else
udiv_qrnnd (tp[i], n1, n1, n0, big_base);
#endif
}
#if UDIV_NEEDS_NORMALIZATION || UDIV_TIME > 2 * UMUL_TIME
/* If we shifted above (at previous UDIV_NEEDS_NORMALIZATION tests)
the remainder will be up-shifted here. Compensate. */
n1 >>= normalization_steps;
#endif
/* Convert N1 from BIG_BASE to a string of digits in BASE
using single precision operations. */
for (i = dig_per_u - 1; i >= 0; i--)
{
*--s = num_to_ascii[n1 % base];
n1 /= base;
/* Break from the loop as soon as we would only write zeros. */
if (n1 == 0 && msize == 0)
break;
}
}
/* There should be no leading zeros. */
if (*s == '0')
abort ();
if (s == str)
{
/* This should be the common case. */
s[out_len] = 0;
}
else if (s == str + 1)
{
/* The string became 1 digit shorter than its maximum. */
/* Need to copy it back one char pos. */
out_len--;
#ifndef HAS_MEMMOVE
{
size_t i;
for (i = 0; i < out_len; i++)
str[i] = s[i];
}
#else
memmove (str, s, out_len);
#endif
str[out_len] = 0;
}
else
{
/* Hopefully never. */
abort ();
}
}
alloca (0);
/* Ugly, we incremented str for negative numbers. Fix that here. */
return str - (m->size < 0);
}

View File

@ -1,258 +0,0 @@
/* _mpz_set_str(mp_dest, string, base) -- Convert the \0-terminated
string STRING in base BASE to multiple precision integer in
MP_DEST. Allow white space in the string. If BASE == 0 determine
the base in the C standard way, i.e. 0xhh...h means base 16,
0oo...o means base 8, otherwise assume base 10.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
enum char_type
{
XX = -3,
SPC = -2,
EOF = -1
};
static signed char ascii_to_num[256] =
{
EOF,XX, XX, XX, XX, XX, XX, XX, XX, SPC,SPC,XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
SPC,XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, XX, XX, XX, XX, XX, XX,
XX, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, XX, XX, XX, XX, XX,
XX, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX,
XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX, XX
};
int
#ifdef __STDC__
_mpz_set_str (MP_INT *x, const char *str, int base)
#else
_mpz_set_str (x, str, base)
MP_INT *x;
const char *str;
int base;
#endif
{
mp_ptr xp;
mp_size size;
mp_limb big_base;
int indigits_per_limb;
int negative = 0;
int inp_rawchar;
mp_limb inp_digit;
mp_limb res_digit;
size_t str_len;
mp_size i;
if (str[0] == '-')
{
negative = 1;
str++;
}
if (base == 0)
{
if (str[0] == '0')
{
if (str[1] == 'x' || str[1] == 'X')
base = 16;
else
base = 8;
}
else
base = 10;
}
big_base = __mp_bases[base].big_base;
indigits_per_limb = __mp_bases[base].chars_per_limb;
str_len = strlen (str);
size = str_len / indigits_per_limb + 1;
if (x->alloc < size)
_mpz_realloc (x, size);
xp = x->d;
size = 0;
if ((base & (base - 1)) == 0)
{
/* The base is a power of 2. Read the input string from
least to most significant character/digit. */
const char *s;
int next_bitpos;
int bits_per_indigit = big_base;
/* Accept and ignore 0x or 0X before hexadecimal numbers. */
if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
{
str += 2;
str_len -= 2;
}
res_digit = 0;
next_bitpos = 0;
for (s = str + str_len - 1; s >= str; s--)
{
inp_rawchar = *s;
inp_digit = ascii_to_num[inp_rawchar];
if (inp_digit >= base)
{
/* Was it white space? Just ignore it. */
if ((char) inp_digit == (char) SPC)
continue;
/* We found rubbish in the string. Return -1 to indicate
the error. */
return -1;
}
res_digit |= inp_digit << next_bitpos;
next_bitpos += bits_per_indigit;
if (next_bitpos >= BITS_PER_MP_LIMB)
{
xp[size] = res_digit;
size++;
next_bitpos -= BITS_PER_MP_LIMB;
res_digit = inp_digit >> (bits_per_indigit - next_bitpos);
}
}
xp[size] = res_digit;
size++;
for (i = size - 1; i >= 0; i--)
{
if (xp[i] != 0)
break;
}
size = i + 1;
}
else
{
/* General case. The base is not a power of 2. */
mp_size i;
int j;
mp_limb cy;
for (;;)
{
res_digit = 0;
for (j = 0; j < indigits_per_limb; )
{
inp_rawchar = (unsigned char) *str++;
inp_digit = ascii_to_num[inp_rawchar];
/* Negative means that the character was not a proper digit. */
if (inp_digit >= base)
{
/* Was it white space? Just ignore it. */
if ((char) inp_digit == (char) SPC)
continue;
goto end_or_error;
}
res_digit = res_digit * base + inp_digit;
/* Increment the loop counter here, since it mustn't be
incremented when we do "continue" above. */
j++;
}
cy = res_digit;
/* Insert RES_DIGIT into the result multi prec integer. */
for (i = 0; i < size; i++)
{
mp_limb p1, p0;
umul_ppmm (p1, p0, big_base, xp[i]);
p0 += cy;
cy = p1 + (p0 < cy);
xp[i] = p0;
}
if (cy != 0)
{
xp[size] = cy;
size++;
}
}
end_or_error:
/* We probably have some digits in RES_DIGIT (J tells how many). */
if ((char) inp_digit != (char) EOF)
{
/* Error return. */
return -1;
}
/* J contains number of digits (in base BASE) remaining in
RES_DIGIT. */
if (j > 0)
{
big_base = 1;
do
{
big_base *= base;
j--;
}
while (j > 0);
cy = res_digit;
/* Insert ultimate RES_DIGIT into the result multi prec integer. */
for (i = 0; i < size; i++)
{
mp_limb p1, p0;
umul_ppmm (p1, p0, big_base, xp[i]);
p0 += cy;
cy = p1 + (p0 < cy);
xp[i] = p0;
}
if (cy != 0)
{
xp[size] = cy;
size++;
}
}
}
if (negative)
size = -size;
x->size = size;
return 0;
}

View File

@ -1,466 +0,0 @@
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* If compiling with GCC, this file's not needed. */
#ifndef alloca
#ifdef emacs
#ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
#ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
#endif /* STACK_DIRECTION undefined */
#endif /* static */
#endif /* emacs */
#ifdef emacs
#define free xfree
#endif
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
#ifdef CRAY
long i00afunc ();
#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
#else
#define ADDRESS_FUNCTION(arg) &(arg)
#endif
#if __STDC__
typedef void *pointer;
#else
typedef char *pointer;
#endif
#define NULL 0
extern pointer (*_mp_allocate_func) ();
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#ifndef STACK_DIRECTION
#define STACK_DIRECTION 0 /* Direction unknown. */
#endif
#if STACK_DIRECTION != 0
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
#else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */
#define STACK_DIR stack_dir
static void
find_stack_direction ()
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
#endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
#endif
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
pointer
alloca (size)
unsigned size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
#if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
#endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free ((pointer) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
}
if (size == 0)
return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
{
register pointer new = (*_mp_allocate_func) (sizeof (header) + size);
/* Address of header. */
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = (header *) new;
/* User storage begins just after header. */
return (pointer) ((char *) new + sizeof (header));
}
}
#ifdef CRAY
#ifdef DEBUG_I00AFUNC
#include <stdio.h>
#endif
#ifndef CRAY_STACK
#define CRAY_STACK
#ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
#else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
STKSTAT (&status);
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
if (trailer == 0)
{
return result;
}
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
return (result);
}
#else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
{
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
#endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
#endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
}
#endif /* not CRAY2 */
#endif /* CRAY */
#endif /* no alloca */

View File

@ -1,592 +0,0 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 93, 94, 95, 1996 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of 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.
#
# This program 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 a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Written by Per Bothner <bothner@cygnus.com>.
# The master version of this file is at the FSF in /home/gd/gnu/lib.
#
# This script attempts to guess a canonical system name similar to
# config.sub. If it succeeds, it prints the system name on stdout, and
# exits with 0. Otherwise, it exits with 1.
#
# The plan is that this can be called by configure scripts if you
# don't specify an explicit system type (host/target name).
#
# Only a few systems have been added to this list; please add others
# (but try to keep the structure clean).
#
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 8/24/94.)
if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
PATH=$PATH:/.attbin ; export PATH
fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15
# Note: order is significant - the case branches are not exclusive.
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
alpha:OSF1:[VX]*:*)
# After 1.2, OSF1 uses "V1.3" for uname -r.
# After 4.x, OSF1 uses "X4.x" for uname -r.
echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VX]//'`
exit 0 ;;
alpha:OSF1:*:*)
# 1.2 uses "1.2" for uname -r.
echo alpha-dec-osf${UNAME_RELEASE}
exit 0 ;;
21064:Windows_NT:50:3)
echo alpha-dec-winnt3.5
exit 0 ;;
Amiga*:UNIX_System_V:4.0:*)
echo m68k-cbm-sysv4
exit 0;;
amiga:NetBSD:*:*)
echo m68k-cbm-netbsd${UNAME_RELEASE}
exit 0 ;;
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
echo arm-acorn-riscix${UNAME_RELEASE}
exit 0;;
Pyramid*:OSx*:*:*)
if test "`(/bin/universe) 2>/dev/null`" = att ; then
echo pyramid-pyramid-sysv3
else
echo pyramid-pyramid-bsd
fi
exit 0 ;;
sun4*:SunOS:5.*:*)
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
i86pc:SunOS:5.*:*)
echo i386-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit 0 ;;
sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in
Series*|S4*)
UNAME_RELEASE=`uname -v`
;;
esac
# Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
exit 0 ;;
sun3*:SunOS:*:*)
echo m68k-sun-sunos${UNAME_RELEASE}
exit 0 ;;
atari*:NetBSD:*:*)
echo m68k-atari-netbsd${UNAME_RELEASE}
exit 0 ;;
sun3*:NetBSD:*:*)
echo m68k-sun-netbsd${UNAME_RELEASE}
exit 0 ;;
mac68k:NetBSD:*:*)
echo m68k-apple-netbsd${UNAME_RELEASE}
exit 0 ;;
RISC*:ULTRIX:*:*)
echo mips-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
VAX*:ULTRIX*:*:*)
echo vax-dec-ultrix${UNAME_RELEASE}
exit 0 ;;
mips:*:4*:UMIPS)
echo mips-mips-riscos4sysv
exit 0 ;;
mips:*:5*:RISCos)
echo mips-mips-riscos${UNAME_RELEASE}
exit 0 ;;
Night_Hawk:Power_UNIX:*:*)
echo powerpc-harris-powerunix
exit 0 ;;
m88k:CX/UX:7*:*)
echo m88k-harris-cxux7
exit 0 ;;
m88k:*:4*:R4*)
echo m88k-motorola-sysv4
exit 0 ;;
m88k:*:3*:R3*)
echo m88k-motorola-sysv3
exit 0 ;;
AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`uname -p`
if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88100 ] ; then
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \
-o ${TARGET_BINARY_INTERFACE}x = x ] ; then
echo m88k-dg-dgux${UNAME_RELEASE}
else
echo m88k-dg-dguxbcs${UNAME_RELEASE}
fi
else echo i586-dg-dgux${UNAME_RELEASE}
fi
exit 0 ;;
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
echo m88k-dolphin-sysv3
exit 0 ;;
M88*:*:R3*:*)
# Delta 88k system running SVR3
echo m88k-motorola-sysv3
exit 0 ;;
XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
echo m88k-tektronix-sysv3
exit 0 ;;
Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
echo m68k-tektronix-bsd
exit 0 ;;
*:IRIX*:*:*)
echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
exit 0 ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX '
i[34]86:AIX:*:*)
echo i386-ibm-aix
exit 0 ;;
*:AIX:2:3)
if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
sed 's/^ //' << EOF >dummy.c
#include <sys/systemcfg.h>
main()
{
if (!__power_pc())
exit(1);
puts("powerpc-ibm-aix3.2.5");
exit(0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo rs6000-ibm-aix3.2.5
elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
echo rs6000-ibm-aix3.2.4
else
echo rs6000-ibm-aix3.2
fi
exit 0 ;;
*:AIX:*:4)
if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then
IBM_ARCH=rs6000
else
IBM_ARCH=powerpc
fi
if [ -x /usr/bin/oslevel ] ; then
IBM_REV=`/usr/bin/oslevel`
else
IBM_REV=4.${UNAME_RELEASE}
fi
echo ${IBM_ARCH}-ibm-aix${IBM_REV}
exit 0 ;;
*:AIX:*:*)
echo rs6000-ibm-aix
exit 0 ;;
ibmrt:4.4BSD:*|romp-ibm:BSD:*)
echo romp-ibm-bsd4.4
exit 0 ;;
ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and
echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
exit 0 ;; # report: romp-ibm BSD 4.3
*:BOSX:*:*)
echo rs6000-bull-bosx
exit 0 ;;
DPX/2?00:B.O.S.:*:*)
echo m68k-bull-sysv3
exit 0 ;;
9000/[34]??:4.3bsd:1.*:*)
echo m68k-hp-bsd
exit 0 ;;
hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
echo m68k-hp-bsd4.4
exit 0 ;;
9000/[3478]??:HP-UX:*:*)
case "${UNAME_MACHINE}" in
9000/31? ) HP_ARCH=m68000 ;;
9000/[34]?? ) HP_ARCH=m68k ;;
9000/7?? | 9000/8?[679] ) HP_ARCH=hppa1.1 ;;
9000/8?? ) HP_ARCH=hppa1.0 ;;
esac
HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
exit 0 ;;
3050*:HI-UX:*:*)
sed 's/^ //' << EOF >dummy.c
#include <unistd.h>
int
main ()
{
long cpu = sysconf (_SC_CPU_VERSION);
/* The order matters, because CPU_IS_HP_MC68K erroneously returns
true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
results, however. */
if (CPU_IS_PA_RISC (cpu))
{
switch (cpu)
{
case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
default: puts ("hppa-hitachi-hiuxwe2"); break;
}
}
else if (CPU_IS_HP_MC68K (cpu))
puts ("m68k-hitachi-hiuxwe2");
else puts ("unknown-hitachi-hiuxwe2");
exit (0);
}
EOF
${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
echo unknown-hitachi-hiuxwe2
exit 0 ;;
9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
echo hppa1.1-hp-bsd
exit 0 ;;
9000/8??:4.3bsd:*:*)
echo hppa1.0-hp-bsd
exit 0 ;;
hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
echo hppa1.1-hp-osf
exit 0 ;;
hp8??:OSF1:*:*)
echo hppa1.0-hp-osf
exit 0 ;;
parisc*:Lites*:*:*)
echo hppa1.1-hp-lites
exit 0 ;;
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
echo c1-convex-bsd
exit 0 ;;
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
echo c34-convex-bsd
exit 0 ;;
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
echo c38-convex-bsd
exit 0 ;;
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
echo c4-convex-bsd
exit 0 ;;
CRAY*X-MP:*:*:*)
echo xmp-cray-unicos
exit 0 ;;
CRAY*Y-MP:*:*:*)
echo ymp-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY*C90:*:*:*)
echo c90-cray-unicos${UNAME_RELEASE}
exit 0 ;;
CRAY-2:*:*:*)
echo cray2-cray-unicos
exit 0 ;;
hp3[0-9][05]:NetBSD:*:*)
echo m68k-hp-netbsd${UNAME_RELEASE}
exit 0 ;;
i[34]86:BSD/386:*:* | *:BSD/OS:*:*)
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit 0 ;;
*:FreeBSD:*:*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit 0 ;;
*:NetBSD:*:*)
echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
exit 0 ;;
i*:CYGWIN*:*)
echo i386-unknown-cygwin32
exit 0 ;;
p*:CYGWIN*:*)
echo powerpcle-unknown-cygwin32
exit 0 ;;
*:GNU:*:*)
echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
exit 0 ;;
*:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us.
ld_help_string=`ld --help 2>&1`
if echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: elf_i[345]86"; then
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86linux"; then
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: i[345]86coff"; then
echo "${UNAME_MACHINE}-unknown-linuxcoff" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68kelf"; then
echo "${UNAME_MACHINE}-unknown-linux" ; exit 0
elif echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations: m68klinux"; then
echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0
elif test "${UNAME_MACHINE}" = "alpha" ; then
echo alpha-unknown-linux ; exit 0
else
# Either a pre-BFD a.out linker (linuxoldld) or one that does not give us
# useful --help. Gcc wants to distinguish between linuxoldld and linuxaout.
test ! -d /usr/lib/ldscripts/. \
&& echo "${UNAME_MACHINE}-unknown-linuxoldld" && exit 0
# Determine whether the default compiler is a.out or elf
cat >dummy.c <<EOF
main(argc, argv)
int argc;
char *argv[];
{
#ifdef __ELF__
printf ("%s-unknown-linux\n", argv[1]);
#else
printf ("%s-unknown-linuxaout\n", argv[1]);
#endif
return 0;
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
fi ;;
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions
# are messed up and put the nodename in both sysname and nodename.
i[34]86:DYNIX/ptx:4*:*)
echo i386-sequent-sysv4
exit 0 ;;
i[34]86:*:4.*:* | i[34]86:SYSTEM_V:4.*:*)
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE}
else
echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}
fi
exit 0 ;;
i[34]86:*:3.2:*)
if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
echo ${UNAME_MACHINE}-unknown-isc$UNAME_REL
elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')`
(/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586
echo ${UNAME_MACHINE}-unknown-sco$UNAME_REL
else
echo ${UNAME_MACHINE}-unknown-sysv32
fi
exit 0 ;;
Intel:Mach:3*:*)
echo i386-unknown-mach3
exit 0 ;;
paragon:*:*:*)
echo i860-intel-osf1
exit 0 ;;
i860:*:4.*:*) # i860-SVR4
if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
else # Add other i860-SVR4 vendors below as they are discovered.
echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
fi
exit 0 ;;
mini*:CTIX:SYS*5:*)
# "miniframe"
echo m68010-convergent-sysv
exit 0 ;;
M680[234]0:*:R3V[567]*:*)
test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0)
uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4.3 && exit 0 ;;
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
uname -p 2>/dev/null | grep 86 >/dev/null \
&& echo i486-ncr-sysv4 && exit 0 ;;
m680[234]0:LynxOS:2.[23]*:*)
echo m68k-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
mc68030:UNIX_System_V:4.*:*)
echo m68k-atari-sysv4
exit 0 ;;
i[34]86:LynxOS:2.[23]*:*)
echo i386-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
TSUNAMI:LynxOS:2.[23]*:*)
echo sparc-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
rs6000:LynxOS:2.[23]*:*)
echo rs6000-lynx-lynxos${UNAME_RELEASE}
exit 0 ;;
RM*:SINIX-*:*:*)
echo mips-sni-sysv4
exit 0 ;;
*:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null`
echo ${UNAME_MACHINE}-sni-sysv4
else
echo ns32k-sni-sysv
fi
exit 0 ;;
mc68*:A/UX:*:*)
echo m68k-apple-aux${UNAME_RELEASE}
exit 0 ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
cat >dummy.c <<EOF
#ifdef _SEQUENT_
# include <sys/types.h>
# include <sys/utsname.h>
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (__arm) && defined (__acorn) && defined (__unix)
printf ("arm-acorn-riscix"); exit (0);
#endif
#if defined (hp300) && !defined (hpux)
printf ("m68k-hp-bsd\n"); exit (0);
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
printf ("%s-next-nextstep%s\n", __ARCHITECTURE__, version==2 ? "2" : "3");
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-unknown-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
printf ("vax-dec-bsd\n"); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0
rm -f dummy.c dummy
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
# Convex versions that predate uname can use getsysinfo(1)
if [ -x /usr/convex/getsysinfo ]
then
case `getsysinfo -f cpu_type` in
c1*)
echo c1-convex-bsd
exit 0 ;;
c2*)
if getsysinfo -f scalar_acc
then echo c32-convex-bsd
else echo c2-convex-bsd
fi
exit 0 ;;
c34*)
echo c34-convex-bsd
exit 0 ;;
c38*)
echo c38-convex-bsd
exit 0 ;;
c4*)
echo c4-convex-bsd
exit 0 ;;
esac
fi
#echo '(Unable to guess system type)' 1>&2
exit 1

File diff suppressed because it is too large Load Diff

1263
gnu/lib/libgmp/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +0,0 @@
# This file is a shell script fragment that supplies the information
# necessary for a configure script to process the program in
# this directory. For more information, look at ../configure.
configdirs="mpn mpz mpf mpq mpbsd"
srctrigger=gmp-impl.h
srcname="GNU Multi-Precision library"
# per-host:
# per-target:
case "${target}" in
sparc8* | microsparc*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-sprc8-gcc
fi
;;
supersparc*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-supspc-gcc
fi
;;
m888110*)
if [ x$with_gcc != xno ]
then
target_makefile_frag=config/mt-m88110
fi
;;
*-*-linux*)
target_makefile_frag=config/mt-linux ;;
esac

View File

@ -1,140 +0,0 @@
/* cre-conv-tab.c -- Create conversion table in a wordsize-dependent way.
$Id$
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <math.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
static unsigned long int
upow (unsigned long int b, unsigned int e)
{
unsigned long int y = 1;
while (e != 0)
{
while ((e & 1) == 0)
{
b = b * b;
e >>= 1;
}
y = y * b;
e -= 1;
}
return y;
}
unsigned int
ulog2 (unsigned long int x)
{
unsigned int i;
for (i = 0; x != 0; i++)
x >>= 1;
return i;
}
void
main (void)
{
int i;
unsigned long idig;
unsigned long big_base, big_base_inverted;
double fdig;
int dummy;
int normalization_steps;
unsigned long int max_uli;
int bits_uli;
max_uli = 1;
for (i = 1; ; i++)
{
if ((max_uli << 1) == 0)
break;
max_uli <<= 1;
}
bits_uli = i;
puts ("/* __mp_bases -- Structure for conversion between internal binary");
puts (" format and strings in base 2..36. The fields are explained in");
puts (" gmp-impl.h.");
puts ("");
puts (" ***** THIS FILE WAS CREATED BY A PROGRAM. DON'T EDIT IT! *****");
puts ("");
puts ("Copyright (C) 1991 Free Software Foundation, Inc.");
puts ("");
puts ("This file is part of the GNU MP Library.");
puts ("");
puts ("The GNU MP Library is free software; you can redistribute it and/or");
puts ("modify it under the terms of the GNU General Public License as");
puts ("published by the Free Software Foundation; either version 2, or");
puts ("(at your option) any later version.");
puts ("");
puts ("The GNU MP Library is distributed in the hope that it will be");
puts ("useful, but WITHOUT ANY WARRANTY; without even the implied warranty");
puts ("of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the");
puts ("GNU General Public License for more details.");
puts ("");
puts ("You should have received a copy of the GNU General Public License");
puts ("along with the GNU MP Library; see the file COPYING. If not, write");
puts ("to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,");
puts ("USA. */");
puts ("");
puts ("#include \"gmp.h\"");
puts ("#include \"gmp-impl.h\"");
puts ("");
puts ("const struct bases __mp_bases[37] =\n{");
puts (" /* 0 */ {0, 0, 0, 0.0},");
puts (" /* 1 */ {0, 0, 0, 0.0},");
for (i = 2; i <= 36; i++)
{
/* The weird expression here is because many /bin/cc compilers
generate incorrect code for conversions from large unsigned
integers to double. */
fdig = log(2.0)/log((double) i);
idig = floor(bits_uli * fdig);
if ((i & (i - 1)) == 0)
{
big_base = ulog2 (i) - 1;
big_base_inverted = 0;
}
else
{
big_base = upow (i, idig);
for (normalization_steps = 0;
(long int) (big_base << normalization_steps) >= 0;
normalization_steps++)
;
udiv_qrnnd (big_base_inverted, dummy,
-(big_base << normalization_steps), 0,
big_base << normalization_steps);
}
printf (" /* %2u */ {%lu, 0x%lX, 0x%lX, %.8f},\n",
i, idig, big_base, big_base_inverted, fdig);
}
puts ("};");
exit (0);
}

View File

@ -1,16 +0,0 @@
#include "gmp.h"
main ()
{
printf ("/* gmp-mparam.h -- Compiler/machine parameter header file.\n\n");
printf (" *** CREATED BY A PROGRAM -- DO NOT EDIT ***\n\n");
printf ("Copyright (C) 1996 Free Software Foundation, Inc. */\n\n");
printf ("#define BITS_PER_MP_LIMB %d\n", 8 * sizeof (mp_limb_t));
printf ("#define BYTES_PER_MP_LIMB %d\n", sizeof (mp_limb_t));
printf ("#define BITS_PER_LONGINT %d\n", 8 * sizeof (long));
printf ("#define BITS_PER_INT %d\n", 8 * sizeof (int));
printf ("#define BITS_PER_SHORTINT %d\n", 8 * sizeof (short));
printf ("#define BITS_PER_CHAR 8\n");
exit (0);
}

View File

@ -1,42 +0,0 @@
/* cre-stddefh.c -- Check the size of a pointer and output an
appropriate size_t declaration.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
main (argc, argv)
int argc;
char **argv;
{
if (sizeof (int *) == sizeof (unsigned long int))
puts ("typedef unsigned long int size_t;");
else
if (sizeof (int *) == sizeof (unsigned int))
puts ("typedef unsigned int size_t;");
else
{
fprintf (stderr,
"%s: Can't find a reasonable definition for \"size_t\".\n",
argv[0]);
exit (1);
}
exit (0);
}

View File

@ -1,160 +0,0 @@
/* __gmp_extract_double -- convert from double to array of mp_limb_t.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
#define MP_BASE_AS_DOUBLE (2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))
/* Extract a non-negative double in d. */
int
#if __STDC__
__gmp_extract_double (mp_ptr rp, double d)
#else
__gmp_extract_double (rp, d)
mp_ptr rp;
double d;
#endif
{
long exp;
unsigned sc;
mp_limb_t manh, manl;
/* BUGS
1. Should handle Inf and NaN in IEEE specific code.
2. Handle Inf and NaN also in default code, to avoid hangs.
3. Generalize to handle all BITS_PER_MP_LIMB >= 32.
4. This lits is incomplete and misspelled.
*/
if (d == 0.0)
{
rp[0] = 0;
rp[1] = 0;
#if BITS_PER_MP_LIMB == 32
rp[2] = 0;
#endif
return 0;
}
#if _GMP_IEEE_FLOATS
{
union ieee_double_extract x;
x.d = d;
exp = x.s.exp;
sc = (unsigned) (exp + 2) % BITS_PER_MP_LIMB;
#if BITS_PER_MP_LIMB == 64
manl = (((mp_limb_t) 1 << 63)
| ((mp_limb_t) x.s.manh << 43) | ((mp_limb_t) x.s.manl << 11));
#else
manh = ((mp_limb_t) 1 << 31) | (x.s.manh << 11) | (x.s.manl >> 21);
manl = x.s.manl << 11;
#endif
}
#else
{
/* Unknown (or known to be non-IEEE) double format. */
exp = 0;
if (d >= 1.0)
{
if (d * 0.5 == d)
abort ();
while (d >= 32768.0)
{
d *= (1.0 / 65536.0);
exp += 16;
}
while (d >= 1.0)
{
d *= 0.5;
exp += 1;
}
}
else if (d < 0.5)
{
while (d < (1.0 / 65536.0))
{
d *= 65536.0;
exp -= 16;
}
while (d < 0.5)
{
d *= 2.0;
exp -= 1;
}
}
sc = (unsigned) exp % BITS_PER_MP_LIMB;
d *= MP_BASE_AS_DOUBLE;
#if BITS_PER_MP_LIMB == 64
manl = d;
#else
manh = d;
manl = (d - manh) * MP_BASE_AS_DOUBLE;
#endif
exp += 1022;
}
#endif
exp = (unsigned) (exp + 1) / BITS_PER_MP_LIMB - 1024 / BITS_PER_MP_LIMB + 1;
#if BITS_PER_MP_LIMB == 64
if (sc != 0)
{
rp[1] = manl >> (BITS_PER_MP_LIMB - sc);
rp[0] = manl << sc;
}
else
{
rp[1] = manl;
rp[0] = 0;
}
#else
if (sc != 0)
{
rp[2] = manh >> (BITS_PER_MP_LIMB - sc);
rp[1] = (manl >> (BITS_PER_MP_LIMB - sc)) | (manh << sc);
rp[0] = manl << sc;
}
else
{
rp[2] = manh;
rp[1] = manl;
rp[0] = 0;
}
#endif
return exp;
}

View File

@ -1,367 +0,0 @@
/* Include file for internal GNU MP types and definitions.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
/* When using gcc, make sure to use its builtin alloca. */
#if ! defined (alloca) && defined (__GNUC__)
#define alloca __builtin_alloca
#define HAVE_ALLOCA
#endif
/* When using cc, do whatever necessary to allow use of alloca. For many
machines, this means including alloca.h. IBM's compilers need a #pragma
in "each module that needs to use alloca". */
#if ! defined (alloca)
/* We need lots of variants for MIPS, to cover all versions and perversions
of OSes for MIPS. */
#if defined (__mips) || defined (MIPSEL) || defined (MIPSEB) \
|| defined (_MIPSEL) || defined (_MIPSEB) || defined (__sgi) \
|| defined (__alpha) || defined (__sparc) || defined (sparc) \
|| defined (__ksr__)
#include <alloca.h>
#define HAVE_ALLOCA
#endif
#if defined (_IBMR2)
#pragma alloca
#define HAVE_ALLOCA
#endif
#if defined (__DECC)
#define alloca(x) __ALLOCA(x)
#define HAVE_ALLOCA
#endif
#endif
#if ! defined (HAVE_ALLOCA) || USE_STACK_ALLOC
#include "stack-alloc.h"
#else
#define TMP_DECL(m)
#define TMP_ALLOC(x) alloca(x)
#define TMP_MARK(m)
#define TMP_FREE(m)
#endif
#ifndef NULL
#define NULL ((void *) 0)
#endif
#if ! defined (__GNUC__)
#define inline /* Empty */
#endif
#define ABS(x) (x >= 0 ? x : -x)
#define MIN(l,o) ((l) < (o) ? (l) : (o))
#define MAX(h,i) ((h) > (i) ? (h) : (i))
/* Field access macros. */
#define SIZ(x) ((x)->_mp_size)
#define ABSIZ(x) ABS (SIZ (x))
#define PTR(x) ((x)->_mp_d)
#define EXP(x) ((x)->_mp_exp)
#define PREC(x) ((x)->_mp_prec)
#define ALLOC(x) ((x)->_mp_alloc)
#include "gmp-mparam.h"
/* #include "longlong.h" */
#if defined (__STDC__) || defined (__cplusplus)
void *malloc (size_t);
void *realloc (void *, size_t);
void free (void *);
extern void * (*_mp_allocate_func) (size_t);
extern void * (*_mp_reallocate_func) (void *, size_t, size_t);
extern void (*_mp_free_func) (void *, size_t);
void *_mp_default_allocate (size_t);
void *_mp_default_reallocate (void *, size_t, size_t);
void _mp_default_free (void *, size_t);
#else
#define const /* Empty */
#define signed /* Empty */
void *malloc ();
void *realloc ();
void free ();
extern void * (*_mp_allocate_func) ();
extern void * (*_mp_reallocate_func) ();
extern void (*_mp_free_func) ();
void *_mp_default_allocate ();
void *_mp_default_reallocate ();
void _mp_default_free ();
#endif
/* Copy NLIMBS *limbs* from SRC to DST. */
#define MPN_COPY_INCR(DST, SRC, NLIMBS) \
do { \
mp_size_t __i; \
for (__i = 0; __i < (NLIMBS); __i++) \
(DST)[__i] = (SRC)[__i]; \
} while (0)
#define MPN_COPY_DECR(DST, SRC, NLIMBS) \
do { \
mp_size_t __i; \
for (__i = (NLIMBS) - 1; __i >= 0; __i--) \
(DST)[__i] = (SRC)[__i]; \
} while (0)
#define MPN_COPY MPN_COPY_INCR
/* Zero NLIMBS *limbs* AT DST. */
#define MPN_ZERO(DST, NLIMBS) \
do { \
mp_size_t __i; \
for (__i = 0; __i < (NLIMBS); __i++) \
(DST)[__i] = 0; \
} while (0)
#define MPN_NORMALIZE(DST, NLIMBS) \
do { \
while (NLIMBS > 0) \
{ \
if ((DST)[(NLIMBS) - 1] != 0) \
break; \
NLIMBS--; \
} \
} while (0)
#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
do { \
while (1) \
{ \
if ((DST)[(NLIMBS) - 1] != 0) \
break; \
NLIMBS--; \
} \
} while (0)
/* Initialize the MP_INT X with space for NLIMBS limbs.
X should be a temporary variable, and it will be automatically
cleared out when the running function returns.
We use __x here to make it possible to accept both mpz_ptr and mpz_t
arguments. */
#define MPZ_TMP_INIT(X, NLIMBS) \
do { \
mpz_ptr __x = (X); \
__x->_mp_alloc = (NLIMBS); \
__x->_mp_d = (mp_ptr) TMP_ALLOC ((NLIMBS) * BYTES_PER_MP_LIMB); \
} while (0)
#define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
do { \
if ((size) < KARATSUBA_THRESHOLD) \
impn_mul_n_basecase (prodp, up, vp, size); \
else \
impn_mul_n (prodp, up, vp, size, tspace); \
} while (0);
#define MPN_SQR_N_RECURSE(prodp, up, size, tspace) \
do { \
if ((size) < KARATSUBA_THRESHOLD) \
impn_sqr_n_basecase (prodp, up, size); \
else \
impn_sqr_n (prodp, up, size, tspace); \
} while (0);
/* Structure for conversion between internal binary format and
strings in base 2..36. */
struct bases
{
/* Number of digits in the conversion base that always fits in an mp_limb_t.
For example, for base 10 on a machine where a mp_limb_t has 32 bits this
is 9, since 10**9 is the largest number that fits into a mp_limb_t. */
int chars_per_limb;
/* log(2)/log(conversion_base) */
float chars_per_bit_exactly;
/* base**chars_per_limb, i.e. the biggest number that fits a word, built by
factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base),
i.e. the number of bits used to represent each digit in the base. */
mp_limb_t big_base;
/* A BITS_PER_MP_LIMB bit approximation to 1/big_base, represented as a
fixed-point number. Instead of dividing by big_base an application can
choose to multiply by big_base_inverted. */
mp_limb_t big_base_inverted;
};
extern const struct bases __mp_bases[];
extern mp_size_t __gmp_default_fp_limb_precision;
/* Divide the two-limb number in (NH,,NL) by D, with DI being the largest
limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB).
If this would yield overflow, DI should be the largest possible number
(i.e., only ones). For correct operation, the most significant bit of D
has to be set. Put the quotient in Q and the remainder in R. */
#define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \
do { \
mp_limb_t _q, _ql, _r; \
mp_limb_t _xh, _xl; \
umul_ppmm (_q, _ql, (nh), (di)); \
_q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small */\
umul_ppmm (_xh, _xl, _q, (d)); \
sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
} \
} \
if (_r >= (d)) \
{ \
_r -= (d); \
_q += 1; \
} \
(r) = _r; \
(q) = _q; \
} while (0)
/* Like udiv_qrnnd_preinv, but for for any value D. DNORM is D shifted left
so that its most significant bit is set. LGUP is ceil(log2(D)). */
#define udiv_qrnnd_preinv2gen(q, r, nh, nl, d, di, dnorm, lgup) \
do { \
mp_limb_t n2, n10, n1, nadj, q1; \
mp_limb_t _xh, _xl; \
n2 = ((nh) << (BITS_PER_MP_LIMB - (lgup))) + ((nl) >> 1 >> (l - 1));\
n10 = (nl) << (BITS_PER_MP_LIMB - (lgup)); \
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
nadj = n10 + (n1 & (dnorm)); \
umul_ppmm (_xh, _xl, di, n2 - n1); \
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
q1 = ~(n2 + _xh); \
umul_ppmm (_xh, _xl, q1, d); \
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
_xh -= (d); \
(r) = _xl + ((d) & _xh); \
(q) = _xh - q1; \
} while (0)
/* Exactly like udiv_qrnnd_preinv, but branch-free. It is not clear which
version to use. */
#define udiv_qrnnd_preinv2norm(q, r, nh, nl, d, di) \
do { \
mp_limb_t n2, n10, n1, nadj, q1; \
mp_limb_t _xh, _xl; \
n2 = (nh); \
n10 = (nl); \
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
nadj = n10 + (n1 & (d)); \
umul_ppmm (_xh, _xl, di, n2 - n1); \
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
q1 = ~(n2 + _xh); \
umul_ppmm (_xh, _xl, q1, d); \
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
_xh -= (d); \
(r) = _xl + ((d) & _xh); \
(q) = _xh - q1; \
} while (0)
#if defined (__GNUC__)
/* Define stuff for longlong.h. */
typedef unsigned int UQItype __attribute__ ((mode (QI)));
typedef int SItype __attribute__ ((mode (SI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef int DItype __attribute__ ((mode (DI)));
typedef unsigned int UDItype __attribute__ ((mode (DI)));
#else
typedef unsigned char UQItype;
typedef long SItype;
typedef unsigned long USItype;
#endif
typedef mp_limb_t UWtype;
typedef unsigned int UHWtype;
#define W_TYPE_SIZE BITS_PER_MP_LIMB
/* Internal mpn calls */
#define impn_mul_n_basecase __MPN(impn_mul_n_basecase)
#define impn_mul_n __MPN(impn_mul_n)
#define impn_sqr_n_basecase __MPN(impn_sqr_n_basecase)
#define impn_sqr_n __MPN(impn_sqr_n)
/* Define ieee_double_extract and _GMP_IEEE_FLOATS. */
#if defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__) \
|| defined (__alpha) \
|| (defined (__arm__) && defined (__ARMWEL__)) \
|| defined (__clipper__) \
|| defined (__cris) \
|| defined (__i386__) \
|| defined (__i860__) \
|| defined (__i960__) \
|| defined (MIPSEL) || defined (_MIPSEL) \
|| defined (__ns32000__) \
|| defined (__WINNT) || defined (_WIN32)
#define _GMP_IEEE_FLOATS 1
union ieee_double_extract
{
struct
{
unsigned int manl:32;
unsigned int manh:20;
unsigned int exp:11;
unsigned int sig:1;
} s;
double d;
};
#else /* Need this as an #else since the tests aren't made exclusive. */
#if defined (_BIG_ENDIAN) \
|| defined (__a29k__) || defined (_AM29K) \
|| defined (__arm__) \
|| (defined (__convex__) && defined (_IEEE_FLOAT_)) \
|| defined (__i370__) || defined (__mvs__) \
|| defined (__mc68000__) || defined (__mc68020__) || defined (__NeXT__)\
|| defined(mc68020) \
|| defined (__m88000__) \
|| defined (MIPSEB) || defined (_MIPSEB) \
|| defined (__hppa) \
|| defined (__pyr__) \
|| defined (__ibm032__) \
|| defined (_IBMR2) || defined (_ARCH_PPC) \
|| defined (__sh__) \
|| defined (__sparc) || defined (sparc) \
|| defined (__we32k__)
#define _GMP_IEEE_FLOATS 1
union ieee_double_extract
{
struct
{
unsigned int sig:1;
unsigned int exp:11;
unsigned int manh:20;
unsigned int manl:32;
} s;
double d;
};
#endif
#endif
#define MP_BASE_AS_DOUBLE (2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))
#if BITS_PER_MP_LIMB == 64
#define LIMBS_PER_DOUBLE 2
#else
#define LIMBS_PER_DOUBLE 3
#endif
double __gmp_scale2 _PROTO ((double, int));
int __gmp_extract_double _PROTO((mp_ptr, double));

View File

@ -1,632 +0,0 @@
/* gmp.h -- Definitions for GNU multiple precision functions.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef __GMP_H__
#ifndef __GNU_MP__
#define __GNU_MP__ 2
#define __need_size_t
#include <stddef.h>
#undef __need_size_t
#if defined (__STDC__) || defined (__cplusplus)
#define __gmp_const const
#else
#define __gmp_const
#endif
#if defined (__GNUC__)
#define __gmp_inline __inline__
#else
#define __gmp_inline
#endif
#ifndef _EXTERN_INLINE
#ifdef __GNUC__
#define _EXTERN_INLINE extern __inline__
#else
#define _EXTERN_INLINE static
#endif
#endif
#ifdef _SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef mp_limb_t * mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
typedef long int mp_size_t;
typedef long int mp_exp_t;
#ifndef __MP_SMALL__
typedef struct
{
int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#else
typedef struct
{
short int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
short int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#endif
#endif /* __GNU_MP__ */
/* User-visible types. */
typedef __mpz_struct MP_INT;
typedef __mpz_struct mpz_t[1];
/* Structure for rational numbers. Zero is represented as 0/any, i.e.
the denominator is ignored. Negative numbers have the sign in
the numerator. */
typedef struct
{
__mpz_struct _mp_num;
__mpz_struct _mp_den;
#if 0
int _mp_num_alloc; /* Number of limbs allocated
for the numerator. */
int _mp_num_size; /* The absolute value of this field is the
length of the numerator; the sign is the
sign of the entire rational number. */
mp_ptr _mp_num; /* Pointer to the numerator limbs. */
int _mp_den_alloc; /* Number of limbs allocated
for the denominator. */
int _mp_den_size; /* Length of the denominator. (This field
should always be positive.) */
mp_ptr _mp_den; /* Pointer to the denominator limbs. */
#endif
} __mpq_struct;
typedef __mpq_struct MP_RAT;
typedef __mpq_struct mpq_t[1];
typedef struct
{
int _mp_prec; /* Max precision, in number of `mp_limb_t's.
Set by mpf_init and modified by
mpf_set_prec. The area pointed to
by the `d' field contains `prec' + 1
limbs. */
int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpf_struct;
/* typedef __mpf_struct MP_FLOAT; */
typedef __mpf_struct mpf_t[1];
/* Types for function declarations in gmp files. */
/* ??? Should not pollute user name space with these ??? */
typedef __gmp_const __mpz_struct *mpz_srcptr;
typedef __mpz_struct *mpz_ptr;
typedef __gmp_const __mpf_struct *mpf_srcptr;
typedef __mpf_struct *mpf_ptr;
typedef __gmp_const __mpq_struct *mpq_srcptr;
typedef __mpq_struct *mpq_ptr;
#ifndef _PROTO
#if defined (__STDC__) || defined (__cplusplus)
#define _PROTO(x) x
#else
#define _PROTO(x) ()
#endif
#endif
#ifndef __MPN
#if defined (__STDC__) || defined (__cplusplus)
#define __MPN(x) __mpn_##x
#else
#define __MPN(x) __mpn_/**/x
#endif
#endif
#if defined (FILE) || defined (H_STDIO) || defined (_H_STDIO) \
|| defined (_STDIO_H) || defined (_STDIO_H_) || defined (__STDIO_H__) \
|| defined (_STDIO_INCLUDED)
#define _GMP_H_HAVE_FILE 1
#endif
void mp_set_memory_functions _PROTO ((void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t)));
extern __gmp_const int mp_bits_per_limb;
/**************** Integer (i.e. Z) routines. ****************/
#if defined (__cplusplus)
extern "C" {
#endif
void *_mpz_realloc _PROTO ((mpz_ptr, mp_size_t));
void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_add _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_and _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_array_init _PROTO ((mpz_ptr, mp_size_t, mp_size_t));
void mpz_cdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_cdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_cdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_clear _PROTO ((mpz_ptr));
void mpz_clrbit _PROTO ((mpz_ptr, unsigned long int));
int mpz_cmp _PROTO ((mpz_srcptr, mpz_srcptr));
int mpz_cmp_si _PROTO ((mpz_srcptr, signed long int));
int mpz_cmp_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_com _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_divexact _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fac_ui _PROTO ((mpz_ptr, unsigned long int));
void mpz_fdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_fdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_fdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
unsigned long int mpz_fdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
void mpz_gcd _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
double mpz_get_d _PROTO ((mpz_srcptr));
/* signed */ long int mpz_get_si _PROTO ((mpz_srcptr));
char *mpz_get_str _PROTO ((char *, int, mpz_srcptr));
unsigned long int mpz_get_ui _PROTO ((mpz_srcptr));
mp_limb_t mpz_getlimbn _PROTO ((mpz_srcptr, mp_size_t));
unsigned long int mpz_hamdist _PROTO ((mpz_srcptr, mpz_srcptr));
void mpz_init _PROTO ((mpz_ptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpz_inp_binary _PROTO ((mpz_ptr, FILE *));
size_t mpz_inp_raw _PROTO ((mpz_ptr, FILE *));
size_t mpz_inp_str _PROTO ((mpz_ptr, FILE *, int));
#endif
void mpz_init_set _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_init_set_d _PROTO ((mpz_ptr, double));
void mpz_init_set_si _PROTO ((mpz_ptr, signed long int));
int mpz_init_set_str _PROTO ((mpz_ptr, const char *, int));
void mpz_init_set_ui _PROTO ((mpz_ptr, unsigned long int));
int mpz_invert _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_ior _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
int mpz_jacobi _PROTO ((mpz_srcptr, mpz_srcptr));
int mpz_legendre _PROTO ((mpz_srcptr, mpz_srcptr));
void mpz_mod _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_mul _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpz_out_binary _PROTO ((FILE *, mpz_srcptr));
size_t mpz_out_raw _PROTO ((FILE *, mpz_srcptr));
size_t mpz_out_str _PROTO ((FILE *, int, mpz_srcptr));
#endif
int mpz_perfect_square_p _PROTO ((mpz_srcptr));
unsigned long int mpz_popcount _PROTO ((mpz_srcptr));
void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr));
void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr));
int mpz_probab_prime_p _PROTO ((mpz_srcptr, int));
void mpz_random _PROTO ((mpz_ptr, mp_size_t));
void mpz_random2 _PROTO ((mpz_ptr, mp_size_t));
unsigned long int mpz_scan0 _PROTO ((mpz_srcptr, unsigned long int));
unsigned long int mpz_scan1 _PROTO ((mpz_srcptr, unsigned long int));
void mpz_set _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_set_d _PROTO ((mpz_ptr, double));
void mpz_set_f _PROTO ((mpz_ptr, mpf_srcptr));
void mpz_set_q _PROTO ((mpz_ptr, mpq_srcptr));
void mpz_set_si _PROTO ((mpz_ptr, signed long int));
int mpz_set_str _PROTO ((mpz_ptr, const char *, int));
void mpz_set_ui _PROTO ((mpz_ptr, unsigned long int));
void mpz_setbit _PROTO ((mpz_ptr, unsigned long int));
size_t mpz_size _PROTO ((mpz_srcptr));
size_t mpz_sizeinbase _PROTO ((mpz_srcptr, int));
void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr));
void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));
void mpz_sub _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
void mpz_tdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
void mpz_ui_pow_ui _PROTO ((mpz_ptr, unsigned long int, unsigned long int));
/**************** Rational (i.e. Q) routines. ****************/
void mpq_init _PROTO ((mpq_ptr));
void mpq_clear _PROTO ((mpq_ptr));
void mpq_set _PROTO ((mpq_ptr, mpq_srcptr));
void mpq_set_ui _PROTO ((mpq_ptr, unsigned long int, unsigned long int));
void mpq_set_si _PROTO ((mpq_ptr, signed long int, unsigned long int));
void mpq_set_z _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_add _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_sub _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_mul _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_div _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
void mpq_neg _PROTO ((mpq_ptr, mpq_srcptr));
int mpq_cmp _PROTO ((mpq_srcptr, mpq_srcptr));
int mpq_cmp_ui _PROTO ((mpq_srcptr, unsigned long int, unsigned long int));
int mpq_equal _PROTO ((mpq_srcptr, mpq_srcptr));
void mpq_inv _PROTO ((mpq_ptr, mpq_srcptr));
void mpq_set_num _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_set_den _PROTO ((mpq_ptr, mpz_srcptr));
void mpq_get_num _PROTO ((mpz_ptr, mpq_srcptr));
void mpq_get_den _PROTO ((mpz_ptr, mpq_srcptr));
double mpq_get_d _PROTO ((mpq_srcptr));
void mpq_canonicalize _PROTO ((mpq_ptr));
/**************** Float (i.e. F) routines. ****************/
void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_add _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_add_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_clear _PROTO ((mpf_ptr));
int mpf_cmp _PROTO ((mpf_srcptr, mpf_srcptr));
int mpf_cmp_si _PROTO ((mpf_srcptr, signed long int));
int mpf_cmp_ui _PROTO ((mpf_srcptr, unsigned long int));
void mpf_div _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_div_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_dump _PROTO ((mpf_srcptr));
int mpf_eq _PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int));
double mpf_get_d _PROTO ((mpf_srcptr));
unsigned long int mpf_get_prec _PROTO ((mpf_srcptr));
char *mpf_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr));
void mpf_init _PROTO ((mpf_ptr));
void mpf_init2 _PROTO ((mpf_ptr, unsigned long int));
#ifdef _GMP_H_HAVE_FILE
size_t mpf_inp_str _PROTO ((mpf_ptr, FILE *, int));
#endif
void mpf_init_set _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_init_set_d _PROTO ((mpf_ptr, double));
void mpf_init_set_si _PROTO ((mpf_ptr, signed long int));
int mpf_init_set_str _PROTO ((mpf_ptr, const char *, int));
void mpf_init_set_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_mul _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_mul_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
#ifdef _GMP_H_HAVE_FILE
size_t mpf_out_str _PROTO ((FILE *, int, size_t, mpf_srcptr));
#endif
void mpf_random2 _PROTO ((mpf_ptr, mp_size_t, mp_exp_t));
void mpf_reldiff _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_set _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_set_d _PROTO ((mpf_ptr, double));
void mpf_set_default_prec _PROTO ((unsigned long int));
void mpf_set_prec _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_prec_raw _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_q _PROTO ((mpf_ptr, mpq_srcptr));
void mpf_set_si _PROTO ((mpf_ptr, signed long int));
int mpf_set_str _PROTO ((mpf_ptr, const char *, int));
void mpf_set_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_set_z _PROTO ((mpf_ptr, mpz_srcptr));
size_t mpf_size _PROTO ((mpf_srcptr));
void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
void mpf_sqrt_ui _PROTO ((mpf_ptr, unsigned long int));
void mpf_sub _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
void mpf_sub_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
void mpf_ui_div _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
#if defined (__cplusplus)
}
#endif
/************ Low level positive-integer (i.e. N) routines. ************/
/* This is ugly, but we need to make usr calls reach the prefixed function. */
#define mpn_add __MPN(add)
#define mpn_add_1 __MPN(add_1)
#define mpn_add_n __MPN(add_n)
#define mpn_addmul_1 __MPN(addmul_1)
#define mpn_bdivmod __MPN(bdivmod)
#define mpn_cmp __MPN(cmp)
#define mpn_divmod_1 __MPN(divmod_1)
#define mpn_divrem __MPN(divrem)
#define mpn_divrem_1 __MPN(divrem_1)
#define mpn_dump __MPN(dump)
#define mpn_gcd __MPN(gcd)
#define mpn_gcd_1 __MPN(gcd_1)
#define mpn_gcdext __MPN(gcdext)
#define mpn_get_str __MPN(get_str)
#define mpn_hamdist __MPN(hamdist)
#define mpn_lshift __MPN(lshift)
#define mpn_mod_1 __MPN(mod_1)
#define mpn_mul __MPN(mul)
#define mpn_mul_1 __MPN(mul_1)
#define mpn_mul_n __MPN(mul_n)
#define mpn_perfect_square_p __MPN(perfect_square_p)
#define mpn_popcount __MPN(popcount)
#define mpn_preinv_mod_1 __MPN(preinv_mod_1)
#define mpn_random2 __MPN(random2)
#define mpn_rshift __MPN(rshift)
#define mpn_scan0 __MPN(scan0)
#define mpn_scan1 __MPN(scan1)
#define mpn_set_str __MPN(set_str)
#define mpn_sqrtrem __MPN(sqrtrem)
#define mpn_sub __MPN(sub)
#define mpn_sub_1 __MPN(sub_1)
#define mpn_sub_n __MPN(sub_n)
#define mpn_submul_1 __MPN(submul_1)
#define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv)
#if defined (__cplusplus)
extern "C" {
#endif
mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
#if defined (__cplusplus)
}
#endif
#if defined (__GNUC__) || defined (_FORCE_INLINES)
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_add_1 (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_limb_t s2_limb)
#else
mpn_add_1 (res_ptr, s1_ptr, s1_size, s2_limb)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_limb_t s2_limb;
#endif
{
register mp_limb_t x;
x = *s1_ptr++;
s2_limb = x + s2_limb;
*res_ptr++ = s2_limb;
if (s2_limb < x)
{
while (--s1_size != 0)
{
x = *s1_ptr++ + 1;
*res_ptr++ = x;
if (x != 0)
goto fin;
}
return 1;
}
fin:
if (res_ptr != s1_ptr)
{
mp_size_t i;
for (i = 0; i < s1_size - 1; i++)
res_ptr[i] = s1_ptr[i];
}
return 0;
}
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_add (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_srcptr s2_ptr,
register mp_size_t s2_size)
#else
mpn_add (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_srcptr s2_ptr;
register mp_size_t s2_size;
#endif
{
mp_limb_t cy_limb = 0;
if (s2_size != 0)
cy_limb = mpn_add_n (res_ptr, s1_ptr, s2_ptr, s2_size);
if (s1_size - s2_size != 0)
cy_limb = mpn_add_1 (res_ptr + s2_size,
s1_ptr + s2_size,
s1_size - s2_size,
cy_limb);
return cy_limb;
}
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_sub_1 (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_limb_t s2_limb)
#else
mpn_sub_1 (res_ptr, s1_ptr, s1_size, s2_limb)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_limb_t s2_limb;
#endif
{
register mp_limb_t x;
x = *s1_ptr++;
s2_limb = x - s2_limb;
*res_ptr++ = s2_limb;
if (s2_limb > x)
{
while (--s1_size != 0)
{
x = *s1_ptr++;
*res_ptr++ = x - 1;
if (x != 0)
goto fin;
}
return 1;
}
fin:
if (res_ptr != s1_ptr)
{
mp_size_t i;
for (i = 0; i < s1_size - 1; i++)
res_ptr[i] = s1_ptr[i];
}
return 0;
}
_EXTERN_INLINE mp_limb_t
#if defined (__STDC__) || defined (__cplusplus)
mpn_sub (register mp_ptr res_ptr,
register mp_srcptr s1_ptr,
register mp_size_t s1_size,
register mp_srcptr s2_ptr,
register mp_size_t s2_size)
#else
mpn_sub (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
register mp_ptr res_ptr;
register mp_srcptr s1_ptr;
register mp_size_t s1_size;
register mp_srcptr s2_ptr;
register mp_size_t s2_size;
#endif
{
mp_limb_t cy_limb = 0;
if (s2_size != 0)
cy_limb = mpn_sub_n (res_ptr, s1_ptr, s2_ptr, s2_size);
if (s1_size - s2_size != 0)
cy_limb = mpn_sub_1 (res_ptr + s2_size,
s1_ptr + s2_size,
s1_size - s2_size,
cy_limb);
return cy_limb;
}
#endif /* __GNUC__ */
/* Allow faster testing for negative, zero, and positive. */
#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
/* Allow direct user access to numerator and denominator of a mpq_t object. */
#define mpq_numref(Q) (&((Q)->_mp_num))
#define mpq_denref(Q) (&((Q)->_mp_den))
/* When using GCC, optimize certain common comparisons. */
#if defined (__GNUC__)
#define mpz_cmp_ui(Z,UI) \
(__builtin_constant_p (UI) && (UI) == 0 \
? mpz_sgn (Z) : mpz_cmp_ui (Z,UI))
#define mpz_cmp_si(Z,UI) \
(__builtin_constant_p (UI) && (UI) == 0 ? mpz_sgn (Z) \
: __builtin_constant_p (UI) && (UI) > 0 ? mpz_cmp_ui (Z,UI) \
: mpz_cmp_si (Z,UI))
#define mpq_cmp_ui(Q,NUI,DUI) \
(__builtin_constant_p (NUI) && (NUI) == 0 \
? mpq_sgn (Q) : mpq_cmp_ui (Q,NUI,DUI))
#endif
#define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
#if 0
#define mpn_divmod_1(qp,np,nsize,dlimb) mpn_divrem_1 (qp,0,np,nsize,dlimb)
#endif
/* Compatibility with GMP 1. */
#define mpz_mdiv mpz_fdiv_q
#define mpz_mdivmod mpz_fdiv_qr
#define mpz_mmod mpz_fdiv_r
#define mpz_mdiv_ui mpz_fdiv_q_ui
#define mpz_mdivmod_ui(q,r,n,d) \
((r == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
#define mpz_mmod_ui(r,n,d) \
((r == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
/* Useful synonyms, but not quite compatible with GMP 1. */
#define mpz_div mpz_fdiv_q
#define mpz_divmod mpz_fdiv_qr
#define mpz_div_ui mpz_fdiv_q_ui
#define mpz_divmod_ui mpz_fdiv_qr_ui
#define mpz_mod_ui mpz_fdiv_r_ui
#define mpz_div_2exp mpz_fdiv_q_2exp
#define mpz_mod_2exp mpz_fdiv_r_2exp
#define __GNU_MP_VERSION 2
#define __GNU_MP_VERSION_MINOR 0
#define __GMP_H__
#endif /* __GMP_H__ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,259 +0,0 @@
This is Info file gmp.info, produced by Makeinfo-1.64 from the input
file gmp.texi.
START-INFO-DIR-ENTRY
* gmp: (gmp.info). GNU Multiple Precision Arithmetic Library.
END-INFO-DIR-ENTRY
This file documents GNU MP, a library for arbitrary-precision
arithmetic.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation,
Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.

File: gmp.info, Node: Function Index, Up: Top
Function and Type Index
***********************
* Menu:
* mp_limb_t: MP Basics.
* mpf_t: MP Basics.
* mpq_t: MP Basics.
* mpz_t: MP Basics.
* __GNU_MP_VERSION: MP Basics.
* __GNU_MP_VERSION_MINOR: MP Basics.
* _mpz_realloc: Initializing Integers.
* allocate_function: Custom Allocation.
* deallocate_function: Custom Allocation.
* gcd: BSD Compatible Functions.
* itom: BSD Compatible Functions.
* madd: BSD Compatible Functions.
* mcmp: BSD Compatible Functions.
* mdiv: BSD Compatible Functions.
* mfree: BSD Compatible Functions.
* min: BSD Compatible Functions.
* mout: BSD Compatible Functions.
* move: BSD Compatible Functions.
* mp_set_memory_functions: Custom Allocation.
* mpf_abs: Float Arithmetic.
* mpf_add: Float Arithmetic.
* mpf_add_ui: Float Arithmetic.
* mpf_clear: Initializing Floats.
* mpf_cmp: Float Comparison.
* mpf_cmp_si: Float Comparison.
* mpf_cmp_ui: Float Comparison.
* mpf_div: Float Arithmetic.
* mpf_div_2exp: Float Arithmetic.
* mpf_div_ui: Float Arithmetic.
* mpf_eq: Float Comparison.
* mpf_get_d: Converting Floats.
* mpf_get_prec: Initializing Floats.
* mpf_get_str: Converting Floats.
* mpf_init: Initializing Floats.
* mpf_init2: Initializing Floats.
* mpf_init_set: Simultaneous Float Init & Assign.
* mpf_init_set_d: Simultaneous Float Init & Assign.
* mpf_init_set_si: Simultaneous Float Init & Assign.
* mpf_init_set_str: Simultaneous Float Init & Assign.
* mpf_init_set_ui: Simultaneous Float Init & Assign.
* mpf_inp_str: I/O of Floats.
* mpf_mul: Float Arithmetic.
* mpf_mul_2exp: Float Arithmetic.
* mpf_mul_ui: Float Arithmetic.
* mpf_neg: Float Arithmetic.
* mpf_out_str: I/O of Floats.
* mpf_random2: Miscellaneous Float Functions.
* mpf_reldiff: Float Comparison.
* mpf_set: Assigning Floats.
* mpf_set_d: Assigning Floats.
* mpf_set_default_prec: Initializing Floats.
* mpf_set_prec: Initializing Floats.
* mpf_set_prec_raw: Initializing Floats.
* mpf_set_q: Assigning Floats.
* mpf_set_si: Assigning Floats.
* mpf_set_str: Assigning Floats.
* mpf_set_ui: Assigning Floats.
* mpf_set_z: Assigning Floats.
* mpf_sgn: Float Comparison.
* mpf_sqrt: Float Arithmetic.
* mpf_sqrt_ui: Float Arithmetic.
* mpf_sub: Float Arithmetic.
* mpf_sub_ui: Float Arithmetic.
* mpf_ui_div: Float Arithmetic.
* mpf_ui_sub: Float Arithmetic.
* mpn_add: Low-level Functions.
* mpn_add_1: Low-level Functions.
* mpn_add_n: Low-level Functions.
* mpn_addmul_1: Low-level Functions.
* mpn_bdivmod: Low-level Functions.
* mpn_cmp: Low-level Functions.
* mpn_divmod: Low-level Functions.
* mpn_divmod_1: Low-level Functions.
* mpn_divrem: Low-level Functions.
* mpn_divrem_1: Low-level Functions.
* mpn_gcd: Low-level Functions.
* mpn_gcd_1: Low-level Functions.
* mpn_gcdext: Low-level Functions.
* mpn_get_str: Low-level Functions.
* mpn_hamdist: Low-level Functions.
* mpn_lshift: Low-level Functions.
* mpn_mod_1: Low-level Functions.
* mpn_mul: Low-level Functions.
* mpn_mul_1: Low-level Functions.
* mpn_mul_n: Low-level Functions.
* mpn_perfect_square_p: Low-level Functions.
* mpn_popcount: Low-level Functions.
* mpn_preinv_mod_1: Low-level Functions.
* mpn_random2: Low-level Functions.
* mpn_rshift: Low-level Functions.
* mpn_scan0: Low-level Functions.
* mpn_scan1: Low-level Functions.
* mpn_set_str: Low-level Functions.
* mpn_sqrtrem: Low-level Functions.
* mpn_sub: Low-level Functions.
* mpn_sub_1: Low-level Functions.
* mpn_sub_n: Low-level Functions.
* mpn_submul_1: Low-level Functions.
* mpq_add: Assigning Rationals.
* mpq_canonicalize: Rational Number Functions.
* mpq_clear: Initializing Rationals.
* mpq_cmp: Comparing Rationals.
* mpq_cmp_ui: Comparing Rationals.
* mpq_denref: Applying Integer Functions.
* mpq_div: Assigning Rationals.
* mpq_equal: Comparing Rationals.
* mpq_get_d: Miscellaneous Rational Functions.
* mpq_get_den: Miscellaneous Rational Functions.
* mpq_get_num: Miscellaneous Rational Functions.
* mpq_init: Initializing Rationals.
* mpq_inv: Assigning Rationals.
* mpq_mul: Assigning Rationals.
* mpq_neg: Assigning Rationals.
* mpq_numref: Applying Integer Functions.
* mpq_set: Initializing Rationals.
* mpq_set_den: Miscellaneous Rational Functions.
* mpq_set_num: Miscellaneous Rational Functions.
* mpq_set_si: Initializing Rationals.
* mpq_set_ui: Initializing Rationals.
* mpq_set_z: Initializing Rationals.
* mpq_sgn: Comparing Rationals.
* mpq_sub: Assigning Rationals.
* mpz_abs: Integer Arithmetic.
* mpz_add: Integer Arithmetic.
* mpz_add_ui: Integer Arithmetic.
* mpz_and: Integer Logic and Bit Fiddling.
* mpz_array_init: Initializing Integers.
* mpz_cdiv_q: Integer Arithmetic.
* mpz_cdiv_q_ui: Integer Arithmetic.
* mpz_cdiv_qr: Integer Arithmetic.
* mpz_cdiv_qr_ui: Integer Arithmetic.
* mpz_cdiv_r: Integer Arithmetic.
* mpz_cdiv_r_ui: Integer Arithmetic.
* mpz_cdiv_ui: Integer Arithmetic.
* mpz_clear: Initializing Integers.
* mpz_clrbit: Integer Logic and Bit Fiddling.
* mpz_cmp: Comparison Functions.
* mpz_cmp_si: Comparison Functions.
* mpz_cmp_ui: Comparison Functions.
* mpz_com: Integer Logic and Bit Fiddling.
* mpz_divexact: Integer Arithmetic.
* mpz_fac_ui: Integer Arithmetic.
* mpz_fdiv_q: Integer Arithmetic.
* mpz_fdiv_q_2exp: Integer Arithmetic.
* mpz_fdiv_q_ui: Integer Arithmetic.
* mpz_fdiv_qr: Integer Arithmetic.
* mpz_fdiv_qr_ui: Integer Arithmetic.
* mpz_fdiv_r: Integer Arithmetic.
* mpz_fdiv_r_2exp: Integer Arithmetic.
* mpz_fdiv_r_ui: Integer Arithmetic.
* mpz_fdiv_ui: Integer Arithmetic.
* mpz_gcd: Integer Arithmetic.
* mpz_gcd_ui: Integer Arithmetic.
* mpz_gcdext: Integer Arithmetic.
* mpz_get_d: Converting Integers.
* mpz_get_si: Converting Integers.
* mpz_get_str: Converting Integers.
* mpz_get_ui: Converting Integers.
* mpz_hamdist: Integer Logic and Bit Fiddling.
* mpz_init: Initializing Integers.
* mpz_init_set: Simultaneous Integer Init & Assign.
* mpz_init_set_d: Simultaneous Integer Init & Assign.
* mpz_init_set_si: Simultaneous Integer Init & Assign.
* mpz_init_set_str: Simultaneous Integer Init & Assign.
* mpz_init_set_ui: Simultaneous Integer Init & Assign.
* mpz_inp_raw: I/O of Integers.
* mpz_inp_str: I/O of Integers.
* mpz_invert: Integer Arithmetic.
* mpz_ior: Integer Logic and Bit Fiddling.
* mpz_jacobi: Integer Arithmetic.
* mpz_legendre: Integer Arithmetic.
* mpz_mod: Integer Arithmetic.
* mpz_mod_ui: Integer Arithmetic.
* mpz_mul: Integer Arithmetic.
* mpz_mul_2exp: Integer Arithmetic.
* mpz_mul_ui: Integer Arithmetic.
* mpz_neg: Integer Arithmetic.
* mpz_out_raw: I/O of Integers.
* mpz_out_str: I/O of Integers.
* mpz_perfect_square_p: Integer Arithmetic.
* mpz_popcount: Integer Logic and Bit Fiddling.
* mpz_pow_ui: Integer Arithmetic.
* mpz_powm: Integer Arithmetic.
* mpz_powm_ui: Integer Arithmetic.
* mpz_probab_prime_p: Integer Arithmetic.
* mpz_random: Miscellaneous Integer Functions.
* mpz_random2: Miscellaneous Integer Functions.
* mpz_scan0: Integer Logic and Bit Fiddling.
* mpz_scan1: Integer Logic and Bit Fiddling.
* mpz_set: Assigning Integers.
* mpz_set_d: Assigning Integers.
* mpz_set_f: Assigning Integers.
* mpz_set_q: Assigning Integers.
* mpz_set_si: Assigning Integers.
* mpz_set_str: Assigning Integers.
* mpz_set_ui: Assigning Integers.
* mpz_setbit: Integer Logic and Bit Fiddling.
* mpz_sgn: Comparison Functions.
* mpz_size: Miscellaneous Integer Functions.
* mpz_sizeinbase: Miscellaneous Integer Functions.
* mpz_sqrt: Integer Arithmetic.
* mpz_sqrtrem: Integer Arithmetic.
* mpz_sub: Integer Arithmetic.
* mpz_sub_ui: Integer Arithmetic.
* mpz_tdiv_q: Integer Arithmetic.
* mpz_tdiv_q_2exp: Integer Arithmetic.
* mpz_tdiv_q_ui: Integer Arithmetic.
* mpz_tdiv_qr: Integer Arithmetic.
* mpz_tdiv_qr_ui: Integer Arithmetic.
* mpz_tdiv_r: Integer Arithmetic.
* mpz_tdiv_r_2exp: Integer Arithmetic.
* mpz_tdiv_r_ui: Integer Arithmetic.
* mpz_ui_pow_ui: Integer Arithmetic.
* msqrt: BSD Compatible Functions.
* msub: BSD Compatible Functions.
* mtox: BSD Compatible Functions.
* mult: BSD Compatible Functions.
* pow: BSD Compatible Functions.
* reallocate_function: Custom Allocation.
* rpow: BSD Compatible Functions.
* sdiv: BSD Compatible Functions.
* xtom: BSD Compatible Functions.

File diff suppressed because it is too large Load Diff

View File

@ -1,70 +0,0 @@
/* __gmp_insert_double -- convert from array of mp_limb_t to double.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifdef XDEBUG
#undef _GMP_IEEE_FLOATS
#endif
#ifndef _GMP_IEEE_FLOATS
#define _GMP_IEEE_FLOATS 0
#endif
double
#if __STDC__
__gmp_scale2 (double d, int exp)
#else
__gmp_scale2 (d, exp)
double d;
int exp;
#endif
{
#if _GMP_IEEE_FLOATS
{
union ieee_double_extract x;
x.d = d;
x.s.exp += exp;
return x.d;
}
#else
{
double factor, r;
factor = 2.0;
if (exp < 0)
{
factor = 0.5;
exp = -exp;
}
r = d;
while (exp != 0)
{
if ((exp & 1) != 0)
r *= factor;
factor *= factor;
exp >>= 1;
}
return r;
}
#endif
}

View File

@ -1,238 +0,0 @@
#! /bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
#
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

View File

@ -1,53 +0,0 @@
/* itom -- BSD compatible allocate and initiate a MINT.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
MINT *
#ifdef __STDC__
itom (signed short int n)
#else
itom (n)
short int n;
#endif
{
MINT *x;
mp_ptr xp;
x = (MINT *) (*_mp_allocate_func) (sizeof (MINT));
x->alloc = 1;
x->d = xp = (mp_ptr) (*_mp_allocate_func) (x->alloc * BYTES_PER_MP_LIMB);
if (n > 0)
{
x->size = 1;
xp[0] = n;
}
else if (n < 0)
{
x->size = -1;
xp[0] = -n;
}
else
x->size = 0;
return x;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,315 +0,0 @@
cd mpn
copy msdos\asm-synt.h asm-synt.h
copy bsd.h sysdep.h
copy generic\inlines.c inlines.c
copy x86\pentium\add_n.S add_n.S
copy x86\pentium\addmul_1.S addmul_1.S
copy generic\cmp.c cmp.c
copy generic\divmod_1.c divmod_1.c
copy generic\divrem.c divrem.c
copy generic\divrem_1.c divrem_1.c
copy generic\dump.c dump.c
copy x86\pentium\lshift.S lshift.S
copy generic\mod_1.c mod_1.c
copy generic\mul.c mul.c
copy x86\pentium\mul_1.S mul_1.S
copy generic\mul_n.c mul_n.c
copy generic\random2.c random2.c
copy x86\pentium\rshift.S rshift.S
copy generic\sqrtrem.c sqrtrem.c
copy x86\pentium\sub_n.S sub_n.S
copy x86\pentium\submul_1.S submul_1.S
copy generic\get_str.c get_str.c
copy generic\set_str.c set_str.c
copy generic\scan0.c scan0.c
copy generic\scan1.c scan1.c
copy generic\popcount.c popcount.c
copy generic\hamdist.c hamdist.c
copy generic\gcd_1.c gcd_1.c
copy generic\pre_mod_1.c pre_mod_1.c
copy generic\perfsqr.c perfsqr.c
copy generic\bdivmod.c bdivmod.c
copy generic\gcd.c gcd.c
copy generic\gcdext.c gcdext.c
copy x86\gmp-mpar.h gmp-mpar.h
cd ..
cd mpbsd
copy ..\mpz\add.c add.c
copy ..\mpz\cmp.c cmp.c
copy ..\mpz\gcd.c gcd.c
copy ..\mpz\mul.c mul.c
copy ..\mpz\pow_ui.c pow_ui.c
copy ..\mpz\powm.c powm.c
copy ..\mpz\sqrtrem.c sqrtrem.c
copy ..\mpz\sub.c sub.c
cd ..
cd mpn
gcc -c -I. -I.. -g -O mp_bases.c
gcc -c -I. -I.. -g -O inlines.c
gcc -E -I. -I.. -g -O add_n.S | grep -v '^#' >tmp-add_n.s
gcc -c tmp-add_n.s -o add_n.o
del tmp-add_n.s
gcc -E -I. -I.. -g -O addmul_1.S | grep -v '^#' >tmp-addmul_1.s
gcc -c tmp-addmul_1.s -o addmul_1.o
del tmp-addmul_1.s
gcc -c -I. -I.. -g -O cmp.c
gcc -c -I. -I.. -g -O divmod_1.c
gcc -c -I. -I.. -g -O divrem.c
gcc -c -I. -I.. -g -O divrem_1.c
gcc -c -I. -I.. -g -O dump.c
gcc -E -I. -I.. -g -O lshift.S | grep -v '^#' >tmp-lshift.s
gcc -c tmp-lshift.s -o lshift.o
del tmp-lshift.s
gcc -c -I. -I.. -g -O mod_1.c
gcc -c -I. -I.. -g -O mul.c
gcc -E -I. -I.. -g -O mul_1.S | grep -v '^#' >tmp-mul_1.s
gcc -c tmp-mul_1.s -o mul_1.o
del tmp-mul_1.s
gcc -c -I. -I.. -g -O mul_n.c
gcc -c -I. -I.. -g -O random2.c
gcc -E -I. -I.. -g -O rshift.S | grep -v '^#' >tmp-rshift.s
gcc -c tmp-rshift.s -o rshift.o
del tmp-rshift.s
gcc -c -I. -I.. -g -O sqrtrem.c
gcc -E -I. -I.. -g -O sub_n.S | grep -v '^#' >tmp-sub_n.s
gcc -c tmp-sub_n.s -o sub_n.o
del tmp-sub_n.s
gcc -E -I. -I.. -g -O submul_1.S | grep -v '^#' >tmp-submul_1.s
gcc -c tmp-submul_1.s -o submul_1.o
del tmp-submul_1.s
gcc -c -I. -I.. -g -O get_str.c
gcc -c -I. -I.. -g -O set_str.c
gcc -c -I. -I.. -g -O scan0.c
gcc -c -I. -I.. -g -O scan1.c
gcc -c -I. -I.. -g -O popcount.c
gcc -c -I. -I.. -g -O hamdist.c
gcc -c -I. -I.. -g -O gcd_1.c
gcc -c -I. -I.. -g -O pre_mod_1.c
gcc -c -I. -I.. -g -O perfsqr.c
gcc -c -I. -I.. -g -O bdivmod.c
gcc -c -I. -I.. -g -O gcd.c
gcc -c -I. -I.. -g -O gcdext.c
del libmpn.a
ar rc libmpn.a *.o
cd ..
cd mpz
gcc -c -I. -I.. -I../mpn -g -O abs.c
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O add_ui.c
gcc -c -I. -I.. -I../mpn -g -O and.c
gcc -c -I. -I.. -I../mpn -g -O array_init.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O cdiv_ui.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O clrbit.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_si.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O com.c
gcc -c -I. -I.. -I../mpn -g -O divexact.c
gcc -c -I. -I.. -I../mpn -g -O fac_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q_2exp.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r_2exp.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O fdiv_ui.c
gcc -c -I. -I.. -I../mpn -g -O gcd.c
gcc -c -I. -I.. -I../mpn -g -O gcd_ui.c
gcc -c -I. -I.. -I../mpn -g -O gcdext.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_si.c
gcc -c -I. -I.. -I../mpn -g -O get_str.c
gcc -c -I. -I.. -I../mpn -g -O get_ui.c
gcc -c -I. -I.. -I../mpn -g -O getlimbn.c
gcc -c -I. -I.. -I../mpn -g -O hamdist.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O inp_raw.c
gcc -c -I. -I.. -I../mpn -g -O inp_str.c
gcc -c -I. -I.. -I../mpn -g -O invert.c
gcc -c -I. -I.. -I../mpn -g -O ior.c
gcc -c -I. -I.. -I../mpn -g -O iset.c
gcc -c -I. -I.. -I../mpn -g -O iset_d.c
gcc -c -I. -I.. -I../mpn -g -O iset_si.c
gcc -c -I. -I.. -I../mpn -g -O iset_str.c
gcc -c -I. -I.. -I../mpn -g -O iset_ui.c
gcc -c -I. -I.. -I../mpn -g -O jacobi.c
gcc -c -I. -I.. -I../mpn -g -O legendre.c
gcc -c -I. -I.. -I../mpn -g -O mod.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O mul_2exp.c
gcc -c -I. -I.. -I../mpn -g -O mul_ui.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O out_raw.c
gcc -c -I. -I.. -I../mpn -g -O out_str.c
gcc -c -I. -I.. -I../mpn -g -O perfsqr.c
gcc -c -I. -I.. -I../mpn -g -O popcount.c
gcc -c -I. -I.. -I../mpn -g -O pow_ui.c
gcc -c -I. -I.. -I../mpn -g -O powm.c
gcc -c -I. -I.. -I../mpn -g -O powm_ui.c
gcc -c -I. -I.. -I../mpn -g -O pprime_p.c
gcc -c -I. -I.. -I../mpn -g -O random.c
gcc -c -I. -I.. -I../mpn -g -O random2.c
gcc -c -I. -I.. -I../mpn -g -O realloc.c
gcc -c -I. -I.. -I../mpn -g -O scan0.c
gcc -c -I. -I.. -I../mpn -g -O scan1.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_d.c
gcc -c -I. -I.. -I../mpn -g -O set_f.c
gcc -c -I. -I.. -I../mpn -g -O set_q.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_str.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O setbit.c
gcc -c -I. -I.. -I../mpn -g -O size.c
gcc -c -I. -I.. -I../mpn -g -O sizeinbase.c
gcc -c -I. -I.. -I../mpn -g -O sqrt.c
gcc -c -I. -I.. -I../mpn -g -O sqrtrem.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
gcc -c -I. -I.. -I../mpn -g -O sub_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q_2exp.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_q_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_qr.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_qr_ui.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r_2exp.c
gcc -c -I. -I.. -I../mpn -g -O tdiv_r_ui.c
gcc -c -I. -I.. -I../mpn -g -O ui_pow_ui.c
del libmpz.a
ar rc libmpz.a *.o
cd ..
cd mpf
gcc -c -I. -I.. -I../mpn -g -O abs.c
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O add_ui.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_si.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O div.c
gcc -c -I. -I.. -I../mpn -g -O div_2exp.c
gcc -c -I. -I.. -I../mpn -g -O div_ui.c
gcc -c -I. -I.. -I../mpn -g -O dump.c
gcc -c -I. -I.. -I../mpn -g -O eq.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_prc.c
gcc -c -I. -I.. -I../mpn -g -O get_str.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O init2.c
gcc -c -I. -I.. -I../mpn -g -O inp_str.c
gcc -c -I. -I.. -I../mpn -g -O iset.c
gcc -c -I. -I.. -I../mpn -g -O iset_d.c
gcc -c -I. -I.. -I../mpn -g -O iset_si.c
gcc -c -I. -I.. -I../mpn -g -O iset_str.c
gcc -c -I. -I.. -I../mpn -g -O iset_ui.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O mul_2exp.c
gcc -c -I. -I.. -I../mpn -g -O mul_ui.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O out_str.c
gcc -c -I. -I.. -I../mpn -g -O random2.c
gcc -c -I. -I.. -I../mpn -g -O reldiff.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_d.c
gcc -c -I. -I.. -I../mpn -g -O set_dfl_prc.c
gcc -c -I. -I.. -I../mpn -g -O set_prc.c
gcc -c -I. -I.. -I../mpn -g -O set_prc_raw.c
gcc -c -I. -I.. -I../mpn -g -O set_q.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_str.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O set_z.c
gcc -c -I. -I.. -I../mpn -g -O size.c
gcc -c -I. -I.. -I../mpn -g -O sqrt.c
gcc -c -I. -I.. -I../mpn -g -O sqrt_ui.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
gcc -c -I. -I.. -I../mpn -g -O sub_ui.c
gcc -c -I. -I.. -I../mpn -g -O ui_div.c
gcc -c -I. -I.. -I../mpn -g -O ui_sub.c
del libmpf.a
ar cr libmpf.a *.o
cd ..
cd mpq
gcc -c -I. -I.. -I../mpn -g -O add.c
gcc -c -I. -I.. -I../mpn -g -O canonicalize.c
gcc -c -I. -I.. -I../mpn -g -O clear.c
gcc -c -I. -I.. -I../mpn -g -O cmp.c
gcc -c -I. -I.. -I../mpn -g -O cmp_ui.c
gcc -c -I. -I.. -I../mpn -g -O div.c
gcc -c -I. -I.. -I../mpn -g -O equal.c
gcc -c -I. -I.. -I../mpn -g -O get_d.c
gcc -c -I. -I.. -I../mpn -g -O get_den.c
gcc -c -I. -I.. -I../mpn -g -O get_num.c
gcc -c -I. -I.. -I../mpn -g -O init.c
gcc -c -I. -I.. -I../mpn -g -O inv.c
gcc -c -I. -I.. -I../mpn -g -O mul.c
gcc -c -I. -I.. -I../mpn -g -O neg.c
gcc -c -I. -I.. -I../mpn -g -O set.c
gcc -c -I. -I.. -I../mpn -g -O set_den.c
gcc -c -I. -I.. -I../mpn -g -O set_num.c
gcc -c -I. -I.. -I../mpn -g -O set_si.c
gcc -c -I. -I.. -I../mpn -g -O set_ui.c
gcc -c -I. -I.. -I../mpn -g -O set_z.c
gcc -c -I. -I.. -I../mpn -g -O sub.c
del libmpq.a
ar cr libmpq.a *.o
cd ..
gcc -c -I. -Impn -I.. -g -O extract-double.c
gcc -c -I. -Impn -I.. -g -O insert-double.c
gcc -c -I. -Impn -I.. -g -O memory.c
gcc -c -I. -Impn -I.. -g -O mp_clz_tab.c
gcc -c -I. -Impn -I.. -g -O mp_set_fns.c
gcc -c -I. -Impn -I.. -g -O stack-alloc.c
gcc -c -I. -Impn -I.. -g -O version.c
deltree/y tmpdir
md tmpdir
md tmpdir\mpn
cd tmpdir\mpn
ar x ../../mpn/libmpn.a
cd ..\..
md tmpdir\mpz
cd tmpdir\mpz
ar x ../../mpz/libmpz.a
cd ..\..
md tmpdir\mpq
cd tmpdir\mpq
ar x ../../mpq/libmpq.a
cd ..\..
md tmpdir\mpf
cd tmpdir\mpf
ar x ../../mpf/libmpf.a
cd ..\..
copy memory.o tmpdir
copy mp_set_fns.o tmpdir
copy mp_clz_tab.o tmpdir
copy version.o tmpdir
copy stack-alloc.o tmpdir
cd tmpdir
ar rc libgmp.a *.o */*.o
ranlib libgmp.a
cd ..
move/y tmpdir\libgmp.a libgmp.a
deltree/y tmpdir

View File

@ -1,38 +0,0 @@
/* mdiv -- BSD compatible divide producing both remainder and quotient.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mdiv (const MINT *num, const MINT *den, MINT *quot, MINT *rem)
#else
mdiv (num, den, quot, rem)
const MINT *num;
const MINT *den;
MINT *quot;
MINT *rem;
#endif
#define COMPUTE_QUOTIENT
#include "mpz_dmincl.c"

View File

@ -1,97 +0,0 @@
/* Memory allocation routines.
Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#ifdef __NeXT__
#define static
#endif
#if __STDC__
void * (*_mp_allocate_func) (size_t) = _mp_default_allocate;
void * (*_mp_reallocate_func) (void *, size_t, size_t)
= _mp_default_reallocate;
void (*_mp_free_func) (void *, size_t) = _mp_default_free;
#else
void * (*_mp_allocate_func) () = _mp_default_allocate;
void * (*_mp_reallocate_func) () = _mp_default_reallocate;
void (*_mp_free_func) () = _mp_default_free;
#endif
/* Default allocation functions. In case of failure to allocate/reallocate
an error message is written to stderr and the program aborts. */
void *
#if __STDC__
_mp_default_allocate (size_t size)
#else
_mp_default_allocate (size)
size_t size;
#endif
{
void *ret;
ret = malloc (size);
if (ret == 0)
{
perror ("cannot allocate in gmp");
abort ();
}
return ret;
}
void *
#if __STDC__
_mp_default_reallocate (void *oldptr, size_t old_size, size_t new_size)
#else
_mp_default_reallocate (oldptr, old_size, new_size)
void *oldptr;
size_t old_size;
size_t new_size;
#endif
{
void *ret;
ret = realloc (oldptr, new_size);
if (ret == 0)
{
perror ("cannot allocate in gmp");
abort ();
}
return ret;
}
void
#if __STDC__
_mp_default_free (void *blk_ptr, size_t blk_size)
#else
_mp_default_free (blk_ptr, blk_size)
void *blk_ptr;
size_t blk_size;
#endif
{
free (blk_ptr);
}

View File

@ -1,35 +0,0 @@
/* mfree -- BSD compatible mfree.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mfree (MINT *m)
#else
mfree (m)
MINT *m;
#endif
{
(*_mp_free_func) (m->d, m->alloc * BYTES_PER_MP_LIMB);
(*_mp_free_func) (m, sizeof (MINT));
}

View File

@ -1,64 +0,0 @@
/* min(MINT) -- Do decimal input from standard input and store result in
MINT.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <ctype.h>
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
min (MINT *x)
#else
min (x)
MINT *x;
#endif
{
char *str;
size_t str_size;
size_t i;
int c;
str_size = 100;
str = (char *) (*_mp_allocate_func) (str_size);
for (i = 0; ; i++)
{
if (i >= str_size)
{
size_t old_str_size = str_size;
str_size = str_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_str_size, str_size);
}
c = getc (stdin);
if (!(isdigit(c) || c == ' ' || c == '\t'))
break;
str[i] = c;
}
ungetc (c, stdin);
str[i] = 0;
_mpz_set_str (x, str, 10);
(*_mp_free_func) (str, str_size);
}

View File

@ -1,32 +0,0 @@
#! /bin/sh
# mkinstalldirs --- make directory hierarchy
# Author: Noah Friedman <friedman@prep.ai.mit.edu>
# Created: 1993-05-16
# Public domain
errstatus=0
for file
do
set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
shift
pathcomp=
for d in ${1+"$@"} ; do
pathcomp="$pathcomp$d"
case "$pathcomp" in
-* ) pathcomp=./$pathcomp ;;
esac
if test ! -d "$pathcomp"; then
echo "mkdir $pathcomp" 1>&2
mkdir "$pathcomp" || errstatus=$?
fi
pathcomp="$pathcomp/"
done
done
exit $errstatus
# mkinstalldirs ends here

View File

@ -1,42 +0,0 @@
/* mout(MINT) -- Do decimal output of MINT to standard output.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mout (const MINT *x)
#else
mout (x)
const MINT *x;
#endif
{
char *str;
size_t str_size;
str_size = ((size_t) (ABS (x->size) * BITS_PER_MP_LIMB
* __mp_bases[10].chars_per_bit_exactly)) + 3;
str = (char *) alloca (str_size);
_mpz_get_str (str, 10, x);
puts (str);
alloca (0);
}

View File

@ -1,15 +0,0 @@
#!/bin/sh
if
test -r $2
then
if
cmp $1 $2 > /dev/null
then
echo $2 is unchanged
rm -f $1
else
mv -f $1 $2
fi
else
mv -f $1 $2
fi

View File

@ -1,45 +0,0 @@
/* move -- BSD compatible assignment.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mp.h"
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
move (const MINT *u, MINT *w)
#else
move (u, w)
const MINT *u;
MINT *w;
#endif
{
mp_size usize;
mp_size abs_usize;
usize = u->size;
abs_usize = ABS (usize);
if (w->alloc < abs_usize)
_mpz_realloc (w, abs_usize);
w->size = usize;
MPN_COPY (w->d, u->d, abs_usize);
}

View File

@ -1,141 +0,0 @@
/* mp.h -- Definitions for Berkeley compatible multiple precision functions.
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#ifndef __MP_H__
#ifndef __GNU_MP__
#define __GNU_MP__ 2
#define __need_size_t
#include <stddef.h>
#undef __need_size_t
#if defined (__STDC__) || defined (__cplusplus)
#define __gmp_const const
#else
#define __gmp_const
#endif
#if defined (__GNUC__)
#define __gmp_inline __inline__
#else
#define __gmp_inline
#endif
#ifndef _EXTERN_INLINE
#ifdef __GNUC__
#define _EXTERN_INLINE extern __inline__
#else
#define _EXTERN_INLINE static
#endif
#endif
#ifdef _SHORT_LIMB
typedef unsigned int mp_limb_t;
typedef int mp_limb_signed_t;
#else
#ifdef _LONG_LONG_LIMB
typedef unsigned long long int mp_limb_t;
typedef long long int mp_limb_signed_t;
#else
typedef unsigned long int mp_limb_t;
typedef long int mp_limb_signed_t;
#endif
#endif
typedef mp_limb_t * mp_ptr;
typedef __gmp_const mp_limb_t * mp_srcptr;
typedef int mp_size_t;
typedef long int mp_exp_t;
#ifndef __MP_SMALL__
typedef struct
{
mp_size_t _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
mp_size_t _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#else
typedef struct
{
short int _mp_alloc; /* Number of *limbs* allocated and pointed
to by the D field. */
short int _mp_size; /* abs(SIZE) is the number of limbs
the last field points to. If SIZE
is negative this is a negative
number. */
mp_limb_t *_mp_d; /* Pointer to the limbs. */
} __mpz_struct;
#endif
#endif /* __GNU_MP__ */
/* User-visible types. */
typedef __mpz_struct MINT;
#ifdef __STDC__
void mp_set_memory_functions (void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t));
MINT *itom (signed short int);
MINT *xtom (const char *);
void move (const MINT *, MINT *);
void madd (const MINT *, const MINT *, MINT *);
void msub (const MINT *, const MINT *, MINT *);
void mult (const MINT *, const MINT *, MINT *);
void mdiv (const MINT *, const MINT *, MINT *, MINT *);
void sdiv (const MINT *, signed short int, MINT *, signed short int *);
void msqrt (const MINT *, MINT *, MINT *);
void pow (const MINT *, const MINT *, const MINT *, MINT *);
void rpow (const MINT *, signed short int, MINT *);
void gcd (const MINT *, const MINT *, MINT *);
int mcmp (const MINT *, const MINT *);
void min (MINT *);
void mout (const MINT *);
char *mtox (const MINT *);
void mfree (MINT *);
#else
void mp_set_memory_functions ();
MINT *itom ();
MINT *xtom ();
void move ();
void madd ();
void msub ();
void mult ();
void mdiv ();
void sdiv ();
void msqrt ();
void pow ();
void rpow ();
void gcd ();
int mcmp ();
void min ();
void mout ();
char *mtox ();
void mfree ();
#endif
#define __MP_H__
#endif /* __MP_H__ */

View File

@ -1,4 +0,0 @@
#include "gmp.h"
#include "gmp-impl.h"
const int mp_bits_per_limb = BITS_PER_MP_LIMB;

View File

@ -1,40 +0,0 @@
/* __clz_tab -- support for longlong.h
Copyright (C) 1991, 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#if 0
#include "gmp.h"
#include "gmp-impl.h"
#endif
#if 0
const
#endif
unsigned char __clz_tab[] =
{
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
};

View File

@ -1,48 +0,0 @@
/* mp_set_memory_functions -- Set the allocate, reallocate, and free functions
for use by the mp package.
Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#if __STDC__
mp_set_memory_functions (void *(*alloc_func) (size_t),
void *(*realloc_func) (void *, size_t, size_t),
void (*free_func) (void *, size_t))
#else
mp_set_memory_functions (alloc_func, realloc_func, free_func)
void *(*alloc_func) ();
void *(*realloc_func) ();
void (*free_func) ();
#endif
{
if (alloc_func == 0)
alloc_func = _mp_default_allocate;
if (realloc_func == 0)
realloc_func = _mp_default_reallocate;
if (free_func == 0)
free_func = _mp_default_free;
_mp_allocate_func = alloc_func;
_mp_reallocate_func = realloc_func;
_mp_free_func = free_func;
}

View File

@ -1,141 +0,0 @@
/* mpn_add -- Add two low-level integers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Add ADD1_PTR/ADD1_SIZE and ADD2_PTR/ADD2_SIZE and store the first
ADD1_SIZE words of the result at SUM_PTR.
Return 1 if carry out was generated, return 0 otherwise.
Argument constraint: ADD1_SIZE >= ADD2_SIZE.
The size of SUM can be calculated as ADD1_SIZE + the return value. */
mp_limb
#ifdef __STDC__
mpn_add (mp_ptr sum_ptr,
mp_srcptr add1_ptr, mp_size add1_size,
mp_srcptr add2_ptr, mp_size add2_size)
#else
mpn_add (sum_ptr, add1_ptr, add1_size, add2_ptr, add2_size)
mp_ptr sum_ptr;
mp_srcptr add1_ptr;
mp_size add1_size;
mp_srcptr add2_ptr;
mp_size add2_size;
#endif
{
mp_limb a1, a2, sum;
mp_size j;
/* The loop counter and index J goes from some negative value to zero.
This way the loops become faster. Need to offset the base pointers
to take care of the negative indices. */
j = -add2_size;
if (j == 0)
goto add2_finished;
add1_ptr -= j;
add2_ptr -= j;
sum_ptr -= j;
/* There are two do-loops, marked NON-CARRY LOOP and CARRY LOOP that
jump between each other. The first loop is for when the previous
addition didn't produce a carry-out; the second is for the
complementary case. */
/* NON-CARRY LOOP */
do
{
a1 = add1_ptr[j];
a2 = add2_ptr[j];
sum = a1 + a2;
sum_ptr[j] = sum;
if (sum < a2)
goto cy_loop;
ncy_loop:
j++;
}
while (j < 0);
/* We have exhausted ADD2. Just copy ADD1 to SUM, and return
0 as an indication of no carry-out. */
add2_finished:
/* Immediate return if the copy would be a no-op. */
if (sum_ptr == add1_ptr)
return 0;
j = add2_size - add1_size;
add1_ptr -= j;
sum_ptr -= j;
while (j < 0)
{
sum_ptr[j] = add1_ptr[j];
j++;
}
return 0;
/* CARRY LOOP */
do
{
a1 = add1_ptr[j];
a2 = add2_ptr[j];
sum = a1 + a2 + 1;
sum_ptr[j] = sum;
if (sum > a2)
goto ncy_loop;
cy_loop:
j++;
}
while (j < 0);
j = add2_size - add1_size;
add1_ptr -= j;
sum_ptr -= j;
while (j < 0)
{
a1 = add1_ptr[j];
sum = a1 + 1;
sum_ptr[j] = sum;
if (sum > 0)
goto copy_add1;
j++;
}
return 1;
copy_add1:
if (sum_ptr == add1_ptr)
return 0;
j++;
while (j < 0)
{
sum_ptr[j] = add1_ptr[j];
j++;
}
return 0;
}

View File

@ -1,52 +0,0 @@
/* mpn_cmp -- Compare two low-level natural-number integers.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
There are no restrictions on the relative sizes of
the two arguments.
Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2. */
int
#ifdef __STDC__
mpn_cmp (mp_srcptr op1_ptr, mp_srcptr op2_ptr, mp_size size)
#else
mpn_cmp (op1_ptr, op2_ptr, size)
mp_srcptr op1_ptr;
mp_srcptr op2_ptr;
mp_size size;
#endif
{
mp_size i;
mp_limb op1_word, op2_word;
for (i = size - 1; i >= 0; i--)
{
op1_word = op1_ptr[i];
op2_word = op2_ptr[i];
if (op1_word != op2_word)
goto diff;
}
return 0;
diff:
return (op1_word > op2_word) ? 1 : -1;
}

View File

@ -1,321 +0,0 @@
/* mpn_div -- Divide natural numbers, producing both remainder and
quotient.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
/* Divide num (NUM_PTR/NUM_SIZE) by den (DEN_PTR/DEN_SIZE) and write
the quotient at QUOT_PTR and the remainder at NUM_PTR.
Return 0 or 1, depending on if the quotient size is (NSIZE - DSIZE)
or (NSIZE - DSIZE + 1).
Argument constraints:
1. The most significant bit of d must be set.
2. QUOT_PTR != DEN_PTR and QUOT_PTR != NUM_PTR, i.e. the quotient storage
area must be distinct from either input operands.
The exact sizes of the quotient and remainder must be determined
by the caller, in spite of the return value. The return value just
informs the caller about if the highest digit is written or not, and
it may very well be 0. */
/* THIS WILL BE IMPROVED SOON. MORE COMMENTS AND FASTER CODE. */
mp_size
#ifdef __STDC__
mpn_div (mp_ptr quot_ptr,
mp_ptr num_ptr, mp_size num_size,
mp_srcptr den_ptr, mp_size den_size)
#else
mpn_div (quot_ptr, num_ptr, num_size, den_ptr, den_size)
mp_ptr quot_ptr;
mp_ptr num_ptr;
mp_size num_size;
mp_srcptr den_ptr;
mp_size den_size;
#endif
{
mp_size q_is_long = 0;
switch (den_size)
{
case 0:
/* We are asked to divide by zero, so go ahead and do it!
(To make the compiler not remove this statement, assign NUM_SIZE
and fall through.) */
num_size = 1 / den_size;
case 1:
{
mp_size i;
mp_limb n1, n0;
mp_limb d;
d = den_ptr[0];
i = num_size - 1;
n1 = num_ptr[i];
i--;
if (n1 >= d)
{
q_is_long = 1;
n1 = 0;
i++;
}
for (; i >= 0; i--)
{
n0 = num_ptr[i];
udiv_qrnnd (quot_ptr[i], n1, n1, n0, d);
}
num_ptr[0] = n1;
}
break;
case 2:
{
mp_size i;
mp_limb n0, n1, n2;
mp_limb d0, d1;
num_ptr += num_size - 2;
d0 = den_ptr[1];
d1 = den_ptr[0];
n0 = num_ptr[1];
n1 = num_ptr[0];
if (n0 >= d0)
{
q_is_long = 1;
n1 = n0;
n0 = 0;
num_ptr++;
num_size++;
}
for (i = num_size - den_size - 1; i >= 0; i--)
{
mp_limb q;
mp_limb r;
num_ptr--;
if (n0 == d0)
{
/* Q should be either 111..111 or 111..110. Need special
treatment of this rare case as normal division would
give overflow. */
q = ~0;
r = n1 + d0;
if (r < d0) /* Carry in the addition? */
{
n2 = num_ptr[0];
add_ssaaaa (n0, n1, r - d1, n2, 0, d1);
quot_ptr[i] = q;
continue;
}
n0 = d1 - (d1 != 0);
n1 = -d1;
}
else
{
udiv_qrnnd (q, r, n0, n1, d0);
umul_ppmm (n0, n1, d1, q);
}
n2 = num_ptr[0];
q_test:
if (n0 > r || (n0 == r && n1 > n2))
{
/* The estimated Q was too large. */
q--;
sub_ddmmss (n0, n1, n0, n1, 0, d1);
r += d0;
if (r >= d0) /* If not carry, test q again. */
goto q_test;
}
quot_ptr[i] = q;
sub_ddmmss (n0, n1, r, n2, n0, n1);
}
num_ptr[1] = n0;
num_ptr[0] = n1;
}
break;
default:
{
mp_size i;
mp_limb d0 = den_ptr[den_size - 1];
mp_limb d1 = den_ptr[den_size - 2];
mp_limb n0 = num_ptr[num_size - 1];
int ugly_hack_flag = 0;
if (n0 >= d0)
{
/* There's a problem with this case, which shows up later in the
code. q becomes 1 (and sometimes 0) the first time when
we've been here, and w_cy == 0 after the main do-loops below.
But c = num_ptr[j] reads rubbish outside the num_ptr vector!
Maybe I can solve this cleanly when I fix the early-end
optimization here in the default case. For now, I change the
add_back entering condition, to kludge. Leaving the stray
memref behind!
HACK: Added ugly_hack_flag to make it work. */
q_is_long = 1;
n0 = 0;
num_size++;
ugly_hack_flag = 1;
}
num_ptr += num_size;
den_ptr += den_size;
for (i = num_size - den_size - 1; i >= 0; i--)
{
mp_limb q;
mp_limb n1;
mp_limb w_cy;
mp_limb d, c;
mp_size j;
num_ptr--;
if (n0 == d0)
/* This might over-estimate q, but it's probably not worth
the extra code here to find out. */
q = ~0;
else
{
mp_limb r;
udiv_qrnnd (q, r, n0, num_ptr[-1], d0);
umul_ppmm (n1, n0, d1, q);
while (n1 > r || (n1 == r && n0 > num_ptr[-2]))
{
q--;
r += d0;
if (r < d0) /* I.e. "carry in previous addition?" */
break;
n1 -= n0 < d1;
n0 -= d1;
}
}
w_cy = 0;
j = -den_size;
do
{
d = den_ptr[j];
c = num_ptr[j];
umul_ppmm (n1, n0, d, q);
n0 += w_cy;
w_cy = (n0 < w_cy) + n1;
n0 = c - n0;
num_ptr[j] = n0;
if (n0 > c)
goto cy_loop;
ncy_loop:
j++;
}
while (j < 0);
if (ugly_hack_flag)
{
c = 0;
ugly_hack_flag = 0;
}
else
c = num_ptr[j];
if (c >= w_cy)
goto store_q;
goto add_back;
do
{
d = den_ptr[j];
c = num_ptr[j];
umul_ppmm (n1, n0, d, q);
n0 += w_cy;
w_cy = (n0 < w_cy) + n1;
n0 = c - n0 - 1;
num_ptr[j] = n0;
if (n0 < c)
goto ncy_loop;
cy_loop:
j++;
}
while (j < 0);
if (ugly_hack_flag)
{
c = 0;
ugly_hack_flag = 0;
}
else
c = num_ptr[j];
w_cy++;
if (c >= w_cy)
goto store_q;
add_back:
j = -den_size;
do
{
d = den_ptr[j];
n0 = num_ptr[j] + d;
num_ptr[j] = n0;
if (n0 < d)
goto ab_cy_loop;
ab_ncy_loop:
j++;
}
while (j < 0);
abort (); /* We should always have a carry out! */
do
{
d = den_ptr[j];
n0 = num_ptr[j] + d + 1;
num_ptr[j] = n0;
if (n0 > d)
goto ab_ncy_loop;
ab_cy_loop:
j++;
}
while (j < 0);
q--;
store_q:
quot_ptr[i] = q;
}
}
}
return q_is_long;
}

View File

@ -1,185 +0,0 @@
/* mpn_divmod_1(quot_ptr, dividend_ptr, dividend_size, divisor_limb) --
Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by DIVISOR_LIMB.
Write DIVIDEND_SIZE limbs of quotient at QUOT_PTR.
Return the single-limb remainder.
There are no constraints on the value of the divisor.
QUOT_PTR and DIVIDEND_PTR might point to the same limb.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#ifndef UMUL_TIME
#define UMUL_TIME 1
#endif
#ifndef UDIV_TIME
#define UDIV_TIME UMUL_TIME
#endif
#if UDIV_TIME > 2 * UMUL_TIME
#undef UDIV_NEEDS_NORMALIZATION
#define UDIV_NEEDS_NORMALIZATION 1
#endif
#define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \
do { \
unsigned long int _q, _ql, _r; \
unsigned long int _xh, _xl; \
umul_ppmm (_q, _ql, (nh), (di)); \
_q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small. */\
umul_ppmm (_xh, _xl, _q, (d)); \
sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
if (_xh != 0) \
{ \
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
_q += 1; \
} \
} \
if (_r >= (d)) \
{ \
_r -= (d); \
_q += 1; \
} \
(r) = _r; \
(q) = _q; \
} while (0)
mp_limb
#ifdef __STDC__
mpn_divmod_1 (mp_ptr quot_ptr,
mp_srcptr dividend_ptr, mp_size dividend_size,
unsigned long int divisor_limb)
#else
mpn_divmod_1 (quot_ptr, dividend_ptr, dividend_size, divisor_limb)
mp_ptr quot_ptr;
mp_srcptr dividend_ptr;
mp_size dividend_size;
unsigned long int divisor_limb;
#endif
{
mp_size i;
mp_limb n1, n0, r;
/* Botch: Should this be handled at all? Rely on callers? */
if (dividend_size == 0)
return 0;
if (UDIV_NEEDS_NORMALIZATION)
{
int normalization_steps;
count_leading_zeros (normalization_steps, divisor_limb);
if (normalization_steps != 0)
{
divisor_limb <<= normalization_steps;
n1 = dividend_ptr[dividend_size - 1];
r = n1 >> (BITS_PER_MP_LIMB - normalization_steps);
/* Possible optimization:
if (r == 0
&& divisor_limb > ((n1 << normalization_steps)
| (dividend_ptr[dividend_size - 2] >> ...)))
...one division less...
[Don't forget to zero most sign. quotient limb!] */
/* If multiplication is much faster than division, and the
dividend is large, pre-invert the divisor, and use
only multiplications in the inner loop. */
if (UDIV_TIME > 2 * UMUL_TIME && dividend_size >= 4)
{
mp_limb divisor_limb_inverted;
int dummy;
/* Compute (2**64 - 2**32 * DIVISOR_LIMB) / DIVISOR_LIMB.
The result is an 33-bit approximation to 1/DIVISOR_LIMB,
with the most significant bit (weight 2**32) implicit. */
/* Special case for DIVISOR_LIMB == 100...000. */
if (divisor_limb << 1 == 0)
divisor_limb_inverted = ~0;
else
udiv_qrnnd (divisor_limb_inverted, dummy,
-divisor_limb, 0, divisor_limb);
for (i = dividend_size - 2; i >= 0; i--)
{
n0 = dividend_ptr[i];
udiv_qrnnd_preinv (quot_ptr[i + 1], r, r,
((n1 << normalization_steps)
| (n0 >> (BITS_PER_MP_LIMB - normalization_steps))),
divisor_limb, divisor_limb_inverted);
n1 = n0;
}
udiv_qrnnd_preinv (quot_ptr[0], r, r,
n1 << normalization_steps,
divisor_limb, divisor_limb_inverted);
return r >> normalization_steps;
}
else
{
for (i = dividend_size - 2; i >= 0; i--)
{
n0 = dividend_ptr[i];
udiv_qrnnd (quot_ptr[i + 1], r, r,
((n1 << normalization_steps)
| (n0 >> (BITS_PER_MP_LIMB - normalization_steps))),
divisor_limb);
n1 = n0;
}
udiv_qrnnd (quot_ptr[0], r, r,
n1 << normalization_steps,
divisor_limb);
return r >> normalization_steps;
}
}
}
/* No normalization needed, either because udiv_qrnnd doesn't require
it, or because DIVISOR_LIMB is already normalized. */
i = dividend_size - 1;
r = dividend_ptr[i];
if (r >= divisor_limb)
{
r = 0;
}
else
{
/* Callers expect the quotient to be DIVIDEND_SIZE limbs. Store
a leading zero to make that expectation come true. */
quot_ptr[i] = 0;
i--;
}
for (; i >= 0; i--)
{
n0 = dividend_ptr[i];
udiv_qrnnd (quot_ptr[i], r, r, n0, divisor_limb);
}
return r;
}

View File

@ -1,83 +0,0 @@
/* mpn_lshift -- Shift left low level.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left
and store the USIZE least significant digits of the result at WP.
Return the bits shifted out from the most significant digit.
Argument constraints:
0. U must be normalized (i.e. it's most significant digit != 0).
1. 0 <= CNT < BITS_PER_MP_LIMB
2. If the result is to be written over the input, WP must be >= UP.
*/
mp_limb
#ifdef __STDC__
mpn_lshift (mp_ptr wp,
mp_srcptr up, mp_size usize,
unsigned cnt)
#else
mpn_lshift (wp, up, usize, cnt)
mp_ptr wp;
mp_srcptr up;
mp_size usize;
unsigned cnt;
#endif
{
mp_limb high_limb, low_limb;
unsigned sh_1, sh_2;
mp_size i;
mp_limb retval;
if (usize == 0)
return 0;
sh_1 = cnt;
if (sh_1 == 0)
{
if (wp != up)
{
/* Copy from high end to low end, to allow specified input/output
overlapping. */
for (i = usize - 1; i >= 0; i--)
wp[i] = up[i];
}
return 0;
}
wp += 1;
sh_2 = BITS_PER_MP_LIMB - sh_1;
i = usize - 1;
low_limb = up[i];
retval = low_limb >> sh_2;
high_limb = low_limb;
while (--i >= 0)
{
low_limb = up[i];
wp[i] = (high_limb << sh_1) | (low_limb >> sh_2);
high_limb = low_limb;
}
wp[i] = high_limb << sh_1;
return retval;
}

View File

@ -1,104 +0,0 @@
/* mpn_mod_1(dividend_ptr, dividend_size, divisor_limb) --
Divide (DIVIDEND_PTR,,DIVIDEND_SIZE) by DIVISOR_LIMB.
Return the single-limb remainder.
There are no constraints on the value of the divisor.
QUOT_PTR and DIVIDEND_PTR might point to the same limb.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
mp_limb
#ifdef __STDC__
mpn_mod_1 (mp_srcptr dividend_ptr, mp_size dividend_size,
unsigned long int divisor_limb)
#else
mpn_mod_1 (dividend_ptr, dividend_size, divisor_limb)
mp_srcptr dividend_ptr;
mp_size dividend_size;
unsigned long int divisor_limb;
#endif
{
int normalization_steps;
mp_size i;
mp_limb n1, n0, r;
int dummy;
/* Botch: Should this be handled at all? Rely on callers? */
if (dividend_size == 0)
return 0;
if (UDIV_NEEDS_NORMALIZATION)
{
count_leading_zeros (normalization_steps, divisor_limb);
if (normalization_steps != 0)
{
divisor_limb <<= normalization_steps;
n1 = dividend_ptr[dividend_size - 1];
r = n1 >> (BITS_PER_MP_LIMB - normalization_steps);
/* Possible optimization:
if (r == 0
&& divisor_limb > ((n1 << normalization_steps)
| (dividend_ptr[dividend_size - 2] >> ...)))
...one division less...
*/
for (i = dividend_size - 2; i >= 0; i--)
{
n0 = dividend_ptr[i];
udiv_qrnnd (dummy, r, r,
((n1 << normalization_steps)
| (n0 >> (BITS_PER_MP_LIMB - normalization_steps))),
divisor_limb);
n1 = n0;
}
udiv_qrnnd (dummy, r, r,
n1 << normalization_steps,
divisor_limb);
return r >> normalization_steps;
}
}
/* No normalization needed, either because udiv_qrnnd doesn't require
it, or because DIVISOR_LIMB is already normalized. */
i = dividend_size - 1;
r = dividend_ptr[i];
if (r >= divisor_limb)
{
r = 0;
}
else
{
i--;
}
for (; i >= 0; i--)
{
n0 = dividend_ptr[i];
udiv_qrnnd (dummy, r, r, n0, divisor_limb);
}
return r;
}

View File

@ -1,414 +0,0 @@
/* mpn_mul -- Multiply two natural numbers.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#ifdef DEBUG
#define MPN_MUL_VERIFY(res_ptr,res_size,op1_ptr,op1_size,op2_ptr,op2_size) \
mpn_mul_verify (res_ptr, res_size, op1_ptr, op1_size, op2_ptr, op2_size)
#include <stdio.h>
static void
mpn_mul_verify (res_ptr, res_size, op1_ptr, op1_size, op2_ptr, op2_size)
mp_ptr res_ptr, op1_ptr, op2_ptr;
mp_size res_size, op1_size, op2_size;
{
mp_ptr tmp_ptr;
mp_size tmp_size;
tmp_ptr = alloca ((op1_size + op2_size) * BYTES_PER_MP_LIMB);
if (op1_size >= op2_size)
tmp_size = mpn_mul_classic (tmp_ptr,
op1_ptr, op1_size, op2_ptr, op2_size);
else
tmp_size = mpn_mul_classic (tmp_ptr,
op2_ptr, op2_size, op1_ptr, op1_size);
if (tmp_size != res_size
|| mpn_cmp (tmp_ptr, res_ptr, tmp_size) != 0)
{
fprintf (stderr, "GNU MP internal error: Wrong result in mpn_mul.\n");
fprintf (stderr, "op1{%d} = ", op1_size); mpn_dump (op1_ptr, op1_size);
fprintf (stderr, "op2{%d} = ", op2_size); mpn_dump (op2_ptr, op2_size);
abort ();
}
}
#else
#define MPN_MUL_VERIFY(a,b,c,d,e,f)
#endif
/* Multiply the natural numbers u (pointed to by UP, with USIZE limbs)
and v (pointed to by VP, with VSIZE limbs), and store the result at
PRODP. USIZE + VSIZE limbs are always stored, but if the input
operands are normalized, the return value will reflect the true
result size (which is either USIZE + VSIZE, or USIZE + VSIZE -1).
NOTE: The space pointed to by PRODP is overwritten before finished
with U and V, so overlap is an error.
Argument constraints:
1. USIZE >= VSIZE.
2. PRODP != UP and PRODP != VP, i.e. the destination
must be distinct from the multiplier and the multiplicand. */
/* If KARATSUBA_THRESHOLD is not already defined, define it to a
value which is good on most machines. */
#ifndef KARATSUBA_THRESHOLD
#define KARATSUBA_THRESHOLD 8
#endif
/* The code can't handle KARATSUBA_THRESHOLD smaller than 4. */
#if KARATSUBA_THRESHOLD < 4
#undef KARATSUBA_THRESHOLD
#define KARATSUBA_THRESHOLD 4
#endif
mp_size
#ifdef __STDC__
mpn_mul (mp_ptr prodp,
mp_srcptr up, mp_size usize,
mp_srcptr vp, mp_size vsize)
#else
mpn_mul (prodp, up, usize, vp, vsize)
mp_ptr prodp;
mp_srcptr up;
mp_size usize;
mp_srcptr vp;
mp_size vsize;
#endif
{
mp_size n;
mp_size prod_size;
mp_limb cy;
if (vsize < KARATSUBA_THRESHOLD)
{
/* Handle simple cases with traditional multiplication.
This is the most critical code of the entire function. All
multiplies rely on this, both small and huge. Small ones arrive
here immediately. Huge ones arrive here as this is the base case
for the recursive algorithm below. */
mp_size i, j;
mp_limb prod_low, prod_high;
mp_limb cy_limb;
mp_limb v_limb;
if (vsize == 0)
return 0;
/* Offset UP and PRODP so that the inner loop can be faster. */
up += usize;
prodp += usize;
/* Multiply by the first limb in V separately, as the result can
be stored (not added) to PROD. We also avoid a loop for zeroing. */
v_limb = vp[0];
if (v_limb <= 1)
{
if (v_limb == 1)
MPN_COPY (prodp - usize, up - usize, usize);
else
MPN_ZERO (prodp - usize, usize);
cy_limb = 0;
}
else
{
cy_limb = 0;
j = -usize;
do
{
umul_ppmm (prod_high, prod_low, up[j], v_limb);
add_ssaaaa (cy_limb, prodp[j], prod_high, prod_low, 0, cy_limb);
j++;
}
while (j < 0);
}
prodp[0] = cy_limb;
prodp++;
/* For each iteration in the outer loop, multiply one limb from
U with one limb from V, and add it to PROD. */
for (i = 1; i < vsize; i++)
{
v_limb = vp[i];
if (v_limb <= 1)
{
cy_limb = 0;
if (v_limb == 1)
cy_limb = mpn_add (prodp - usize,
prodp - usize, usize, up - usize, usize);
}
else
{
cy_limb = 0;
j = -usize;
do
{
umul_ppmm (prod_high, prod_low, up[j], v_limb);
add_ssaaaa (cy_limb, prod_low,
prod_high, prod_low, 0, cy_limb);
add_ssaaaa (cy_limb, prodp[j],
cy_limb, prod_low, 0, prodp[j]);
j++;
}
while (j < 0);
}
prodp[0] = cy_limb;
prodp++;
}
return usize + vsize - (cy_limb == 0);
}
n = (usize + 1) / 2;
/* Is USIZE larger than 1.5 times VSIZE? Avoid Karatsuba's algorithm. */
if (2 * usize > 3 * vsize)
{
/* If U has at least twice as many limbs as V. Split U in two
pieces, U1 and U0, such that U = U0 + U1*(2**BITS_PER_MP_LIMB)**N,
and recursively multiply the two pieces separately with V. */
mp_size u0_size;
mp_ptr tmp;
mp_size tmp_size;
/* V1 (the high part of V) is zero. */
/* Calculate the length of U0. It is normally equal to n, but
of course not for sure. */
for (u0_size = n; u0_size > 0 && up[u0_size - 1] == 0; u0_size--)
;
/* Perform (U0 * V). */
if (u0_size >= vsize)
prod_size = mpn_mul (prodp, up, u0_size, vp, vsize);
else
prod_size = mpn_mul (prodp, vp, vsize, up, u0_size);
MPN_MUL_VERIFY (prodp, prod_size, up, u0_size, vp, vsize);
/* We have to zero-extend the lower partial product to n limbs,
since the mpn_add some lines below expect the first n limbs
to be well defined. (This is normally a no-op. It may
do something when U1 has many leading 0 limbs.) */
while (prod_size < n)
prodp[prod_size++] = 0;
tmp = (mp_ptr) alloca ((usize + vsize - n) * BYTES_PER_MP_LIMB);
/* Perform (U1 * V). Make sure the first source argument to mpn_mul
is not less than the second source argument. */
if (vsize <= usize - n)
tmp_size = mpn_mul (tmp, up + n, usize - n, vp, vsize);
else
tmp_size = mpn_mul (tmp, vp, vsize, up + n, usize - n);
MPN_MUL_VERIFY (tmp, tmp_size, up + n, usize - n, vp, vsize);
/* In this addition hides a potentially large copying of TMP. */
if (prod_size - n >= tmp_size)
cy = mpn_add (prodp + n, prodp + n, prod_size - n, tmp, tmp_size);
else
cy = mpn_add (prodp + n, tmp, tmp_size, prodp + n, prod_size - n);
if (cy)
abort (); /* prodp[prod_size] = cy; */
alloca (0);
return tmp_size + n;
}
else
{
/* Karatsuba's divide-and-conquer algorithm.
Split U in two pieces, U1 and U0, such that
U = U0 + U1*(B**n),
and V in V1 and V0, such that
V = V0 + V1*(B**n).
UV is then computed recursively using the identity
2n n n n
UV = (B + B )U V + B (U -U )(V -V ) + (B + 1)U V
1 1 1 0 0 1 0 0
Where B = 2**BITS_PER_MP_LIMB.
*/
/* It's possible to decrease the temporary allocation by using the
prodp area for temporary storage of the middle term, and doing
that recursive multiplication first. (Do this later.) */
mp_size u0_size;
mp_size v0_size;
mp_size u0v0_size;
mp_size u1v1_size;
mp_ptr temp;
mp_size temp_size;
mp_size utem_size;
mp_size vtem_size;
mp_ptr ptem;
mp_size ptem_size;
int negflg;
mp_ptr pp;
pp = (mp_ptr) alloca (4 * n * BYTES_PER_MP_LIMB);
/* Calculate the lengths of U0 and V0. They are normally equal
to n, but of course not for sure. */
for (u0_size = n; u0_size > 0 && up[u0_size - 1] == 0; u0_size--)
;
for (v0_size = n; v0_size > 0 && vp[v0_size - 1] == 0; v0_size--)
;
/*** 1. PROD]2n..0] := U0 x V0
(Recursive call to mpn_mul may NOT overwrite input operands.)
________________ ________________
|________________||____U0 x V0_____| */
if (u0_size >= v0_size)
u0v0_size = mpn_mul (pp, up, u0_size, vp, v0_size);
else
u0v0_size = mpn_mul (pp, vp, v0_size, up, u0_size);
MPN_MUL_VERIFY (pp, u0v0_size, up, u0_size, vp, v0_size);
/* Zero-extend to 2n limbs. */
while (u0v0_size < 2 * n)
pp[u0v0_size++] = 0;
/*** 2. PROD]4n..2n] := U1 x V1
(Recursive call to mpn_mul may NOT overwrite input operands.)
________________ ________________
|_____U1 x V1____||____U0 x V0_____| */
u1v1_size = mpn_mul (pp + 2*n,
up + n, usize - n,
vp + n, vsize - n);
MPN_MUL_VERIFY (pp + 2*n, u1v1_size,
up + n, usize - n, vp + n, vsize - n);
prod_size = 2 * n + u1v1_size;
/*** 3. PTEM]2n..0] := (U1-U0) x (V0-V1)
(Recursive call to mpn_mul may overwrite input operands.)
________________
|_(U1-U0)(V0-V1)_| */
temp = (mp_ptr) alloca ((2 * n + 1) * BYTES_PER_MP_LIMB);
if (usize - n > u0_size
|| (usize - n == u0_size
&& mpn_cmp (up + n, up, u0_size) >= 0))
{
utem_size = usize - n
+ mpn_sub (temp, up + n, usize - n, up, u0_size);
negflg = 0;
}
else
{
utem_size = u0_size
+ mpn_sub (temp, up, u0_size, up + n, usize - n);
negflg = 1;
}
if (vsize - n > v0_size
|| (vsize - n == v0_size
&& mpn_cmp (vp + n, vp, v0_size) >= 0))
{
vtem_size = vsize - n
+ mpn_sub (temp + n, vp + n, vsize - n, vp, v0_size);
negflg ^= 1;
}
else
{
vtem_size = v0_size
+ mpn_sub (temp + n, vp, v0_size, vp + n, vsize - n);
/* No change of NEGFLG. */
}
ptem = (mp_ptr) alloca (2 * n * BYTES_PER_MP_LIMB);
if (utem_size >= vtem_size)
ptem_size = mpn_mul (ptem, temp, utem_size, temp + n, vtem_size);
else
ptem_size = mpn_mul (ptem, temp + n, vtem_size, temp, utem_size);
MPN_MUL_VERIFY (ptem, ptem_size, temp, utem_size, temp + n, vtem_size);
/*** 4. TEMP]2n..0] := PROD]2n..0] + PROD]4n..2n]
________________
|_____U1 x V1____|
________________
|_____U0_x_V0____| */
cy = mpn_add (temp, pp, 2*n, pp + 2*n, u1v1_size);
if (cy != 0)
{
temp[2*n] = cy;
temp_size = 2*n + 1;
}
else
{
/* Normalize temp. pp[2*n-1] might have been zero in the
mpn_add call above, and thus temp might be unnormalized. */
for (temp_size = 2*n; temp_size > 0 && temp[temp_size - 1] == 0;
temp_size--)
;
}
if (prod_size - n >= temp_size)
cy = mpn_add (pp + n, pp + n, prod_size - n, temp, temp_size);
else
{
/* This is a weird special case that should not happen (often)! */
cy = mpn_add (pp + n, temp, temp_size, pp + n, prod_size - n);
prod_size = temp_size + n;
}
if (cy != 0)
{
pp[prod_size] = cy;
prod_size++;
}
#ifdef DEBUG
if (prod_size > 4 * n)
abort();
#endif
if (negflg)
prod_size = prod_size
+ mpn_sub (pp + n, pp + n, prod_size - n, ptem, ptem_size);
else
{
if (prod_size - n < ptem_size)
abort();
cy = mpn_add (pp + n, pp + n, prod_size - n, ptem, ptem_size);
if (cy != 0)
{
pp[prod_size] = cy;
prod_size++;
#ifdef DEBUG
if (prod_size > 4 * n)
abort();
#endif
}
}
MPN_COPY (prodp, pp, prod_size);
alloca (0);
return prod_size;
}
}

View File

@ -1,90 +0,0 @@
/* mpn_rshift -- Shift right a low-level natural-number integer.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Shift U (pointed to by UP and USIZE limbs long) CNT bits to the right
and store the USIZE least significant limbs of the result at WP.
Return the size of the result.
Argument constraints:
0. U must be normalized (i.e. it's most significant limb != 0).
1. 0 <= CNT < BITS_PER_MP_LIMB
2. If the result is to be written over the input, WP must be <= UP.
*/
mp_size
#ifdef __STDC__
mpn_rshift (mp_ptr wp,
mp_srcptr up, mp_size usize,
unsigned cnt)
#else
mpn_rshift (wp, up, usize, cnt)
mp_ptr wp;
mp_srcptr up;
mp_size usize;
unsigned cnt;
#endif
{
mp_limb high_limb, low_limb;
unsigned sh_1, sh_2;
mp_size i;
if (usize == 0)
return 0;
sh_1 = cnt;
if (sh_1 == 0)
{
if (wp != up)
{
/* Copy from low end to high end, to allow specified input/output
overlapping. */
for (i = 0; i < usize; i++)
wp[i] = up[i];
}
return usize;
}
wp -= 1;
sh_2 = BITS_PER_MP_LIMB - sh_1;
high_limb = up[0];
#if 0
if (cy_limb != NULL)
*cy_limb = high_limb << sh_2;
#endif
low_limb = high_limb;
for (i = 1; i < usize; i++)
{
high_limb = up[i];
wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
low_limb = high_limb;
}
low_limb >>= sh_1;
if (low_limb != 0)
{
wp[i] = low_limb;
return usize;
}
return usize - 1;
}

View File

@ -1,86 +0,0 @@
/* mpn_rshiftci -- Shift a low level natural-number integer with carry in.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Shift U (pointed to by UP and USIZE digits long) CNT bits to the right
and store the USIZE least significant digits of the result at WP.
Return the size of the result.
Argument constraints:
0. U must be normalized (i.e. it's most significant digit != 0).
1. 0 <= CNT < BITS_PER_MP_LIMB
2. If the result is to be written over the input, WP must be <= UP.
*/
mp_size
#ifdef __STDC__
mpn_rshiftci (mp_ptr wp,
mp_srcptr up, mp_size usize,
unsigned cnt,
mp_limb carry_in)
#else
mpn_rshiftci (wp, up, usize, cnt, carry_in)
mp_ptr wp;
mp_srcptr up;
mp_size usize;
unsigned cnt;
mp_limb carry_in;
#endif
{
mp_limb high_limb, low_limb;
unsigned sh_1, sh_2;
mp_size i;
if (usize <= 0)
return 0;
sh_1 = cnt;
if (sh_1 == 0)
{
if (wp != up)
{
/* Copy from low end to high end, to allow specified input/output
overlapping. */
for (i = 0; i < usize; i++)
wp[i] = up[i];
}
return usize;
}
wp -= 1;
sh_2 = BITS_PER_MP_LIMB - sh_1;
low_limb = up[0];
for (i = 1; i < usize; i++)
{
high_limb = up[i];
wp[i] = (low_limb >> sh_1) | (high_limb << sh_2);
low_limb = high_limb;
}
low_limb = (low_limb >> sh_1) | (carry_in << sh_2);
if (low_limb != 0)
{
wp[i] = low_limb;
return usize;
}
return usize - 1;
}

View File

@ -1,479 +0,0 @@
/* mpn_sqrt(root_ptr, rem_ptr, op_ptr, op_size)
Write the square root of {OP_PTR, OP_SIZE} at ROOT_PTR.
Write the remainder at REM_PTR, if REM_PTR != NULL.
Return the size of the remainder.
(The size of the root is always half of the size of the operand.)
OP_PTR and ROOT_PTR may not point to the same object.
OP_PTR and REM_PTR may point to the same object.
If REM_PTR is NULL, only the root is computed and the return value of
the function is 0 if OP is a perfect square, and *any* non-zero number
otherwise.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This code is just correct if "unsigned char" has at least 8 bits. It
doesn't help to use CHAR_BIT from limits.h, as the real problem is
the static arrays. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
/* Square root algorithm:
1. Shift OP (the input) to the left an even number of bits s.t. there
are an even number of words and either (or both) of the most
significant bits are set. This way, sqrt(OP) has exactly half as
many words as OP, and has its most significant bit set.
2. Get a 9-bit approximation to sqrt(OP) using the pre-computed tables.
This approximation is used for the first single-precision
iterations of Newton's method, yielding a full-word approximation
to sqrt(OP).
3. Perform multiple-precision Newton iteration until we have the
exact result. Only about half of the input operand is used in
this calculation, as the square root is perfectly determinable
from just the higher half of a number. */
/* Define this macro for IEEE P854 machines with a fast sqrt instruction. */
#if defined __GNUC__
#if defined __sparc__
#define SQRT(a) \
({ \
double __sqrt_res; \
asm ("fsqrtd %1,%0" : "=f" (__sqrt_res) : "f" (a)); \
__sqrt_res; \
})
#endif
#if defined __HAVE_68881__
#define SQRT(a) \
({ \
double __sqrt_res; \
asm ("fsqrtx %1,%0" : "=f" (__sqrt_res) : "f" (a)); \
__sqrt_res; \
})
#endif
#if defined __hppa
#define SQRT(a) \
({ \
double __sqrt_res; \
asm ("fsqrt,dbl %1,%0" : "=fx" (__sqrt_res) : "fx" (a)); \
__sqrt_res; \
})
#endif
#endif
#ifndef SQRT
/* Tables for initial approximation of the square root. These are
indexed with bits 1-8 of the operand for which the square root is
calculated, where bit 0 is the most significant non-zero bit. I.e.
the most significant one-bit is not used, since that per definition
is one. Likewise, the tables don't return the highest bit of the
result. That bit must be inserted by or:ing the returned value with
0x100. This way, we get a 9-bit approximation from 8-bit tables! */
/* Table to be used for operands with an even total number of bits.
(Exactly as in the decimal system there are similarities between the
square root of numbers with the same initial digits and an even
difference in the total number of digits. Consider the square root
of 1, 10, 100, 1000, ...) */
static unsigned char even_approx_tab[256] =
{
0x6a, 0x6a, 0x6b, 0x6c, 0x6c, 0x6d, 0x6e, 0x6e,
0x6f, 0x70, 0x71, 0x71, 0x72, 0x73, 0x73, 0x74,
0x75, 0x75, 0x76, 0x77, 0x77, 0x78, 0x79, 0x79,
0x7a, 0x7b, 0x7b, 0x7c, 0x7d, 0x7d, 0x7e, 0x7f,
0x80, 0x80, 0x81, 0x81, 0x82, 0x83, 0x83, 0x84,
0x85, 0x85, 0x86, 0x87, 0x87, 0x88, 0x89, 0x89,
0x8a, 0x8b, 0x8b, 0x8c, 0x8d, 0x8d, 0x8e, 0x8f,
0x8f, 0x90, 0x90, 0x91, 0x92, 0x92, 0x93, 0x94,
0x94, 0x95, 0x96, 0x96, 0x97, 0x97, 0x98, 0x99,
0x99, 0x9a, 0x9b, 0x9b, 0x9c, 0x9c, 0x9d, 0x9e,
0x9e, 0x9f, 0xa0, 0xa0, 0xa1, 0xa1, 0xa2, 0xa3,
0xa3, 0xa4, 0xa4, 0xa5, 0xa6, 0xa6, 0xa7, 0xa7,
0xa8, 0xa9, 0xa9, 0xaa, 0xaa, 0xab, 0xac, 0xac,
0xad, 0xad, 0xae, 0xaf, 0xaf, 0xb0, 0xb0, 0xb1,
0xb2, 0xb2, 0xb3, 0xb3, 0xb4, 0xb5, 0xb5, 0xb6,
0xb6, 0xb7, 0xb7, 0xb8, 0xb9, 0xb9, 0xba, 0xba,
0xbb, 0xbb, 0xbc, 0xbd, 0xbd, 0xbe, 0xbe, 0xbf,
0xc0, 0xc0, 0xc1, 0xc1, 0xc2, 0xc2, 0xc3, 0xc3,
0xc4, 0xc5, 0xc5, 0xc6, 0xc6, 0xc7, 0xc7, 0xc8,
0xc9, 0xc9, 0xca, 0xca, 0xcb, 0xcb, 0xcc, 0xcc,
0xcd, 0xce, 0xce, 0xcf, 0xcf, 0xd0, 0xd0, 0xd1,
0xd1, 0xd2, 0xd3, 0xd3, 0xd4, 0xd4, 0xd5, 0xd5,
0xd6, 0xd6, 0xd7, 0xd7, 0xd8, 0xd9, 0xd9, 0xda,
0xda, 0xdb, 0xdb, 0xdc, 0xdc, 0xdd, 0xdd, 0xde,
0xde, 0xdf, 0xe0, 0xe0, 0xe1, 0xe1, 0xe2, 0xe2,
0xe3, 0xe3, 0xe4, 0xe4, 0xe5, 0xe5, 0xe6, 0xe6,
0xe7, 0xe7, 0xe8, 0xe8, 0xe9, 0xea, 0xea, 0xeb,
0xeb, 0xec, 0xec, 0xed, 0xed, 0xee, 0xee, 0xef,
0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf3,
0xf3, 0xf4, 0xf4, 0xf5, 0xf5, 0xf6, 0xf6, 0xf7,
0xf7, 0xf8, 0xf8, 0xf9, 0xf9, 0xfa, 0xfa, 0xfb,
0xfb, 0xfc, 0xfc, 0xfd, 0xfd, 0xfe, 0xfe, 0xff,
};
/* Table to be used for operands with an odd total number of bits.
(Further comments before previous table.) */
static unsigned char odd_approx_tab[256] =
{
0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03,
0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x06, 0x07,
0x07, 0x08, 0x08, 0x09, 0x09, 0x0a, 0x0a, 0x0b,
0x0b, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0e, 0x0f,
0x0f, 0x10, 0x10, 0x10, 0x11, 0x11, 0x12, 0x12,
0x13, 0x13, 0x14, 0x14, 0x15, 0x15, 0x16, 0x16,
0x16, 0x17, 0x17, 0x18, 0x18, 0x19, 0x19, 0x1a,
0x1a, 0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1d, 0x1d,
0x1e, 0x1e, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x21,
0x21, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24,
0x25, 0x25, 0x26, 0x26, 0x27, 0x27, 0x27, 0x28,
0x28, 0x29, 0x29, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b,
0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2f,
0x2f, 0x30, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32,
0x32, 0x33, 0x33, 0x34, 0x34, 0x35, 0x35, 0x35,
0x36, 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x39,
0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3b, 0x3c,
0x3c, 0x3d, 0x3d, 0x3d, 0x3e, 0x3e, 0x3f, 0x3f,
0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x42, 0x42,
0x43, 0x43, 0x43, 0x44, 0x44, 0x45, 0x45, 0x45,
0x46, 0x46, 0x47, 0x47, 0x47, 0x48, 0x48, 0x49,
0x49, 0x49, 0x4a, 0x4a, 0x4b, 0x4b, 0x4b, 0x4c,
0x4c, 0x4c, 0x4d, 0x4d, 0x4e, 0x4e, 0x4e, 0x4f,
0x4f, 0x50, 0x50, 0x50, 0x51, 0x51, 0x51, 0x52,
0x52, 0x53, 0x53, 0x53, 0x54, 0x54, 0x54, 0x55,
0x55, 0x56, 0x56, 0x56, 0x57, 0x57, 0x57, 0x58,
0x58, 0x59, 0x59, 0x59, 0x5a, 0x5a, 0x5a, 0x5b,
0x5b, 0x5b, 0x5c, 0x5c, 0x5d, 0x5d, 0x5d, 0x5e,
0x5e, 0x5e, 0x5f, 0x5f, 0x60, 0x60, 0x60, 0x61,
0x61, 0x61, 0x62, 0x62, 0x62, 0x63, 0x63, 0x63,
0x64, 0x64, 0x65, 0x65, 0x65, 0x66, 0x66, 0x66,
0x67, 0x67, 0x67, 0x68, 0x68, 0x68, 0x69, 0x69,
};
#endif
mp_size
#ifdef __STDC__
mpn_sqrt (mp_ptr root_ptr, mp_ptr rem_ptr, mp_srcptr op_ptr, mp_size op_size)
#else
mpn_sqrt (root_ptr, rem_ptr, op_ptr, op_size)
mp_ptr root_ptr;
mp_ptr rem_ptr;
mp_srcptr op_ptr;
mp_size op_size;
#endif
{
/* R (root result) */
mp_ptr rp; /* Pointer to least significant word */
mp_size rsize; /* The size in words */
/* T (OP shifted to the left a.k.a. normalized) */
mp_ptr tp; /* Pointer to least significant word */
mp_size tsize; /* The size in words */
mp_ptr t_end_ptr; /* Pointer right beyond most sign. word */
mp_limb t_high0, t_high1; /* The two most significant words */
/* TT (temporary for numerator/remainder) */
mp_ptr ttp; /* Pointer to least significant word */
/* X (temporary for quotient in main loop) */
mp_ptr xp; /* Pointer to least significant word */
mp_size xsize; /* The size in words */
unsigned cnt;
mp_limb initial_approx; /* Initially made approximation */
mp_size tsizes[BITS_PER_MP_LIMB]; /* Successive calculation precisions */
mp_size tmp;
mp_size i;
/* If OP is zero, both results are zero. */
if (op_size == 0)
return 0;
count_leading_zeros (cnt, op_ptr[op_size - 1]);
tsize = op_size;
if ((tsize & 1) != 0)
{
cnt += BITS_PER_MP_LIMB;
tsize++;
}
rsize = tsize / 2;
rp = root_ptr;
/* Shift OP an even number of bits into T, such that either the most or
the second most significant bit is set, and such that the number of
words in T becomes even. This way, the number of words in R=sqrt(OP)
is exactly half as many as in OP, and the most significant bit of R
is set.
Also, the initial approximation is simplified by this up-shifted OP.
Finally, the Newtonian iteration which is the main part of this
program performs division by R. The fast division routine expects
the divisor to be "normalized" in exactly the sense of having the
most significant bit set. */
tp = (mp_ptr) alloca (tsize * BYTES_PER_MP_LIMB);
t_high0 = mpn_lshift (tp + cnt / BITS_PER_MP_LIMB, op_ptr, op_size,
(cnt & ~1) % BITS_PER_MP_LIMB);
if (cnt >= BITS_PER_MP_LIMB)
tp[0] = 0;
t_high0 = tp[tsize - 1];
t_high1 = tp[tsize - 2]; /* Never stray. TSIZE is >= 2. */
/* Is there a fast sqrt instruction defined for this machine? */
#ifdef SQRT
{
initial_approx = SQRT (t_high0 * 2.0
* ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1))
+ t_high1);
/* If t_high0,,t_high1 is big, the result in INITIAL_APPROX might have
become incorrect due to overflow in the conversion from double to
mp_limb above. It will typically be zero in that case, but might be
a small number on some machines. The most significant bit of
INITIAL_APPROX should be set, so that bit is a good overflow
indication. */
if ((mp_limb_signed) initial_approx >= 0)
initial_approx = ~0;
}
#else
/* Get a 9 bit approximation from the tables. The tables expect to
be indexed with the 8 high bits right below the highest bit.
Also, the highest result bit is not returned by the tables, and
must be or:ed into the result. The scheme gives 9 bits of start
approximation with just 256-entry 8 bit tables. */
if ((cnt & 1) == 0)
{
/* The most sign bit of t_high0 is set. */
initial_approx = t_high0 >> (BITS_PER_MP_LIMB - 8 - 1);
initial_approx &= 0xff;
initial_approx = even_approx_tab[initial_approx];
}
else
{
/* The most significant bit of T_HIGH0 is unset,
the second most significant is set. */
initial_approx = t_high0 >> (BITS_PER_MP_LIMB - 8 - 2);
initial_approx &= 0xff;
initial_approx = odd_approx_tab[initial_approx];
}
initial_approx |= 0x100;
initial_approx <<= BITS_PER_MP_LIMB - 8 - 1;
/* Perform small precision Newtonian iterations to get a full word
approximation. For small operands, these iteration will make the
entire job. */
if (t_high0 == ~0)
initial_approx = t_high0;
else
{
mp_limb quot;
if (t_high0 >= initial_approx)
initial_approx = t_high0 + 1;
/* First get about 18 bits with pure C arithmetics. */
quot = t_high0 / (initial_approx >> BITS_PER_MP_LIMB/2) << BITS_PER_MP_LIMB/2;
initial_approx = (initial_approx + quot) / 2;
initial_approx |= (mp_limb) 1 << (BITS_PER_MP_LIMB - 1);
/* Now get a full word by one (or for > 36 bit machines) several
iterations. */
for (i = 16; i < BITS_PER_MP_LIMB; i <<= 1)
{
mp_limb ignored_remainder;
udiv_qrnnd (quot, ignored_remainder,
t_high0, t_high1, initial_approx);
initial_approx = (initial_approx + quot) / 2;
initial_approx |= (mp_limb) 1 << (BITS_PER_MP_LIMB - 1);
}
}
#endif
rp[0] = initial_approx;
rsize = 1;
xp = (mp_ptr) alloca (tsize * BYTES_PER_MP_LIMB);
ttp = (mp_ptr) alloca (tsize * BYTES_PER_MP_LIMB);
t_end_ptr = tp + tsize;
#ifdef DEBUG
printf ("\n\nT = ");
_mp_mout (tp, tsize);
#endif
if (tsize > 2)
{
/* Determine the successive precisions to use in the iteration. We
minimize the precisions, beginning with the highest (i.e. last
iteration) to the lowest (i.e. first iteration). */
tmp = tsize / 2;
for (i = 0;;i++)
{
tsize = (tmp + 1) / 2;
if (tmp == tsize)
break;
tsizes[i] = tsize + tmp;
tmp = tsize;
}
/* Main Newton iteration loop. For big arguments, most of the
time is spent here. */
/* It is possible to do a great optimization here. The successive
divisors in the mpn_div call below has more and more leading
words equal to its predecessor. Therefore the beginning of
each division will repeat the same work as did the last
division. If we could guarantee that the leading words of two
consecutive divisors are the same (i.e. in this case, a later
divisor has just more digits at the end) it would be a simple
matter of just using the old remainder of the last division in
a subsequent division, to take care of this optimization. This
idea would surely make a difference even for small arguments. */
/* Loop invariants:
R <= shiftdown_to_same_size(floor(sqrt(OP))) < R + 1.
X - 1 < shiftdown_to_same_size(floor(sqrt(OP))) <= X.
R <= shiftdown_to_same_size(X). */
while (--i >= 0)
{
mp_limb cy;
#ifdef DEBUG
mp_limb old_least_sign_r = rp[0];
mp_size old_rsize = rsize;
printf ("R = ");
_mp_mout (rp, rsize);
#endif
tsize = tsizes[i];
/* Need to copy the numerator into temporary space, as
mpn_div overwrites its numerator argument with the
remainder (which we currently ignore). */
MPN_COPY (ttp, t_end_ptr - tsize, tsize);
cy = mpn_div (xp, ttp, tsize, rp, rsize);
xsize = tsize - rsize;
cy = cy ? xp[xsize] : 0;
#ifdef DEBUG
printf ("X =%d", cy);
_mp_mout (xp, xsize);
#endif
/* Add X and R with the most significant limbs aligned,
temporarily ignoring at least one limb at the low end of X. */
tmp = xsize - rsize;
cy += mpn_add (xp + tmp, rp, rsize, xp + tmp, rsize);
/* If T begins with more than 2 x BITS_PER_MP_LIMB of ones, we get
intermediate roots that'd need an extra bit. We don't want to
handle that since it would make the subsequent divisor
non-normalized, so round such roots down to be only ones in the
current precision. */
if (cy == 2)
{
mp_size j;
for (j = xsize; j >= 0; j--)
xp[j] = ~(mp_limb)0;
}
/* Divide X by 2 and put the result in R. This is the new
approximation. Shift in the carry from the addition. */
rsize = mpn_rshiftci (rp, xp, xsize, 1, (mp_limb) 1);
#ifdef DEBUG
if (old_least_sign_r != rp[rsize - old_rsize])
printf (">>>>>>>> %d: %08x, %08x <<<<<<<<\n",
i, old_least_sign_r, rp[rsize - old_rsize]);
#endif
}
}
#ifdef DEBUG
printf ("(final) R = ");
_mp_mout (rp, rsize);
#endif
/* We computed the square root of OP * 2**(2*floor(cnt/2)).
This has resulted in R being 2**floor(cnt/2) to large.
Shift it down here to fix that. */
rsize = mpn_rshift (rp, rp, rsize, cnt/2);
/* Calculate the remainder. */
tsize = mpn_mul (tp, rp, rsize, rp, rsize);
if (op_size < tsize
|| (op_size == tsize && mpn_cmp (op_ptr, tp, op_size) < 0))
{
/* R is too large. Decrement it. */
mp_limb one = 1;
tsize = tsize + mpn_sub (tp, tp, tsize, rp, rsize);
tsize = tsize + mpn_sub (tp, tp, tsize, rp, rsize);
tsize = tsize + mpn_add (tp, tp, tsize, &one, 1);
(void) mpn_sub (rp, rp, rsize, &one, 1);
#ifdef DEBUG
printf ("(adjusted) R = ");
_mp_mout (rp, rsize);
#endif
}
if (rem_ptr != NULL)
{
mp_size retval = op_size + mpn_sub (rem_ptr, op_ptr, op_size, tp, tsize);
alloca (0);
return retval;
}
else
{
mp_size retval = (op_size != tsize || mpn_cmp (op_ptr, tp, op_size));
alloca (0);
return retval;
}
}
#ifdef DEBUG
_mp_mout (mp_srcptr p, mp_size size)
{
mp_size ii;
for (ii = size - 1; ii >= 0; ii--)
printf ("%08X", p[ii]);
puts ("");
}
#endif

View File

@ -1,162 +0,0 @@
/* mpn_sub -- Subtract two low-level natural-number integers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Subtract SUB_PTR/SUB_SIZE from MIN_PTR/MIN_SIZE and store the
result (MIN_SIZE words) at DIF_PTR.
Return 1 if min < sub (result is negative). Otherwise, return the
negative difference between the number of words in dif and min.
(I.e. return 0 if the result has MIN_SIZE words, -1 if it has
MIN_SIZE - 1 words, etc.)
Argument constraint: MIN_SIZE >= SUB_SIZE.
The size of DIF can be calculated as MIN_SIZE + the return value. */
mp_size
#ifdef __STDC__
mpn_sub (mp_ptr dif_ptr,
mp_srcptr min_ptr, mp_size min_size,
mp_srcptr sub_ptr, mp_size sub_size)
#else
mpn_sub (dif_ptr, min_ptr, min_size, sub_ptr, sub_size)
mp_ptr dif_ptr;
mp_srcptr min_ptr;
mp_size min_size;
mp_srcptr sub_ptr;
mp_size sub_size;
#endif
{
mp_limb m, s, dif;
mp_size j;
/* The loop counter and index J goes from some negative value to zero.
This way the loops are faster. Need to offset the base pointers
to take care of the negative indices. */
j = -sub_size;
if (j == 0)
goto sub_finished;
min_ptr -= j;
sub_ptr -= j;
dif_ptr -= j;
/* There are two do-loops, marked NON-CARRY LOOP and CARRY LOOP that
jump between each other. The first loop is for when the previous
subtraction didn't produce a carry-out; the second is for the
complementary case. */
/* NON-CARRY LOOP */
do
{
m = min_ptr[j];
s = sub_ptr[j];
dif = m - s;
dif_ptr[j] = dif;
if (dif > m)
goto cy_loop;
ncy_loop:
j++;
}
while (j < 0);
/* We have exhausted SUB, with no carry out. Copy remaining part of
MIN to DIF. */
sub_finished:
j = sub_size - min_size;
/* If there's no difference between the length of the operands, the
last words might have become zero, and re-normalization is needed. */
if (j == 0)
goto normalize;
min_ptr -= j;
dif_ptr -= j;
goto copy;
/* CARRY LOOP */
do
{
m = min_ptr[j];
s = sub_ptr[j];
dif = m - s - 1;
dif_ptr[j] = dif;
if (dif < m)
goto ncy_loop;
cy_loop:
j++;
}
while (j < 0);
/* We have exhausted SUB, but need to propagate carry. */
j = sub_size - min_size;
if (j == 0)
return 1; /* min < sub. Flag it to the caller */
min_ptr -= j;
dif_ptr -= j;
/* Propagate carry. Sooner or later the carry will cancel with a
non-zero word, because the minuend is normalized. Considering this,
there's no need to test the index J. */
for (;;)
{
m = min_ptr[j];
dif = m - 1;
dif_ptr[j] = dif;
j++;
if (dif < m)
break;
}
if (j == 0)
goto normalize;
copy:
/* Don't copy the remaining words of MIN to DIF if MIN_PTR and DIF_PTR
are equal. It would just be a no-op copying. Return 0, as the length
of the result equals that of the minuend. */
if (dif_ptr == min_ptr)
return 0;
do
{
dif_ptr[j] = min_ptr[j];
j++;
}
while (j < 0);
return 0;
normalize:
for (j = -1; j >= -min_size; j--)
{
if (dif_ptr[j] != 0)
return j + 1;
}
return -min_size;
}

View File

@ -1,85 +0,0 @@
/* mpq_add -- add two rational numbers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_add (MP_RAT *sum, const MP_RAT *a1, const MP_RAT *a2)
#else
mpq_add (sum, a1, a2)
MP_RAT *sum;
const MP_RAT *a1;
const MP_RAT *a2;
#endif
{
MP_INT gcd1, gcd2;
MP_INT tmp1, tmp2;
mpz_init (&gcd1);
mpz_init (&gcd2);
mpz_init (&tmp1);
mpz_init (&tmp2);
/* SUM might be identical to either operand, so don't store the
result there until we are finished with the input operands. We
dare to overwrite the numerator of SUM when we are finished
with the numerators of A1 and A2. */
mpz_gcd (&gcd1, &(a1->den), &(a2->den));
if (gcd1.size > 1 || gcd1.d[0] != 1)
{
MP_INT t;
mpz_init (&t);
mpz_div (&tmp1, &(a2->den), &gcd1);
mpz_mul (&tmp1, &(a1->num), &tmp1);
mpz_div (&tmp2, &(a1->den), &gcd1);
mpz_mul (&tmp2, &(a2->num), &tmp2);
mpz_add (&t, &tmp1, &tmp2);
mpz_gcd (&gcd2, &t, &gcd1);
mpz_div (&(sum->num), &t, &gcd2);
mpz_div (&tmp1, &(a1->den), &gcd1);
mpz_div (&tmp2, &(a2->den), &gcd2);
mpz_mul (&(sum->den), &tmp1, &tmp2);
mpz_clear (&t);
}
else
{
/* The common divisior is 1. This is the case (for random input) with
probability 6/(pi**2). */
mpz_mul (&tmp1, &(a1->num), &(a2->den));
mpz_mul (&tmp2, &(a2->num), &(a1->den));
mpz_add (&(sum->num), &tmp1, &tmp2);
mpz_mul (&(sum->den), &(a1->den), &(a2->den));
}
mpz_clear (&tmp2);
mpz_clear (&tmp1);
mpz_clear (&gcd2);
mpz_clear (&gcd1);
}

View File

@ -1,34 +0,0 @@
/* mpq_clear -- free the space occupied by a MP_RAT.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_clear (MP_RAT *m)
#else
mpq_clear (m)
MP_RAT *m;
#endif
{
(*_mp_free_func) (m->num.d, m->num.alloc * BYTES_PER_MP_LIMB);
(*_mp_free_func) (m->den.d, m->den.alloc * BYTES_PER_MP_LIMB);
}

View File

@ -1,76 +0,0 @@
/* mpq_cmp(u,v) -- Compare U, V. Return positive, zero, or negative
based on if U > V, U == V, or U < V.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#ifdef __STDC__
mpq_cmp (const MP_RAT *op1, const MP_RAT *op2)
#else
mpq_cmp (op1, op2)
const MP_RAT *op1;
const MP_RAT *op2;
#endif
{
mp_size num1_size = op1->num.size;
mp_size den1_size = op1->den.size;
mp_size num2_size = op2->num.size;
mp_size den2_size = op2->den.size;
mp_size tmp1_size, tmp2_size;
mp_ptr tmp1_ptr, tmp2_ptr;
mp_size num1_sign;
int cc;
if (num1_size == 0)
return -num2_size;
if (num2_size == 0)
return num1_size;
if ((num1_size ^ num2_size) < 0) /* I.e. are the signs different? */
return num1_size;
num1_sign = num1_size;
num1_size = ABS (num1_size);
num2_size = ABS (num2_size);
tmp1_size = num1_size + den2_size;
tmp2_size = num2_size + den1_size;
if (tmp1_size != tmp2_size)
return (tmp1_size - tmp2_size) ^ num1_sign;
tmp1_ptr = (mp_ptr) alloca (tmp1_size * BYTES_PER_MP_LIMB);
tmp2_ptr = (mp_ptr) alloca (tmp2_size * BYTES_PER_MP_LIMB);
tmp1_size = (num1_size >= den2_size)
? mpn_mul (tmp1_ptr, op1->num.d, num1_size, op2->den.d, den2_size)
: mpn_mul (tmp1_ptr, op2->den.d, den2_size, op1->num.d, num1_size);
tmp2_size = (num2_size >= den1_size)
? mpn_mul (tmp2_ptr, op2->num.d, num2_size, op1->den.d, den1_size)
: mpn_mul (tmp2_ptr, op1->den.d, den1_size, op2->num.d, num2_size);
cc = tmp1_size - tmp2_size != 0
? tmp1_size - tmp2_size : mpn_cmp (tmp1_ptr, tmp2_ptr, tmp1_size);
alloca (0);
return (num1_sign < 0) ? -cc : cc;
}

View File

@ -1,92 +0,0 @@
/* mpq_div -- divide two rational numbers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_div (MP_RAT *quot, const MP_RAT *dividend, const MP_RAT *divisor)
#else
mpq_div (quot, dividend, divisor)
MP_RAT *quot;
const MP_RAT *dividend;
const MP_RAT *divisor;
#endif
{
MP_INT gcd1, gcd2;
MP_INT tmp1, tmp2;
MP_INT numtmp;
mpz_init (&gcd1);
mpz_init (&gcd2);
mpz_init (&tmp1);
mpz_init (&tmp2);
mpz_init (&numtmp);
/* QUOT might be identical to either operand, so don't store the
result there until we are finished with the input operands. We
dare to overwrite the numerator of QUOT when we are finished
with the numerators of DIVIDEND and DIVISOR. */
mpz_gcd (&gcd1, &(dividend->num), &(divisor->num));
mpz_gcd (&gcd2, &(divisor->den), &(dividend->den));
if (gcd1.size > 1 || gcd1.d[0] != 1)
mpz_div (&tmp1, &(dividend->num), &gcd1);
else
mpz_set (&tmp1, &(dividend->num));
if (gcd2.size > 1 || gcd2.d[0] != 1)
mpz_div (&tmp2, &(divisor->den), &gcd2);
else
mpz_set (&tmp2, &(divisor->den));
mpz_mul (&numtmp, &tmp1, &tmp2);
if (gcd1.size > 1 || gcd1.d[0] != 1)
mpz_div (&tmp1, &(divisor->num), &gcd1);
else
mpz_set (&tmp1, &(divisor->num));
if (gcd2.size > 1 || gcd2.d[0] != 1)
mpz_div (&tmp2, &(dividend->den), &gcd2);
else
mpz_set (&tmp2, &(dividend->den));
mpz_mul (&(quot->den), &tmp1, &tmp2);
/* We needed to go via NUMTMP to take care of QUOT being the same
as either input operands. Now move NUMTMP to QUOT->NUM. */
mpz_set (&(quot->num), &numtmp);
/* Keep the denominator positive. */
if (quot->den.size < 0)
{
quot->den.size = -quot->den.size;
quot->num.size = -quot->num.size;
}
mpz_clear (&numtmp);
mpz_clear (&tmp2);
mpz_clear (&tmp1);
mpz_clear (&gcd2);
mpz_clear (&gcd1);
}

View File

@ -1,40 +0,0 @@
/* mpq_get_den(den,rat_src) -- Set DEN to the denominator of RAT_SRC.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_get_den (MP_INT *den, const MP_RAT *src)
#else
mpq_get_den (den, src)
MP_INT *den;
const MP_RAT *src;
#endif
{
mp_size size = src->den.size;
if (den->alloc < size)
_mpz_realloc (den, size);
MPN_COPY (den->d, src->den.d, size);
den->size = size;
}

View File

@ -1,41 +0,0 @@
/* mpq_get_num(num,rat_src) -- Set NUM to the numerator of RAT_SRC.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_get_num (MP_INT *num, const MP_RAT *src)
#else
mpq_get_num (num, src)
MP_INT *num;
const MP_RAT *src;
#endif
{
mp_size size = src->num.size;
mp_size abs_size = ABS (size);
if (num->alloc < abs_size)
_mpz_realloc (num, abs_size);
MPN_COPY (num->d, src->num.d, abs_size);
num->size = size;
}

View File

@ -1,39 +0,0 @@
/* mpq_init -- Make a new rational number with value 0/1.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_init (MP_RAT *x)
#else
mpq_init (x)
MP_RAT *x;
#endif
{
x->num.alloc = 1;
x->num.d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB * x->num.alloc);
x->num.size = 0;
x->den.alloc = 1;
x->den.d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB * x->den.alloc);
x->den.d[0] = 1;
x->den.size = 1;
}

View File

@ -1,74 +0,0 @@
/* mpq_inv(dest,src) -- invert a rational number, i.e. set DEST to SRC
with the numerator and denominator swapped.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_inv (MP_RAT *dest, const MP_RAT *src)
#else
mpq_inv (dest, src)
MP_RAT *dest;
const MP_RAT *src;
#endif
{
mp_size num_size = src->num.size;
mp_size den_size = src->den.size;
if (num_size == 0)
num_size = 1 / num_size; /* Divide by zero! */
if (num_size < 0)
{
num_size = -num_size;
den_size = -den_size;
}
dest->den.size = num_size;
dest->num.size = den_size;
/* If dest == src we may just swap the numerator and denominator, but
we have to ensure the new denominator is positive. */
if (dest == src)
{
mp_size alloc = dest->num.alloc;
mp_ptr limb_ptr = dest->num.d;
dest->num.alloc = dest->den.alloc;
dest->num.d = dest->den.d;
dest->den.alloc = alloc;
dest->den.d = limb_ptr;
}
else
{
den_size = ABS (den_size);
if (dest->num.alloc < den_size)
_mpz_realloc (&(dest->num), den_size);
if (dest->den.alloc < num_size)
_mpz_realloc (&(dest->den), num_size);
MPN_COPY (dest->num.d, src->den.d, den_size);
MPN_COPY (dest->den.d, src->num.d, num_size);
}
}

View File

@ -1,78 +0,0 @@
/* mpq_mul -- mutiply two rational numbers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_mul (MP_RAT *prod, const MP_RAT *m1, const MP_RAT *m2)
#else
mpq_mul (prod, m1, m2)
MP_RAT *prod;
const MP_RAT *m1;
const MP_RAT *m2;
#endif
{
MP_INT gcd1, gcd2;
MP_INT tmp1, tmp2;
mpz_init (&gcd1);
mpz_init (&gcd2);
mpz_init (&tmp1);
mpz_init (&tmp2);
/* PROD might be identical to either operand, so don't store the
result there until we are finished with the input operands. We
dare to overwrite the numerator of PROD when we are finished
with the numerators of M1 and M1. */
mpz_gcd (&gcd1, &(m1->num), &(m2->den));
mpz_gcd (&gcd2, &(m2->num), &(m1->den));
if (gcd1.size > 1 || gcd1.d[0] != 1)
mpz_div (&tmp1, &(m1->num), &gcd1);
else
mpz_set (&tmp1, &(m1->num));
if (gcd2.size > 1 || gcd2.d[0] != 1)
mpz_div (&tmp2, &(m2->num), &gcd2);
else
mpz_set (&tmp2, &(m2->num));
mpz_mul (&(prod->num), &tmp1, &tmp2);
if (gcd1.size > 1 || gcd1.d[0] != 1)
mpz_div (&tmp1, &(m2->den), &gcd1);
else
mpz_set (&tmp1, &(m2->den));
if (gcd2.size > 1 || gcd2.d[0] != 1)
mpz_div (&tmp2, &(m1->den), &gcd2);
else
mpz_set (&tmp2, &(m1->den));
mpz_mul (&(prod->den), &tmp1, &tmp2);
mpz_clear (&tmp2);
mpz_clear (&tmp1);
mpz_clear (&gcd2);
mpz_clear (&gcd1);
}

View File

@ -1,35 +0,0 @@
/* mpq_neg(dst, src) -- Assign the negated value of SRC to DST.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_neg (MP_RAT *dst, const MP_RAT *src)
#else
mpq_neg (dst, src)
MP_RAT *dst;
const MP_RAT *src;
#endif
{
mpz_neg (&dst->num, &src->num);
mpz_set (&dst->den, &src->den);
}

View File

@ -1,48 +0,0 @@
/* mpq_set(dest,src) -- Set DEST to SRC.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_set (MP_RAT *dest, const MP_RAT *src)
#else
mpq_set (dest, src)
MP_RAT *dest;
const MP_RAT *src;
#endif
{
mp_size num_size, den_size;
mp_size abs_num_size;
num_size = src->num.size;
abs_num_size = ABS (num_size);
if (dest->num.alloc < abs_num_size)
_mpz_realloc (&(dest->num), abs_num_size);
MPN_COPY (dest->num.d, src->num.d, abs_num_size);
dest->num.size = num_size;
den_size = src->den.size;
if (dest->den.alloc < den_size)
_mpz_realloc (&(dest->den), den_size);
MPN_COPY (dest->den.d, src->den.d, den_size);
dest->den.size = den_size;
}

View File

@ -1,46 +0,0 @@
/* mpq_set_den(dest,den) -- Set the denominator of DEST from DEN.
If DEN < 0 change the sign of the numerator of DEST.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_set_den (MP_RAT *dest, const MP_INT *den)
#else
mpq_set_den (dest, den)
MP_RAT *dest;
const MP_INT *den;
#endif
{
mp_size size = den->size;
mp_size abs_size = ABS (size);
if (dest->den.alloc < abs_size)
_mpz_realloc (&(dest->den), abs_size);
MPN_COPY (dest->den.d, den->d, abs_size);
dest->den.size = abs_size;
/* The denominator is always positive; move the sign to the numerator. */
if (size < 0)
dest->num.size = -dest->num.size;
}

View File

@ -1,41 +0,0 @@
/* mpq_set_num(dest,num) -- Set the numerator of DEST from NUM.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_set_num (MP_RAT *dest, const MP_INT *num)
#else
mpq_set_num (dest, num)
MP_RAT *dest;
const MP_INT *num;
#endif
{
mp_size size = num->size;
mp_size abs_size = ABS (size);
if (dest->num.alloc < abs_size)
_mpz_realloc (&(dest->num), abs_size);
MPN_COPY (dest->num.d, num->d, abs_size);
dest->num.size = size;
}

View File

@ -1,76 +0,0 @@
/* mpq_set_si(dest,ulong_num,ulong_den) -- Set DEST to the retional number
ULONG_NUM/ULONG_DEN.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
static unsigned long int
gcd (x, y)
unsigned long int x, y;
{
for (;;)
{
x = x % y;
if (x == 0)
return y;
y = y % x;
if (y == 0)
return x;
}
}
void
#ifdef __STDC__
mpq_set_si (MP_RAT *dest, signed long int num, unsigned long int den)
#else
mpq_set_si (dest, num, den)
MP_RAT *dest;
signed long int num;
unsigned long int den;
#endif
{
unsigned long int g;
unsigned long int abs_num;
abs_num = ABS (num);
if (num == 0)
{
/* Canonicalize 0/d to 0/1. */
den = 1;
dest->num.size = 0;
}
else
{
/* Remove any common factor in NUM and DEN. */
/* Pass DEN as the second argument to gcd, in order to make the
gcd function divide by zero if DEN is zero. */
g = gcd (abs_num, den);
abs_num /= g;
den /= g;
dest->num.d[0] = abs_num;
dest->num.size = num > 0 ? 1 : -1;
}
dest->den.d[0] = den;
dest->den.size = 1;
}

View File

@ -1,73 +0,0 @@
/* mpq_set_ui(dest,ulong_num,ulong_den) -- Set DEST to the retional number
ULONG_NUM/ULONG_DEN.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
static unsigned long int
gcd (x, y)
unsigned long int x, y;
{
for (;;)
{
x = x % y;
if (x == 0)
return y;
y = y % x;
if (y == 0)
return x;
}
}
void
#ifdef __STDC__
mpq_set_ui (MP_RAT *dest, unsigned long int num, unsigned long int den)
#else
mpq_set_ui (dest, num, den)
MP_RAT *dest;
unsigned long int num;
unsigned long int den;
#endif
{
unsigned long int g;
if (num == 0)
{
/* Canonicalize 0/n to 0/1. */
den = 1;
dest->num.size = 0;
}
else
{
/* Remove any common factor in NUM and DEN. */
/* Pass DEN as the second argument to gcd, in order to make the
gcd function divide by zero if DEN is zero. */
g = gcd (num, den);
num /= g;
den /= g;
dest->num.d[0] = num;
dest->num.size = 1;
}
dest->den.d[0] = den;
dest->den.size = 1;
}

View File

@ -1,85 +0,0 @@
/* mpq_sub -- subtract two rational numbers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpq_sub (MP_RAT *dif, const MP_RAT *min, const MP_RAT *sub)
#else
mpq_sub (dif, min, sub)
MP_RAT *dif;
const MP_RAT *min;
const MP_RAT *sub;
#endif
{
MP_INT gcd1, gcd2;
MP_INT tmp1, tmp2;
mpz_init (&gcd1);
mpz_init (&gcd2);
mpz_init (&tmp1);
mpz_init (&tmp2);
/* DIF might be identical to either operand, so don't store the
result there until we are finished with the input operands. We
dare to overwrite the numerator of DIF when we are finished
with the numerators of MIN and SUB. */
mpz_gcd (&gcd1, &(min->den), &(sub->den));
if (gcd1.size > 1 || gcd1.d[0] != 1)
{
MP_INT t;
mpz_init (&t);
mpz_div (&tmp1, &(sub->den), &gcd1);
mpz_mul (&tmp1, &(min->num), &tmp1);
mpz_div (&tmp2, &(min->den), &gcd1);
mpz_mul (&tmp2, &(sub->num), &tmp2);
mpz_sub (&t, &tmp1, &tmp2);
mpz_gcd (&gcd2, &t, &gcd1);
mpz_div (&(dif->num), &t, &gcd2);
mpz_div (&tmp1, &(min->den), &gcd1);
mpz_div (&tmp2, &(sub->den), &gcd2);
mpz_mul (&(dif->den), &tmp1, &tmp2);
mpz_clear (&t);
}
else
{
/* The common divisior is 1. This is the case (for random input) with
probability 6/(pi**2). */
mpz_mul (&tmp1, &(min->num), &(sub->den));
mpz_mul (&tmp2, &(sub->num), &(min->den));
mpz_sub (&(dif->num), &tmp1, &tmp2);
mpz_mul (&(dif->den), &(min->den), &(sub->den));
}
mpz_clear (&tmp2);
mpz_clear (&tmp1);
mpz_clear (&gcd2);
mpz_clear (&gcd1);
}

View File

@ -1,44 +0,0 @@
/* mpz_abs(MP_INT *dst, MP_INT *src) -- Assign the absolute value of SRC to DST.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_abs (MP_INT *dst, const MP_INT *src)
#else
mpz_abs (dst, src)
MP_INT *dst;
const MP_INT *src;
#endif
{
mp_size src_size = ABS (src->size);
if (src != dst)
{
if (dst->alloc < src_size)
_mpz_realloc (dst, src_size);
MPN_COPY (dst->d, src->d, src_size);
}
dst->size = src_size;
}

View File

@ -1,121 +0,0 @@
/* mpz_add -- Add two integers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#ifndef BERKELEY_MP
void
#ifdef __STDC__
mpz_add (MP_INT *sum, const MP_INT *u, const MP_INT *v)
#else
mpz_add (sum, u, v)
MP_INT *sum;
const MP_INT *u;
const MP_INT *v;
#endif
#else /* BERKELEY_MP */
void
#ifdef __STDC__
madd (const MP_INT *u, const MP_INT *v, MP_INT *sum)
#else
madd (u, v, sum)
const MP_INT *u;
const MP_INT *v;
MP_INT *sum;
#endif
#endif /* BERKELEY_MP */
{
mp_srcptr up, vp;
mp_ptr sump;
mp_size usize, vsize, sumsize;
mp_size abs_usize;
mp_size abs_vsize;
usize = u->size;
vsize = v->size;
abs_usize = ABS (usize);
abs_vsize = ABS (vsize);
if (abs_usize < abs_vsize)
{
/* Swap U and V. */
{const MP_INT *t = u; u = v; v = t;}
{mp_size t = usize; usize = vsize; vsize = t;}
{mp_size t = abs_usize; abs_usize = abs_vsize; abs_vsize = t;}
}
/* True: abs(USIZE) >= abs(VSIZE) */
/* If not space for sum (and possible carry), increase space. */
sumsize = abs_usize + 1;
if (sum->alloc < sumsize)
_mpz_realloc (sum, sumsize);
/* These must be after realloc (u or v may be the same as sum). */
up = u->d;
vp = v->d;
sump = sum->d;
if (usize >= 0)
{
if (vsize >= 0)
{
sumsize = mpn_add (sump, up, abs_usize, vp, abs_vsize);
if (sumsize != 0)
sump[abs_usize] = 1;
sumsize = sumsize + abs_usize;
}
else
{
/* The signs are different. Need exact comparision to determine
which operand to subtract from which. */
if (abs_usize == abs_vsize && mpn_cmp (up, vp, abs_usize) < 0)
sumsize = -(abs_usize
+ mpn_sub (sump, vp, abs_usize, up, abs_usize));
else
sumsize = (abs_usize
+ mpn_sub (sump, up, abs_usize, vp, abs_vsize));
}
}
else
{
if (vsize >= 0)
{
/* The signs are different. Need exact comparision to determine
which operand to subtract from which. */
if (abs_usize == abs_vsize && mpn_cmp (up, vp, abs_usize) < 0)
sumsize = (abs_usize
+ mpn_sub (sump, vp, abs_usize, up, abs_usize));
else
sumsize = -(abs_usize
+ mpn_sub (sump, up, abs_usize, vp, abs_vsize));
}
else
{
sumsize = mpn_add (sump, up, abs_usize, vp, abs_vsize);
if (sumsize != 0)
sump[abs_usize] = 1;
sumsize = -(sumsize + abs_usize);
}
}
sum->size = sumsize;
}

View File

@ -1,84 +0,0 @@
/* mpz_add_ui -- Add an MP_INT and an unsigned one-word integer.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_add_ui (MP_INT *sum, const MP_INT *add1, mp_limb add2)
#else
mpz_add_ui (sum, add1, add2)
MP_INT *sum;
const MP_INT *add1;
mp_limb add2;
#endif
{
mp_srcptr add1p;
mp_ptr sump;
mp_size add1size, sumsize;
mp_size abs_add1size;
add1size = add1->size;
abs_add1size = ABS (add1size);
/* If not space for SUM (and possible carry), increase space. */
sumsize = abs_add1size + 1;
if (sum->alloc < sumsize)
_mpz_realloc (sum, sumsize);
/* These must be after realloc (ADD1 may be the same as SUM). */
add1p = add1->d;
sump = sum->d;
if (add2 == 0)
{
MPN_COPY (sump, add1p, abs_add1size);
sum->size = add1size;
return;
}
if (abs_add1size == 0)
{
sump[0] = add2;
sum->size = 1;
return;
}
if (add1size >= 0)
{
sumsize = mpn_add (sump, add1p, abs_add1size, &add2, 1);
if (sumsize != 0)
sump[abs_add1size] = 1;
sumsize = sumsize + abs_add1size;
}
else
{
/* The signs are different. Need exact comparision to determine
which operand to subtract from which. */
if (abs_add1size == 1 && add1p[0] < add2)
sumsize = (abs_add1size
+ mpn_sub (sump, &add2, 1, add1p, 1));
else
sumsize = -(abs_add1size
+ mpn_sub (sump, add1p, abs_add1size, &add2, 1));
}
sum->size = sumsize;
}

View File

@ -1,267 +0,0 @@
/* mpz_and -- Logical and.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#define min(l,o) ((l) < (o) ? (l) : (o))
#define max(h,i) ((h) > (i) ? (h) : (i))
void
#ifdef __STDC__
mpz_and (MP_INT *res, const MP_INT *op1, const MP_INT *op2)
#else
mpz_and (res, op1, op2)
MP_INT *res;
const MP_INT *op1;
const MP_INT *op2;
#endif
{
mp_srcptr op1_ptr, op2_ptr;
mp_size op1_size, op2_size;
mp_ptr res_ptr;
mp_size res_size;
mp_size i;
op1_size = op1->size;
op2_size = op2->size;
op1_ptr = op1->d;
op2_ptr = op2->d;
res_ptr = res->d;
if (op1_size >= 0)
{
if (op2_size >= 0)
{
res_size = min (op1_size, op2_size);
/* First loop finds the size of the result. */
for (i = res_size - 1; i >= 0; i--)
if ((op1_ptr[i] & op2_ptr[i]) != 0)
break;
res_size = i + 1;
/* Handle allocation, now when we know exactly how much space is
needed for the result. */
if (res->alloc < res_size)
{
_mpz_realloc (res, res_size);
op1_ptr = op1->d;
op2_ptr = op2->d;
res_ptr = res->d;
}
/* Second loop computes the real result. */
for (i = res_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] & op2_ptr[i];
res->size = res_size;
return;
}
else /* op2_size < 0 */
/* Fall through to the code at the end of the function. */
;
}
else
{
if (op2_size < 0)
{
mp_ptr opx;
mp_limb cy;
mp_limb one = 1;
mp_size res_alloc;
/* Both operands are negative, so will be the result.
-((-OP1) & (-OP2)) = -(~(OP1 - 1) & ~(OP2 - 1)) =
= ~(~(OP1 - 1) & ~(OP2 - 1)) + 1 =
= ((OP1 - 1) | (OP2 - 1)) + 1 */
op1_size = -op1_size;
op2_size = -op2_size;
res_alloc = 1 + max (op1_size, op2_size);
opx = (mp_ptr) alloca (op1_size * BYTES_PER_MP_LIMB);
op1_size += mpn_sub (opx, op1_ptr, op1_size, &one, 1);
op1_ptr = opx;
opx = (mp_ptr) alloca (op2_size * BYTES_PER_MP_LIMB);
op2_size += mpn_sub (opx, op2_ptr, op2_size, &one, 1);
op2_ptr = opx;
if (res->alloc < res_alloc)
{
_mpz_realloc (res, res_alloc);
res_ptr = res->d;
/* Don't re-read OP1_PTR and OP2_PTR. They point to
temporary space--never to the space RES->D used
to point to before reallocation. */
}
if (op1_size >= op2_size)
{
MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
op1_size - op2_size);
for (i = op2_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] | op2_ptr[i];
res_size = op1_size;
}
else
{
MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
op2_size - op1_size);
for (i = op1_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] | op2_ptr[i];
res_size = op2_size;
}
if (res_size != 0)
{
cy = mpn_add (res_ptr, res_ptr, res_size, &one, 1);
if (cy)
{
res_ptr[res_size] = cy;
res_size++;
}
}
else
{
res_ptr[0] = 1;
res_size = 1;
}
res->size = -res_size;
return;
}
else
{
/* We should compute -OP1 & OP2. Swap OP1 and OP2 and fall
through to the code that handles OP1 & -OP2. */
{const MP_INT *t = op1; op1 = op2; op2 = t;}
{mp_srcptr t = op1_ptr; op1_ptr = op2_ptr; op2_ptr = t;}
{mp_size t = op1_size; op1_size = op2_size; op2_size = t;}
}
}
{
#if 0
mp_size op2_lim;
/* OP2 must be negated as with infinite precision.
Scan from the low end for a non-zero limb. The first non-zero
limb is simply negated (two's complement). Any subsequent
limbs are one's complemented. Of course, we don't need to
handle more limbs than there are limbs in the other, positive
operand as the result for those limbs is going to become zero
anyway. */
/* Scan for the least significant. non-zero OP2 limb, and zero the
result meanwhile for those limb positions. (We will surely
find a non-zero limb, so we can write the loop with one
termination condition only.) */
for (i = 0; op2_ptr[i] == 0; i++)
res_ptr[i] = 0;
op2_lim = i;
op2_size = -op2_size;
if (op1_size <= op2_size)
{
/* The ones-extended OP2 is >= than the zero-extended OP1.
RES_SIZE <= OP1_SIZE. Find the exact size. */
for (i = op1_size - 1; i > op2_lim; i--)
if ((op1_ptr[i] & ~op2_ptr[i]) != 0)
break;
res_size = i + 1;
}
else
{
/* The ones-extended OP2 is < than the zero-extended OP1.
RES_SIZE == OP1_SIZE, since OP1 is normalized. */
res_size = op1_size;
}
#endif
/* OP1 is positive and zero-extended,
OP2 is negative and ones-extended.
The result will be positive.
OP1 & -OP2 = OP1 & ~(OP2 - 1). */
mp_ptr opx;
const mp_limb one = 1;
op2_size = -op2_size;
opx = (mp_ptr) alloca (op2_size * BYTES_PER_MP_LIMB);
op2_size += mpn_sub (opx, op2_ptr, op2_size, &one, 1);
op2_ptr = opx;
if (op1_size > op2_size)
{
/* The result has the same size as OP1, since OP1 is normalized
and longer than the ones-extended OP2. */
res_size = op1_size;
/* Handle allocation, now when we know exactly how much space is
needed for the result. */
if (res->alloc < res_size)
{
_mpz_realloc (res, res_size);
res_ptr = res->d;
op1_ptr = op1->d;
/* Don't re-read OP2_PTR. It points to temporary space--never
to the space RES->D used to point to before reallocation. */
}
MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
res_size - op2_size);
for (i = op2_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] & ~op2_ptr[i];
res->size = res_size;
}
else
{
/* Find out the exact result size. Ignore the high limbs of OP2,
OP1 is zero-extended and would make the result zero. */
for (i = op1_size - 1; i >= 0; i--)
if ((op1_ptr[i] & ~op2_ptr[i]) != 0)
break;
res_size = i + 1;
/* Handle allocation, now when we know exactly how much space is
needed for the result. */
if (res->alloc < res_size)
{
_mpz_realloc (res, res_size);
res_ptr = res->d;
op1_ptr = op1->d;
/* Don't re-read OP2_PTR. It points to temporary space--never
to the space RES->D used to point to before reallocation. */
}
for (i = res_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] & ~op2_ptr[i];
res->size = res_size;
}
}
}

View File

@ -1,34 +0,0 @@
/* mpz_clear -- de-allocate the space occupied by the dynamic digit space of
an integer.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_clear (MP_INT *m)
#else
mpz_clear (m)
MP_INT *m;
#endif
{
(*_mp_free_func) (m->d, m->alloc * BYTES_PER_MP_LIMB);
}

View File

@ -1,124 +0,0 @@
/* mpz_clrbit -- clear a specified bit.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#define MPN_NORMALIZE(p, size) \
do { \
mp_size i; \
for (i = (size) - 1; i >= 0; i--) \
if ((p)[i] != 0) \
break; \
(size) = i + 1; \
} while (0)
void
#ifdef __STDC__
mpz_clrbit (MP_INT *d, unsigned long int bit_index)
#else
mpz_clrbit (d, bit_index)
MP_INT *d;
unsigned long int bit_index;
#endif
{
mp_size dsize = d->size;
mp_ptr dp = d->d;
mp_size limb_index;
limb_index = bit_index / BITS_PER_MP_LIMB;
if (dsize >= 0)
{
if (limb_index < dsize)
{
dp[limb_index] &= ~((mp_limb) 1 << (bit_index % BITS_PER_MP_LIMB));
MPN_NORMALIZE (dp, dsize);
d->size = dsize;
}
else
;
}
else
{
mp_size zero_bound;
/* Simulate two's complement arithmetic, i.e. simulate
1. Set OP = ~(OP - 1) [with infinitely many leading ones].
2. clear the bit.
3. Set OP = ~OP + 1. */
dsize = -dsize;
/* No upper bound on this loop, we're sure there's a non-zero limb
sooner ot later. */
for (zero_bound = 0; ; zero_bound++)
if (dp[zero_bound] != 0)
break;
if (limb_index > zero_bound)
{
if (limb_index < dsize)
{
dp[limb_index] |= ((mp_limb) 1 << (bit_index % BITS_PER_MP_LIMB));
}
else
{
/* Ugh. The bit should be cleared outside of the end of the
number. We have to increase the size of the number. */
if (d->alloc < limb_index + 1)
{
_mpz_realloc (d, limb_index + 1);
dp = d->d;
}
MPN_ZERO (dp + dsize, limb_index - dsize);
dp[limb_index] = ((mp_limb) 1 << (bit_index % BITS_PER_MP_LIMB));
d->size = -(limb_index + 1);
}
}
else if (limb_index == zero_bound)
{
dp[limb_index] = ((dp[limb_index] - 1)
| ((mp_limb) 1 << (bit_index % BITS_PER_MP_LIMB))) + 1;
if (dp[limb_index] == 0)
{
mp_size i;
for (i = limb_index + 1; i < dsize; i++)
{
dp[i] += 1;
if (dp[i] != 0)
goto fin;
}
/* We got carry all way out beyond the end of D. Increase
its size (and allocation if necessary). */
dsize++;
if (d->alloc < dsize)
{
_mpz_realloc (d, dsize);
dp = d->d;
}
dp[i] = 1;
d->size = -dsize;
fin:;
}
}
else
;
}
}

View File

@ -1,84 +0,0 @@
/* mpz_cmp(u,v) -- Compare U, V. Return postive, zero, or negative
based on if U > V, U == V, or U < V.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef BERKELEY_MP
#include "mp.h"
#endif
#include "gmp.h"
#include "gmp-impl.h"
#ifndef BERKELEY_MP
int
#ifdef __STDC__
mpz_cmp (const MP_INT *u, const MP_INT *v)
#else
mpz_cmp (u, v)
const MP_INT *u;
const MP_INT *v;
#endif
#else /* BERKELEY_MP */
int
#ifdef __STDC__
mcmp (const MP_INT *u, const MP_INT *v)
#else
mcmp (u, v)
const MP_INT *u;
const MP_INT *v;
#endif
#endif /* BERKELEY_MP */
{
mp_size usize = u->size;
mp_size vsize = v->size;
mp_size size;
mp_size i;
mp_limb a, b;
mp_srcptr up, vp;
if (usize != vsize)
return usize - vsize;
if (usize == 0)
return 0;
size = ABS (usize);
up = u->d;
vp = v->d;
i = size - 1;
do
{
a = up[i];
b = vp[i];
i--;
if (i < 0)
break;
}
while (a == b);
if (a == b)
return 0;
if ((a < b) == (usize < 0))
return 1;
else
return -1;
}

View File

@ -1,62 +0,0 @@
/* mpz_cmp_si(u,v) -- Compare an integer U with a single-word int V.
Return positive, zero, or negative based on if U > V, U == V, or U < V.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#ifdef __STDC__
mpz_cmp_si (const MP_INT *u, signed long int v_digit)
#else
mpz_cmp_si (u, v_digit)
const MP_INT *u;
signed long int v_digit;
#endif
{
mp_size usize = u->size;
mp_size vsize;
mp_limb u_digit;
vsize = 0;
if (v_digit > 0)
vsize = 1;
else if (v_digit < 0)
{
vsize = -1;
v_digit = -v_digit;
}
if (usize != vsize)
return usize - vsize;
if (usize == 0)
return 0;
u_digit = u->d[0];
if (u_digit == v_digit)
return 0;
if ((u_digit < v_digit) == (usize < 0))
return 1;
else
return -1;
}

View File

@ -1,52 +0,0 @@
/* mpz_cmp_ui.c -- Compare a MP_INT a with an mp_limb b. Return positive,
zero, or negative based on if a > b, a == b, or a < b.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
int
#ifdef __STDC__
mpz_cmp_ui (const MP_INT *u, mp_limb v_digit)
#else
mpz_cmp_ui (u, v_digit)
const MP_INT *u;
mp_limb v_digit;
#endif
{
mp_size usize = u->size;
if (usize == 0)
return -(v_digit != 0);
if (usize == 1)
{
mp_limb u_digit;
u_digit = u->d[0];
if (u_digit > v_digit)
return 1;
if (u_digit < v_digit)
return -1;
return 0;
}
return (usize > 0) ? 1 : -1;
}

View File

@ -1,96 +0,0 @@
/* mpz_com(MP_INT *dst, MP_INT *src) -- Assign the bit-complemented value of
SRC to DST.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_com (MP_INT *dst, const MP_INT *src)
#else
mpz_com (dst, src)
MP_INT *dst;
const MP_INT *src;
#endif
{
mp_size size = src->size;
mp_srcptr src_ptr;
mp_ptr dst_ptr;
if (size >= 0)
{
/* As with infinite precision: one's complement, two's complement.
But this can be simplified using the identity -x = ~x + 1.
So we're going to compute (~~x) + 1 = x + 1! */
if (dst->alloc < size + 1)
_mpz_realloc (dst, size + 1);
src_ptr = src->d;
dst_ptr = dst->d;
if (size == 0)
{
/* Special case, as mpn_add wants the first arg's size >= the
second arg's size. */
dst_ptr[0] = 1;
dst->size = -1;
return;
}
{
mp_limb one = 1;
int cy;
cy = mpn_add (dst_ptr, src_ptr, size, &one, 1);
if (cy)
{
dst_ptr[size] = cy;
size++;
}
}
/* Store a negative size, to indicate ones-extension. */
dst->size = -size;
}
else
{
/* As with infinite precision: two's complement, then one's complement.
But that can be simplified using the identity -x = ~(x - 1).
So we're going to compute ~~(x - 1) = x - 1! */
size = -size;
if (dst->alloc < size)
_mpz_realloc (dst, size);
src_ptr = src->d;
dst_ptr = dst->d;
{
mp_limb one = 1;
size += mpn_sub (dst_ptr, src_ptr, size, &one, 1);
}
/* Store a positive size, to indicate zero-extension. */
dst->size = size;
}
}

View File

@ -1,117 +0,0 @@
/* mpz_div -- divide two integers and produce a quotient.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mpz_div (MP_INT *quot, const MP_INT *num, const MP_INT *den)
#else
mpz_div (quot, num, den)
MP_INT *quot;
const MP_INT *num;
const MP_INT *den;
#endif
{
mp_srcptr np, dp;
mp_ptr qp, rp;
mp_size nsize = num->size;
mp_size dsize = den->size;
mp_size qsize, rsize;
mp_size sign_quotient = nsize ^ dsize;
unsigned normalization_steps;
nsize = ABS (nsize);
dsize = ABS (dsize);
/* Ensure space is enough for quotient. */
qsize = nsize - dsize + 1; /* qsize cannot be bigger than this. */
if (qsize <= 0)
{
quot->size = 0;
return;
}
if (quot->alloc < qsize)
_mpz_realloc (quot, qsize);
qp = quot->d;
np = num->d;
dp = den->d;
rp = (mp_ptr) alloca ((nsize + 1) * BYTES_PER_MP_LIMB);
count_leading_zeros (normalization_steps, dp[dsize - 1]);
/* Normalize the denominator and the numerator. */
if (normalization_steps != 0)
{
mp_ptr tp;
mp_limb ndigit;
/* Shift up the denominator setting the most significant bit of
the most significant word. Use temporary storage not to clobber
the original contents of the denominator. */
tp = (mp_ptr) alloca (dsize * BYTES_PER_MP_LIMB);
(void) mpn_lshift (tp, dp, dsize, normalization_steps);
dp = tp;
/* Shift up the numerator, possibly introducing a new most
significant word. Move the shifted numerator in the remainder
meanwhile. */
ndigit = mpn_lshift (rp, np, nsize, normalization_steps);
if (ndigit != 0)
{
rp[nsize] = ndigit;
rsize = nsize + 1;
}
else
rsize = nsize;
}
else
{
/* The denominator is already normalized, as required.
Copy it to temporary space if it overlaps with the quotient. */
if (dp == qp)
{
dp = (mp_ptr) alloca (dsize * BYTES_PER_MP_LIMB);
MPN_COPY ((mp_ptr) dp, qp, dsize);
}
/* Move the numerator to the remainder. */
MPN_COPY (rp, np, nsize);
rsize = nsize;
}
qsize = rsize - dsize + mpn_div (qp, rp, rsize, dp, dsize);
/* Normalize the quotient. We may have at most one leading
zero-word, so no loop is needed. */
if (qsize > 0)
qsize -= (qp[qsize - 1] == 0);
if (sign_quotient < 0)
qsize = -qsize;
quot->size = qsize;
alloca (0);
}

View File

@ -1,53 +0,0 @@
/* mpz_div_2exp -- Divide a bignum by 2**CNT
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_div_2exp (MP_INT *w, const MP_INT *u, unsigned long int cnt)
#else
mpz_div_2exp (w, u, cnt)
MP_INT *w;
const MP_INT *u;
unsigned long int cnt;
#endif
{
mp_size usize = u->size;
mp_size wsize;
mp_size abs_usize = ABS (usize);
mp_size limb_cnt;
limb_cnt = cnt / BITS_PER_MP_LIMB;
wsize = abs_usize - limb_cnt;
if (wsize <= 0)
wsize = 0;
else
{
if (w->alloc < wsize)
_mpz_realloc (w, wsize);
wsize = mpn_rshift (w->d, u->d + limb_cnt, abs_usize - limb_cnt,
cnt % BITS_PER_MP_LIMB);
}
w->size = (usize >= 0) ? wsize : -wsize;
}

View File

@ -1,65 +0,0 @@
/* mpz_div_ui(quot, dividend, divisor_limb)
-- Divide DIVIDEND by DIVISOR_LIMB and store the result in QUOT.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mpz_div_ui (MP_INT *quot, const MP_INT *dividend, unsigned long int divisor_limb)
#else
mpz_div_ui (quot, dividend, divisor_limb)
MP_INT *quot;
const MP_INT *dividend;
unsigned long int divisor_limb;
#endif
{
mp_size sign_dividend;
mp_size dividend_size, quot_size;
mp_ptr dividend_ptr, quot_ptr;
sign_dividend = dividend->size;
dividend_size = ABS (dividend->size);
if (dividend_size == 0)
{
quot->size = 0;
return;
}
/* No need for temporary allocation and copying if QUOT == DIVIDEND as
the divisor is just one limb, and thus no intermediate remainders
need to be stored. */
if (quot->alloc < dividend_size)
_mpz_realloc (quot, dividend_size);
quot_ptr = quot->d;
dividend_ptr = dividend->d;
mpn_divmod_1 (quot_ptr, dividend_ptr, dividend_size, divisor_limb);
/* The quotient is DIVIDEND_SIZE limbs, but the most significant
might be zero. Set QUOT_SIZE properly. */
quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0);
quot->size = sign_dividend >= 0 ? quot_size : -quot_size;
}

View File

@ -1,38 +0,0 @@
/* mpz_divmod(quot,rem,dividend,divisor) -- Set QUOT to DIVIDEND/DIVISOR,
and REM to DIVIDEND mod DIVISOR.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mpz_divmod (MP_INT *quot, MP_INT *rem, const MP_INT *num, const MP_INT *den)
#else
mpz_divmod (quot, rem, num, den)
MP_INT *quot;
MP_INT *rem;
const MP_INT *num;
const MP_INT *den;
#endif
#define COMPUTE_QUOTIENT
#include "mpz_dmincl.c"

View File

@ -1,81 +0,0 @@
/* mpz_divmod_ui(quot,rem,dividend,short_divisor) --
Set QUOT to DIVIDEND / SHORT_DIVISOR
and REM to DIVIDEND mod SHORT_DIVISOR.
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mpz_divmod_ui (MP_INT *quot, MP_INT *rem,
const MP_INT *dividend, unsigned long int divisor_limb)
#else
mpz_divmod_ui (quot, rem, dividend, divisor_limb)
MP_INT *quot;
MP_INT *rem;
const MP_INT *dividend;
unsigned long int divisor_limb;
#endif
{
mp_size sign_dividend;
mp_size dividend_size, quot_size;
mp_ptr dividend_ptr, quot_ptr;
mp_limb remainder_limb;
sign_dividend = dividend->size;
dividend_size = ABS (dividend->size);
if (dividend_size == 0)
{
quot->size = 0;
rem->size = 0;
return;
}
/* No need for temporary allocation and copying if QUOT == DIVIDEND as
the divisor is just one limb, and thus no intermediate remainders
need to be stored. */
if (quot->alloc < dividend_size)
_mpz_realloc (quot, dividend_size);
quot_ptr = quot->d;
dividend_ptr = dividend->d;
remainder_limb = mpn_divmod_1 (quot_ptr,
dividend_ptr, dividend_size, divisor_limb);
if (remainder_limb == 0)
rem->size = 0;
else
{
/* Store the single-limb remainder. We don't check if there's space
for just one limb, since no function ever makes zero space. */
rem->size = sign_dividend >= 0 ? 1 : -1;
rem->d[0] = remainder_limb;
}
/* The quotient is DIVIDEND_SIZE limbs, but the most significant
might be zero. Set QUOT_SIZE properly. */
quot_size = dividend_size - (quot_ptr[dividend_size - 1] == 0);
quot->size = sign_dividend >= 0 ? quot_size : -quot_size;
}

View File

@ -1,172 +0,0 @@
/* mpz_dmincl.c -- include file for mpz_dm.c, mpz_mod.c, mdiv.c.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* THIS CODE IS OBSOLETE. IT WILL SOON BE REPLACED BY CLEANER CODE WITH
LESS MEMORY ALLOCATION OVERHEAD. */
/* If den == quot, den needs temporary storage.
If den == rem, den needs temporary storage.
If num == quot, num needs temporary storage.
If den has temporary storage, it can be normalized while being copied,
i.e no extra storage should be allocated. */
/* This is the function body of mdiv, mpz_divmod, and mpz_mod.
If COMPUTE_QUOTIENT is defined, the quotient is put in the MP_INT
object quot, otherwise that variable is not referenced at all.
The remainder is always computed, and the result is put in the MP_INT
object rem. */
{
mp_ptr np, dp;
mp_ptr qp, rp;
mp_size nsize = num->size;
mp_size dsize = den->size;
mp_size qsize, rsize;
mp_size sign_remainder = nsize;
#ifdef COMPUTE_QUOTIENT
mp_size sign_quotient = nsize ^ dsize;
#endif
unsigned normalization_steps;
nsize = ABS (nsize);
dsize = ABS (dsize);
/* Ensure space is enough for quotient and remainder. */
/* We need space for an extra limb in the remainder, because it's
up-shifted (normalized) below. */
rsize = nsize + 1;
if (rem->alloc < rsize)
_mpz_realloc (rem, rsize);
qsize = nsize - dsize + 1; /* qsize cannot be bigger than this. */
if (qsize <= 0)
{
#ifdef COMPUTE_QUOTIENT
quot->size = 0;
#endif
if (num != rem)
{
rem->size = num->size;
MPN_COPY (rem->d, num->d, nsize);
}
return;
}
#ifdef COMPUTE_QUOTIENT
if (quot->alloc < qsize)
_mpz_realloc (quot, qsize);
qp = quot->d;
#else
qp = (mp_ptr) alloca (qsize * BYTES_PER_MP_LIMB);
#endif
np = num->d;
dp = den->d;
rp = rem->d;
/* Make sure quot and num are different. Otherwise the numerator
would be successively overwritten by the quotient digits. */
if (qp == np)
{
np = (mp_ptr) alloca (nsize * BYTES_PER_MP_LIMB);
MPN_COPY (np, qp, nsize);
}
count_leading_zeros (normalization_steps, dp[dsize - 1]);
/* Normalize the denominator, i.e. make its most significant bit set by
shifting it NORMALIZATION_STEPS bits to the left. Also shift the
numerator the same number of steps (to keep the quotient the same!). */
if (normalization_steps != 0)
{
mp_ptr tp;
mp_limb ndigit;
/* Shift up the denominator setting the most significant bit of
the most significant word. Use temporary storage not to clobber
the original contents of the denominator. */
tp = (mp_ptr) alloca (dsize * BYTES_PER_MP_LIMB);
(void) mpn_lshift (tp, dp, dsize, normalization_steps);
dp = tp;
/* Shift up the numerator, possibly introducing a new most
significant word. Move the shifted numerator in the remainder
meanwhile. */
ndigit = mpn_lshift (rp, np, nsize, normalization_steps);
if (ndigit != 0)
{
rp[nsize] = ndigit;
rsize = nsize + 1;
}
else
rsize = nsize;
}
else
{
#ifdef COMPUTE_QUOTIENT
if (rem == den || quot == den)
#else
if (rem == den)
#endif
{
mp_ptr tp;
tp = (mp_ptr) alloca (dsize * BYTES_PER_MP_LIMB);
MPN_COPY (tp, dp, dsize);
dp = tp;
}
/* Move the numerator to the remainder. */
if (rp != np)
MPN_COPY (rp, np, nsize);
rsize = nsize;
}
qsize = rsize - dsize + mpn_div (qp, rp, rsize, dp, dsize);
rsize = dsize;
/* Normalize the remainder. */
while (rsize > 0)
{
if (rp[rsize - 1] != 0)
break;
rsize--;
}
if (normalization_steps != 0)
rsize = mpn_rshift (rp, rp, rsize, normalization_steps);
rem->size = (sign_remainder >= 0) ? rsize : -rsize;
#ifdef COMPUTE_QUOTIENT
/* Normalize the quotient. We may have at most one leading
zero-word, so no loop is needed. */
if (qsize > 0)
qsize -= (qp[qsize - 1] == 0);
quot->size = (sign_quotient >= 0) ? qsize : -qsize;
#endif
alloca (0);
}

View File

@ -1,156 +0,0 @@
/* mpz_fac_ui(result, n) -- Set RESULT to N!.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef DBG
#include <stdio.h>
#endif
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
void
#ifdef __STDC__
mpz_fac_ui (MP_INT *result, unsigned long int n)
#else
mpz_fac_ui (result, n)
MP_INT *result;
unsigned long int n;
#endif
{
#if SIMPLE_FAC
/* Be silly. Just multiply the numbers in ascending order. O(n**2). */
mp_limb k;
mpz_set_ui (result, (mp_limb) 1);
for (k = 2; k <= n; k++)
mpz_mul_ui (result, result, k);
#else
/* Be smarter. Multiply groups of numbers in ascending order until the
product doesn't fit in a limb. Multiply these partial products in a
balanced binary tree fashion, to make the operand have as equal sizes
as possible. (When the operands have about the same size, mpn_mul
becomes faster.) */
mp_limb k;
mp_limb p1, p0, p;
/* Stack of partial products, used to make the computation balanced
(i.e. make the sizes of the multiplication operands equal). The
topmost position of MP_STACK will contain a one-limb partial product,
the second topmost will contain a two-limb partial product, and so
on. MP_STACK[0] will contain a partial product with 2**t limbs.
To compute n! MP_STACK needs to be less than
log(n)**2/log(BITS_PER_MP_LIMB), so 30 is surely enough. */
#define MP_STACK_SIZE 30
MP_INT mp_stack[MP_STACK_SIZE];
/* TOP is an index into MP_STACK, giving the topmost element.
TOP_LIMIT_SO_FAR is the largets value it has taken so far. */
int top, top_limit_so_far;
/* Count of the total number of limbs put on MP_STACK so far. This
variable plays an essential role in making the compututation balanced.
See below. */
unsigned int tree_cnt;
top = top_limit_so_far = -1;
tree_cnt = 0;
p = 1;
for (k = 2; k <= n; k++)
{
/* Multiply the partial product in P with K. */
umul_ppmm (p1, p0, p, k);
/* Did we get overflow into the high limb, i.e. is the partial
product now more than one limb? */
if (p1 != 0)
{
tree_cnt++;
if (tree_cnt % 2 == 0)
{
mp_size i;
/* TREE_CNT is even (i.e. we have generated an even number of
one-limb partial products), which means that we have a
single-limb product on the top of MP_STACK. */
mpz_mul_ui (&mp_stack[top], &mp_stack[top], p);
/* If TREE_CNT is divisable by 4, 8,..., we have two
similar-sized partial products with 2, 4,... limbs at
the topmost two positions of MP_STACK. Multiply them
to form a new partial product with 4, 8,... limbs. */
for (i = 4; (tree_cnt & (i - 1)) == 0; i <<= 1)
{
mpz_mul (&mp_stack[top - 1],
&mp_stack[top], &mp_stack[top - 1]);
top--;
}
}
else
{
/* Put the single-limb partial product in P on the stack.
(The next time we get a single-limb product, we will
multiply the two together.) */
top++;
if (top > top_limit_so_far)
{
if (top > MP_STACK_SIZE)
abort();
/* The stack is now bigger than ever, initialize the top
element. */
mpz_init_set_ui (&mp_stack[top], p);
top_limit_so_far++;
}
else
mpz_set_ui (&mp_stack[top], p);
}
/* We ignored the last result from umul_ppmm. Put K in P as the
first component of the next single-limb partial product. */
p = k;
}
else
/* We didn't get overflow in umul_ppmm. Put p0 in P and try
with one more value of K. */
p = p0;
}
/* We have partial products in mp_stack[0..top], in descending order.
We also have a small partial product in p.
Their product is the final result. */
if (top < 0)
mpz_set_ui (result, p);
else
mpz_mul_ui (result, &mp_stack[top--], p);
while (top >= 0)
mpz_mul (result, result, &mp_stack[top--]);
/* Free the storage allocated for MP_STACK. */
for (top = top_limit_so_far; top >= 0; top--)
mpz_clear (&mp_stack[top]);
#endif
}

View File

@ -1,169 +0,0 @@
/* mpz_gcd -- Calculate the greatest common divisior of two integers.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
#ifndef BERKELEY_MP
void
#ifdef __STDC__
mpz_gcd (MP_INT *w, const MP_INT *u, const MP_INT *v)
#else
mpz_gcd (w, u, v)
MP_INT *w;
const MP_INT *u;
const MP_INT *v;
#endif
#else /* BERKELEY_MP */
void
#ifdef __STDC__
gcd (const MP_INT *u, const MP_INT *v, MP_INT *w)
#else
gcd (u, v, w)
const MP_INT *u;
const MP_INT *v;
MP_INT *w;
#endif
#endif /* BERKELEY_MP */
{
mp_size usize, vsize, wsize;
mp_ptr up_in, vp_in;
mp_ptr up, vp;
mp_ptr wp;
mp_size i;
mp_limb d;
int bcnt;
mp_size w_bcnt;
mp_limb cy_digit;
usize = ABS (u->size);
vsize = ABS (v->size);
/* GCD(0,v) == v. */
if (usize == 0)
{
if (w->alloc < vsize)
_mpz_realloc (w, vsize);
w->size = vsize;
MPN_COPY (w->d, v->d, vsize);
return;
}
/* GCD(0,u) == u. */
if (vsize == 0)
{
if (w->alloc < usize)
_mpz_realloc (w, usize);
w->size = usize;
MPN_COPY (w->d, u->d, usize);
return;
}
/* Make U odd by shifting it down as many bit positions as there
are zero bits. Put the result in temporary space. */
up = (mp_ptr) alloca (usize * BYTES_PER_MP_LIMB);
up_in = u->d;
for (i = 0; (d = up_in[i]) == 0; i++)
;
count_leading_zeros (bcnt, d & -d);
bcnt = BITS_PER_MP_LIMB - 1 - bcnt;
usize = mpn_rshift (up, up_in + i, usize - i, bcnt);
bcnt += i * BITS_PER_MP_LIMB;
w_bcnt = bcnt;
/* Make V odd by shifting it down as many bit positions as there
are zero bits. Put the result in temporary space. */
vp = (mp_ptr) alloca (vsize * BYTES_PER_MP_LIMB);
vp_in = v->d;
for (i = 0; (d = vp_in[i]) == 0; i++)
;
count_leading_zeros (bcnt, d & -d);
bcnt = BITS_PER_MP_LIMB - 1 - bcnt;
vsize = mpn_rshift (vp, vp_in + i, vsize - i, bcnt);
/* W_BCNT is set to the minimum of the number of zero bits in U and V.
Thus it represents the number of common 2 factors. */
bcnt += i * BITS_PER_MP_LIMB;
if (bcnt < w_bcnt)
w_bcnt = bcnt;
for (;;)
{
int cmp;
cmp = usize - vsize != 0 ? usize - vsize : mpn_cmp (up, vp, usize);
/* If U and V have become equal, we have found the GCD. */
if (cmp == 0)
break;
if (cmp > 0)
{
/* Replace U by (U - V) >> cnt, with cnt being the least value
making U odd again. */
usize += mpn_sub (up, up, usize, vp, vsize);
for (i = 0; (d = up[i]) == 0; i++)
;
count_leading_zeros (bcnt, d & -d);
bcnt = BITS_PER_MP_LIMB - 1 - bcnt;
usize = mpn_rshift (up, up + i, usize - i, bcnt);
}
else
{
/* Replace V by (V - U) >> cnt, with cnt being the least value
making V odd again. */
vsize += mpn_sub (vp, vp, vsize, up, usize);
for (i = 0; (d = vp[i]) == 0; i++)
;
count_leading_zeros (bcnt, d & -d);
bcnt = BITS_PER_MP_LIMB - 1 - bcnt;
vsize = mpn_rshift (vp, vp + i, vsize - i, bcnt);
}
}
/* GCD(U_IN, V_IN) now is U * 2**W_BCNT. */
wsize = usize + w_bcnt / BITS_PER_MP_LIMB + 1;
if (w->alloc < wsize)
_mpz_realloc (w, wsize);
wp = w->d;
MPN_ZERO (wp, w_bcnt / BITS_PER_MP_LIMB);
cy_digit = mpn_lshift (wp + w_bcnt / BITS_PER_MP_LIMB, up, usize,
w_bcnt % BITS_PER_MP_LIMB);
wsize = usize + w_bcnt / BITS_PER_MP_LIMB;
if (cy_digit != 0)
{
wp[wsize] = cy_digit;
wsize++;
}
w->size = wsize;
alloca (0);
}

View File

@ -1,80 +0,0 @@
/* mpz_gcdext(g, s, t, a, b) -- Set G to gcd(a, b), and S and T such that
g = as + bt.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
/* Botch: SLOW! */
void
#ifdef __STDC__
mpz_gcdext (MP_INT *g, MP_INT *s, MP_INT *t, const MP_INT *a, const MP_INT *b)
#else
mpz_gcdext (g, s, t, a, b)
MP_INT *g;
MP_INT *s;
MP_INT *t;
const MP_INT *a;
const MP_INT *b;
#endif
{
MP_INT s0, s1, q, r, x, d0, d1;
mpz_init_set_ui (&s0, 1);
mpz_init_set_ui (&s1, 0);
mpz_init (&q);
mpz_init (&r);
mpz_init (&x);
mpz_init_set (&d0, a);
mpz_init_set (&d1, b);
while (d1.size != 0)
{
mpz_divmod (&q, &r, &d0, &d1);
mpz_set (&d0, &d1);
mpz_set (&d1, &r);
mpz_mul (&x, &s1, &q);
mpz_sub (&x, &s0, &x);
mpz_set (&s0, &s1);
mpz_set (&s1, &x);
}
if (t != NULL)
{
mpz_mul (&x, &s0, a);
mpz_sub (&x, &d0, &x);
if (b->size == 0)
t->size = 0;
else
mpz_div (t, &x, b);
}
mpz_set (s, &s0);
mpz_set (g, &d0);
mpz_clear (&s0);
mpz_clear (&s1);
mpz_clear (&q);
mpz_clear (&r);
mpz_clear (&x);
mpz_clear (&d0);
mpz_clear (&d1);
}

View File

@ -1,40 +0,0 @@
/* mpz_get_si(integer) -- Return the least significant digit from INTEGER.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
signed long int
#ifdef __STDC__
mpz_get_si (const MP_INT *integer)
#else
mpz_get_si (integer)
const MP_INT *integer;
#endif
{
mp_size size = integer->size;
if (size > 0)
return integer->d[0] % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1));
else if (size < 0)
return -(integer->d[0] % ((mp_limb) 1 << (BITS_PER_MP_LIMB - 1)));
else
return 0;
}

View File

@ -1,39 +0,0 @@
/* mpz_get_str (string, base, mp_src) -- Convert the multiple precision
number MP_SRC to a string STRING of base BASE. If STRING is NULL
allocate space for the result. In any case, return a pointer to the
result. If STRING is not NULL, the caller must ensure enough space is
available to store the result.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
char *
#ifdef __STDC__
mpz_get_str (char *str, int base, const MP_INT *m)
#else
mpz_get_str (str, base, m)
char *str;
int base;
const MP_INT *m;
#endif
{
return _mpz_get_str (str, base, m);
}

View File

@ -1,36 +0,0 @@
/* mpz_get_ui(integer) -- Return the least significant digit from INTEGER.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
unsigned long int
#ifdef __STDC__
mpz_get_ui (const MP_INT *integer)
#else
mpz_get_ui (integer)
const MP_INT *integer;
#endif
{
if (integer->size == 0)
return 0;
else
return integer->d[0];
}

View File

@ -1,35 +0,0 @@
/* mpz_init() -- Make a new multiple precision number with value 0.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_init (MP_INT *x)
#else
mpz_init (x)
MP_INT *x;
#endif
{
x->alloc = 1;
x->d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB * x->alloc);
x->size = 0;
}

View File

@ -1,72 +0,0 @@
/* mpz_inp_raw -- Input a MP_INT in raw, but endianess, and wordsize
independent format (as output by mpz_out_raw).
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
void
#ifdef __STDC__
mpz_inp_raw (MP_INT *x, FILE *file)
#else
mpz_inp_raw (x, file)
MP_INT *x;
FILE *file;
#endif
{
int i;
mp_size s;
mp_size xsize;
mp_ptr xp;
unsigned int c;
mp_limb x_digit;
mp_size x_index;
xsize = 0;
for (i = 4 - 1; i >= 0; i--)
{
c = fgetc (file);
xsize = (xsize << BITS_PER_CHAR) | c;
}
/* ??? Sign extend xsize for non-32 bit machines? */
x_index = (ABS (xsize) + BYTES_PER_MP_LIMB - 1) / BYTES_PER_MP_LIMB - 1;
if (x->alloc < x_index)
_mpz_realloc (x, x_index);
xp = x->d;
x->size = xsize / BYTES_PER_MP_LIMB;
x_digit = 0;
for (s = ABS (xsize) - 1; s >= 0; s--)
{
i = s % BYTES_PER_MP_LIMB;
c = fgetc (file);
x_digit = (x_digit << BITS_PER_CHAR) | c;
if (i == 0)
{
xp[x_index--] = x_digit;
x_digit = 0;
}
}
}

View File

@ -1,105 +0,0 @@
/* mpz_inp_str(dest_integer, stream, base) -- Input a number in base
BASE from stdio stream STREAM and store the result in DEST_INTEGER.
Copyright (C) 1991, 1993 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <ctype.h>
#include "gmp.h"
#include "gmp-impl.h"
static int
char_ok_for_base (c, base)
int c;
int base;
{
if (isdigit (c))
return (unsigned) c - '0' < base;
if (islower (c))
return (unsigned) c - 'a' + 10 < base;
if (isupper (c))
return (unsigned) c - 'A' + 10 < base;
return 0;
}
void
#ifdef __STDC__
mpz_inp_str (MP_INT *dest, FILE *stream, int base)
#else
mpz_inp_str (dest, stream, base)
MP_INT *dest;
FILE *stream;
int base;
#endif
{
char *str;
size_t str_size;
size_t i;
int c;
int negative = 0;
str_size = 100;
str = (char *) (*_mp_allocate_func) (str_size);
c = getc (stream);
if (c == '-')
{
negative = 1;
c = getc (stream);
}
/* If BASE is 0, try to find out the base by looking at the initial
characters. */
if (base == 0)
{
base = 10;
if (c == '0')
{
base = 8;
c = getc (stream);
if (c == 'x' || c == 'X')
{
base = 16;
c = getc (stream);
}
}
}
for (i = 0; char_ok_for_base (c, base); i++)
{
if (i >= str_size)
{
size_t old_str_size = str_size;
str_size = str_size * 3 / 2;
str = (char *) (*_mp_reallocate_func) (str, old_str_size, str_size);
}
str[i] = c;
c = getc (stream);
}
ungetc (c, stream);
str[i] = 0;
_mpz_set_str (dest, str, base);
if (negative)
dest->size = -dest->size;
(*_mp_free_func) (str, str_size);
}

View File

@ -1,242 +0,0 @@
/* mpz_ior -- Logical inclusive or.
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
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 a copy of the GNU General Public License
along with the GNU MP Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gmp.h"
#include "gmp-impl.h"
#define min(l,o) ((l) < (o) ? (l) : (o))
#define max(h,i) ((h) > (i) ? (h) : (i))
void
#ifdef __STDC__
mpz_ior (MP_INT *res, const MP_INT *op1, const MP_INT *op2)
#else
mpz_ior (res, op1, op2)
MP_INT *res;
const MP_INT *op1;
const MP_INT *op2;
#endif
{
mp_srcptr op1_ptr, op2_ptr;
mp_size op1_size, op2_size;
mp_ptr res_ptr;
mp_size res_size;
mp_size i;
op1_size = op1->size;
op2_size = op2->size;
op1_ptr = op1->d;
op2_ptr = op2->d;
res_ptr = res->d;
if (op1_size >= 0)
{
if (op2_size >= 0)
{
if (op1_size >= op2_size)
{
if (res->alloc < op1_size)
{
_mpz_realloc (res, op1_size);
op1_ptr = op1->d;
op2_ptr = op2->d;
res_ptr = res->d;
}
if (res_ptr != op1_ptr)
MPN_COPY (res_ptr + op2_size, op1_ptr + op2_size,
op1_size - op2_size);
for (i = op2_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] | op2_ptr[i];
res_size = op1_size;
}
else
{
if (res->alloc < op2_size)
{
_mpz_realloc (res, op2_size);
op1_ptr = op1->d;
op2_ptr = op2->d;
res_ptr = res->d;
}
if (res_ptr != op2_ptr)
MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
op2_size - op1_size);
for (i = op1_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] | op2_ptr[i];
res_size = op2_size;
}
res->size = res_size;
return;
}
else /* op2_size < 0 */
/* Fall through to the code at the end of the function. */
;
}
else
{
if (op2_size < 0)
{
mp_ptr opx;
mp_limb cy;
mp_limb one = 1;
/* Both operands are negative, so will be the result.
-((-OP1) | (-OP2)) = -(~(OP1 - 1) | ~(OP2 - 1)) =
= ~(~(OP1 - 1) | ~(OP2 - 1)) + 1 =
= ((OP1 - 1) & (OP2 - 1)) + 1 */
op1_size = -op1_size;
op2_size = -op2_size;
res_size = min (op1_size, op2_size);
/* Possible optimization: Decrease mpn_sub precision,
as we won't use the entire res of both. */
opx = (mp_ptr) alloca (op1_size * BYTES_PER_MP_LIMB);
op1_size += mpn_sub (opx, op1_ptr, op1_size, &one, 1);
op1_ptr = opx;
opx = (mp_ptr) alloca (op2_size * BYTES_PER_MP_LIMB);
op2_size += mpn_sub (opx, op2_ptr, op2_size, &one, 1);
op2_ptr = opx;
if (res->alloc < res_size)
{
_mpz_realloc (res, res_size);
res_ptr = res->d;
/* Don't re-read OP1_PTR and OP2_PTR. They point to
temporary space--never to the space RES->D used
to point to before reallocation. */
}
/* First loop finds the size of the result. */
for (i = res_size - 1; i >= 0; i--)
if ((op1_ptr[i] & op2_ptr[i]) != 0)
break;
res_size = i + 1;
/* Second loop computes the real result. */
for (i = res_size - 1; i >= 0; i--)
res_ptr[i] = op1_ptr[i] & op2_ptr[i];
if (res_size != 0)
{
cy = mpn_add (res_ptr, res_ptr, res_size, &one, 1);
if (cy)
{
res_ptr[res_size] = cy;
res_size++;
}
}
else
{
res_ptr[0] = 1;
res_size = 1;
}
res->size = -res_size;
return;
}
else
{
/* We should compute -OP1 | OP2. Swap OP1 and OP2 and fall
through to the code that handles OP1 | -OP2. */
{const MP_INT *t = op1; op1 = op2; op2 = t;}
{mp_srcptr t = op1_ptr; op1_ptr = op2_ptr; op2_ptr = t;}
{mp_size t = op1_size; op1_size = op2_size; op2_size = t;}
}
}
{
mp_ptr opx;
mp_limb cy;
mp_limb one = 1;
mp_size res_alloc;
/* Operand 2 negative, so will be the result.
-(OP1 | (-OP2)) = -(OP1 | ~(OP2 - 1)) =
= ~(OP1 | ~(OP2 - 1)) + 1 =
= (~OP1 & (OP2 - 1)) + 1 */
op2_size = -op2_size;
res_alloc = op2_size;
opx = (mp_ptr) alloca (op2_size * BYTES_PER_MP_LIMB);
op2_size += mpn_sub (opx, op2_ptr, op2_size, &one, 1);
op2_ptr = opx;
if (res->alloc < res_alloc)
{
_mpz_realloc (res, res_alloc);
op1_ptr = op1->d;
res_ptr = res->d;
/* Don't re-read OP2_PTR. It points to temporary space--never
to the space RES->D used to point to before reallocation. */
}
if (op1_size >= op2_size)
{
/* We can just ignore the part of OP1 that stretches above OP2,
because the result limbs are zero there. */
/* First loop finds the size of the result. */
for (i = op2_size - 1; i >= 0; i--)
if ((~op1_ptr[i] & op2_ptr[i]) != 0)
break;
res_size = i + 1;
}
else
{
res_size = op2_size;
/* Copy the part of OP2 that stretches above OP1, to RES. */
MPN_COPY (res_ptr + op1_size, op2_ptr + op1_size,
op2_size - op1_size);
}
/* Second loop computes the real result. */
for (i = res_size - 1; i >= 0; i--)
res_ptr[i] = ~op1_ptr[i] & op2_ptr[i];
if (res_size != 0)
{
cy = mpn_add (res_ptr, res_ptr, res_size, &one, 1);
if (cy)
{
res_ptr[res_size] = cy;
res_size++;
}
}
else
{
res_ptr[0] = 1;
res_size = 1;
}
res->size = -res_size;
alloca (0);
return;
}
}

Some files were not shown because too many files have changed in this diff Show More