diff --git a/src/math/Makefile b/src/math/Makefile new file mode 100644 index 0000000..9001a76 --- /dev/null +++ b/src/math/Makefile @@ -0,0 +1,4 @@ +TROOT=../.. +include $(TROOT)/Makefile.inc + +CFLAGS += -D_GNU_SOURCE diff --git a/src/math/acos.c b/src/math/acos.c new file mode 100644 index 0000000..c38d7f2 --- /dev/null +++ b/src/math/acos.c @@ -0,0 +1,12 @@ +#include "test.h" +#include + +void bench_acos(int N) +{ + int i; + volatile double y; + + for (i = 0; i < N; i++) { + y = acos(0.3456); + } +} diff --git a/src/math/fenv.c b/src/math/fenv.c new file mode 100644 index 0000000..ae1f897 --- /dev/null +++ b/src/math/fenv.c @@ -0,0 +1,60 @@ +#include "test.h" +#include +#include +#include +#include +#include + + +void test_fenv() +{ + int r; + + r = fesetround(FE_UPWARD); + if (r != 0) + error("fesetround %d\n", r); + r = fegetround(); + if (r != FE_UPWARD) + error("fegetround %x wanted %x\n", r, FE_UPWARD); + r = fesetround(FE_TONEAREST); + if (r != 0) + error("fesetround %d\n", r); + r = fegetround(); + if (r != FE_TONEAREST) + error("fegetround %x wanted %x\n", r, FE_TONEAREST); +} + +void test_fenv_except() +{ + int i,r; + + for (i = 0; i < 64; i++) { + feclearexcept(FE_ALL_EXCEPT); + + r = feraiseexcept(i); + if (r) + error("feraise %d returned %d\n", i, r); + r = fetestexcept(FE_ALL_EXCEPT); + if (r != i) + error("feraise want %d got %d\n", i, r); + } +} + +void bench_feraiseexcept(int N) +{ + int i; + for (i = 0; i < N; i++) { + feraiseexcept(i&63); + } +} + +void bench_fesetround(int N) +{ + int i; + int r = 0; + + for (i = 0; i < N; i++) { + r ^= 0x400; + fesetround(r); + } +} diff --git a/src/math/fma.c b/src/math/fma.c new file mode 100644 index 0000000..6baa635 --- /dev/null +++ b/src/math/fma.c @@ -0,0 +1,212 @@ +#include "test.h" +#include +#include +#include +#include +#include +#include + +static struct { + double x, y, z, r; +} testdata[] = { +-0x1p+0, 0x0p0, -0x0p+0, -0x0p+0, +-0x1p+0, 0x1p+0, 0x1p+0, 0x0p+0, +0x1p+0, 0x1p+0, -0x1p+0, 0x0p+0, +-0x1p+0, -0x1p+0, -0x1p+0, 0x0p+0, +0x1.0000000000001p+0, 0x1p+0, 0x1p+53, 0x1.0000000000001p+53, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1p+53, 0x1.0000000000001p+53, +0x1p+0, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp+53, 0x1.fffffffffffffp+53, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffep+53, 0x1.fffffffffffffp+53, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1p-52, 0x1.0000000000001p+0, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp-53, 0x1.0000000000001p+0, +0x1.0000000000005p+0, 0x1.ffffffffffffbp-1, 0x1p-52, 0x1.0000000000003p+0, +0x1.0000000000006p+0, 0x1.ffffffffffffdp-1, 0x1p-52, 0x1.0000000000005p+0, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, -0x1p+0, 0x1.ffffffffffffep-54, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, -0x1.fffffffffffffp-1, 0x1.fffffffffffffp-53, +0x1.0000000000001p+0, 0x1.ffffffffffffep-1, -0x1p+0, -0x1p-104, +0x1.0000000000001p+0, 0x1.ffffffffffffep-1, -0x1.fffffffffffffp-1, 0x1.ffffffffffffcp-54, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1p+0, -0x1.0000000000003p-53, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1.fffffffffffffp-1, -0x1.8p-104, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, -0x1.ffffffffffffep-1, 0x1.ffffffffffffap-54, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1p+0, -0x1.0000000000002p-52, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.fffffffffffffp-1, -0x1.0000000000004p-53, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.ffffffffffffep-1, -0x1p-103, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, -0x1.ffffffffffffdp-1, 0x1.ffffffffffff8p-54, +0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, -0x1.fffffffffffffp-1, -0x1.fffffffffffffp-54, +0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1, 0x1p-106, +0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.fffffffffffffp-1, -0x1.fffffffffffffp-53, +0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffep-1, -0x1.ffffffffffffep-54, +0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffdp-1, 0x1p-105, +0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, -0x1.ffffffffffffcp-1, 0x1.0000000000001p-53, +0x1.fffffffffffffp-1, 0x1.ffffffffffffdp-1, -0x1p+0, -0x1.fffffffffffffp-52, +0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff5p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1p+0, 0x1.ffffffffffff9p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffcp-1, 0x1.ffffffffffff7p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffff5p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffffdp-1, 0x1.ffffffffffff7p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffff5p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffep-1, 0x1.ffffffffffff7p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffff5p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.fffffffffffffp-1, 0x1.ffffffffffff7p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffff5p+0, +0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffff3p+0, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffep-1, 0x1.fffffffffffffp+0, +0x1.0000000000001p+0, 0x1.fffffffffffffp-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffdp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.fffffffffffffp-1, 0x1.fffffffffffffp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffdp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffep-1, 0x1.ffffffffffff7p-1, 0x1.ffffffffffffbp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1p+0, 0x1.fffffffffffffp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1.ffffffffffffcp-1, 0x1.ffffffffffffdp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffdp-1, 0x1.ffffffffffff8p-1, 0x1.ffffffffffffbp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, 0x1.ffffffffffffdp-1, 0x1.ffffffffffffdp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffcp-1, 0x1.ffffffffffff9p-1, 0x1.ffffffffffffbp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffep-1, 0x1.ffffffffffffdp+0, +0x1.0000000000001p+0, 0x1.ffffffffffffbp-1, 0x1.ffffffffffffap-1, 0x1.ffffffffffffbp+0, +0x1.5872449b765b9p+0, 0x1.c9acf91f8de2bp+0, 0x1.9265607e4d168p+0, 0x1.fd190c77c2a67p+1, +0x1.81d010b146d0ep+0, 0x1.2d3c680dc9071p+0, 0x1.a80b69538754cp+0, 0x1.b7040b44973a7p+1, +0x1.6a44f2252b6a2p+0, 0x1.da452a378b832p+0, 0x1.1fe2ce329104p+0, 0x1.df842b6f48b13p+1, +0x1.096b1d26463eep+0, 0x1.d846d3e34333p+0, 0x1.721e3480922b8p+0, 0x1.ade2909c0269fp+1, +0x1.99bd3434c454bp+0, 0x1.03cb8e4115bdep+0, 0x1.109f107188b08p+0, 0x1.5837a47d37fafp+1, +0x1.ba930a0a78ed2p+0, 0x1.8c24e8d67f636p+0, 0x1.ac49dbfbf8affp+0, 0x1.164947ae6a5d9p+2, +0x1.be224ad773191p+0, 0x1.d96b77169731fp+0, 0x1.662cfb75d8edep+0, 0x1.27cd67e720f79p+2, +0x1.59e7a1b0bdb3cp+0, 0x1.2decba4d46421p+0, 0x1.88f4062e96df5p+0, 0x1.90749e4794f79p+1, +0x1.22edf4b4da9a7p+0, 0x1.dfa8d65f506cdp+0, 0x1.2799208da2fbap+0, 0x1.a45a1e99ed7a9p+1, +0x1.ad5b991a2a279p+0, 0x1.f02fd26706024p+0, 0x1.831cdd5c8797cp+0, 0x1.30d3a2ac90a61p+2, +0x1.531f9620e764ap+0, 0x1.cad61b54d4425p+0, 0x1.df817cae8a9afp+0, 0x1.0fd4e7f8671ddp+2, +0x1.629a5ad79494fp+0, 0x1.049e58693f4c4p+0, 0x1.45b0109e4d00cp+0, 0x1.5758154e14965p+1, +0x1.2f52b53f9240ap+0, 0x1.1d5c686dbb0dap+0, 0x1.6da3e392a4fd4p+0, 0x1.5fe03a6795913p+1, +0x1.058667552b49ep+0, 0x1.23307bacc1c42p+0, 0x1.5b059b47cd8f5p+0, 0x1.423f752486d13p+1, +0x1.a717d95337ed8p+0, 0x1.2b1c37846aaadp+0, 0x1.be65672f885b1p+0, 0x1.d65e72303c075p+1, +0x1.deb79287b3d32p+0, 0x1.62776b829babap+0, 0x1.67daf18bd2eb1p+0, 0x1.ff5a0d45c69d7p+1, +0x1.fbf12d3a6de91p+0, 0x1.879fe6124f11p+0, 0x1.9f3f1247a8641p+0, 0x1.2a126c6980019p+2, +0x1.c589628460e01p+0, 0x1.e1bec1c797533p+0, 0x1.349f30cdb84bbp+0, 0x1.2286118b6f6e5p+2, +0x1.46fd6c2c924ebp+0, 0x1.65e2f02e730a1p+0, 0x1.37739d2751098p+0, 0x1.804a71c1f1273p+1, +0x1.f99e595ae11fdp+0, 0x1.bd33d9a1d81bp+0, 0x1.932a2a2e244c1p+0, 0x1.409e34f8f2f89p+2, +0x1.59ea1e56bfe55p+0, 0x1.6f46b7d412a44p+0, 0x1.80f2bc9a32cc3p+0, 0x1.b89c7640e32ffp+1, +0x1.61490fcb44129p+0, 0x1.0038ec4fc35c2p+0, 0x1.df7436ed7a7b7p+0, 0x1.a085ea68d05cfp+1, +0x1.d41b98788502bp+0, 0x1.1a7b77843aca6p+0, 0x1.05be891837d36p+0, 0x1.8523596ceced9p+1, +0x1.3153cf6f69af9p+0, 0x1.aaa947e38e57ap+0, 0x1.8519f9b590645p+0, 0x1.c0fcab7b46369p+1, +0x1.c25a1f73581aap+0, 0x1.0a51ffca372ap+0, 0x1.0c77e3ebac5f3p+0, 0x1.707ce48c7d72dp+1, +0x1.829c2cde44b7p+0, 0x1.f692e86d8cb36p+0, 0x1.455e72d264bfp+0, 0x1.0f16a3b8b3f97p+2, +0x1.94729588dcc69p+0, 0x1.c3bb794c6edf8p+0, 0x1.9da4e94d262d2p+0, 0x1.19d4bd84d9fd3p+2, +0x1.e6a5e7e39c3d5p+0, 0x1.1b69af2bdd978p+0, 0x1.e7ef1eafa119cp+0, 0x1.00ac5b44c9f31p+2, +0x1.bc9ba1320700cp-1022, 0x1.981f2e1a451a8p-2, 0x1.046144efc0ceap-1022, 0x1.b594d0e4368efp-1022, +0x1.022db53c98d14p-1022, 0x1.21157eef74848p-2, 0x1.2f880432b1bc1p-1022, 0x1.786ad60a02b3dp-1022, +0x1.805a491fa9597p-1022, 0x1.e0f49d782ff87p-2, 0x1.172a62346206p-1022, 0x1.cbb085199a3f5p-1022, +0x1.adbc3a9d816dep-1022, 0x1.e039d4431e3cdp-2, 0x1.93ceef6fe18a2p-1022, 0x1.2eabb7dc0e2f1p-1021, +0x1.645aa5c2df3afp-1022, 0x1.649edfcad854fp-2, 0x1.8b43e0bbaeb01p-1022, 0x1.03af571d2b505p-1021, +0x1.133474a2c0fb1p-1022, 0x1.72442bcbfa01dp-2, 0x1.4a1a21971c5dbp-1022, 0x1.ad9ce7fcefa3fp-1022, +0x1.8ee3feb00c3e7p-1022, 0x1.53bd9353313bcp-2, 0x1.5501b57dc3b6fp-1022, 0x1.d9598906f0bb3p-1022, +0x1.161225cfa61e2p-1022, 0x1.b6dd69a0af5bp-2, 0x1.924ffc3ead5c3p-1022, 0x1.04be6fc25367bp-1021, +0x1.820f7faf219afp-1022, 0x1.06717ae771f6dp-2, 0x1.0dc5035f5e2afp-1022, 0x1.70b6c3169f043p-1022, +0x1.ce0e2ea55040ep-1022, 0x1.ce5a55fa3828dp-2, 0x1.f2f444d50ce59p-1022, 0x1.61ca36f5a8a79p-1021, +0x1.a7a271c67cdcfp-1022, 0x1.1e979090e218p-2, 0x1.b1f10b6e2177ap-1022, 0x1.1440cf1c105ebp-1021, +0x1.76df065829dc6p-1022, 0x1.fb22ab1b86b8bp-2, 0x1.6966267f317cp-1022, 0x1.1186e1f77012dp-1021, +0x1.8b004a28b70dbp-1022, 0x1.48e5805a8b453p-2, 0x1.0ea791f716557p-1022, 0x1.8d86310bad175p-1022, +0x1.fb3391a4b1d23p-1022, 0x1.4d8705b057caep-2, 0x1.d026cb6dae73bp-1022, 0x1.3aad18b424c67p-1021, +0x1.a5ba39730e197p-1022, 0x1.794df89b1cc49p-2, 0x1.24a0a388d0b6bp-1022, 0x1.c0048fd33a417p-1022, +0x1.aa9eff070281cp-1022, 0x1.fab05661b48ebp-2, 0x1.cbe2af6c69c6ep-1022, 0x1.4f7ddbe122765p-1021, +0x1.758bbff0ec4bap-1022, 0x1.a4a197f3fa424p-2, 0x1.47761e8d142ddp-1022, 0x1.e0e762ee2e7c5p-1022, +0x1.4dab43918a9a8p-1022, 0x1.ed667442b4751p-2, 0x1.3f25f82e02e3ep-1022, 0x1.dfec0ee732dcbp-1022, +0x1.7943735951931p-1022, 0x1.fa6a357c5c9ddp-2, 0x1.0bed44b0b71b4p-1022, 0x1.c6803a6059abfp-1022, +0x1.66c26bc29a5e8p-1022, 0x1.3faed079f761ap-2, 0x1.163ff906dd651p-1022, 0x1.8640492c45959p-1022, +0x1.f52172c56bdf5p-1022, 0x1.672b2de422734p-2, 0x1.7bc5d708e5a34p-1022, 0x1.15c5b95145cc7p-1021, +0x1.2f94e89aa7558p-1022, 0x1.dfa6d30835f5ep-2, 0x1.59c6b0d504cf9p-1022, 0x1.e7fa0dd76fbefp-1022, +0x1.6159897ae533cp-1022, 0x1.f3b8892e3a3c8p-2, 0x1.09ca702b7759p-1022, 0x1.b63a7f56fce1fp-1022, +0x1.f73d5f4e81fd8p-1022, 0x1.7ccff2642124ap-2, 0x1.e7d836a0c8308p-1022, 0x1.517f1763126d3p-1021, +0x1.b4328925969fbp-1022, 0x1.8fa02832a22d5p-2, 0x1.2084598e2f8c6p-1022, 0x1.cabf43838dc51p-1022, +0x1.66ee60a92676fp-1022, 0x1.eddd2e7681ce4p-2, 0x1.b81d57daeb3a7p-1022, 0x1.329c918ffb683p-1021, +0x1.ff2737585895dp-1022, 0x1.fb4bf3828ae4ap-2, 0x1.4a866847740fp-1022, 0x1.23e07e4dbbeabp-1021, +0x1.5e2008d269a86p-1022, 0x1.507bbbe4d78eep-2, 0x1.6220c6f83f636p-1022, 0x1.d52d9874f1c75p-1022, +0x1.ce7e2e5812d86p-1022, 0x1.0e6689d092e5fp-2, 0x1.1e43fd55c3458p-1022, 0x1.9864925e2fb0fp-1022, +0x1.7b353b81e793dp-1022, 0x1.82b426f874c6dp-2, 0x1.d92b19d21fd5cp-1022, 0x1.342fb0c544a79p-1021, +0x1.5be667823370ap-1022, 0x1.a8a99b163869bp-2, 0x1.95456b68dc3bcp-1022, 0x1.12c638de03c71p-1021, +0x1.17b0fc6c850e5p-1022, 0x1.d1d0a4853c315p-2, 0x1.36b79f7c0c24p-1022, 0x1.b5f2baff5635dp-1022, +0x1.bd97819bacfd8p-1022, 0x1.2c25f267ba4eep-2, 0x1.804b5204a3f3ap-1022, 0x1.01739c190fd97p-1021, +0x1.596577053873dp-1022, 0x1.3562ab2d29949p-2, 0x1.b3f1ee75db6e7p-1022, 0x1.0e268a498009bp-1021, +0x1.3c7a68cf0f7b3p-1022, 0x1.9a55c15b167bdp-2, 0x1.7635b7b163c07p-1022, 0x1.f5073b93b7b81p-1022, +0x1.5825164bc4068p-1022, 0x1.dcbb6e5ff3245p-2, 0x1.52fc3be0e84dap-1022, 0x1.f334771c2dcfbp-1022, +0x1.139ea77b760ecp+1022, 0x1.9b25f2fd017eap+2, -0x1.bc16788922b6fp+1023, 0x1.b93aac527380fp+1023, +0x1.0e6f9c1657d7cp+1022, 0x1.4d5c6b55ab5f1p+2, -0x1.e027dd5742e2cp+1023, 0x1.c0538372b4bbfp+1022, +0x1.1182524fa411cp+1022, 0x1.a3dba56842d19p+2, -0x1.c1ad59474d71fp+1023, 0x1.bf78969300a77p+1023, +0x1.1cbf4fb8ec82p+1022, 0x1.5e32019a84fbbp+2, -0x1.985af08f32edep+1023, 0x1.72af6bbad4a29p+1023, +0x1.311e25c6db346p+1022, 0x1.4e30db6c4b51dp+2, -0x1.7681f7a9786a7p+1023, 0x1.a61d29434fc13p+1023, +0x1.1201cf577052fp+1022, 0x1.59730b2db7a16p+2, -0x1.56f1a64a078d5p+1023, 0x1.8c8d801df34d9p+1023, +0x1.3e52335b76e81p+1022, 0x1.4dbd56f857479p+2, -0x1.509340c11bd2ep+1023, 0x1.ed6576837f653p+1023, +0x1.18566b4f843cbp+1022, 0x1.444fba10eaf29p+2, -0x1.f927beae57f0ap+1023, 0x1.9a433b9796559p+1022, +0x1.3fbe544fe1be8p+1022, 0x1.2d2a5fda03639p+2, -0x1.007407dbfd03cp+1023, 0x1.efdb644b613e5p+1023, +0x1.263a0d3bc2e4p+1022, 0x1.4cc198adbc651p+2, -0x1.734b1c1f7fdb8p+1023, 0x1.899878afc0fa3p+1023, +0x1.5bf4aec8efc8ep+1022, 0x1.555f0341516c9p+2, -0x1.c706408acd14cp+1023, 0x1.d8f5e18b868bdp+1023, +0x1.1e57f1af78279p+1022, 0x1.34bc0c7f082b3p+2, -0x1.497b92c1365edp+1023, 0x1.692cb7ec68a93p+1023, +0x1.1d9824cd73511p+1022, 0x1.1d557ddfe47ffp+2, -0x1.556cdb1d20a72p+1023, 0x1.2736a6b6e35f3p+1023, +0x1.1ff85a24aff31p+1022, 0x1.39ab374b2680dp+2, -0x1.35e6b07b651b8p+1023, 0x1.8bc7ce2087081p+1023, +0x1.0449b3965227ep+1022, 0x1.4430d4441f9f2p+2, -0x1.a6966c96307ep+1023, 0x1.d94eda8c81771p+1022, +0x1.3c91fa00fd0c7p+1022, 0x1.1b6661c0b0303p+2, -0x1.f1f2846b64483p+1023, 0x1.95eae0d2644d3p+1022, +0x1.0979b36d46534p+1022, 0x1.12fa205f41f7fp+2, -0x1.a83ecf4544a63p+1023, 0x1.2420f34e2aa3dp+1022, +0x1.4c89df582a599p+1022, 0x1.55f3dc473ea8fp+2, -0x1.e35037292ddfp+1023, 0x1.95109fdbc3771p+1023, +0x1.35ee0a669c4fbp+1022, 0x1.2263cb63f386ap+2, -0x1.449218ae35ac7p+1023, 0x1.7a8ed977d817bp+1023, +0x1.117cc860f61bcp+1022, 0x1.440985b25d994p+2, -0x1.d7a7d82000449p+1023, 0x1.b960b7088e74fp+1022, +0x1.1e78a37be320fp+1022, 0x1.0db0fce62287bp+2, -0x1.376337da5eb53p+1023, 0x1.24326b9956dfbp+1023, +0x1.0c79b5c8331c2p+1022, 0x1.0aba6ea746b5p+2, -0x1.c86f1fcaf0741p+1023, 0x1.9c135bb2cff85p+1021, +0x1.556c4c072f272p+1022, 0x1.347758d7d4eb5p+2, -0x1.c6fe4f24b248dp+1023, 0x1.6fcc9f756df6dp+1023, +-0x1.e8349b891b2fp-1, 0x1.4a6dec9b72578p-1, 0x1.3b6151ce809ddp-1, 0x1.3a62fe330b355p-11, +0x1.2996632ac7d74p-1, -0x1.bb3c58b654d94p-1, 0x1.01a6660e64a31p-1, 0x1.ed045bb956a8ep-15, +-0x1.c602e894c1df8p-1, 0x1.a1c980e7d3f94p-1, 0x1.7271244b43386p-1, -0x1.ba251fe026e5bp-15, +-0x1.c84baf47e85cp-1, 0x1.770b5149ef2ep-1, 0x1.4d80f139320bap-1, -0x1.79277433b9e23p-10, +-0x1.36e667dcf9c6p-1, 0x1.2591f82556b88p-1, 0x1.2452a0f795f95p-1, 0x1.c83c8e63c159fp-3, +0x1.88b2cede61e4cp-1, -0x1.71dcab5ad9e9p-3, 0x1.32b27fea2ae97p-3, 0x1.70461909b25e2p-7, +0x1.8d1e44002c98p-3, -0x1.af9fdfb347834p-1, 0x1.e280942fb4146p-4, -0x1.761ac23896dfdp-5, +0x1.236e8cb9492c8p-1, -0x1.d37443a57f1c4p-1, 0x1.ca10df801aabcp-4, -0x1.a1a2cdf0138f9p-2, +-0x1.6ad943e610fb8p-1, -0x1.cef92a7bb18bcp-1, 0x1.f28587d8fb0ep-4, 0x1.866b5204b9aecp-1, +-0x1.60a8569a5d894p-1, -0x1.ca07e29dd171cp-1, 0x1.b6c475ace09ecp-4, 0x1.72549291e2f7ap-1, +0x1.d1962720d678cp-1, -0x1.4548ee45c4084p-1, 0x1.f416ab193d75cp-4, -0x1.d2929879dc853p-2, +-0x1.9ddcb295a7d64p-1, 0x1.67fb3a2068a78p-1, 0x1.da9cd4597fe0ap-4, -0x1.cf4f6eb4fc5d8p-2, +0x1.c00d16ed45b88p+0, 0x1.c787eddda3664p+0, 0x1.1e3e6f0cc1802p-5, 0x1.931b8f379dcc3p+1, +0x1.19c2a2372c184p+0, -0x1.cb506961c19fp+0, 0x1.db1abf3f7ba3ap-6, -0x1.f21c0eab0bc18p+0, +-0x1.3a263218ccd1cp+0, -0x1.e818d390df27cp+0, 0x1.2a81ed71785f5p-5, 0x1.3025ab0f63925p+1, +0x1.b0b041fbaca58p+0, -0x1.9d5f76d178e6p+0, 0x1.0215c7bb84cf9p-6, -0x1.5b52aec7ef4p+1, +-0x1.377549d9a87f4p+0, -0x1.a13d4a03dd6d8p+0, 0x1.f190388bc5cc6p-7, 0x1.ff83bebbd6fe4p+0, +0x1.6a726c0762ac8p-1, -0x1.d32f2d30e483cp+0, 0x1.f953eb70fbde6p-7, -0x1.46c61b3070332p+0, +0x1.94cf2509d40cp-1, 0x1.721976af6dfbp+0, 0x1.f51a456921c3ep-7, 0x1.28880842acc6p+0, +0x1.b128eb0ad8728p-1, 0x1.7682566a54268p+0, 0x1.bd4122a074cafp-8, 0x1.3e9469530e762p+0, +0x1.c4ae75976e35cp+0, -0x1.11c329dd1160cp+0, 0x1.9993f5e13c9bdp-8, -0x1.e27d925b07cf1p+0, +-0x1.85f81f88fa3c4p+0, -0x1.17648a494fa18p-1, 0x1.37d305113b48p-10, 0x1.aa367b7490e57p-1, +-0x1.311f2b4319efcp+0, 0x1.abbb5272e3d18p-1, 0x1.35841b7bdbcfep-10, -0x1.fd337f24b39ep-1, +0x1.ab94369a9a0dp-1, 0x1.9d1e0e0aa3bacp+0, 0x1.0a63ca87cfa78p-11, 0x1.592173ee296b6p+0, +}; + +void bench_fma(int N) +{ + int i; + double x, y, z; + volatile double r; + + x = 0x1.629a5ad79494fp+0; + y = 0x1.049e58693f4c4p+0; + z = 0x1.45b0109e4d00cp+0; + for (i = 0; i < N; i++) { + r = fma(x, y, z); + x += 0.00001; + } +} + +void test_fma() +{ + int j, c; + double x, y, z, r, r0; + + c = 0; + for (j = 0; j < sizeof testdata / sizeof *testdata; j++) { + x = testdata[j].x; + y = testdata[j].y; + z = testdata[j].z; + r0 = testdata[j].r; + r = fma(x, y, z); + if (r != r0 || signbit(r) != signbit(r0)) { + c++; + error("fma(%a,%a,%a): wanted %a got %a\n", x, y, z, r0, r); + } + } + if (c) + printf("errors: %d\n", c); +} diff --git a/src/math/lrint.c b/src/math/lrint.c new file mode 100644 index 0000000..22328d1 --- /dev/null +++ b/src/math/lrint.c @@ -0,0 +1,277 @@ +#include "test.h" +#include +#include +#include +#include +#include + +static struct { + int flag; + char *s; +} eflags[] = { + {FE_INVALID, "FE_INVALID"}, + {FE_DIVBYZERO, "FE_DIVBYZERO"}, + {FE_OVERFLOW, "FE_OVERFLOW"}, + {FE_UNDERFLOW, "FE_UNDERFLOW"}, + {FE_INEXACT, "FE_INEXACT"}, +}; +static int ne = sizeof eflags / sizeof *eflags; + +static struct { + int flag; + char *s; +} rflags[] = { + {FE_TONEAREST,"FE_TONEAREST,"}, + {FE_DOWNWARD,"FE_DOWNWARD,"}, + {FE_UPWARD,"FE_UPWARD,"}, + {FE_TOWARDZERO,"FE_TOWARDZERO,"}, +}; +static int nr = sizeof rflags / sizeof *rflags; + +void printexcept(int f) { + int i, all=0; + + for (i = 0; i < ne; i++) + if (f & eflags[i].flag) { + printf("%s%s", all ? "|" : "", eflags[i].s); + all |= eflags[i].flag; + } + if (all != f) { + printf("%s%d", all ? "|" : "", f & ~all); + all = f; + } + printf("%s,", all ? "" : "0"); +} + +void printround(int f) { + int i; + + for (i = 0; i < nr; i++) + if (f == rflags[i].flag) { + printf("%s ", rflags[i].s); + return; + } + printf("%d, ", f); +} + +/* +struct {double x;} t[] = { +0.0, +0.25, +-0.25, +0.5, +-0.5, +0.75, +-0.75, +1.0, +-1.0, +1.25, +-1.25, +0x1p30, +-0x1p30, +0x1p31-1, +-0x1p31+1, +0x1p31, +-0x1p31, +0x1p31+1, +-0x1p31-1, +0x1p31-0.5, +-0x1p31+0.5, +0x1p31+0.5, +-0x1p31-0.5, +0x1p32, +-0x1p32, +0x1p32 - 0.5, +-0x1p32 + 0.5, +}; + +void test_gendata() +{ + int f, i, j; + long n; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + for (j = 0; j < nr; j++) { + fesetround(rflags[j].flag); + feclearexcept(FE_ALL_EXCEPT); + n = lrint(t[i].x); + f = fetestexcept(FE_ALL_EXCEPT); + if (f == FE_INVALID) + n = 0; + + printround(rflags[j].flag); + printf("%18a, %11ld, ", t[i].x, n); + printexcept(f); + printf("\n"); + } + } +} +*/ + +static struct { + int round; + double x; + long n; + int except; +} t[] = { +FE_TONEAREST, 0x0p+0, 0, 0, +FE_DOWNWARD, 0x0p+0, 0, 0, +FE_UPWARD, 0x0p+0, 0, 0, +FE_TOWARDZERO, 0x0p+0, 0, 0, +FE_TONEAREST, 0x1p-2, 0, FE_INEXACT, +FE_DOWNWARD, 0x1p-2, 0, FE_INEXACT, +FE_UPWARD, 0x1p-2, 1, FE_INEXACT, +FE_TOWARDZERO, 0x1p-2, 0, FE_INEXACT, +FE_TONEAREST, -0x1p-2, 0, FE_INEXACT, +FE_DOWNWARD, -0x1p-2, -1, FE_INEXACT, +FE_UPWARD, -0x1p-2, 0, FE_INEXACT, +FE_TOWARDZERO, -0x1p-2, 0, FE_INEXACT, +FE_TONEAREST, 0x1p-1, 0, FE_INEXACT, +FE_DOWNWARD, 0x1p-1, 0, FE_INEXACT, +FE_UPWARD, 0x1p-1, 1, FE_INEXACT, +FE_TOWARDZERO, 0x1p-1, 0, FE_INEXACT, +FE_TONEAREST, -0x1p-1, 0, FE_INEXACT, +FE_DOWNWARD, -0x1p-1, -1, FE_INEXACT, +FE_UPWARD, -0x1p-1, 0, FE_INEXACT, +FE_TOWARDZERO, -0x1p-1, 0, FE_INEXACT, +FE_TONEAREST, 0x1.8p-1, 1, FE_INEXACT, +FE_DOWNWARD, 0x1.8p-1, 0, FE_INEXACT, +FE_UPWARD, 0x1.8p-1, 1, FE_INEXACT, +FE_TOWARDZERO, 0x1.8p-1, 0, FE_INEXACT, +FE_TONEAREST, -0x1.8p-1, -1, FE_INEXACT, +FE_DOWNWARD, -0x1.8p-1, -1, FE_INEXACT, +FE_UPWARD, -0x1.8p-1, 0, FE_INEXACT, +FE_TOWARDZERO, -0x1.8p-1, 0, FE_INEXACT, +FE_TONEAREST, 0x1p+0, 1, 0, +FE_DOWNWARD, 0x1p+0, 1, 0, +FE_UPWARD, 0x1p+0, 1, 0, +FE_TOWARDZERO, 0x1p+0, 1, 0, +FE_TONEAREST, -0x1p+0, -1, 0, +FE_DOWNWARD, -0x1p+0, -1, 0, +FE_UPWARD, -0x1p+0, -1, 0, +FE_TOWARDZERO, -0x1p+0, -1, 0, +FE_TONEAREST, 0x1.4p+0, 1, FE_INEXACT, +FE_DOWNWARD, 0x1.4p+0, 1, FE_INEXACT, +FE_UPWARD, 0x1.4p+0, 2, FE_INEXACT, +FE_TOWARDZERO, 0x1.4p+0, 1, FE_INEXACT, +FE_TONEAREST, -0x1.4p+0, -1, FE_INEXACT, +FE_DOWNWARD, -0x1.4p+0, -2, FE_INEXACT, +FE_UPWARD, -0x1.4p+0, -1, FE_INEXACT, +FE_TOWARDZERO, -0x1.4p+0, -1, FE_INEXACT, +FE_TONEAREST, 0x1p+30, 1073741824, 0, +FE_DOWNWARD, 0x1p+30, 1073741824, 0, +FE_UPWARD, 0x1p+30, 1073741824, 0, +FE_TOWARDZERO, 0x1p+30, 1073741824, 0, +FE_TONEAREST, -0x1p+30, -1073741824, 0, +FE_DOWNWARD, -0x1p+30, -1073741824, 0, +FE_UPWARD, -0x1p+30, -1073741824, 0, +FE_TOWARDZERO, -0x1p+30, -1073741824, 0, +FE_TONEAREST, 0x1.fffffffcp+30, 2147483647, 0, +FE_DOWNWARD, 0x1.fffffffcp+30, 2147483647, 0, +FE_UPWARD, 0x1.fffffffcp+30, 2147483647, 0, +FE_TOWARDZERO, 0x1.fffffffcp+30, 2147483647, 0, +FE_TONEAREST, -0x1.fffffffcp+30, -2147483647, 0, +FE_DOWNWARD, -0x1.fffffffcp+30, -2147483647, 0, +FE_UPWARD, -0x1.fffffffcp+30, -2147483647, 0, +FE_TOWARDZERO, -0x1.fffffffcp+30, -2147483647, 0, +FE_TONEAREST, 0x1p+31, 0, FE_INVALID, +FE_DOWNWARD, 0x1p+31, 0, FE_INVALID, +FE_UPWARD, 0x1p+31, 0, FE_INVALID, +FE_TOWARDZERO, 0x1p+31, 0, FE_INVALID, +FE_TONEAREST, -0x1p+31, -2147483648, 0, +FE_DOWNWARD, -0x1p+31, -2147483648, 0, +FE_UPWARD, -0x1p+31, -2147483648, 0, +FE_TOWARDZERO, -0x1p+31, -2147483648, 0, +FE_TONEAREST, 0x1.00000002p+31, 0, FE_INVALID, +FE_DOWNWARD, 0x1.00000002p+31, 0, FE_INVALID, +FE_UPWARD, 0x1.00000002p+31, 0, FE_INVALID, +FE_TOWARDZERO, 0x1.00000002p+31, 0, FE_INVALID, +FE_TONEAREST, -0x1.00000002p+31, 0, FE_INVALID, +FE_DOWNWARD, -0x1.00000002p+31, 0, FE_INVALID, +FE_UPWARD, -0x1.00000002p+31, 0, FE_INVALID, +FE_TOWARDZERO, -0x1.00000002p+31, 0, FE_INVALID, +FE_TONEAREST, 0x1.fffffffep+30, 0, FE_INVALID, +FE_DOWNWARD, 0x1.fffffffep+30, 2147483647, FE_INEXACT, +FE_UPWARD, 0x1.fffffffep+30, 0, FE_INVALID, +FE_TOWARDZERO, 0x1.fffffffep+30, 2147483647, FE_INEXACT, +FE_TONEAREST, -0x1.fffffffep+30, -2147483648, FE_INEXACT, +FE_DOWNWARD, -0x1.fffffffep+30, -2147483648, FE_INEXACT, +FE_UPWARD, -0x1.fffffffep+30, -2147483647, FE_INEXACT, +FE_TOWARDZERO, -0x1.fffffffep+30, -2147483647, FE_INEXACT, +FE_TONEAREST, 0x1.00000001p+31, 0, FE_INVALID, +FE_DOWNWARD, 0x1.00000001p+31, 0, FE_INVALID, +FE_UPWARD, 0x1.00000001p+31, 0, FE_INVALID, +FE_TOWARDZERO, 0x1.00000001p+31, 0, FE_INVALID, +FE_TONEAREST, -0x1.00000001p+31, -2147483648, FE_INEXACT, +FE_DOWNWARD, -0x1.00000001p+31, 0, FE_INVALID, +FE_UPWARD, -0x1.00000001p+31, -2147483648, FE_INEXACT, +FE_TOWARDZERO, -0x1.00000001p+31, -2147483648, FE_INEXACT, +FE_TONEAREST, 0x1p+32, 0, FE_INVALID, +FE_DOWNWARD, 0x1p+32, 0, FE_INVALID, +FE_UPWARD, 0x1p+32, 0, FE_INVALID, +FE_TOWARDZERO, 0x1p+32, 0, FE_INVALID, +FE_TONEAREST, -0x1p+32, 0, FE_INVALID, +FE_DOWNWARD, -0x1p+32, 0, FE_INVALID, +FE_UPWARD, -0x1p+32, 0, FE_INVALID, +FE_TOWARDZERO, -0x1p+32, 0, FE_INVALID, +FE_TONEAREST, 0x1.ffffffffp+31, 0, FE_INVALID, +FE_DOWNWARD, 0x1.ffffffffp+31, 0, FE_INVALID, +FE_UPWARD, 0x1.ffffffffp+31, 0, FE_INVALID, +FE_TOWARDZERO, 0x1.ffffffffp+31, 0, FE_INVALID, +FE_TONEAREST, -0x1.ffffffffp+31, 0, FE_INVALID, +FE_DOWNWARD, -0x1.ffffffffp+31, 0, FE_INVALID, +FE_UPWARD, -0x1.ffffffffp+31, 0, FE_INVALID, +FE_TOWARDZERO, -0x1.ffffffffp+31, 0, FE_INVALID, +}; + +void test_lrint() +{ + int f, i, j; + long n; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + fesetround(t[i].round); + feclearexcept(FE_ALL_EXCEPT); + n = lrint(t[i].x); + f = fetestexcept(FE_ALL_EXCEPT); + + if (t[i].except != FE_INVALID && n != t[i].n) { + error("round="); + printround(t[i].round); + printf("lrint(%a) want %ld got %ld\n", t[i].x, t[i].n, n); + } + if (f != t[i].except) { + error("round="); + printround(t[i].round); + printf("lrint(%a)==%ld want except=", t[i].x, t[i].n); + printexcept(t[i].except); + printf(" got except="); + printexcept(f); + printf("\n"); + } + } +} + +void bench_lrint_simple(int N) +{ + int i; + volatile int n; + + for (i = 0; i < N; i++) { + n = lrint(1.25); + } +} + +void bench_lrint_hard(int N) +{ + int i; + volatile int n; + + for (i = 0; i < N; i++) { +// feclearexcept(FE_ALL_EXCEPT); +// n = lrint(1.5); +// n = lrint(0x1p32); +// n = lrint(-0x1p31); + n = lrint(0x1p31+0.5); + } +} diff --git a/src/math/sanity.c b/src/math/sanity.c new file mode 100644 index 0000000..e765987 --- /dev/null +++ b/src/math/sanity.c @@ -0,0 +1,253 @@ +#include +#include +#include "test.h" + +static int check(double a, double b) +{ + double d = a - b; + return fabs(d) <= 0x1p-52*fabs(a); +} + +static int checkf(float a, float b) +{ + float d = a - b; + return fabsf(d) <= 0x1p-23*fabsf(a); +} + +static int checkl(long double a, long double b) +{ + long double d = a - b; + return fabsl(d) <= 0x1p-63L*fabsl(a); +} + +#define D(fx, y) do{ \ + double yy = fx; \ + if (!check(yy, y)) \ + error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \ +}while(0) + +#define F(fx, y) do{ \ + float yy = fx; \ + if (!checkf(yy, y)) \ + error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \ +}while(0) + +#define L(fx, y) do{ \ + long double yy = fx; \ + if (!checkl(yy, y)) \ + error("%s got %La = %.21Le want %La = %.21Le\n", #fx, yy, yy, y, y); \ +}while(0) + +#define I(fx, y) do{ \ + int yy = fx; \ + if (yy != y) \ + error("%s got %d want %d\n", #fx, yy, y); \ +}while(0) + +#define IL(fx, y) do{ \ + long yy = fx; \ + if (yy != y) \ + error("%s got %ld want %ld\n", #fx, yy, y); \ +}while(0) + +#define ILL(fx, y) do{ \ + long long yy = fx; \ + if (yy != y) \ + error("%s got %lld want %lld\n", #fx, yy, y); \ +}while(0) + +int test_math_sanity() +{ + int i; + double q; + float qf; + long double ql; + +D(acos(0.7), 0x1.973e83f5d5c9bp-1); +F(acosf(0.7f), 0x1.973e84p-1); +L(acosl(0.7L), 0x1.973e83f5d5c9aaf8p-1L); +D(acosh(1.7), 0x1.1f8c10d010fe6p+0); +F(acoshf(1.7f), 0x1.1f8c12p+0); +L(acoshl(1.7L), 0x1.1f8c10d010fe5d96p+0L); +D(asin(0.7), 0x1.8d00e692afd95p-1); +F(asinf(0.7f), 0x1.8d00e6p-1); +L(asinl(0.7L), 0x1.8d00e692afd95ddap-1L); +D(asinh(0.7), 0x1.4e2a4fe9085ddp-1); +F(asinhf(0.7f), 0x1.4e2a5p-1); +L(asinhl(0.7L), 0x1.4e2a4fe9085dd732p-1L); +D(atan(0.7), 0x1.38b112d7bd4adp-1); +F(atanf(0.7f), 0x1.38b112p-1); +L(atanl(0.7L), 0x1.38b112d7bd4ad786p-1L); +D(atan2(0.7, 1.0), 0x1.38b112d7bd4adp-1); +F(atan2f(0.7f, 1.0f), 0x1.38b112p-1); +L(atan2l(0.7L, 1.0L), 0x1.38b112d7bd4ad786p-1L); +D(atanh(0.7), 0x1.bc0ed0947fbe8p-1); +F(atanhf(0.7f), 0x1.bc0edp-1); +L(atanhl(0.7L), 0x1.bc0ed0947fbe9068p-1L); +D(cbrt(0.7), 0x1.c69b5a72f1a99p-1); +F(cbrtf(0.7f), 0x1.c69b5ap-1); +L(cbrtl(0.7L), 0x1.c69b5a72f1a99902p-1L); +D(ceil(0.7), 0x1p+0); +F(ceilf(0.7f), 0x1p+0); +L(ceill(0.7L), 0x1p+0L); +D(copysign(0.7, -1.0), -0x1.6666666666666p-1); +F(copysignf(0.7f, -1.0f), -0x1.666666p-1); +L(copysignl(0.7L, -1.0L), -0x1.6666666666666666p-1L); +D(cos(0.7), 0x1.87996529f9d93p-1); +F(cosf(0.7f), 0x1.879966p-1); +L(cosl(0.7L), 0x1.87996529f9d92618p-1L); +D(cosh(0.7), 0x1.4152c1862342fp+0); +F(coshf(0.7f), 0x1.4152c2p+0); +L(coshl(0.7L), 0x1.4152c1862342ef8ep+0L); +D(erf(0.7), 0x1.5b08c21171646p-1); +F(erff(0.7f), 0x1.5b08c2p-1); +L(erfl(0.7L), 0x1.5b08c21171646544p-1L); +D(erfc(0.7), 0x1.49ee7bdd1d374p-2); +F(erfcf(0.7f), 0x1.49ee7cp-2); +L(erfcl(0.7L), 0x1.49ee7bdd1d373576p-2L); +D(exp(0.7), 0x1.01c2a61268987p+1); +F(expf(0.7f), 0x1.01c2a6p+1); +L(expl(0.7L), 0x1.01c2a61268986bfep+1L); +D(exp2(0.7), 0x1.9fdf8bcce533dp+0); +F(exp2f(0.7f), 0x1.9fdf8cp+0); +L(exp2l(0.7L), 0x1.9fdf8bcce533d72p+0L); +D(expm1(0.7), 0x1.03854c24d130dp+0); +F(expm1f(0.7f), 0x1.03854cp+0); +L(expm1l(0.7L), 0x1.03854c24d130d7fep+0L); +D(fabs(-0.7), 0x1.6666666666666p-1); +F(fabsf(-0.7f), 0x1.666666p-1); +L(fabsl(-0.7L), 0x1.6666666666666666p-1L); +D(fdim(0.7, 0.5), 0x1.9999999999998p-3); +F(fdimf(0.7f, 0.5f), 0x1.999998p-3); +L(fdiml(0.7L, 0.5L), 0x1.9999999999999998p-3L); +D(floor(0.7), 0x0p+0); +F(floorf(0.7f), 0x0p+0); +L(floorl(0.7L), 0x0p+0L); +D(fma(0.7, 2.0, 0.1), 0x1.8p+0); +F(fmaf(0.7f, 2.0f, 0.1f), 0x1.8p+0); +L(fmal(0.7L, 2.0L, 0.1L), 0x1.8p+0L); +D(fmax(0.7, 0.5), 0x1.6666666666666p-1); +F(fmaxf(0.7f, 0.5), 0x1.666666p-1); +L(fmaxl(0.7L, 0.5), 0x1.6666666666666666p-1L); +D(fmin(0.7, 0.5), 0x1p-1); +F(fminf(0.7f, 0.5f), 0x1p-1); +L(fminl(0.7L, 0.5L), 0x1p-1L); +D(fmod(0.7, 0.5), 0x1.9999999999998p-3); +F(fmodf(0.7f, 0.5f), 0x1.999998p-3); +L(fmodl(0.7L, 0.5L), 0x1.9999999999999998p-3L); +D(frexp(0.7, &i), 0x1.6666666666666p-1); +F(frexpf(0.7f, &i), 0x1.666666p-1); +L(frexpl(0.7L, &i), 0x1.6666666666666666p-1L); +D(hypot(0.7, 1.0), 0x1.387ce204a35d2p+0); +F(hypotf(0.7f, 1.0f), 0x1.387ce2p+0); +L(hypotl(0.7L, 1.0L), 0x1.387ce204a35d1ff6p+0L); +I(ilogb(0.7), -1); +I(ilogbf(0.7f), -1); +I(ilogbl(0.7L), -1); +D(j0(0.7), 0x1.c32cc34b8cc59p-1); +F(j0f(0.7f), 0x1.c32cc4p-1); +D(j1(0.7), 0x1.50e44279c0546p-2); +F(j1f(0.7f), 0x1.50e442p-2); +D(jn(2, 0.7), 0x1.e195286f3b2fbp-5); +F(jnf(2, 0.7f), 0x1.e19528p-5); +D(ldexp(0.7, 3), 0x1.6666666666666p+2); +F(ldexpf(0.7f, 3), 0x1.666666p+2); +L(ldexpl(0.7L, 3), 0x1.6666666666666666p+2L); +D(lgamma(0.7), 0x1.0b20c891cde73p-2); +F(lgammaf(0.7f), 0x1.0b20cap-2); +L(lgammal(0.7L), 0x1.0b20c891cde72846p-2L); +D(lgamma_r(0.7, &i), 0x1.0b20c891cde73p-2); +F(lgammaf_r(0.7f, &i), 0x1.0b20cap-2); +L(lgammal_r(0.7L, &i), 0x1.0b20c891cde72846p-2L); +ILL(llrint(0.7), 1); +ILL(llrintf(0.7f), 1); +ILL(llrintl(0.7l), 1); +ILL(llround(0.7), 1); +ILL(llroundf(0.7f), 1); +ILL(llroundl(0.7L), 1); +D(log(0.7), -0x1.6d3c324e13f5p-2); +F(logf(0.7f), -0x1.6d3c34p-2); +L(logl(0.7L), -0x1.6d3c324e13f4ec54p-2L); +D(log10(0.7), -0x1.3d3d3d21ccf04p-3); +F(log10f(0.7f), -0x1.3d3d3ep-3); +L(log10l(0.7L), -0x1.3d3d3d21ccf035a6p-3L); +D(log1p(0.7), 0x1.0fae81914a991p-1); +F(log1pf(0.7f), 0x1.0fae82p-1); +L(log1pl(0.7L), 0x1.0fae81914a991308p-1L); +D(log2(0.7), -0x1.0776228967d13p-1); +F(log2f(0.7f), -0x1.077624p-1); +L(log2l(0.7L), -0x1.0776228967d1218cp-1L); +D(logb(0.7), -0x1p+0); +F(logbf(0.7f), -0x1p+0); +L(logbl(0.7L), -0x1p+0L); +IL(lrint(0.7), 1); +IL(lrintf(0.7f), 1); +IL(lrintl(0.7l), 1); +IL(lround(0.7), 1); +IL(lroundf(0.7f), 1); +IL(lroundl(0.7L), 1); +D(modf(0.7, &q), 0x1.6666666666666p-1); +F(modff(0.7f, &qf), 0x1.666666p-1); +L(modfl(0.7L, &ql), 0x1.6666666666666666p-1L); +D(nearbyint(0.7), 0x1p+0); +F(nearbyintf(0.7f), 0x1p+0); +L(nearbyintl(0.7L), 0x1p+0L); +D(nextafter(0.7, 1.0), 0x1.6666666666667p-1); +F(nextafterf(0.7f, 1.0f), 0x1.666668p-1); +L(nextafterl(0.7L, 1.0L), 0x1.6666666666666667p-1L); +D(nexttoward(0.7, 1.0L), 0x1.6666666666667p-1); +F(nexttowardf(0.7f, 1.0L), 0x1.666668p-1); +L(nexttowardl(0.7L, 1.0L), 0x1.6666666666666667p-1L); +D(pow(0.7, 1.5), 0x1.2bdbe460916ep-1); +F(powf(0.7f, 1.5f), 0x1.2bdbe4p-1); +L(powl(0.7L, 1.5L), 0x1.2bdbe460916e0b5p-1L); +D(remainder(0.7, 0.5), 0x1.9999999999998p-3); +F(remainderf(0.7f, 0.5f), 0x1.999998p-3); +L(remainderl(0.7L, 0.5L), 0x1.9999999999999998p-3L); +D(remquo(0.7, 0.5, &i), 0x1.9999999999998p-3); +F(remquof(0.7f, 0.5f, &i), 0x1.999998p-3); +L(remquol(0.7L, 0.5L, &i), 0x1.9999999999999998p-3L); +D(rint(0.7), 0x1p+0); +F(rintf(0.7f), 0x1p+0); +L(rintl(0.7L), 0x1p+0L); +D(round(0.7), 0x1p+0); +F(roundf(0.7f), 0x1p+0); +L(roundl(0.7L), 0x1p+0L); +D(scalb(0.7, 3), 0x1.6666666666666p+2); +F(scalbf(0.7f, 3), 0x1.666666p+2); +D(scalbln(0.7, 3), 0x1.6666666666666p+2); +F(scalblnf(0.7f, 3), 0x1.666666p+2); +L(scalblnl(0.7L, 3), 0x1.6666666666666666p+2L); +D(scalbn(0.7, 3), 0x1.6666666666666p+2); +F(scalbnf(0.7f, 3), 0x1.666666p+2); +L(scalbnl(0.7L, 3), 0x1.6666666666666666p+2L); +D(sin(0.7), 0x1.49d6e694619b8p-1); +F(sinf(0.7f), 0x1.49d6e6p-1); +L(sinl(0.7L), 0x1.49d6e694619b854ep-1L); +D(sinh(0.7), 0x1.8465153d5bdbdp-1); +F(sinhf(0.7f), 0x1.846514p-1); +L(sinhl(0.7L), 0x1.8465153d5bdbd0dep-1L); +D(sqrt(0.7), 0x1.ac5eb3f7ab2f8p-1); +F(sqrtf(0.7f), 0x1.ac5eb4p-1); +L(sqrtl(0.7L), 0x1.ac5eb3f7ab2f7de2p-1L); +D(tan(0.7), 0x1.af406c2fc78aep-1); +F(tanf(0.7f), 0x1.af406cp-1); +L(tanl(0.7L), 0x1.af406c2fc78ae54cp-1L); +D(tanh(0.7), 0x1.356fb17af2e91p-1); +F(tanhf(0.7f), 0x1.356fb2p-1); +L(tanhl(0.7L), 0x1.356fb17af2e9100ap-1L); +D(tgamma(0.7), 0x1.4c4d5ab21ea23p+0); +F(tgammaf(0.7f), 0x1.4c4d5cp+0); +L(tgammal(0.7L), 0x1.4c4d5ab21ea22798p+0L); +D(trunc(0.7), 0x0p+0); +F(truncf(0.7f), 0x0p+0); +L(truncl(0.7L), 0x0p+0L); +D(y0(0.7), -0x1.867b559ffc715p-3); +F(y0f(0.7f), -0x1.867b58p-3); +D(y1(0.7), -0x1.1a6e956728d35p+0); +F(y1f(0.7f), -0x1.1a6e96p+0); +D(yn(2, 0.7), -0x1.7b11b25df166ep+1); +F(ynf(2, 0.7f), -0x1.7b11b4p+1); + + return 0; +} diff --git a/src/math/scalbn.c b/src/math/scalbn.c new file mode 100644 index 0000000..b4a56be --- /dev/null +++ b/src/math/scalbn.c @@ -0,0 +1,72 @@ +#include "test.h" +#include +#include +#include +#include +#include + +static struct { + double x; + int n; + double y; +} t[] = { + 0.0, 0, 0.0, + -0.0, 0, -0.0, + 0.0, -1234567, 0.0, + -0.0, 1234567, -0.0, + 0x1.234p0, 13, 0x1.234p13, + 0x1.234p0, -13, 0x1.234p-13, + -0x1.234p1, 137, -0x1.234p138, + -0x1.234p1, -137, -0x1.234p-136, + 0x1.234p1023, 1, INFINITY, + 0x1.234p1023, -1022, 0x1.234p1, + 0x1.234p1023, -1023, 0x1.234p0, + 0x1.234p1023, -1024, 0x1.234p-1, + 0x1.234p1023, -2023, 0x1.234p-1000, + 0x1.234p1023, -2045, 0x1.234p-1022, + 0x1.234p1023, -2046, 0x1.234p-1023, + 0x1.234p1023, -2048, 0x1.234p-1025, + 0x1.234p1023, -2049, 0x1.234p-1026, + 0x1p1023, -2096, 0x1p-1073, + 0x1p1023, -2097, 0x1p-1074, + 0x1p1023, -2098, 0, + 0x1.234p-1022, 1022, 0x1.234p0, + 0x1.234p-1022, 2045, 0x1.234p1023, + 0x1p-1074, 2097, 0x1p1023, + 0x1p-1074, 2098, INFINITY, + 0x1p-1074, 1, 0x1p-1073, + 0x1p-1073, -1, 0x1p-1074, + 0x1p-1074, -1, 0, +}; + +void test_scalbn() +{ + int i; + double y; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + y = scalbn(t[i].x, t[i].n); + if (y != t[i].y) + error("scalbn(%a,%d) want %a got %a\n", t[i].x, t[i].n, t[i].y, y); + } +} + +void bench_scalbn_simple(int N) +{ + int i; + volatile double y; + + for (i = 0; i < N; i++) { + y = scalbn(1.25, 73); + } +} + +void bench_scalbn_hard(int N) +{ + int i; + volatile double y; + + for (i = 0; i < N; i++) { + y = scalbn(0x1.23p-1050, 2070); + } +} diff --git a/src/math/sqrt.c b/src/math/sqrt.c new file mode 100644 index 0000000..3dce651 --- /dev/null +++ b/src/math/sqrt.c @@ -0,0 +1,92 @@ +#include "test.h" +#include +#include + +static struct { + double x,y; +} testdata[] = { +0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+511, +0x1.ffffffffffffbp+1023, 0x1.ffffffffffffdp+511, +0x1.ffffffffffff7p+1023, 0x1.ffffffffffffbp+511, +0x1.ffffffffffff3p+1023, 0x1.ffffffffffff9p+511, +0x1.fffffffffffefp+1023, 0x1.ffffffffffff7p+511, +0x1.fffffffffffebp+1023, 0x1.ffffffffffff5p+511, +0x1.fffffffffffe7p+1023, 0x1.ffffffffffff3p+511, +0x1.fffffffffffe3p+1023, 0x1.ffffffffffff1p+511, +0x1.fffffffffffdfp+1023, 0x1.fffffffffffefp+511, +0x1.fffffffffffdbp+1023, 0x1.fffffffffffedp+511, +0x1.fffffffffffd7p+1023, 0x1.fffffffffffebp+511, +0x1.0000000000003p-1022, 0x1.0000000000001p-511, +0x1.0000000000007p-1022, 0x1.0000000000003p-511, +0x1.000000000000bp-1022, 0x1.0000000000005p-511, +0x1.000000000000fp-1022, 0x1.0000000000007p-511, +0x1.0000000000013p-1022, 0x1.0000000000009p-511, +0x1.0000000000017p-1022, 0x1.000000000000bp-511, +0x1.000000000001bp-1022, 0x1.000000000000dp-511, +0x1.000000000001fp-1022, 0x1.000000000000fp-511, +0x1.0000000000023p-1022, 0x1.0000000000011p-511, +0x1.0000000000027p-1022, 0x1.0000000000013p-511, +0x1.000000000002bp-1022, 0x1.0000000000015p-511, +0x1.000000000002fp-1022, 0x1.0000000000017p-511, +0x1.0000000000033p-1022, 0x1.0000000000019p-511, +0x1.0000000000037p-1022, 0x1.000000000001bp-511, +0x1.7167bc36eaa3bp+6, 0x1.3384c7db650cdp+3, +0x1.7570994273ad7p+6, 0x1.353186e89b8ffp+3, +0x1.7dae969442fe6p+6, 0x1.389640fb18b75p+3, +0x1.7f8444fcf67e5p+6, 0x1.395659e94669fp+3, +0x1.8364650e63a54p+6, 0x1.3aea9efe1a3d7p+3, +0x1.85bedd274edd8p+6, 0x1.3bdf20c867057p+3, +0x1.8609cf496ab77p+6, 0x1.3bfd7e14b5eabp+3, +0x1.873849c70a375p+6, 0x1.3c77ed341d27fp+3, +0x1.8919c962cbaaep+6, 0x1.3d3a7113ee82fp+3, +0x1.8de4493e22dc6p+6, 0x1.3f27d448220c3p+3, +0x1.924829a17a288p+6, 0x1.40e9552eec28fp+3, +0x1.92702cd992f12p+6, 0x1.40f94a6fdfddfp+3, +0x1.92b763a8311fdp+6, 0x1.4115af614695fp+3, +0x1.947da013c7293p+6, 0x1.41ca91102940fp+3, +0x1.9536091c494d2p+6, 0x1.4213e334c77adp+3, +0x1.61b04c6p-1019, 0x1.a98b88f18b46dp-510, +0x1.93789f1p-1018, 0x1.4162ae43d5821p-509, +0x1.a1989b4p-1018, 0x1.46f6736eb44bbp-509, +0x1.f93bc9p-1018, 0x1.67a36ec403bafp-509, +0x1.2f675e3p-1017, 0x1.8a22ab6dcfee1p-509, +0x1.a158508p-1017, 0x1.ce418a96cf589p-509, +0x1.cd31f078p-1017, 0x1.e5ef1c65dccebp-509, +0x1.33b43b08p-1016, 0x1.18a9f607e1701p-508, +0x1.6e66a858p-1016, 0x1.324402a00b45fp-508, +0x1.8661cbf8p-1016, 0x1.3c212046bfdffp-508, +0x1.bbb221b4p-1016, 0x1.510681b939931p-508, +0x1.c4942f3cp-1016, 0x1.5461e59227ab5p-508, +0x1.dbb258c8p-1016, 0x1.5cf7b0f78d3afp-508, +0x1.57103ea4p-1015, 0x1.a31ab946d340bp-508, +0x1.9b294f88p-1015, 0x1.cad197e28e85bp-508, +0x1.0000000000001p+0, 0x1p+0, +0x1.fffffffffffffp-1, 0x1.fffffffffffffp-1, +}; + +void test_sqrt(void) +{ + int j; + double x, y, y0; + + for (j = 0; j < sizeof testdata / sizeof *testdata; j++) { + x = testdata[j].x; + y = testdata[j].y; + y0 = sqrt(x); + if (y != y0) + error("sqrt(%a): wanted %a got %a\n", x, y, y0); + } +} + +void bench_sqrt(int N) +{ + int i; + double x; + volatile double y; + + x = 0x1.23456p7; + for (i = 0; i < N; i++) { + y = sqrt(x); + x += 0.0000001; + } +} diff --git a/src/stdio/memstream.c b/src/stdio/memstream.c new file mode 100644 index 0000000..baca42b --- /dev/null +++ b/src/stdio/memstream.c @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include "test.h" + +#define TEST(r, f, x, m) ( \ +((r) = (f)) == (x) || \ +(error("%s failed (" m ")\n", #f, r, x), 0) ) + +#define TEST_E(f) ( (errno = 0), (f) || \ +(error("%s failed (errno = %d)\n", #f, errno), 0) ) + +#define TEST_S(s, x, m) ( \ +!strcmp((s),(x)) || \ +(error("[%s] != [%s] (%s)\n", s, x, m), 0) ) + +#define TEST_M(s, x, n, m) ( \ +!memcmp((s),(x),(n)) || \ +(error("[%s] != [%s] (%s)\n", s, x, m), 0) ) + +void test_memstream(void) +{ + FILE *f; + char *s; + size_t l; + char buf[100]; + int i; + + s = 0; + TEST_E(f = open_memstream(&s, &l)); + TEST_E(putc('a', f) == 'a'); + TEST_E(putc('b', f) == 'b'); + TEST_E(putc('c', f) == 'c'); + TEST_E(!fflush(f)); + fclose(f); + if (s) TEST_S(s, "abc", "wrong output"); + free(s); + + s = 0; + TEST_E(f = open_memstream(&s, &l)); + TEST_E(fseek(f,1,SEEK_CUR)>=0); + TEST_E(putc('q', f) == 'q'); + TEST_E(!fflush(f)); + if (s) TEST_M(s, "\0q", 3, "wrong output"); + TEST(i, fseek(f,-3,SEEK_CUR), -1, "invalid seek allowed"); + TEST(i, errno, EINVAL, "%d != %d"); + TEST(i, ftell(f), 2, "%d != %d"); + TEST_E(fseek(f,-2,SEEK_CUR)>=0); + TEST_E(putc('e', f) == 'e'); + TEST_E(!fflush(f)); + if (s) TEST_S(s, "eq", "wrong output"); + fclose(f); + free(s); + + TEST_E(f = fmemopen(buf, 10, "r+")); + TEST_E(fputs("hello", f) >= 0); + TEST_E(fputc(0, f)==0); + TEST_E(fseek(f, 0, SEEK_SET)>=0); + i=0; + TEST_E(fscanf(f, "hello%n", &i)==0); + TEST(i, i, 5, "%d != %d"); + TEST(i, ftell(f), 5, "%d != %d"); + errno = 0; + TEST(i, fseek(f, 6, SEEK_CUR)<0, 1, ""); + TEST(i, errno!=0, 1, ""); + TEST(i, ftell(f), 5, "%d != %d"); + TEST_S(buf, "hello", ""); + fclose(f); + + TEST_E(f = fmemopen(buf, 10, "a+")); + TEST(i, ftell(f), 5, "%d != %d"); + TEST_E(fseek(f, 0, SEEK_SET)>=0); + TEST(i, getc(f), 'h', "%d != %d"); + TEST(i, getc(f), 'e', "%d != %d"); + TEST(i, getc(f), 'l', "%d != %d"); + TEST(i, getc(f), 'l', "%d != %d"); + TEST(i, getc(f), 'o', "%d != %d"); + TEST(i, getc(f), EOF, "%d != %d"); + TEST_E(fseek(f, 6, SEEK_SET)>=0); + TEST(i, ftell(f), 6, "%d != %d"); + TEST(i, getc(f), EOF, "%d != %d"); + TEST(i, ftell(f), 6, "%d != %d"); + TEST_E(fseek(f, 0, SEEK_SET)>=0); + TEST(i, getc(f), 'h', "%d != %d"); + TEST_E(fseek(f, 0, SEEK_CUR)>=0); + buf[7] = 'x'; + TEST_E(fprintf(f, "%d", i)==3); + TEST_E(fflush(f)==0); + TEST(i, ftell(f), 8, "%d != %d"); + TEST_S(buf, "hello104", ""); + fclose(f); +} diff --git a/src/udiv/Makefile b/src/udiv/Makefile new file mode 100644 index 0000000..278e884 --- /dev/null +++ b/src/udiv/Makefile @@ -0,0 +1,2 @@ +TROOT=../.. +include $(TROOT)/Makefile.inc diff --git a/src/udiv/udiv.c b/src/udiv/udiv.c new file mode 100644 index 0000000..945e144 --- /dev/null +++ b/src/udiv/udiv.c @@ -0,0 +1,197 @@ +#include "test.h" +#include + +/* +static uint64_t randstate = 0x123456789abcdef0ull; +static uint64_t rnd(void) { + randstate = 6364136223846793005ull*randstate + 1; + return randstate; +} +void test_maketest() +{ + int i; + uint64_t x,y; + for (i = 0; i < 128; i++) { + x = rnd(); + y = rnd()>>(i/2); + if (!y) + continue; + printf("0x%llxull, 0x%llxull, 0x%llxull, 0x%llxull,\n", x, y, x/y, x%y); + } +} +*/ + +static struct { + uint64_t x, y, div, mod; +} t[] = { +0x8ddb1a43e77c4031ull, 0x5950e8c33d34979eull, 0x1ull, 0x348a3180aa47a893ull, +0x723f4114006c08c7ull, 0x817de530db2b43fcull, 0x0ull, 0x723f4114006c08c7ull, +0x47811fa5f00f74dull, 0x3d98e7d3fcd5d5c5ull, 0x0ull, 0x47811fa5f00f74dull, +0x51ffcc7cdc989d43ull, 0x36be8bd6746b70e4ull, 0x1ull, 0x1b4140a6682d2c5full, +0x57bf9128512fe829ull, 0x197b3858155d498dull, 0x3ull, 0xb4de82011180b82ull, +0x89fc1c5968fa817full, 0xdcea797734c7115ull, 0x9ull, 0xdb838065b4a87c2ull, +0x4ed5264cf7092ec5ull, 0xde40d1e15ef3e74ull, 0x5ull, 0x960e4b6895cf681ull, +0xffd86b253d97317bull, 0x13f9ff2d24b6d6f4ull, 0xcull, 0x1020750785051e0bull, +0x8771fa2da656a721ull, 0x9210fe654c59bfcull, 0xeull, 0x7a31b9503881f59ull, +0xb5961d12bcd3e937ull, 0xbdb5a33662f547aull, 0xfull, 0x3bbd40fc00df611ull, +0x93c79eecdac7ed3dull, 0x6f267c57ea2b7b5ull, 0x15ull, 0x1e51bb9776edb64ull, +0x6b93ffce49f1a4b3ull, 0x3583d1f9702ee03ull, 0x20ull, 0x8c5bdb6993e453ull, +0x138aefcc98ce5d19ull, 0x117002fa7600b11ull, 0x11ull, 0x103eca27b6da0f8ull, +0xb3da641cef491fefull, 0x357615f638334b8ull, 0x35ull, 0x2c33b5d551f35d7ull, +0x71c4b06e463912b5ull, 0x1c286ad9e8f5229ull, 0x40ull, 0x1230506a2648875ull, +0x97d4cf7df046d6ebull, 0x1e9412f5c77b2b8ull, 0x4full, 0xd9b1e06756b023ull, +0x1428f04bd490ea11ull, 0x9d97f29a897c93ull, 0x20ull, 0x75f1f8836157b1ull, +0x35256c76832705a7ull, 0xa962f1a447dcd7ull, 0x50ull, 0x3680f32cb20277ull, +0x2969e82bd9347f2dull, 0x723d68574d4156ull, 0x5cull, 0x5bd6ac79710445ull, +0x9061a12aae71a823ull, 0x4186d8a1a66175ull, 0x234ull, 0x48be68be2f25full, +0x695b8d33ef342e09ull, 0x3ed1fe1a998fe3ull, 0x1adull, 0x15a6615bde0ea2ull, +0x46b4dd1e06367a5full, 0xa04e70622e4e8ull, 0x70eull, 0x64750bc0b9dafull, +0xd68b05ba7eee12a5ull, 0x72ab3fb682444ull, 0x1defull, 0x3c437fc988329ull, +0x1e59cc2ac508f85bull, 0xeb15ae6d4d7f9ull, 0x210ull, 0xc00aeae0b86cbull, +0x296f8d2c76a0901ull, 0xf65628b31b01ull, 0x2b0ull, 0xf14566117651ull, +0x7036f5ad7cbc5e17ull, 0xa09d3bfcf72cfull, 0xb2dull, 0x72236db564ab4ull, +0x915d6883c575ad1dull, 0x3a38d68d3a38eull, 0x27f2ull, 0x241de6f7a6ee1ull, +0x845ba74f5adfa793ull, 0x2f6950e58d00bull, 0x2caaull, 0x249dc90239c45ull, +0xb910d16c54805af9ull, 0x1fc2ca5c99a7aull, 0x5d3aull, 0x1771487b50955ull, +0x27a2e280bcf990cfull, 0x389aa0c0b0cc0ull, 0xb34ull, 0x9d71d12eb9cfull, +0x1e032f04a5372e95ull, 0x63c2a1d58710ull, 0x4d04ull, 0x154ce4414255ull, +0x3a1a5659908495cbull, 0x279dcd85418aull, 0x17775ull, 0x132c6f9c7bb9ull, +0xd769a376e5e103f1ull, 0xadacb670e0c7ull, 0x13d85ull, 0x8ad256e5d18eull, +0x269f4f4baaaf287ull, 0x1aed2ad9daf0ull, 0x16f3ull, 0x426550f80b7ull, +0x6700daeeb87a770dull, 0xeca7ab1aa93ull, 0x6f6c5ull, 0x70d9466f1eeull, +0xd0201f3783c2a303ull, 0x3a0c01aa3e6aull, 0x395e1ull, 0x18b33b9015d9ull, +0xca3f2e00d291e3e9ull, 0xbe0e048cd94ull, 0x1106c2ull, 0x37f7fc0a1c1ull, +0xec4d240dc289633full, 0x4f8aadb7483ull, 0x2f8855ull, 0x46e0db91bc0ull, +0xd7967b29e2e36685ull, 0xe61d902db27ull, 0xefd69ull, 0x36811fff886ull, +0xe3ecd4374320af3bull, 0x4edd0edd0a0ull, 0x2e3defull, 0x4ad0da4c9dbull, +0x7a08fe1d98b4dae1ull, 0x6bced9c0c15ull, 0x121c89ull, 0x40c856617a4ull, +0x34435992a5c9c2f7ull, 0x4f4a94c109full, 0xa8bc9ull, 0x94c5d46120ull, +0x6fd0027468f1dcfdull, 0x597186b0153ull, 0x140060ull, 0x16f26555dddull, +0x4fe37c1db1619a73ull, 0x47a0c30bd15ull, 0x11d861ull, 0x5964fb3d7eull, +0x77aa77f86d07c8d9ull, 0x3a39cf03d65ull, 0x20e21cull, 0x37f7fede7cdull, +0xc072e76ad59cf1afull, 0x3a786701dull, 0x34a98c59ull, 0x22b6b1b9aull, +0xfb8e8f1f7781ba75ull, 0xe8ca427d3eull, 0x114a34dull, 0xa344eb94cfull, +0x160e34cf590444abull, 0xe2388f12feull, 0x18f574ull, 0xc303329393ull, +0x2509ddea3a648dd1ull, 0xec762d81bcull, 0x281955ull, 0xc0463d1e65ull, +0xc9ba10cd6eafcf67ull, 0x96a51d06f7ull, 0x156ce72ull, 0x133e2df369ull, +0x1dd4fe261b4adeedull, 0x2736e25406ull, 0xc2bfefull, 0x1354c1f353ull, +0x480258f92fc38de3ull, 0x2599b52bb0ull, 0x1ea450cull, 0x2879f11a3ull, +0x5a3257b1114109c9ull, 0x2978f9f1aaull, 0x22cc30aull, 0x1317311b25ull, +0xf4eeda8f34ab3c1full, 0x1aa70450d9ull, 0x9309d64ull, 0x1187b6925bull, +0x3c2c319ca8612a65ull, 0x73fc01eceull, 0x84d0088ull, 0x3165accf5ull, +0x4f6034e74a16561bull, 0x1f29d53707ull, 0x28c0daaull, 0xd88e07075ull, +0x206665a7072f1cc1ull, 0xda87e7ceaull, 0x25f48c1ull, 0xd3ddb2057ull, +0x100c559d7db417d7ull, 0xb907ebbc2ull, 0x1634188ull, 0xa2eae16c7ull, +0x64c5f83691b47cddull, 0x5aced6ebbull, 0x11c17fb7ull, 0x344109030ull, +0x32a812777eaf7d53ull, 0x1cb63fe4full, 0x1c3a9675ull, 0xb113f938ull, +0x67478d96865ca6b9ull, 0x142fa03aull, 0x51dcb463dull, 0x11359ce7ull, +0x71024e740deb428full, 0x142d3885ull, 0x599d9edd5ull, 0x13b1ae6ull, +0x52c78160b090b655ull, 0xd02101c6ull, 0x65d1b205ull, 0x1c0a0177ull, +0x16917d5f9fde38bull, 0xfb1566c7ull, 0x17029e0ull, 0x1bbe166bull, +0xa6ee688a0d1387b1ull, 0x22c4d384ull, 0x4cd19afcfull, 0x77143f5ull, +0x74babc1be2ed9c47ull, 0x22eda9a6ull, 0x3578b1967ull, 0x189b247dull, +0x7c5cbf2dfc1db6cdull, 0x5f09c060ull, 0x14efd44d4ull, 0x5210e74dull, +0x7c046071c1ac68c3ull, 0x3696c8e6ull, 0x24596d86bull, 0x26060a1ull, +0x84728ab55d399fa9ull, 0x267d7771ull, 0x370ea7405ull, 0x255d1674ull, +0x99f57100ef5404ffull, 0x10c0df86ull, 0x9308fef0dull, 0x9009131ull, +0x3f4c0514b0df5e45ull, 0xf2c3810ull, 0x42bf84d39ull, 0x3aa12b5ull, +0xd01edb572821ecfbull, 0x2a443aeull, 0x4ec8b88639ull, 0x111c73dull, +0xeecb08561bd0cea1ull, 0xbeca231ull, 0x140692508bull, 0x9b36e06ull, +0x8c856facc6335cb7ull, 0x398eab4ull, 0x271008c7a5ull, 0x922ab3ull, +0x23fb9839e8358cbdull, 0x24deb54ull, 0xf9d714151ull, 0xb9c329ull, +0x2005d5de30015033ull, 0x47c06dbull, 0x7240bccbaull, 0x104d115ull, +0x67d59c29e076f499ull, 0x179f009ull, 0x465554ac22ull, 0x10b0767ull, +0x32d2dd34369c836full, 0x13d3fbfull, 0x2902f2fb54ull, 0x7553c3ull, +0x3960c3c99fdc2235ull, 0x1b808baull, 0x21618743cdull, 0x11e7743ull, +0x343bad5adfa9726bull, 0xeef444ull, 0x37f58c51a6ull, 0x3d8a53ull, +0x7a4aadd7b4e5f191ull, 0x129c9ull, 0x6921bb5a2a53ull, 0x6b66ull, +0x9eb7dae5d71c5927ull, 0x31d7f5ull, 0x32f2ff2c6d5ull, 0x22c4eull, +0x1b285999316afeadull, 0x115477ull, 0x1912cf6611eull, 0x801bbull, +0x917aee3d84b533a3ull, 0x71d26full, 0x1473408589aull, 0x6e74ddull, +0x18e6a86b0473a589ull, 0x50a12ull, 0x4f0fabc67d4ull, 0x210a1ull, +0xf22c9887813bbddfull, 0x5b17aull, 0x2a897505c07bull, 0x1f841ull, +0xef7a551239d60225ull, 0x7fb5aull, 0x1e00b98e188bull, 0x41847ull, +0xffd2ad0e77b73dbull, 0x146f14ull, 0xc8500600a3ull, 0xba1full, +0x76743abdfb91f081ull, 0xd5888ull, 0x8e0303c479cull, 0x245a1ull, +0xc2eeb030bcff9197ull, 0x7a4e8ull, 0x198034e02c37ull, 0x343bfull, +0x63cc9c23f0ed0c9dull, 0x6c1e5ull, 0xec4d5841041ull, 0x38178ull, +0x7ad70f846e8f1313ull, 0x7fdf5ull, 0xf5ecec69bc9ull, 0x756b6ull, +0x60de3d71574eb279ull, 0x6ea3ull, 0xe02421997a61ull, 0x18b6ull, +0xd27054901c68b44full, 0x2dd0full, 0x497d639c8f46ull, 0xe135ull, +0xbcf297b8f0dbfe15ull, 0xcf17ull, 0xe992af0ca1abull, 0x32b8ull, +0x96c3ae70323ef14bull, 0xbbdcull, 0xcd7329b68d81ull, 0x1b6full, +0xdc1a13cfa4d3cb71ull, 0xdb16ull, 0x1012fe5ed296full, 0x46e7ull, +0xa1d40a2986f40607ull, 0x8067ull, 0x142a473fdb7beull, 0x1895ull, +0x227f92ef6daab68dull, 0x15ecull, 0x192dda5d5ed25ull, 0xf71ull, +0xc0a4a7810015ee83ull, 0x6064ull, 0x1ffa220762fc8ull, 0x4463ull, +0xd38b6eb9f0e71b69ull, 0x1909ull, 0x8732ce2cc77f4ull, 0xfd5ull, +0x2e588bdb751a66bfull, 0x229cull, 0x156d025c70d97ull, 0x10bbull, +0xd90f7e11dcbd1605ull, 0x760ull, 0x1d6e934381ba2eull, 0x2c5ull, +0x60ab67a4e5aeabbull, 0x1bf7ull, 0x374f26f3e3edull, 0x210ull, +0x224f627be76a8261ull, 0x4f4ull, 0x6ed4d3882b567ull, 0x35ull, +0x300d1ab91bd0b677ull, 0xe9cull, 0x34a002fb76e63ull, 0x823ull, +0x2a63d80e0c52fc7dull, 0x32ull, 0xd90970ebc4383full, 0x2full, +0xb0e94bbc1f90c5f3ull, 0x3b3ull, 0x2fd2ef70381c52ull, 0x29dull, +0x2b5dc22562dbe059ull, 0x30aull, 0xe45055015fff5ull, 0x1c7ull, +0x4a7fd1078807d52full, 0x18dull, 0x300a32f60677d4ull, 0x16bull, +0x41a01ee8ab0849f5ull, 0x13cull, 0x352a3971f57e9dull, 0x29ull, +0x95a7287ad5f6602bull, 0x1d0ull, 0x529130d1034a23ull, 0xbbull, +0x723bacc76bd51551ull, 0x16ull, 0x53142091089af83ull, 0xfull, +0x81c49febaa2ca2e7ull, 0xcdull, 0xa20d44956f5bf4ull, 0x83ull, +0x11593d6b3f54de6dull, 0x63ull, 0x2cdc6b1a7f9078ull, 0x5ull, +0x756c82d6f7069963ull, 0x5cull, 0x146bea3ba565525ull, 0x17ull, +0xda882ab2a88c0149ull, 0x1bull, 0x8180194d6d5c728ull, 0x11ull, +0xbb03671751a7ff9full, 0x20ull, 0x5d81b38ba8d3ffcull, 0x1full, +0x6884fa0a8f0c99e5ull, 0x12ull, 0x5ce7fab40d6088cull, 0xdull, +0x5052a2953c528441ull, 0x7ull, 0xb7984f0bf79809bull, 0x4ull, +0x58dd1583185ecb57ull, 0x9ull, 0x9dfad0e90ee1697ull, 0x8ull, +0xaa6870c376df5c5dull, 0x3ull, 0x38cd7aebd24a741full, 0x0ull, +0x4b21d01617167e39ull, 0x2ull, 0x2590e80b0b8b3f1cull, 0x1ull, +}; + +void test_udiv() +{ + uint64_t x, y, div, mod; + int i; + + for (i = 0; i < sizeof t/sizeof *t; i++) { + x = t[i].x; + y = t[i].y; + div = x / y; + mod = x % y; + if (div != t[i].div) + error("udiv %llu/%llu want %llu got %llu\n", x, y, t[i].div, div); + if (mod != t[i].mod) + error("umod %llu%%%llu want %llu got %llu\n", x, y, t[i].mod, mod); + } +} + +void bench_div(int N) +{ + int i; + volatile uint64_t r = 0; + uint64_t d = 111222333444ull; + + for (i = 0; i < N; i++) + r += ((uint64_t)i<<32) / d; +} + +void bench_mod(int N) +{ + int i; + volatile uint64_t r = 0; + uint64_t d = 111222333444ull; + + for (i = 0; i < N; i++) + r += ((uint64_t)i<<32) % d; +} + +void bench_fdiv(int N) +{ + int i; + volatile double r = 0; + double d = 111222333444.0; + + for (i = 0; i < N; i++) + r += i / d; +}