mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make further progress on non-x86 support
This commit is contained in:
parent
aef9a69a60
commit
036b9a0002
155 changed files with 2307 additions and 653 deletions
1
libc/tinymath/LICENSE.fdlibm
Normal file
1
libc/tinymath/LICENSE.fdlibm
Normal file
|
@ -0,0 +1 @@
|
|||
Q29weXJpZ2h0IChDKSAxOTkzLTIwMDQgYnkgU3VuIE1pY3Jvc3lzdGVtcywgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLgoKRGV2ZWxvcGVkIGF0IFN1blNvZnQsIGEgU3VuIE1pY3Jvc3lzdGVtcywgSW5jLiBidXNpbmVzcy4KUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kIGRpc3RyaWJ1dGUgdGhpcwpzb2Z0d2FyZSBpcyBmcmVlbHkgZ3JhbnRlZCwgcHJvdmlkZWQgdGhhdCB0aGlzIG5vdGljZQppcyBwcmVzZXJ2ZWQuCg==
|
125
libc/tinymath/LICENSE.freebsd
Normal file
125
libc/tinymath/LICENSE.freebsd
Normal file
|
@ -0,0 +1,125 @@
|
|||
# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
|
||||
|
||||
The compilation of software known as FreeBSD is distributed under the
|
||||
following terms:
|
||||
|
||||
Copyright (c) 1992-2023 The FreeBSD Project.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
The 4.4BSD and 4.4BSD-Lite software is distributed under the following
|
||||
terms:
|
||||
|
||||
All of the documentation and software included in the 4.4BSD and 4.4BSD-Lite
|
||||
Releases is copyrighted by The Regents of the University of California.
|
||||
|
||||
Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
|
||||
The Regents of the University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this software
|
||||
must display the following acknowledgement:
|
||||
This product includes software developed by the University of
|
||||
California, Berkeley and its contributors.
|
||||
4. Neither the name of the University nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
The Institute of Electrical and Electronics Engineers and the American
|
||||
National Standards Committee X3, on Information Processing Systems have
|
||||
given us permission to reprint portions of their documentation.
|
||||
|
||||
In the following statement, the phrase ``this text'' refers to portions
|
||||
of the system documentation.
|
||||
|
||||
Portions of this text are reprinted and reproduced in electronic form in
|
||||
the second BSD Networking Software Release, from IEEE Std 1003.1-1988, IEEE
|
||||
Standard Portable Operating System Interface for Computer Environments
|
||||
(POSIX), copyright C 1988 by the Institute of Electrical and Electronics
|
||||
Engineers, Inc. In the event of any discrepancy between these versions
|
||||
and the original IEEE Standard, the original IEEE Standard is the referee
|
||||
document.
|
||||
|
||||
In the following statement, the phrase ``This material'' refers to portions
|
||||
of the system documentation.
|
||||
|
||||
This material is reproduced with permission from American National
|
||||
Standards Committee X3, on Information Processing Systems. Computer and
|
||||
Business Equipment Manufacturers Association (CBEMA), 311 First St., NW,
|
||||
Suite 500, Washington, DC 20001-2178. The developmental work of
|
||||
Programming Language C was completed by the X3J11 Technical Committee.
|
||||
|
||||
The views and conclusions contained in the software and documentation are
|
||||
those of the authors and should not be interpreted as representing official
|
||||
policies, either expressed or implied, of the Regents of the University
|
||||
of California.
|
||||
|
||||
|
||||
NOTE: The copyright of UC Berkeley's Berkeley Software Distribution ("BSD")
|
||||
source has been updated. The copyright addendum may be found at
|
||||
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change and is
|
||||
included below.
|
||||
|
||||
July 22, 1999
|
||||
|
||||
To All Licensees, Distributors of Any Version of BSD:
|
||||
|
||||
As you know, certain of the Berkeley Software Distribution ("BSD") source
|
||||
code files require that further distributions of products containing all or
|
||||
portions of the software, acknowledge within their advertising materials
|
||||
that such products contain software developed by UC Berkeley and its
|
||||
contributors.
|
||||
|
||||
Specifically, the provision reads:
|
||||
|
||||
" * 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors."
|
||||
|
||||
Effective immediately, licensees and distributors are no longer required to
|
||||
include the acknowledgement within advertising materials. Accordingly, the
|
||||
foregoing paragraph of those BSD Unix files containing it is hereby deleted
|
||||
in its entirety.
|
||||
|
||||
William Hoskins
|
||||
Director, Office of Technology Licensing
|
||||
University of California, Berkeley
|
193
libc/tinymath/LICENSE.musl
Normal file
193
libc/tinymath/LICENSE.musl
Normal file
|
@ -0,0 +1,193 @@
|
|||
musl as a whole is licensed under the following standard MIT license:
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Copyright © 2005-2020 Rich Felker, et al.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Authors/contributors include:
|
||||
|
||||
A. Wilcox
|
||||
Ada Worcester
|
||||
Alex Dowad
|
||||
Alex Suykov
|
||||
Alexander Monakov
|
||||
Andre McCurdy
|
||||
Andrew Kelley
|
||||
Anthony G. Basile
|
||||
Aric Belsito
|
||||
Arvid Picciani
|
||||
Bartosz Brachaczek
|
||||
Benjamin Peterson
|
||||
Bobby Bingham
|
||||
Boris Brezillon
|
||||
Brent Cook
|
||||
Chris Spiegel
|
||||
Clément Vasseur
|
||||
Daniel Micay
|
||||
Daniel Sabogal
|
||||
Daurnimator
|
||||
David Carlier
|
||||
David Edelsohn
|
||||
Denys Vlasenko
|
||||
Dmitry Ivanov
|
||||
Dmitry V. Levin
|
||||
Drew DeVault
|
||||
Emil Renner Berthing
|
||||
Fangrui Song
|
||||
Felix Fietkau
|
||||
Felix Janda
|
||||
Gianluca Anzolin
|
||||
Hauke Mehrtens
|
||||
He X
|
||||
Hiltjo Posthuma
|
||||
Isaac Dunham
|
||||
Jaydeep Patil
|
||||
Jens Gustedt
|
||||
Jeremy Huntwork
|
||||
Jo-Philipp Wich
|
||||
Joakim Sindholt
|
||||
John Spencer
|
||||
Julien Ramseier
|
||||
Justin Cormack
|
||||
Kaarle Ritvanen
|
||||
Khem Raj
|
||||
Kylie McClain
|
||||
Leah Neukirchen
|
||||
Luca Barbato
|
||||
Luka Perkov
|
||||
M Farkas-Dyck (Strake)
|
||||
Mahesh Bodapati
|
||||
Markus Wichmann
|
||||
Masanori Ogino
|
||||
Michael Clark
|
||||
Michael Forney
|
||||
Mikhail Kremnyov
|
||||
Natanael Copa
|
||||
Nicholas J. Kain
|
||||
orc
|
||||
Pascal Cuoq
|
||||
Patrick Oppenlander
|
||||
Petr Hosek
|
||||
Petr Skocik
|
||||
Pierre Carrier
|
||||
Reini Urban
|
||||
Rich Felker
|
||||
Richard Pennington
|
||||
Ryan Fairfax
|
||||
Samuel Holland
|
||||
Segev Finer
|
||||
Shiz
|
||||
sin
|
||||
Solar Designer
|
||||
Stefan Kristiansson
|
||||
Stefan O'Rear
|
||||
Szabolcs Nagy
|
||||
Timo Teräs
|
||||
Trutz Behn
|
||||
Valentin Ochs
|
||||
Will Dietz
|
||||
William Haddon
|
||||
William Pitcock
|
||||
|
||||
Portions of this software are derived from third-party works licensed
|
||||
under terms compatible with the above MIT license:
|
||||
|
||||
The TRE regular expression implementation (src/regex/reg* and
|
||||
src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
|
||||
under a 2-clause BSD license (license text in the source files). The
|
||||
included version has been heavily modified by Rich Felker in 2012, in
|
||||
the interests of size, simplicity, and namespace cleanliness.
|
||||
|
||||
Much of the math library code (src/math/* and src/complex/*) is
|
||||
Copyright © 1993,2004 Sun Microsystems or
|
||||
Copyright © 2003-2011 David Schultz or
|
||||
Copyright © 2003-2009 Steven G. Kargl or
|
||||
Copyright © 2003-2009 Bruce D. Evans or
|
||||
Copyright © 2008 Stephen L. Moshier or
|
||||
Copyright © 2017-2018 Arm Limited
|
||||
and labelled as such in comments in the individual source files. All
|
||||
have been licensed under extremely permissive terms.
|
||||
|
||||
The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
|
||||
The Android Open Source Project and is licensed under a two-clause BSD
|
||||
license. It was taken from Bionic libc, used on Android.
|
||||
|
||||
The AArch64 memcpy and memset code (src/string/aarch64/*) are
|
||||
Copyright © 1999-2019, Arm Limited.
|
||||
|
||||
The implementation of DES for crypt (src/crypt/crypt_des.c) is
|
||||
Copyright © 1994 David Burren. It is licensed under a BSD license.
|
||||
|
||||
The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
|
||||
originally written by Solar Designer and placed into the public
|
||||
domain. The code also comes with a fallback permissive license for use
|
||||
in jurisdictions that may not recognize the public domain.
|
||||
|
||||
The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
|
||||
Valentin Ochs and is licensed under an MIT-style license.
|
||||
|
||||
The x86_64 port was written by Nicholas J. Kain and is licensed under
|
||||
the standard MIT terms.
|
||||
|
||||
The mips and microblaze ports were originally written by Richard
|
||||
Pennington for use in the ellcc project. The original code was adapted
|
||||
by Rich Felker for build system and code conventions during upstream
|
||||
integration. It is licensed under the standard MIT terms.
|
||||
|
||||
The mips64 port was contributed by Imagination Technologies and is
|
||||
licensed under the standard MIT terms.
|
||||
|
||||
The powerpc port was also originally written by Richard Pennington,
|
||||
and later supplemented and integrated by John Spencer. It is licensed
|
||||
under the standard MIT terms.
|
||||
|
||||
All other files which have no copyright comments are original works
|
||||
produced specifically for use as part of this library, written either
|
||||
by Rich Felker, the main author of the library, or by one or more
|
||||
contibutors listed above. Details on authorship of individual files
|
||||
can be found in the git version control history of the project. The
|
||||
omission of copyright and license comments in each file is in the
|
||||
interest of source tree size.
|
||||
|
||||
In addition, permission is hereby granted for all public header files
|
||||
(include/* and arch/*/bits/*) and crt files intended to be linked into
|
||||
applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
|
||||
the copyright notice and permission notice otherwise required by the
|
||||
license, and to use these files without any requirement of
|
||||
attribution. These files include substantial contributions from:
|
||||
|
||||
Bobby Bingham
|
||||
John Spencer
|
||||
Nicholas J. Kain
|
||||
Rich Felker
|
||||
Richard Pennington
|
||||
Stefan Kristiansson
|
||||
Szabolcs Nagy
|
||||
|
||||
all of whom have explicitly granted such permission.
|
||||
|
||||
This file previously contained text expressing a belief that most of
|
||||
the files covered by the above exception were sufficiently trivial not
|
||||
to be subject to copyright, resulting in confusion over whether it
|
||||
negated the permissions granted in the license. In the spirit of
|
||||
permissive licensing, and of not having licensing issues being an
|
||||
obstacle to adoption, that text has been removed.
|
394
libc/tinymath/LICENSE.openbsd
Normal file
394
libc/tinymath/LICENSE.openbsd
Normal file
|
@ -0,0 +1,394 @@
|
|||
OpenBSD Copyright Policy
|
||||
https://www.openbsd.org/policy.html
|
||||
|
||||
Goal
|
||||
|
||||
Copyright law is complex, OpenBSD policy is simple — OpenBSD
|
||||
strives to provide code that can be freely used, copied, modified,
|
||||
and distributed by anyone and for any purpose. This maintains the
|
||||
spirit of the original Berkeley Software Distribution. The
|
||||
preferred wording of a license to be applied to new code can be
|
||||
found in the license template.
|
||||
|
||||
OpenBSD can exist as it does today because of the example set by
|
||||
the Computer Systems Research Group at Berkeley and the battles
|
||||
which they and others fought to create a Unix source distribution
|
||||
un-encumbered by proprietary code and commercial licensing.
|
||||
|
||||
The ability of a freely redistributable "Berkeley" Unix to move
|
||||
forward on a competitive basis with other operating systems
|
||||
depends on the willingness of the various development groups to
|
||||
exchange code amongst themselves and with other projects.
|
||||
Understanding the legal issues surrounding copyright is
|
||||
fundamental to the ability to exchange and re-distribute code,
|
||||
while honoring the spirit of the copyright and concept of
|
||||
attribution is fundamental to promoting the cooperation of the
|
||||
people involved.
|
||||
|
||||
The Berkeley Copyright
|
||||
|
||||
The original Berkeley copyright poses no restrictions on private
|
||||
or commercial use of the software and imposes only simple and
|
||||
uniform requirements for maintaining copyright notices in
|
||||
redistributed versions and crediting the originator of the
|
||||
material only in advertising.
|
||||
|
||||
For instance:
|
||||
|
||||
* Copyright (c) 1982, 1986, 1990, 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
|
||||
Berkeley rescinded the 3rd term (the advertising term) on 22 July
|
||||
1999. Verbatim copies of the Berkeley license in the OpenBSD tree
|
||||
have that term removed. In addition, many 3rd-party BSD-style
|
||||
licenses consist solely of the first two terms.
|
||||
|
||||
Because the OpenBSD copyright imposes no conditions beyond those
|
||||
imposed by the Berkeley copyright, OpenBSD can hope to share the
|
||||
same wide distribution and applicability as the Berkeley
|
||||
distributions. It follows however, that OpenBSD cannot include
|
||||
material which includes copyrights which are more restrictive than
|
||||
the Berkeley copyright, or must relegate this material to a
|
||||
secondary status, i.e. OpenBSD as a whole is freely
|
||||
redistributable, but some optional components may not be.
|
||||
|
||||
Copyright Law
|
||||
|
||||
While the overall subject of copyright law is far beyond the scope
|
||||
of this document, some basics are in order. Under the current
|
||||
copyright law, copyrights are implicit in the creation of a new
|
||||
work and reside with the creator. In general the copyright applies
|
||||
only to the new work, not the material the work was derived from,
|
||||
nor those portions of the derivative material included in the new
|
||||
work.
|
||||
|
||||
Copyright law admits to three general categories of works:
|
||||
|
||||
Original Work
|
||||
A new work that is not derived from an existing work.
|
||||
|
||||
Derivative Work
|
||||
Work that is derived from, includes or amends existing
|
||||
works.
|
||||
|
||||
Compilation
|
||||
A work that is a compilation of existing new and
|
||||
derivative works.
|
||||
|
||||
The fundamental concept is that there is primacy of the copyright,
|
||||
that is a copyright of a derivative work does not affect the
|
||||
rights held by the owner of the copyright of the original work,
|
||||
rather only the part added. Likewise the copyright of a
|
||||
compilation does not affect the rights of the owner of the
|
||||
included works, only the compilation as an entity.
|
||||
|
||||
It is vitally important to understand that copyrights are broad
|
||||
protections as defined by national and international copyright
|
||||
law. The "copyright notices" usually included in source files are
|
||||
not copyrights, but rather notices that a party asserts that they
|
||||
hold copyright to the material or to part of the material.
|
||||
Typically these notices are associated with license terms which
|
||||
grant permissions subject to copyright law and with disclaimers
|
||||
that state the position of the copyright holder/distributor with
|
||||
respect to liability surrounding use of the material.
|
||||
|
||||
By international law, specifically the Berne Convention for the
|
||||
Protection of Literary and Artistic Works, part of the author's
|
||||
copyright, the so-called moral rights, are inalienable. This
|
||||
includes the author's right "to claim authorship of the work and
|
||||
to object to any distortion, mutilation or other modification of,
|
||||
or other derogatory action in relation to, the said work, which
|
||||
would be prejudicial to his honor or reputation". In some
|
||||
countries, the law reserves additional inalienable moral rights to
|
||||
the author. On the other hand, the author is free to transfer
|
||||
other parts of his copyright, the so-called economic rights, in
|
||||
particular the rights to use, copy, modify, distribute, and
|
||||
license the work.
|
||||
|
||||
Permissions — the flip side
|
||||
|
||||
Because copyrights arise from the creation of a work, rather than
|
||||
through a registration process, there needs to be a practical way
|
||||
to extend permission to use a work beyond what might be allowed by
|
||||
"fair use" provisions of the copyright laws.
|
||||
|
||||
This permission typically takes the form of a "release" or
|
||||
"license" included in the work, which grants the additional uses
|
||||
beyond those granted by copyright law, usually subject to a
|
||||
variety of conditions. At one extreme sits "public domain" where
|
||||
the originator asserts that he imposes no restrictions on use of
|
||||
the material, at the other restrictive clauses that actually grant
|
||||
no additional rights or impose restrictive, discriminatory or
|
||||
impractical conditions on use of the work.
|
||||
|
||||
Note that a license is not to be confused with a copyright
|
||||
transfer. While a transfer would give the new copyright holder
|
||||
exclusive rights to use the code and take these rights away from
|
||||
the author, a license typically grants additional people
|
||||
non-exclusive rights to use the code, while the authors retain all
|
||||
their rights.
|
||||
|
||||
The above observations regarding moral rights imply that putting
|
||||
code under an ISC or two-clause BSD license essentially makes the
|
||||
code as free as it can possibly get. Modifying the wording of
|
||||
these licenses can only result in one of the three following
|
||||
effects:
|
||||
* making the code less free by adding additional restrictions
|
||||
regarding its use, copying, modification or distribution;
|
||||
* or effectively not changing anything by merely changing the
|
||||
wording, but not changing anything substantial regarding the
|
||||
legal content;
|
||||
* or making the license illegal by attempting to deprive the
|
||||
authors of rights they cannot legally give away.
|
||||
|
||||
Again, an important point to note is that the release and
|
||||
conditions can only apply to the portion of the work that was
|
||||
originated by the copyright holder—the holder of a copyright on a
|
||||
derivative work can neither grant additional permissions for use
|
||||
of the original work, nor impose more restrictive conditions for
|
||||
use of that work.
|
||||
|
||||
Because copyright arises from the creation of a work and not the
|
||||
text or a registration process, removing or altering a copyright
|
||||
notice or associated release terms has no bearing on the existence
|
||||
of the copyright, rather all that is accomplished is to cast doubt
|
||||
upon whatever rights the person making the modifications had to
|
||||
use the material in the first place. Likewise, adding terms and
|
||||
conditions in conflict with the original terms and conditions does
|
||||
not supersede them, rather it casts doubts on the rights of the
|
||||
person making the amendments to use the material and creates
|
||||
confusion as to whether anyone can use the amended version or
|
||||
derivatives thereof.
|
||||
|
||||
Finally, releases are generally binding on the material that they
|
||||
are distributed with. This means that if the originator of a work
|
||||
distributes that work with a release granting certain permissions,
|
||||
those permissions apply as stated, without discrimination, to all
|
||||
persons legitimately possessing a copy of the work. That means
|
||||
that having granted a permission, the copyright holder can not
|
||||
retroactively say that an individual or class of individuals are
|
||||
no longer granted those permissions. Likewise should the copyright
|
||||
holder decide to "go commercial" he can not revoke permissions
|
||||
already granted for the use of the work as distributed, though he
|
||||
may impose more restrictive permissions in his future
|
||||
distributions of that work.
|
||||
|
||||
Specific Cases
|
||||
|
||||
This section attempts to summarize the position of OpenBSD
|
||||
relative to some commonly encountered copyrights.
|
||||
|
||||
Berkeley
|
||||
|
||||
The Berkeley copyright is the model for the OpenBSD
|
||||
copyright. It retains the rights of the copyright holder,
|
||||
while imposing minimal conditions on the use of the
|
||||
copyrighted material. Material with Berkeley copyrights,
|
||||
or copyrights closely adhering to the Berkeley model can
|
||||
generally be included in OpenBSD.
|
||||
|
||||
AT&T
|
||||
|
||||
As part of its settlement with AT&T, Berkeley included an
|
||||
AT&T copyright notice on some of the files in 4.4BSD lite
|
||||
and lite2. The terms of this license are identical to the
|
||||
standard Berkeley license.
|
||||
|
||||
Additionally, OpenBSD includes some other AT&T code with
|
||||
non-restrictive copyrights, such as the reference
|
||||
implementation of awk.
|
||||
|
||||
Caldera
|
||||
|
||||
The original Unix code (AT&T versions 1 through 7 UNIX,
|
||||
including 32V) was freed by Caldera, Inc. on 23 January
|
||||
2002 and is now available under a 4-term BSD-style
|
||||
license. As a result, it would theoretically be possible
|
||||
to incorporate original Unix code into OpenBSD. However,
|
||||
that code is now so old that it does not satisfy today's
|
||||
interface and quality standards.
|
||||
|
||||
DEC, Sun, other manufacturers/software houses.
|
||||
|
||||
In general OpenBSD does not include material copyrighted
|
||||
by manufacturers or software houses. Material may be
|
||||
included where the copyright owner has granted general
|
||||
permission for reuse without conditions, with terms
|
||||
similar to the Berkeley copyright, or where the material
|
||||
is the product of an employee and the employer's copyright
|
||||
notice effectively releases any rights they might have to
|
||||
the work.
|
||||
|
||||
Carnegie-Mellon (CMU, Mach)
|
||||
|
||||
The Carnegie-Mellon copyright is similar to the Berkeley
|
||||
copyright, except that it requests that derivative works
|
||||
be made available to Carnegie-Mellon. Because this is only
|
||||
a request and not a condition, such material can still be
|
||||
included in OpenBSD. It should be noted that existing
|
||||
versions of Mach are still subject to AT&T copyrights,
|
||||
which prevents the general distribution of Mach sources.
|
||||
|
||||
Apache
|
||||
|
||||
The original Apache license was similar to the Berkeley
|
||||
license, but source code published under version 2 of the
|
||||
Apache license is subject to additional restrictions and
|
||||
cannot be included into OpenBSD. In particular, if you use
|
||||
code under the Apache 2 license, some of your rights will
|
||||
terminate if you claim in court that the code violates a
|
||||
patent.
|
||||
|
||||
A license can only be considered fully permissive if it
|
||||
allows use by anyone for all the future without giving up
|
||||
any of their rights. If there are conditions that might
|
||||
terminate any rights in the future, or if you have to give
|
||||
up a right that you would otherwise have, even if
|
||||
exercising that right could reasonably be regarded as
|
||||
morally objectionable, the code is not free.
|
||||
|
||||
In addition, the clause about the patent license is
|
||||
problematic because a patent license cannot be granted
|
||||
under Copyright law, but only under contract law, which
|
||||
drags the whole license into the domain of contract law.
|
||||
But while Copyright law is somewhat standardized by
|
||||
international agreements, contract law differs wildly
|
||||
among jurisdictions. So what the license means in
|
||||
different jurisdictions may vary and is hard to predict.
|
||||
|
||||
ISC
|
||||
|
||||
The ISC copyright is functionally equivalent to a two-term
|
||||
BSD copyright with language removed that is made
|
||||
unnecessary by the Berne convention. This is the preferred
|
||||
license for new code incorporated into OpenBSD. A sample
|
||||
license is available in the file
|
||||
/usr/share/misc/license.template.
|
||||
|
||||
GNU General Public License, GPL, LGPL, copyleft, etc.
|
||||
|
||||
The GNU Public License and licenses modeled on it impose
|
||||
the restriction that source code must be distributed or
|
||||
made available for all works that are derivatives of the
|
||||
GNU copyrighted code.
|
||||
|
||||
While this may superficially look like a noble strategy,
|
||||
it is a condition that is typically unacceptable for
|
||||
commercial use of software. So in practice, it usually
|
||||
ends up hindering free sharing and reuse of code and ideas
|
||||
rather than encouraging it. As a consequence, no
|
||||
additional software bound by the GPL terms will be
|
||||
considered for inclusion into the OpenBSD base system.
|
||||
|
||||
For historical reasons, the OpenBSD base system still
|
||||
includes the following GPL-licensed components: the GNU
|
||||
compiler collection (GCC) with supporting binutils and
|
||||
libraries, GNU CVS, GNU texinfo, the mkhybrid file system
|
||||
creation tool, and the readline library. Replacement by
|
||||
equivalent, more freely licensed tools is a long-term
|
||||
desideratum.
|
||||
|
||||
NetBSD
|
||||
|
||||
Much of OpenBSD is originally based on and evolved from
|
||||
NetBSD, since some of the OpenBSD developers were involved
|
||||
in the NetBSD project. The general NetBSD license terms
|
||||
are compatible with the Berkeley license and permit such
|
||||
use. Material subject only to the general NetBSD license
|
||||
can generally be included in OpenBSD.
|
||||
|
||||
In the past, NetBSD has included material copyrighted by
|
||||
individuals who have imposed license conditions beyond
|
||||
that of the general NetBSD license, but granted the NetBSD
|
||||
Foundation license to distribute the material. Such
|
||||
material can not be included in OpenBSD as long as the
|
||||
conditions imposed are at odds with the OpenBSD license
|
||||
terms or releases from those terms are offered on a
|
||||
discriminatory basis.
|
||||
|
||||
FreeBSD
|
||||
|
||||
Most of FreeBSD is also based on Berkeley licensed
|
||||
material or includes copyright notices based on the
|
||||
Berkeley model. Such material can be included in OpenBSD,
|
||||
while those parts that are subject to GPL or various
|
||||
individual copyright terms that are at odds with the
|
||||
OpenBSD license can not be included in OpenBSD.
|
||||
|
||||
Linux
|
||||
|
||||
Most of Linux is subject to GPL style licensing terms and
|
||||
therefore can not be included in OpenBSD. Individual
|
||||
components may be eligible, subject to the terms of the
|
||||
originator's copyright notices. Note that Linux
|
||||
"distributions" may also be subject to additional
|
||||
copyright claims of the distributing organization, either
|
||||
as a compilation or on material included that is not part
|
||||
of the Linux core.
|
||||
|
||||
X.Org
|
||||
|
||||
The X.Org Foundation maintains and distributes the X
|
||||
Window System under a modified MIT license, which is quite
|
||||
similar to the BSD license and additionally allows
|
||||
sublicensing. Under the name of Xenocara, the OpenBSD base
|
||||
system includes an improved and actively maintained
|
||||
version of the X.Org code.
|
||||
|
||||
Shareware, Charityware, Freeware, etc.
|
||||
|
||||
Most "shareware" copyright notices impose conditions for
|
||||
redistribution, use or visibility that are at conflict
|
||||
with the OpenBSD project goals. Review on a case-by-case
|
||||
basis is required as to whether the wording of the
|
||||
conditions is acceptable in terms of conditions being
|
||||
requested vs. demanded and whether the spirit of the
|
||||
conditions is compatible with goals of the OpenBSD
|
||||
project.
|
||||
|
||||
Public Domain
|
||||
|
||||
While material that is truly entered into the "public
|
||||
domain" can be included in OpenBSD, review is required on
|
||||
a case by case basis. Frequently the "public domain"
|
||||
assertion is made by someone who does not really hold all
|
||||
rights under copyright law to grant that status or there
|
||||
are a variety of conditions imposed on use. For a work to
|
||||
be truly in the "public domain" all rights are abandoned
|
||||
and the material is offered without restrictions.
|
||||
|
||||
In some jurisdictions, it is doubtful whether voluntarily
|
||||
placing one's own work into the public domain is legally
|
||||
possible. For that reason, to make any substantial body of
|
||||
code free, it is preferable to state the copyright and put
|
||||
it under an ISC or BSD license instead of attempting to
|
||||
release it into the public domain.
|
249
libc/tinymath/LICENSE.optimized-routines
Normal file
249
libc/tinymath/LICENSE.optimized-routines
Normal file
|
@ -0,0 +1,249 @@
|
|||
MIT OR Apache-2.0 WITH LLVM-exception
|
||||
=====================================
|
||||
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
Copyright (c) 1999-2022, Arm Limited.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
Apache-2.0 WITH LLVM-exception
|
||||
------------------------------
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
--- LLVM Exceptions to the Apache 2.0 License ----
|
||||
|
||||
As an exception, if, as a result of your compiling your source code, portions
|
||||
of this Software are embedded into an Object form of such source code, you
|
||||
may redistribute such embedded portions in such Object form without complying
|
||||
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
|
||||
|
||||
In addition, if you combine or link compiled forms of this Software with
|
||||
software that is licensed under the GPLv2 ("Combined Software") and if a
|
||||
court of competent jurisdiction determines that the patent provision (Section
|
||||
3), the indemnity provision (Section 9) or other Section of the License
|
||||
conflicts with the conditions of the GPLv2, you may retroactively and
|
||||
prospectively choose to deem waived or otherwise exclude such Section(s) of
|
||||
the License, but only in their entirety and only with respect to the Combined
|
||||
Software.
|
25
libc/tinymath/README.cosmo
Normal file
25
libc/tinymath/README.cosmo
Normal file
|
@ -0,0 +1,25 @@
|
|||
README
|
||||
|
||||
This folder provides libm scalar math functions, sourced from Musl
|
||||
Libc, FreeBSD, OpenBSD, and ARM's Optimized Routines project.
|
||||
|
||||
LICENSE
|
||||
|
||||
All code is covered by notice licenses (e.g. BSD, MIT) which are
|
||||
documented on a file-by-file basis.
|
||||
|
||||
ORIGIN
|
||||
|
||||
git://git.musl-libc.org/musl
|
||||
commit f5f55d6589940fd2c2188d76686efe3a530e64e0
|
||||
Author: Rich Felker <dalias@aerifal.cx>
|
||||
Date: Mon May 1 23:39:41 2023 -0400
|
||||
|
||||
release 1.2.4
|
||||
|
||||
git@github.com:ARM-software/optimized-routines.git
|
||||
commit f9f58aa37edc3486f18b1dd8701b74b5e3873699
|
||||
Author: Joe Ramsay <Joe.Ramsay@arm.com>
|
||||
Date: Fri May 5 14:19:06 2023 +0100
|
||||
|
||||
math: Cleanup Neon cos and cosf
|
|
@ -32,17 +32,16 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns inverse hyperbolic cosine of 𝑥.
|
||||
* @define acosh(x) = log(x + sqrt(x*x-1))
|
||||
*/
|
||||
long double acoshl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double acoshl(long double x)
|
||||
{
|
||||
return acosh(x);
|
||||
}
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
/* acosh(x) = log(x + sqrt(x*x-1)) */
|
||||
long double acoshl(long double x)
|
||||
{
|
||||
union ldshape u = {x};
|
||||
int e = u.i.se & 0x7fff;
|
||||
|
||||
|
@ -53,11 +52,10 @@ long double acoshl(long double x)
|
|||
/* |x| < 0x1p32 */
|
||||
return logl(2*x - 1/(x+sqrtl(x*x-1)));
|
||||
return logl(x) + 0.693147180559945309417232121458176568L;
|
||||
}
|
||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
long double acoshl(long double x)
|
||||
{
|
||||
return acosh(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */
|
||||
/*
|
||||
|
@ -54,11 +54,15 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns arc cosine of 𝑥.
|
||||
*
|
||||
* @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
||||
* @domain -1 ≤ 𝑥 ≤ 1
|
||||
*/
|
||||
long double acosl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double acosl(long double x)
|
||||
{
|
||||
return acos(x);
|
||||
}
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
#if LDBL_MANT_DIG == 64
|
||||
#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
|
||||
|
@ -66,14 +70,6 @@ long double acosl(long double x)
|
|||
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns arc cosine of 𝑥.
|
||||
*
|
||||
* @define atan2(fabs(sqrt((1-𝑥)*(1+𝑥))),𝑥)
|
||||
* @domain -1 ≤ 𝑥 ≤ 1
|
||||
*/
|
||||
long double acosl(long double x)
|
||||
{
|
||||
union ldshape u = {x};
|
||||
long double z, s, c, f;
|
||||
uint16_t e = u.i.se & 0x7fff;
|
||||
|
@ -106,6 +102,8 @@ long double acosl(long double x)
|
|||
f = u.f;
|
||||
c = (z - f*f)/(s + f);
|
||||
return 2*(__invtrigl_R(z)*s + c + f);
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -34,21 +34,16 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double asinhl(long double x)
|
||||
{
|
||||
return asinh(x);
|
||||
}
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns inverse hyperbolic sine of 𝑥.
|
||||
* @define asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5)
|
||||
*/
|
||||
long double asinhl(long double x)
|
||||
{
|
||||
long double asinhl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return asinh(x);
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
union ldshape u = {x};
|
||||
unsigned e = u.i.se & 0x7fff;
|
||||
unsigned s = u.i.se >> 15;
|
||||
|
@ -71,12 +66,10 @@ long double asinhl(long double x)
|
|||
FORCE_EVAL(x + 0x1p120f);
|
||||
}
|
||||
return s ? -x : x;
|
||||
}
|
||||
|
||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
long double asinhl(long double x)
|
||||
{
|
||||
return asinh(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */
|
||||
/*
|
||||
|
@ -55,11 +55,15 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns arc sine of 𝑥.
|
||||
*
|
||||
* @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
||||
* @domain -1 ≤ 𝑥 ≤ 1
|
||||
*/
|
||||
long double asinl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double asinl(long double x)
|
||||
{
|
||||
return asin(x);
|
||||
}
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
#if LDBL_MANT_DIG == 64
|
||||
#define CLOSETO1(u) (u.i.m>>56 >= 0xf7)
|
||||
|
@ -69,14 +73,6 @@ long double asinl(long double x)
|
|||
#define CLEARBOTTOM(u) (u.i.lo = 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns arc sine of 𝑥.
|
||||
*
|
||||
* @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥)))
|
||||
* @domain -1 ≤ 𝑥 ≤ 1
|
||||
*/
|
||||
long double asinl(long double x)
|
||||
{
|
||||
union ldshape u = {x};
|
||||
long double z, r, s;
|
||||
uint16_t e = u.i.se & 0x7fff;
|
||||
|
@ -111,6 +107,8 @@ long double asinl(long double x)
|
|||
x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f));
|
||||
}
|
||||
return sign ? -x : x;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Optimized Routines (MIT License)\\n\
|
||||
Copyright 2022 ARM Limited\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
#define Pi (0x1.921fb6p+1f)
|
||||
#define PiOver2 (0x1.921fb6p+0f)
|
||||
|
|
|
@ -37,7 +37,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */
|
||||
/*
|
||||
|
@ -56,18 +56,13 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* Converted to long double by David Schultz <das@FreeBSD.ORG>.
|
||||
*/
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double atan2l(long double y, long double x)
|
||||
{
|
||||
return atan2(y, x);
|
||||
}
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
|
||||
/**
|
||||
* Returns arc tangent of 𝑦/𝑥.
|
||||
*/
|
||||
long double atan2l(long double y, long double x)
|
||||
{
|
||||
long double atan2l(long double y, long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return atan2(y, x);
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
#ifdef __x86__
|
||||
|
||||
long double res;
|
||||
|
@ -133,7 +128,9 @@ long double atan2l(long double y, long double x)
|
|||
default: /* case 3 */
|
||||
return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */
|
||||
}
|
||||
#endif /* __x86__ */
|
||||
}
|
||||
|
||||
#endif /* __x86__ */
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -72,4 +72,6 @@ long double atanhl(long double x)
|
|||
return s ? -x : x;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */
|
||||
/*
|
||||
|
@ -231,4 +231,6 @@ long double atanl(long double x)
|
|||
return sign ? -z : z;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -27,16 +27,14 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
long double complex cacoshl(long double complex z)
|
||||
{
|
||||
long double complex cacoshl(long double complex z) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return cacosh(z);
|
||||
#else
|
||||
|
|
|
@ -26,13 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
long double complex cacosl(long double complex z) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
|
|
|
@ -26,26 +26,18 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
long double complex casinhl(long double complex z) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double complex casinhl(long double complex z)
|
||||
{
|
||||
return casinh(z);
|
||||
}
|
||||
#else
|
||||
long double complex casinhl(long double complex z)
|
||||
{
|
||||
z = casinl(CMPLXL(-cimagl(z), creall(z)));
|
||||
return CMPLXL(cimagl(z), -creall(z));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
|
|
@ -26,14 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
long double complex catanhl(long double complex z) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
|
|
|
@ -165,4 +165,6 @@ long double cbrtl(long double x)
|
|||
return t;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -36,8 +36,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */
|
||||
/*-
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
//FIXME
|
||||
long double complex ccoshl(long double complex z)
|
||||
|
|
|
@ -26,19 +26,14 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
|
||||
|
||||
long double complex ccosl(long double complex z)
|
||||
{
|
||||
long double complex ccosl(long double complex z) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return ccos(z);
|
||||
#else
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -41,8 +43,35 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
#endif
|
||||
static const double_t toint = 1/EPS;
|
||||
|
||||
/**
|
||||
* Returns smallest integral value not less than 𝑥.
|
||||
*/
|
||||
double ceil(double x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintp\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("frip\t%0,%1" : "=d"(x) : "d"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fidbra\t%0,6,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundsd\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {double f; uint64_t i;} u = {x};
|
||||
int e = u.i >> 52 & 0x7ff;
|
||||
double_t y;
|
||||
|
@ -62,4 +91,6 @@ double ceil(double x)
|
|||
if (y < 0)
|
||||
return x + y + 1;
|
||||
return x + y;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -34,8 +35,35 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns smallest integral value not less than 𝑥.
|
||||
*/
|
||||
float ceilf(float x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintp\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("frip\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fiebra\t%0,6,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundss\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {float f; uint32_t i;} u = {x};
|
||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
||||
uint32_t m;
|
||||
|
@ -58,4 +86,6 @@ float ceilf(float x)
|
|||
u.f = 1.0;
|
||||
}
|
||||
return u.f;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns smallest integral value not less than 𝑥.
|
||||
*/
|
||||
long double ceill(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return ceil(x);
|
||||
|
@ -43,7 +46,6 @@ long double ceill(long double x) {
|
|||
union ldshape u = {x};
|
||||
int e = u.i.se & 0x7fff;
|
||||
long double y;
|
||||
|
||||
if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0)
|
||||
return x;
|
||||
/* y = int(x) - x, where int(x) is an integer neighbor of x */
|
||||
|
@ -59,5 +61,7 @@ long double ceill(long double x) {
|
|||
if (y < 0)
|
||||
return x + y + 1;
|
||||
return x + y;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
//FIXME
|
||||
long double complex cexpl(long double complex z)
|
||||
|
|
|
@ -33,9 +33,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double complex clogl(long double complex z)
|
||||
|
@ -47,7 +45,6 @@ long double complex clogl(long double complex z)
|
|||
long double complex clogl(long double complex z)
|
||||
{
|
||||
long double r, phi;
|
||||
|
||||
r = cabsl(z);
|
||||
phi = cargl(z);
|
||||
return CMPLXL(logl(r), phi);
|
||||
|
|
|
@ -30,5 +30,7 @@ long double copysignl(long double x, long double y) {
|
|||
ux.i.se &= 0x7fff;
|
||||
ux.i.se |= uy.i.se & 0x8000;
|
||||
return ux.f;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -79,5 +79,7 @@ long double coshl(long double x) {
|
|||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
return cosh(x);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -68,5 +68,7 @@ long double cosl(long double x) {
|
|||
default:
|
||||
return __sinl(hi, lo, 1);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double complex cpowl(long double complex z, long double complex c)
|
||||
|
|
|
@ -36,8 +36,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */
|
||||
/*-
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
//FIXME
|
||||
long double complex csinhl(long double complex z)
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double complex csinl(long double complex z)
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
//FIXME
|
||||
long double complex csqrtl(long double complex z)
|
||||
|
|
|
@ -26,16 +26,12 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
// clang-format off
|
||||
|
||||
//FIXME
|
||||
long double complex ctanhl(long double complex z)
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -35,8 +33,6 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double complex ctanl(long double complex z)
|
||||
{
|
||||
|
|
|
@ -53,5 +53,7 @@ long double exp10l(long double x) {
|
|||
return y * p10[(int)n+15];
|
||||
}
|
||||
return powl(10.0, x);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include "libc/tinymath/ldshape.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
exp2l (BSD-2 License)\\n\
|
||||
Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>\"");
|
||||
FreeBSD libm (BSD-2 License)\\n\
|
||||
Copyright (c) 2005-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.\"");
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
|
@ -654,4 +654,6 @@ exp2l(long double x)
|
|||
|
||||
return scalbnl(r, k.i);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -162,4 +162,6 @@ long double expl(long double x)
|
|||
{
|
||||
return exp(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -157,4 +157,6 @@ long double expm1l(long double x)
|
|||
{
|
||||
return expm1(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
|
||||
/**
|
||||
* Returns absolute value of floating point number.
|
||||
*/
|
||||
double fabs(double x) {
|
||||
union {
|
||||
double f;
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/libcxx/math.h"
|
||||
|
||||
/**
|
||||
* Returns absolute value of floating point number.
|
||||
*/
|
||||
float fabsf(float x) {
|
||||
union {
|
||||
float f;
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include "libc/math.h"
|
||||
#include "libc/tinymath/ldshape.internal.h"
|
||||
|
||||
/**
|
||||
* Returns absolute value of floating point number.
|
||||
*/
|
||||
long double fabsl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return fabs(x);
|
||||
|
@ -26,5 +29,7 @@ long double fabsl(long double x) {
|
|||
union ldshape u = {x};
|
||||
u.i.se &= 0x7fff;
|
||||
return u.f;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -41,8 +43,35 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
#endif
|
||||
static const double_t toint = 1/EPS;
|
||||
|
||||
/**
|
||||
* Returns largest integral value not greater than 𝑥.
|
||||
*/
|
||||
double floor(double x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintm\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("frim\t%0,%1" : "=d"(x) : "d"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fidbra\t%0,7,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundsd\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {double f; uint64_t i;} u = {x};
|
||||
int e = u.i >> 52 & 0x7ff;
|
||||
double_t y;
|
||||
|
@ -62,4 +91,6 @@ double floor(double x)
|
|||
if (y > 0)
|
||||
return x + y - 1;
|
||||
return x + y;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
#include "third_party/libcxx/math.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -34,8 +35,35 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns largest integral value not greater than 𝑥.
|
||||
*/
|
||||
float floorf(float x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintm\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("frim\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fiebra\t%0,7,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundss\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {float f; uint32_t i;} u = {x};
|
||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f;
|
||||
uint32_t m;
|
||||
|
@ -58,4 +86,6 @@ float floorf(float x)
|
|||
u.f = -1.0;
|
||||
}
|
||||
return u.f;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Returns largest integral value not greater than 𝑥.
|
||||
*/
|
||||
long double floorl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return floor(x);
|
||||
|
@ -60,5 +63,7 @@ long double floorl(long double x) {
|
|||
if (y > 0)
|
||||
return x + y - 1;
|
||||
return x + y;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -31,13 +31,17 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
#define ASUINT64(x) ((union {double f; uint64_t i;}){x}).i
|
||||
#define ZEROINFNAN (0x7ff-0x3ff-52-1)
|
||||
|
||||
static inline int a_clz_64(uint64_t x)
|
||||
{
|
||||
#ifdef __GNUC__
|
||||
if (!x) return 63;
|
||||
return __builtin_clzll(x);
|
||||
#else
|
||||
uint32_t y;
|
||||
int r;
|
||||
if (x>>32) y=x>>32, r=0; else y=x, r=32;
|
||||
|
@ -46,6 +50,7 @@ static inline int a_clz_64(uint64_t x)
|
|||
if (y>>4) y>>=4; else r |= 4;
|
||||
if (y>>2) y>>=2; else r |= 2;
|
||||
return r | !(y>>1);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct num { uint64_t m; int e; int sign; };
|
||||
|
@ -73,7 +78,6 @@ static void mul(uint64_t *hi, uint64_t *lo, uint64_t x, uint64_t y)
|
|||
uint64_t t1,t2,t3;
|
||||
uint64_t xlo = (uint32_t)x, xhi = x>>32;
|
||||
uint64_t ylo = (uint32_t)y, yhi = y>>32;
|
||||
|
||||
t1 = xlo*ylo;
|
||||
t2 = xlo*yhi + xhi*ylo;
|
||||
t3 = xhi*yhi;
|
||||
|
@ -81,8 +85,48 @@ static void mul(uint64_t *hi, uint64_t *lo, uint64_t x, uint64_t y)
|
|||
*hi = t3 + (t2>>32) + (t1 > *lo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs fused multiply add.
|
||||
*
|
||||
* @return `𝑥 * 𝑦 + 𝑧` rounded as one ternary operation
|
||||
*/
|
||||
double fma(double x, double y, double z)
|
||||
{
|
||||
#if defined(__x86_64__) && defined(__FMA__)
|
||||
|
||||
// Intel Haswell+ (c. 2013)
|
||||
// AMD Piledriver+ (c. 2011)
|
||||
asm("vfmadd132sd\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__FMA4__)
|
||||
|
||||
// AMD Bulldozer+ (c. 2011)
|
||||
asm("vfmaddsd\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
asm("fmadd\t%d0,%d1,%d2,%d3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__)
|
||||
|
||||
asm("fmadd\t%0,%1,%2,%3" : "=d"(x) : "d"(x), "d"(y), "d"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__riscv) && __riscv_flen >= 64
|
||||
|
||||
asm("fmadd.d\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__)
|
||||
|
||||
asm("madbr\t%0,\t%1,\t%2" : "+f"(z) : "f"(x), "f"(y));
|
||||
return z;
|
||||
|
||||
#else
|
||||
|
||||
/* normalize so top 10bits and last bit are 0 */
|
||||
struct num nx, ny, nz;
|
||||
nx = normalize(x);
|
||||
|
@ -220,4 +264,6 @@ double fma(double x, double y, double z)
|
|||
}
|
||||
}
|
||||
return scalbn(r, e);
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.c */
|
||||
/*-
|
||||
|
@ -64,16 +64,53 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Fused multiply-add: Compute x * y + z with a single rounding error.
|
||||
/**
|
||||
* Performs fused multiply add.
|
||||
*
|
||||
* A double has more than twice as much precision than a float, so
|
||||
* direct double-precision arithmetic suffices, except where double
|
||||
* rounding occurs.
|
||||
* @return `𝑥 * 𝑦 + 𝑧` with a single rounding error
|
||||
*/
|
||||
float fmaf(float x, float y, float z)
|
||||
{
|
||||
// #pragma STDC FENV_ACCESS ON
|
||||
#if defined(__x86_64__) && defined(__FMA__)
|
||||
|
||||
// Intel Haswell+ (c. 2013)
|
||||
// AMD Piledriver+ (c. 2011)
|
||||
asm("vfmadd132ss\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__FMA4__)
|
||||
|
||||
// AMD Bulldozer+ (c. 2011)
|
||||
asm("vfmaddss\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
asm("fmadd\t%s0,%s1,%s2,%s3" : "=w"(x) : "w"(x), "w"(y), "w"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__)
|
||||
|
||||
asm("fmadds\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__riscv) && __riscv_flen >= 32
|
||||
|
||||
asm("fmadd.s\t%0,%1,%2,%3" : "=f"(x) : "f"(x), "f"(y), "f"(z));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__)
|
||||
|
||||
asm("maebr\t%0,%1,%2" : "+f"(z) : "f"(x), "f"(y));
|
||||
return z;
|
||||
|
||||
#else
|
||||
|
||||
/* A double has more than twice as much precision than a float,
|
||||
so direct double-precision arithmetic suffices, except where
|
||||
double rounding occurs. */
|
||||
|
||||
/* #pragma STDC FENV_ACCESS ON */
|
||||
double xy, result;
|
||||
union {double f; uint64_t i;} u;
|
||||
int e;
|
||||
|
@ -124,4 +161,6 @@ float fmaf(float x, float y, float z)
|
|||
u.i--;
|
||||
z = u.f;
|
||||
return z;
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
}
|
||||
|
|
|
@ -131,5 +131,7 @@ long double fmodl(long double x, long double y) {
|
|||
} else
|
||||
ux.i.se = ex|sx;
|
||||
return ux.f;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
/**
|
||||
* Splits number normalized fraction and exponent.
|
||||
*/
|
||||
long double frexpl(long double x, int *e)
|
||||
{
|
||||
long double frexpl(long double x, int *e) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return frexp(x, e);
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
|
@ -59,5 +58,7 @@ long double frexpl(long double x, int *e)
|
|||
u.i.se &= 0x8000;
|
||||
u.i.se |= 0x3ffe;
|
||||
return u.f;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -97,4 +97,6 @@ long double hypotl(long double x, long double y)
|
|||
sq(&hy, &ly, y);
|
||||
return z*sqrtl(ly+lx+hy+hx);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -82,6 +82,8 @@ int ilogbl(long double x) {
|
|||
return u.f ? FP_ILOGBNAN : INT_MAX;
|
||||
}
|
||||
return e - 0x3fff;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -180,4 +180,6 @@ long double __tanl(long double x, long double y, int odd) {
|
|||
s = 1.0 + t * z;
|
||||
return t + a * (s + t * v);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
|
@ -16,26 +16,21 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/tinymath/tinymath.h"
|
||||
|
||||
// Thunks float(*fn)(float,float) -> long double fn.
|
||||
//
|
||||
// @param %xmm0[0] contains float param
|
||||
// @return %xmm0[0] contains float result
|
||||
// @note 100% negligible overhead
|
||||
_f2ld2: push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
sub $32,%rsp
|
||||
movss %xmm0,-32(%rbp)
|
||||
flds -32(%rbp)
|
||||
fstpt -32(%rbp)
|
||||
movsd %xmm1,-16(%rbp)
|
||||
flds -16(%rbp)
|
||||
fstpt -16(%rbp)
|
||||
call *%rax
|
||||
fstps -16(%rbp)
|
||||
movss -16(%rbp),%xmm0
|
||||
leave
|
||||
ret
|
||||
.endfn _f2ld2,globl,hidden
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
long long llrint(double x) {
|
||||
long long res;
|
||||
#ifdef __x86_64__
|
||||
asm("cvtsd2si\t%1,%0" : "=r"(res) : "x"(x));
|
||||
#elif defined(__aarch64__)
|
||||
asm("frintx\t%d1,%d1\n\t"
|
||||
"fcvtzs\t%x0,%d1"
|
||||
: "=r"(res), "+w"(x));
|
||||
#else
|
||||
res = rint(x);
|
||||
#endif /* __x86_64__ */
|
||||
return res;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
|
@ -16,21 +16,21 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
|
||||
// Returns 𝑥 × 2ʸ.
|
||||
//
|
||||
// @param 𝑥 is long double passed on stack
|
||||
// @param 𝑦 is long double passed on stack
|
||||
// @return result in %st0
|
||||
// @see ldexpl()
|
||||
scalbl: push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
fldt 32(%rbp)
|
||||
fldt 16(%rbp)
|
||||
fscale
|
||||
fstp %st(1)
|
||||
pop %rbp
|
||||
ret
|
||||
.endfn scalbl,globl
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
long long llrintf(float x) {
|
||||
long long res;
|
||||
#ifdef __x86_64__
|
||||
asm("cvtss2si\t%1,%0" : "=res"(res) : "x"(x));
|
||||
#elif defined(__aarch64__)
|
||||
asm("frintx\t%s1,%s1\n\t"
|
||||
"fcvtzs\t%x0,%s1"
|
||||
: "=r"(res), "+w"(x));
|
||||
#else
|
||||
res = rintf(x);
|
||||
#endif /* __x86_64__ */
|
||||
return res;
|
||||
}
|
|
@ -34,7 +34,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
|
||||
/*
|
||||
|
@ -62,6 +62,9 @@ Lg2 = 0xccce13.0p-25, /* 0.40000972152 */
|
|||
Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
|
||||
Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
|
||||
|
||||
/**
|
||||
* Calculates log₁₀𝑥.
|
||||
*/
|
||||
float log10f(float x)
|
||||
{
|
||||
union {float f; uint32_t i;} u = {x};
|
||||
|
|
|
@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */
|
||||
/*
|
||||
|
@ -152,8 +152,23 @@ static const long double S[4] = {
|
|||
|
||||
#define SQRTH 0.70710678118654752440L
|
||||
|
||||
/**
|
||||
* Calculates log₁₀𝑥.
|
||||
*/
|
||||
long double log10l(long double x)
|
||||
{
|
||||
#ifdef __x86__
|
||||
|
||||
long double lg2;
|
||||
asm("fldlg2" : "=t"(lg2));
|
||||
asm("fyl2x"
|
||||
: "=t"(x)
|
||||
: "0"(x), "u"(lg2)
|
||||
: "st(1)");
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
long double y, z;
|
||||
int e;
|
||||
|
||||
|
@ -218,11 +233,16 @@ done:
|
|||
z += x * (L10EA);
|
||||
z += e * (L102A);
|
||||
return z;
|
||||
|
||||
#endif /* __x86__ */
|
||||
}
|
||||
|
||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
long double log10l(long double x)
|
||||
{
|
||||
return log10(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -215,4 +215,6 @@ long double log1pl(long double x)
|
|||
{
|
||||
return log1p(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -217,4 +217,6 @@ long double log2l(long double x)
|
|||
{
|
||||
return log2(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -209,4 +209,6 @@ long double logl(long double x)
|
|||
{
|
||||
return log(x);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/limits.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/expo.internal.h"
|
||||
#include "libc/tinymath/feval.internal.h"
|
||||
|
||||
|
@ -33,7 +35,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/*
|
||||
If the result cannot be represented (overflow, nan), then
|
||||
|
@ -64,15 +66,9 @@ as a double.
|
|||
#elif FLT_EVAL_METHOD==2
|
||||
#define EPS LDBL_EPSILON
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
/* avoid stack frame in lrint */
|
||||
__attribute__((__noinline__))
|
||||
#endif
|
||||
static long lrint_slow(double x)
|
||||
{
|
||||
static dontinline long lrint_slow(double x) {
|
||||
// #pragma STDC FENV_ACCESS ON
|
||||
int e;
|
||||
|
||||
e = fetestexcept(FE_INEXACT);
|
||||
x = rint(x);
|
||||
if (!e && (x > LONG_MAX || x < LONG_MIN))
|
||||
|
@ -80,12 +76,33 @@ static long lrint_slow(double x)
|
|||
/* conversion */
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
#define JUST_CALL_RINT
|
||||
#endif
|
||||
|
||||
long lrint(double x)
|
||||
{
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
long lrint(double x) {
|
||||
#ifdef __x86_64__
|
||||
long res;
|
||||
asm("cvtsd2si\t%1,%0" : "=r"(res) : "x"(x));
|
||||
return res;
|
||||
#elif defined(__aarch64__)
|
||||
long res;
|
||||
asm("frintx\t%d1,%d1\n\t"
|
||||
"fcvtzs\t%x0,%d1"
|
||||
: "=r"(res), "+w"(x));
|
||||
return res;
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
long res;
|
||||
asm("fctid\t%0,%1" : "=d"(res) : "d"(x));
|
||||
return res;
|
||||
#elif defined(JUST_CALL_RINT)
|
||||
return rint(x);
|
||||
#else
|
||||
uint32_t abstop = asuint64(x)>>32 & 0x7fffffff;
|
||||
uint64_t sign = asuint64(x) & (1ULL << 63);
|
||||
|
||||
if (abstop < 0x41dfffff) {
|
||||
/* |x| < 0x7ffffc00, no overflow */
|
||||
double_t toint = asdouble(asuint64(1/EPS) | sign);
|
||||
|
@ -93,10 +110,5 @@ long lrint(double x)
|
|||
return (long)y;
|
||||
}
|
||||
return lrint_slow(x);
|
||||
#endif /* __x86_64__ */
|
||||
}
|
||||
#else
|
||||
long lrint(double x)
|
||||
{
|
||||
return rint(x);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,21 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
long lrintf(float x) {
|
||||
return rintf(x);
|
||||
long res;
|
||||
#ifdef __x86_64__
|
||||
asm("cvtss2si\t%1,%0" : "=res"(res) : "x"(x));
|
||||
#elif defined(__aarch64__)
|
||||
asm("frintx\t%s1,%s1\n\t"
|
||||
"fcvtzs\t%x0,%s1"
|
||||
: "=r"(res), "+w"(x));
|
||||
#elif defined(__powerpc64__)
|
||||
asm("fctid\t%0,%1" : "=d"(res) : "f"(x));
|
||||
#else
|
||||
res = rintf(x);
|
||||
#endif /* __x86_64__ */
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
|
||||
/**
|
||||
* Rounds 𝑥 to nearest integer, away from zero.
|
||||
*/
|
||||
long lround(double x) {
|
||||
return round(x);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,19 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
|
||||
/**
|
||||
* Rounds 𝑥 to nearest integer, away from zero.
|
||||
*/
|
||||
long lroundf(float x) {
|
||||
return roundf(x);
|
||||
long res;
|
||||
#ifdef __aarch64__
|
||||
asm("fcvtas\t%x0,%s1" : "=r"(res) : "w"(x));
|
||||
#elif defined(__powerpc64__) && defined(__VSX__)
|
||||
asm("xsrdpi\t%1,%1\n\t"
|
||||
"fctid\t%0,%1"
|
||||
: "=d"(res), "+f"(x));
|
||||
#else
|
||||
res = roundf(x);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,19 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
long double modfl(long double x, long double *iptr)
|
||||
{
|
||||
double d;
|
||||
long double r;
|
||||
|
||||
r = modf(x, &d);
|
||||
*iptr = d;
|
||||
return r;
|
||||
}
|
||||
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
|
||||
|
||||
static const long double toint = 1/LDBL_EPSILON;
|
||||
|
||||
|
@ -77,3 +89,7 @@ long double modfl(long double x, long double *iptr)
|
|||
*iptr = x + y;
|
||||
return -y;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,15 @@
|
|||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
double nearbyint(double x) {
|
||||
#ifdef __aarch64__
|
||||
asm("frinti\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
asm("fidbra\t%0,0,%1,4" : "=f"(x) : "f"(x));
|
||||
#else
|
||||
#ifdef FE_INEXACT
|
||||
// #pragma STDC FENV_ACCESS ON
|
||||
int e;
|
||||
|
@ -29,5 +37,6 @@ double nearbyint(double x) {
|
|||
#ifdef FE_INEXACT
|
||||
if (!e) feclearexcept(FE_INEXACT);
|
||||
#endif
|
||||
#endif /* __aarch64__ */
|
||||
return x;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
float nearbyintf(float x) {
|
||||
#ifdef FE_INEXACT
|
||||
// #pragma STDC FENV_ACCESS ON
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
/**
|
||||
* Rounds to nearest integer.
|
||||
*/
|
||||
long double nearbyintl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return nearbyint(x);
|
||||
|
|
|
@ -100,5 +100,7 @@ long double nextafterl(long double x, long double y) {
|
|||
if ((ux.i.se & 0x7fff) == 0)
|
||||
FORCE_EVAL(x*x + ux.f*ux.f);
|
||||
return ux.f;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -33,7 +33,9 @@ long double powl(long double x, long double y) {
|
|||
if (x) {
|
||||
if (y) {
|
||||
if (x < 0 && y != truncl(y)) {
|
||||
#ifndef __NO_MATH_ERRNO__
|
||||
errno = EDOM;
|
||||
#endif
|
||||
return NAN;
|
||||
}
|
||||
asm("fyl2x" : "=t"(u) : "0"(fabsl(x)), "u"(y) : "st(1)");
|
||||
|
@ -57,7 +59,9 @@ long double powl(long double x, long double y) {
|
|||
} else if (!y) {
|
||||
return 1;
|
||||
} else {
|
||||
#ifndef __NO_MATH_ERRNO__
|
||||
errno = ERANGE;
|
||||
#endif
|
||||
if (y == truncl(y) && ((int64_t)y & 1)) {
|
||||
return copysignl(INFINITY, x);
|
||||
} else {
|
||||
|
@ -619,6 +623,8 @@ long double powl(long double x, long double y)
|
|||
{
|
||||
return pow(x, y);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/kernel.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/kernel.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
|
|
@ -197,4 +197,6 @@ int __rem_pio2l(long double x, long double *y)
|
|||
return n;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
|
|
|
@ -153,5 +153,7 @@ long double remquol(long double x, long double y, int *quo) {
|
|||
q &= 0x7fffffff;
|
||||
*quo = sx^sy ? -(int)q : (int)q;
|
||||
return sx ? -x : x;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
|
|
@ -54,5 +54,7 @@ long double rintl(long double x) {
|
|||
if (y == 0)
|
||||
return 0*x;
|
||||
return y;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -41,8 +42,28 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
#endif
|
||||
static const double_t toint = 1/EPS;
|
||||
|
||||
/**
|
||||
* Rounds 𝑥 to nearest integer, away from zero.
|
||||
*/
|
||||
double round(double x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frinta\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("frin\t%0,%1" : "=d"(x) : "d"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fidbra\t%0,1,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {double f; uint64_t i;} u = {x};
|
||||
int e = u.i >> 52 & 0x7ff;
|
||||
double_t y;
|
||||
|
@ -66,4 +87,6 @@ double round(double x)
|
|||
if (u.i >> 63)
|
||||
y = -y;
|
||||
return y;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/fenv.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -43,8 +44,18 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
#endif
|
||||
static const float_t toint = 1/EPS;
|
||||
|
||||
/**
|
||||
* Rounds 𝑥 to nearest integer, away from zero.
|
||||
*/
|
||||
float roundf(float x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frinta\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {float f; uint32_t i;} u = {x};
|
||||
int e = u.i >> 23 & 0xff;
|
||||
float_t y;
|
||||
|
@ -67,4 +78,6 @@ float roundf(float x)
|
|||
if (u.i >> 31)
|
||||
y = -y;
|
||||
return y;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -63,5 +63,7 @@ long double roundl(long double x) {
|
|||
if (u.i.se >> 15)
|
||||
y = -y;
|
||||
return y;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -53,6 +53,9 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* should use scalbn() instead.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns 𝑥 × 2ʸ.
|
||||
*/
|
||||
double scalb(double x, double fn)
|
||||
{
|
||||
if (isnan(x) || isnan(fn))
|
||||
|
|
|
@ -22,5 +22,5 @@
|
|||
* Returns 𝑥 × 2ʸ.
|
||||
*/
|
||||
double scalbln(double x, long n) {
|
||||
return ldexp(x, n);
|
||||
return ldexp(x, n > 65536 ? 65536 : n < -65536 ? -65536 : (int)n);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */
|
||||
/*
|
||||
|
|
|
@ -37,7 +37,7 @@ asm(".ident\t\"\\n\\n\
|
|||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
// clang-format off
|
||||
|
||||
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */
|
||||
/*
|
||||
|
|
|
@ -90,5 +90,7 @@ void sincosl(long double x, long double *sin, long double *cos) {
|
|||
*cos = s;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -74,5 +74,7 @@ long double sinhl(long double x) {
|
|||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
return sinh(x);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -69,5 +69,7 @@ long double sinl(long double x) {
|
|||
default:
|
||||
return -__cosl(hi, lo);
|
||||
}
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -53,13 +53,35 @@ static inline uint64_t mul64(uint64_t a, uint64_t b)
|
|||
return ahi*bhi + (ahi*blo >> 32) + (alo*bhi >> 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns square root of 𝑥.
|
||||
*/
|
||||
double sqrt(double x)
|
||||
{
|
||||
#ifdef __x86__
|
||||
#ifdef __SSE2__
|
||||
|
||||
double res;
|
||||
asm("sqrtsd\t%1,%0" : "=x"(res) : "x"(x));
|
||||
return res;
|
||||
asm("sqrtsd\t%1,%0" : "=x"(x) : "x"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
asm("fsqrt\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__)
|
||||
|
||||
asm("fsqrt\t%0,%1" : "=d"(x) : "d"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__riscv) && __riscv_flen >= 64
|
||||
|
||||
asm("fsqrt.d\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("sqdbr\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
|
@ -196,5 +218,5 @@ double sqrt(double x)
|
|||
}
|
||||
return y;
|
||||
|
||||
#endif
|
||||
#endif /* __SSE2__ */
|
||||
}
|
||||
|
|
|
@ -44,13 +44,35 @@ static inline uint32_t mul32(uint32_t a, uint32_t b)
|
|||
|
||||
/* see sqrt.c for more detailed comments. */
|
||||
|
||||
/**
|
||||
* Returns square root of 𝑥.
|
||||
*/
|
||||
float sqrtf(float x)
|
||||
{
|
||||
#ifdef __x86__
|
||||
#ifdef __SSE2__
|
||||
|
||||
float res;
|
||||
asm("sqrtss\t%1,%0" : "=x"(res) : "x"(x));
|
||||
return res;
|
||||
asm("sqrtss\t%1,%0" : "=x"(x) : "x"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
asm("fsqrt\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__)
|
||||
|
||||
asm("fsqrts\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__riscv) && __riscv_flen >= 32
|
||||
|
||||
asm("fsqrt.s\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("sqebr\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
|
@ -121,5 +143,5 @@ float sqrtf(float x)
|
|||
}
|
||||
return y;
|
||||
|
||||
#endif
|
||||
#endif /* __SSE2__ */
|
||||
}
|
||||
|
|
|
@ -205,11 +205,20 @@ static inline u128 mul128_tail(u128 a, u128 b)
|
|||
return lo;
|
||||
}
|
||||
|
||||
|
||||
/* see sqrt.c for detailed comments. */
|
||||
|
||||
/**
|
||||
* Returns square root of 𝑥.
|
||||
*/
|
||||
long double sqrtl(long double x)
|
||||
{
|
||||
#ifdef __x86__
|
||||
|
||||
asm("fsqrt" : "+t"(x));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
u128 ix, ml;
|
||||
uint64_t top;
|
||||
|
||||
|
@ -285,7 +294,10 @@ long double sqrtl(long double x)
|
|||
y += mkldbl(top, (u128){0});
|
||||
}
|
||||
return y;
|
||||
|
||||
#endif /* __x86__ */
|
||||
}
|
||||
|
||||
#else
|
||||
#error unsupported long double format
|
||||
#endif
|
||||
|
|
|
@ -78,5 +78,7 @@ long double tanhl(long double x) {
|
|||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
return tanh(x);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -57,5 +57,7 @@ long double tanl(long double x) {
|
|||
}
|
||||
n = __rem_pio2l(x, y);
|
||||
return __tanl(y[0], y[1], n&1);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
0
libc/tinymath/tinymath.h
Executable file
0
libc/tinymath/tinymath.h
Executable file
|
@ -27,6 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -39,6 +40,30 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
*/
|
||||
double trunc(double x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintz\t%d0,%d1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("friz\t%0,%1" : "=d"(x) : "d"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fidbra\t%0,5,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundsd\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {double f; uint64_t i;} u = {x};
|
||||
int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12;
|
||||
uint64_t m;
|
||||
|
@ -52,4 +77,6 @@ double trunc(double x)
|
|||
FORCE_EVAL(x + 0x1p120f);
|
||||
u.i &= ~m;
|
||||
return u.f;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "third_party/intel/smmintrin.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
|
@ -34,12 +35,38 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
|
|||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/**
|
||||
* Rounds to integer, towards zero.
|
||||
*/
|
||||
float truncf(float x)
|
||||
{
|
||||
#ifdef __aarch64__
|
||||
|
||||
asm("frintz\t%s0,%s1" : "=w"(x) : "w"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
|
||||
|
||||
asm("friz\t%0,%1" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
|
||||
|
||||
asm("fiebra\t%0,5,%1,4" : "=f"(x) : "f"(x));
|
||||
return x;
|
||||
|
||||
#elif defined(__x86_64__) && defined(__SSE4_1__)
|
||||
|
||||
asm("roundss\t%2,%1,%0"
|
||||
: "=x"(x)
|
||||
: "x"(x), "i"(_MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC));
|
||||
return x;
|
||||
|
||||
#else
|
||||
|
||||
union {float f; uint32_t i;} u = {x};
|
||||
int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9;
|
||||
uint32_t m;
|
||||
|
||||
if (e >= 23 + 9)
|
||||
return x;
|
||||
if (e < 9)
|
||||
|
@ -50,4 +77,6 @@ float truncf(float x)
|
|||
FORCE_EVAL(x + 0x1p120f);
|
||||
u.i &= ~m;
|
||||
return u.f;
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
}
|
||||
|
|
|
@ -60,5 +60,7 @@ long double truncl(long double x) {
|
|||
y -= 1;
|
||||
x += y;
|
||||
return s ? -x : x;
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue