From patchwork Mon Sep 15 22:51:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Serebryany X-Patchwork-Id: 389842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5EDB314003E for ; Tue, 16 Sep 2014 08:52:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=ozSdzNl83tya4wR8kYLVAKrXeStIE TsMIAxywvQ5Sxxz3BS+kdRS/G2m4Si6AWbvW+7m7KXw+YQZ+8ATUITRqqgf1qNIZ a/L4/ZRSYxmPqeI7vav2ahdF9LTfbkS2bP5oaZbwZJFsh9JyAi7o/7+XNXrxGEDc W9U5mq0Hu/11Eg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=gj6SExDvQvPqgetEY63FRvQXRTo=; b=kd+ ey+GrIVEQqNu0Mr5Vs/XATU3CSckR/qxKvroNajAa297g9j5IT35IVgtOz0+EVP1 yOS3+u5s2HbHKhEfzzAoMK9lyQlY4QkRRhmQmR9GIsis6RvAq3lSVMOkYFCkXidn RkLsZieyOGgDlEtV+o5SxmnLZS9Y0MkwMe2xMcg8= Received: (qmail 31996 invoked by alias); 15 Sep 2014 22:52:24 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 31987 invoked by uid 89); 15 Sep 2014 22:52:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vc0-f176.google.com X-Received: by 10.52.89.198 with SMTP id bq6mr16936453vdb.41.1410821539320; Mon, 15 Sep 2014 15:52:19 -0700 (PDT) MIME-Version: 1.0 From: Konstantin Serebryany Date: Mon, 15 Sep 2014 15:51:59 -0700 Message-ID: Subject: [PATCH] remove nested function hack_digit To: Roland McGrath , GNU C Library Please review the patch which removes a nested function hack_digit and replaces it with a non-nested static function. No functionality change intended. un-nesting glibc function was previously discussed here: https://sourceware.org/ml/libc-alpha/2014-05/msg00400.html Thanks! --kcc 2014-09-15 Kostya Serebryany * stdio-common/printf_fp.c (hack_digit): New function. (___printf_fp): Remove nested function hack_digit. Call non-nested function hack_digit. diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 9cd4b4b..d25bcbf 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -148,6 +148,49 @@ static wchar_t *group_number (wchar_t *buf, wchar_t *bufend, wchar_t thousands_sep, int ngroups) internal_function; +static wchar_t hack_digit (int expsign, int type, int exponent, + mp_limb_t *frac, mp_size_t fracsize, + mp_limb_t *scale, mp_size_t scalesize, + mp_limb_t *tmp) +{ + mp_limb_t hi; + + if (expsign != 0 && type == 'f' && exponent-- > 0) + hi = 0; + else if (scalesize == 0) + { + hi = frac[fracsize - 1]; + frac[fracsize - 1] = __mpn_mul_1 (frac, frac, fracsize - 1, 10); + } + else + { + if (fracsize < scalesize) + hi = 0; + else + { + hi = mpn_divmod (tmp, frac, fracsize, scale, scalesize); + tmp[fracsize - scalesize] = hi; + hi = tmp[0]; + + fracsize = scalesize; + while (fracsize != 0 && frac[fracsize - 1] == 0) + --fracsize; + if (fracsize == 0) + { + /* We're not prepared for an mpn variable with zero + limbs. */ + fracsize = 1; + return L'0' + hi; + } + } + + mp_limb_t _cy = __mpn_mul_1 (frac, frac, fracsize, 10); + if (_cy != 0) + frac[fracsize++] = _cy; + } + + return L'0' + hi; +} int ___printf_fp (FILE *fp, @@ -213,50 +256,6 @@ ___printf_fp (FILE *fp, /* Flag whether wbuffer is malloc'ed or not. */ int buffer_malloced = 0; - auto wchar_t hack_digit (void); - - wchar_t hack_digit (void) - { - mp_limb_t hi; - - if (expsign != 0 && type == 'f' && exponent-- > 0) - hi = 0; - else if (scalesize == 0) - { - hi = frac[fracsize - 1]; - frac[fracsize - 1] = __mpn_mul_1 (frac, frac, fracsize - 1, 10); - } - else - { - if (fracsize < scalesize) - hi = 0; - else - { - hi = mpn_divmod (tmp, frac, fracsize, scale, scalesize); - tmp[fracsize - scalesize] = hi; - hi = tmp[0]; - - fracsize = scalesize; - while (fracsize != 0 && frac[fracsize - 1] == 0) - --fracsize; - if (fracsize == 0) - { - /* We're not prepared for an mpn variable with zero - limbs. */ - fracsize = 1; - return L'0' + hi; - } - } - - mp_limb_t _cy = __mpn_mul_1 (frac, frac, fracsize, 10); - if (_cy != 0) - frac[fracsize++] = _cy; - } - - return L'0' + hi; - } - - /* Figure out the decimal point character. */ if (info->extra == 0) { @@ -914,7 +913,8 @@ ___printf_fp (FILE *fp, while (intdig_no < intdig_max) { ++intdig_no; - *wcp++ = hack_digit (); + *wcp++ = hack_digit (expsign, type, exponent, frac, fracsize, + scale, scalesize, tmp); } significant = 1; if (info->alt @@ -938,7 +938,8 @@ ___printf_fp (FILE *fp, || (fracdig_no < fracdig_max && (fracsize > 1 || frac[0] != 0))) { ++fracdig_no; - *wcp = hack_digit (); + *wcp = hack_digit (expsign, type, exponent, frac, fracsize, + scale, scalesize, tmp); if (*wcp++ != L'0') significant = 1; else if (significant == 0) @@ -951,7 +952,8 @@ ___printf_fp (FILE *fp, /* Do rounding. */ wchar_t last_digit = wcp[-1] != decimalwc ? wcp[-1] : wcp[-2]; - wchar_t next_digit = hack_digit (); + wchar_t next_digit = hack_digit (expsign, type, exponent, frac, fracsize, + scale, scalesize, tmp); bool more_bits; if (next_digit != L'0' && next_digit != L'5') more_bits = true;