9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: adr <adr@SDF.ORG>
To: 9fans <9fans@9fans.net>
Subject: Re: [9fans] Conversion of constants in C compiler
Date: Mon, 9 May 2022 19:31:06 +0000 (UTC)	[thread overview]
Message-ID: <c950fbd9-2053-1c2-b71d-d0e233c64d4@SDF.ORG> (raw)
In-Reply-To: <b2e1bdc-2839-a94c-4d40-3526901ef939@SDF.ORG>

On Sun, 1 May 2022, adr wrote:

> Yeah, i was thinking
>   int -> long -> vlong -> uvlong

No, it was a mistake, I forgot to check again that the conversion to
unsigned when the constant is using the sign bit doesn't occurs to
decimal constants.

Also, reading 9front's mailing list I noticed the mess ignoring
that convvtox will return vlong, type casting should do the trick:

[...]
        vv = yylval.vval;
        if(c1 & Numvlong ||
          (uvlong)convvtox(vv, TUVLONG) > convvtox(vv, TULONG) ||
          (c1 & (Numdec|Numuns)) == Numdec && convvtox(vv, TLONG) < 0) {
                if((c1 & Numuns) || convvtox(vv, TVLONG) < 0 && (c1 & Numdec) == 0) {
                        c = LUVLCONST;
                        t = TUVLONG;
                        goto nret;
                }
                c = LVLCONST;
                t = TVLONG;
                goto nret;
        }
        if(c1 & Numlong ||
          convvtox(vv, TULONG) > convvtox(vv, TUINT) ||
          (c1 & (Numdec|Numuns)) == Numdec && convvtox(vv, TINT) < 0) {
                if((c1 & Numuns) || convvtox(vv, TLONG) < 0 && (c1 & Numdec) == 0) {
                        c = LULCONST;
                        t = TULONG;
                        goto nret;
                }
                c = LLCONST;
                t = TLONG;
                goto nret;
        }
        if((c1 & Numuns) || convvtox(vv, TINT) < 0 && (c1 & Numdec) == 0) {
                c = LUCONST;
                t = TUINT;
                goto nret;
        }
        c = LCONST;
        t = TINT;
        goto nret;
[...]

It looks complex at first, but each line is telling you the reason
to expand the constant, and when to use unsigned types first. For
me is absolutely better than insert size assumptions in a piece of
code which is making a great effort to let that to machine dependent
code well kept in another place.

I'll make some tests.

adr

------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T22754f10b241991c-M64323f2f5a4e8db8ea11250b
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription

  reply	other threads:[~2022-05-09 19:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20 10:19 adr
2022-04-20 11:38 ` Charles Forsyth
2022-04-20 14:37   ` adr
2022-04-20 14:37 ` ori
2022-04-21  7:54   ` adr
2022-04-21 15:29     ` ori
2022-04-28  1:10     ` ori
2022-05-01 12:03       ` adr
2022-04-28  2:43     ` ori
2022-04-28  3:12       ` ori
2022-05-01 12:35       ` adr
2022-05-09 19:31         ` adr [this message]
2022-05-10 13:06           ` adr
2022-05-10 14:48             ` adr
2022-06-06  0:35 adr

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=c950fbd9-2053-1c2-b71d-d0e233c64d4@SDF.ORG \
    --to=adr@sdf.org \
    --cc=9fans@9fans.net \
    --subject='Re: [9fans] Conversion of constants in C compiler' \
    /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

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 NNTP newsgroup(s).