From a4e56aac56d06a78a756bb979dfc7bd3c84edbcb Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 29 Dec 2020 15:39:33 +0100 Subject: [PATCH] Mes C Library: m2/ntoab.c: Remove specialization. * lib/mes/ntoab.c (__mesabi_uldiv)[__M2_PLANET__ || !(__MESC__ && __arm__)]: New function. * lib/mes/ntoab.c (ntoab): Use it to cater for M2-Planet. * lib/m2/ntoab.c: Remove. * kaem.run: Update accordingly. * simple.make (M2_SOURCES, (M2_TODO): Likewise. --- kaem.run | 4 +-- lib/m2/ntoab.c | 69 ------------------------------------------------- lib/mes/ntoab.c | 34 ++++++++++++------------ simple.make | 6 ++--- 4 files changed, 22 insertions(+), 91 deletions(-) delete mode 100644 lib/m2/ntoab.c diff --git a/kaem.run b/kaem.run index bd9c1ea4..7451c922 100644 --- a/kaem.run +++ b/kaem.run @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright © 2019 Jan (janneke) Nieuwenhuizen +# Copyright © 2019,2020 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -63,7 +63,7 @@ M2-Planet \ -f lib/string/strncmp.c \ -f lib/posix/getenv.c \ -f lib/mes/fdputs.c \ - -f lib/m2/ntoab.c \ + -f lib/mes/ntoab.c \ -f lib/ctype/isdigit.c \ -f lib/ctype/isxdigit.c \ -f lib/ctype/isspace.c \ diff --git a/lib/m2/ntoab.c b/lib/m2/ntoab.c deleted file mode 100644 index 076fb727..00000000 --- a/lib/m2/ntoab.c +++ /dev/null @@ -1,69 +0,0 @@ -/* -*-comment-start: "//";comment-end:""-*- - * GNU Mes --- Maxwell Equations of Software - * Copyright © 2016,2017,2018,2019,2020 Jan (janneke) Nieuwenhuizen - * - * This file is part of GNU Mes. - * - * GNU Mes is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or (at - * your option) any later version. - * - * GNU Mes is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Mes. If not, see . - */ - -#include -#include -#include - -char *__itoa_buf; - -char * -ntoab (long x, int base, int signed_p) -{ - if (__itoa_buf == 0) - __itoa_buf = malloc (20); - - char *buf = __itoa_buf; - char *p = buf + 11; - p[0] = 0; - p = p - 1; - assert_msg (base > 0, "base > 0"); - - int sign_p = 0; - unsigned u; - unsigned i; - if (signed_p != 0 && x < 0) - { - sign_p = 1; - u = -x; - } - else - u = x; - - do - { - i = u % base; - u = u / base; - if (i > 9) - p[0] = 'a' + i - 10; - else - p[0] = '0' + i; - p = p - 1; - } - while (u != 0); - - if (sign_p && p[1] != '0') - { - p[0] = '-'; - p = p - 1; - } - - return p + 1; -} diff --git a/lib/mes/ntoab.c b/lib/mes/ntoab.c index 988a0b25..e75108ba 100644 --- a/lib/mes/ntoab.c +++ b/lib/mes/ntoab.c @@ -23,45 +23,45 @@ #include #include +#if __M2_PLANET__ || !(__MESC__ && __arm__) +size_t +__mesabi_uldiv (size_t a, size_t b, size_t *remainder) +{ + remainder[0] = a % b; + return a / b; +} +#endif + char *__itoa_buf; char * ntoab (long x, unsigned base, int signed_p) { -#if 0 - if (! __itoa_buf) + if (__itoa_buf == 0) __itoa_buf = malloc (20); - p = __itoa_buf + 11; -#else - static char buf[20]; - char *p = buf + 19; -#endif + char *p = __itoa_buf + 11; p[0] = 0; p = p - 1; assert_msg (base > 0, "base > 0"); int sign_p = 0; - unsigned long u; + size_t i; + size_t u; + size_t b = base; if (signed_p != 0 && x < 0) { sign_p = 1; /* Avoid LONG_MIN */ - u = (unsigned long) (-(x + 1)); - ++u; + u = (-(x + 1)); + u = u + 1; } else u = x; do { - unsigned long i; -#if __MESC__ && __arm__ - u = __mesabi_uldiv (u, (unsigned long) base, &i); -#else - i = u % base; - u = u / base; -#endif + u = __mesabi_uldiv (u, b, &i); if (i > 9) p[0] = 'a' + i - 10; else diff --git a/simple.make b/simple.make index 5dfb7c68..f26c7df8 100644 --- a/simple.make +++ b/simple.make @@ -1,6 +1,6 @@ # GNU Mes --- Maxwell Equations of Software # Copyright © 2019 Jeremiah Orians -# Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen +# Copyright © 2018,2019,2020 Jan (janneke) Nieuwenhuizen # # This file is part of GNU Mes. # @@ -102,7 +102,7 @@ M2_SOURCES = \ lib/string/strncmp.c \ lib/posix/getenv.c \ lib/mes/fdputs.c \ - lib/m2/ntoab.c \ + lib/mes/ntoab.c \ lib/ctype/isdigit.c \ lib/ctype/isxdigit.c \ lib/ctype/isspace.c \ @@ -139,7 +139,7 @@ M2_SOURCES = \ M2_TODO = \ lib/m2/file_print.c \ - lib/m2/ntoab.c \ + lib/mes/ntoab.c \ lib/mes/fdgetc.c \ lib/mes/fdungetc.c