public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Pavel Pisa <ppisa4lists@pikron.com>
To: newlib@sourceware.org
Cc: Corinna Vinschen <vinschen@redhat.com>
Subject: Re: ARM-only [Patch] Allow 4 byte enum size (-fno-short-enums) | Remove hard coded short enum flag from the build scripts?
Date: Tue, 30 Aug 2016 23:26:00 -0000	[thread overview]
Message-ID: <201608310126.35104.ppisa4lists@pikron.com> (raw)
In-Reply-To: <20160830182757.GC5955@calimero.vinschen.de>

Hello Corinna and all others,

On Tuesday 30 of August 2016 20:27:57 Corinna Vinschen wrote:
> Given that, per Richard, the enum usage in the affected files is
> internal a change here is apparently not ABI-relevant.  From my
> rather neutral stance it looks like a pretty safe change so far...

When I look to

  newlib/libc/stdlib/mbtowc_r.c

then it seems that tables using enums as base type can have considerable
impact on size for tiny/nano targets.

typedef enum { ESCAPE, DOLLAR, BRACKET, AT, B, J,
               NUL, JIS_CHAR, OTHER, JIS_C_NUM } JIS_CHAR_TYPE;
typedef enum { ASCII, JIS, A_ESC, A_ESC_DL, JIS_1, J_ESC, J_ESC_BR,
               INV, JIS_S_NUM } JIS_STATE;
typedef enum { COPY_A, COPY_J1, COPY_J2, MAKE_A, NOOP, EMPTY, ERROR } JIS_ACTION;

But I am not sure if using -fshort-enums is the right way to solve that.
If we can agree that enums in C are mainly usesfull for unique values
in the set assignment but in the fact there is no check that enum
values are assigned to the variables of same type, then much better
solution is to count cases by hand and decide about type.

In this particular case, I expect that next is most space conserving

enum { ESCAPE, DOLLAR, BRACKET, AT, B, J, NUL, JIS_CHAR, OTHER, JIS_C_NUM };
typedef int_least8_t JIS_CHAR_TYPE;

enum { ASCII, JIS, A_ESC, A_ESC_DL, JIS_1, J_ESC, J_ESC_BR,
     INV, JIS_S_NUM };
typedef int_least8_t JIS_STATE;

enum { COPY_A, COPY_J1, COPY_J2, MAKE_A, NOOP, EMPTY, ERROR };
typedef int_least8_t JIS_ACTION;

What makes me worry for waste of memory in this particular file is
that tables go to data section

#ifndef  __CYGWIN__
static JIS_STATE JIS_state_table[JIS_S_NUM][JIS_C_NUM] = {

I think, that they should be
static const JIS_STATE JIS_state_table[JIS_S_NUM][JIS_C_NUM] = {

Same for

static mbtowc_p __cp_xxx_mbtowc[26] = {

For newlib/libc/stdio/vfprintf.c, it looks like enums are used only as
variables inside functions. The size is not big deal for local variables.
If registers halves, quarters etc. can used for multiple variables
on some targets then space for enum types can be defined as uint_fast8_t .
But generally difference is minimal.

Best wishes,

                Pavel



  reply	other threads:[~2016-08-30 23:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-28 14:31 Dennis Pahl
2016-08-30  9:47 ` ARM-only " Corinna Vinschen
2016-08-30 12:45   ` Joel Sherrill
2016-08-30 13:07   ` Richard Earnshaw (lists)
2016-08-30 18:23     ` Corinna Vinschen
2016-08-30 13:17   ` Schwarz, Konrad
2016-08-30 18:28     ` Corinna Vinschen
2016-08-30 23:26       ` Pavel Pisa [this message]
2016-08-31  7:56       ` Schwarz, Konrad
2016-08-31 11:15         ` Richard Earnshaw (lists)
2016-08-31 11:36           ` Schwarz, Konrad
2016-08-31 12:37             ` Richard Earnshaw (lists)
2016-08-31 12:44               ` Schwarz, Konrad
2016-08-31 14:33                 ` Richard Earnshaw (lists)
2016-08-31 16:04                   ` Richard Earnshaw (lists)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201608310126.35104.ppisa4lists@pikron.com \
    --to=ppisa4lists@pikron.com \
    --cc=newlib@sourceware.org \
    --cc=vinschen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).