From 87962d75d1c1a416b89e927cd4ab8e3327a47509 Mon Sep 17 00:00:00 2001 From: drahn Date: Tue, 27 Apr 2021 04:36:00 +0000 Subject: [PATCH] riscv64 libc floating point, a portion of the files are ready. ok kettenis. --- lib/libc/arch/riscv64/gen/fpclassifyl.c | 45 +++++++++++++++++++++++++ lib/libc/arch/riscv64/gen/infinity.c | 14 ++++++++ lib/libc/arch/riscv64/gen/isfinitel.c | 28 +++++++++++++++ lib/libc/arch/riscv64/gen/isinfl.c | 30 +++++++++++++++++ lib/libc/arch/riscv64/gen/isnanl.c | 30 +++++++++++++++++ lib/libc/arch/riscv64/gen/isnormall.c | 28 +++++++++++++++ lib/libc/arch/riscv64/gen/nan.c | 13 +++++++ 7 files changed, 188 insertions(+) create mode 100644 lib/libc/arch/riscv64/gen/fpclassifyl.c create mode 100644 lib/libc/arch/riscv64/gen/infinity.c create mode 100644 lib/libc/arch/riscv64/gen/isfinitel.c create mode 100644 lib/libc/arch/riscv64/gen/isinfl.c create mode 100644 lib/libc/arch/riscv64/gen/isnanl.c create mode 100644 lib/libc/arch/riscv64/gen/isnormall.c create mode 100644 lib/libc/arch/riscv64/gen/nan.c diff --git a/lib/libc/arch/riscv64/gen/fpclassifyl.c b/lib/libc/arch/riscv64/gen/fpclassifyl.c new file mode 100644 index 00000000000..9e74a6d9bcd --- /dev/null +++ b/lib/libc/arch/riscv64/gen/fpclassifyl.c @@ -0,0 +1,45 @@ +/* $OpenBSD: fpclassifyl.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +__fpclassifyl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + if (p->ext_exp == 0) { + if (p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if (p->ext_exp == EXT_EXP_INFNAN) { + if (p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0) + return FP_INFINITE; + else + return FP_NAN; + } + + return FP_NORMAL; +} +DEF_STRONG(__fpclassifyl); diff --git a/lib/libc/arch/riscv64/gen/infinity.c b/lib/libc/arch/riscv64/gen/infinity.c new file mode 100644 index 00000000000..96fd51278d4 --- /dev/null +++ b/lib/libc/arch/riscv64/gen/infinity.c @@ -0,0 +1,14 @@ +/* $OpenBSD: infinity.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * IEEE-compatible infinity.c -- public domain. + */ + +#include +#include + +char __infinity[] __attribute__((__aligned__(sizeof(double)))) = +#if BYTE_ORDER == BIG_ENDIAN + { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0}; +#else + { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f}; +#endif diff --git a/lib/libc/arch/riscv64/gen/isfinitel.c b/lib/libc/arch/riscv64/gen/isfinitel.c new file mode 100644 index 00000000000..e37d2d13cf9 --- /dev/null +++ b/lib/libc/arch/riscv64/gen/isfinitel.c @@ -0,0 +1,28 @@ +/* $OpenBSD: isfinitel.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +__isfinitel(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp != EXT_EXP_INFNAN); +} diff --git a/lib/libc/arch/riscv64/gen/isinfl.c b/lib/libc/arch/riscv64/gen/isinfl.c new file mode 100644 index 00000000000..f459fe99a77 --- /dev/null +++ b/lib/libc/arch/riscv64/gen/isinfl.c @@ -0,0 +1,30 @@ +/* $OpenBSD: isinfl.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +__isinfl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp == EXT_EXP_INFNAN && + p->ext_frach == 0 && p->ext_frachm == 0 && + p->ext_fraclm == 0 && p->ext_fracl == 0); +} diff --git a/lib/libc/arch/riscv64/gen/isnanl.c b/lib/libc/arch/riscv64/gen/isnanl.c new file mode 100644 index 00000000000..8633385e93e --- /dev/null +++ b/lib/libc/arch/riscv64/gen/isnanl.c @@ -0,0 +1,30 @@ +/* $OpenBSD: isnanl.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +__isnanl(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp == EXT_EXP_INFNAN && + (p->ext_frach != 0 || p->ext_frachm != 0 || + p->ext_fraclm != 0 || p->ext_fracl != 0)); +} diff --git a/lib/libc/arch/riscv64/gen/isnormall.c b/lib/libc/arch/riscv64/gen/isnormall.c new file mode 100644 index 00000000000..f17e6a2473f --- /dev/null +++ b/lib/libc/arch/riscv64/gen/isnormall.c @@ -0,0 +1,28 @@ +/* $OpenBSD: isnormall.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +int +__isnormall(long double e) +{ + struct ieee_ext *p = (struct ieee_ext *)&e; + + return (p->ext_exp != 0 && p->ext_exp != EXT_EXP_INFNAN); +} diff --git a/lib/libc/arch/riscv64/gen/nan.c b/lib/libc/arch/riscv64/gen/nan.c new file mode 100644 index 00000000000..71f5393ee7c --- /dev/null +++ b/lib/libc/arch/riscv64/gen/nan.c @@ -0,0 +1,13 @@ +/* $OpenBSD: nan.c,v 1.1 2021/04/27 04:36:00 drahn Exp $ */ +/* Written by Martynas Venckus. Public Domain. */ + +#include +#include + +/* bytes for qNaN on an arm (IEEE single format) */ +char __nan[] __attribute__((__aligned__(sizeof(float)))) = +#if BYTE_ORDER == BIG_ENDIAN + { 0x7f, 0xc0, 0, 0 }; +#else /* BYTE_ORDER == BIG_ENDIAN */ + { 0, 0, 0xc0, 0x7f }; +#endif /* BYTE_ORDER == BIG_ENDIAN */ -- 2.20.1