Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #108095

Re: LLVM and Forth

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: LLVM and Forth
Date Wed, 12 Apr 2017 20:04:45 -0700
Organization None to speak of
Lines 45
Message-ID <lnlgr5uhwy.fsf@kst-u.example.com> (permalink)
References <21153661-abf5-4958-82c7-e3c442b45cb9@googlegroups.com> <ZqGdnRes4qCBI33FnZ2dnUU7-VednZ2d@supernews.com> <065e774c-c5fb-4e68-9489-00b5357142d6@googlegroups.com> <qOKdneQNfs-vmH_FnZ2dnUU7-UednZ2d@supernews.com> <2017Apr3.145550@mips.complang.tuwien.ac.at> <NNSdnXwvutwb-H_FnZ2dnUU7-XXNnZ2d@supernews.com> <2017Apr3.190545@mips.complang.tuwien.ac.at> <a-SdnVgDEexEVH7FnZ2dnUU7-RHNnZ2d@supernews.com> <2017Apr5.170145@mips.complang.tuwien.ac.at> <s4wFA.637264$3a3.286206@fx43.am4> <2017Apr9.165301@mips.complang.tuwien.ac.at> <xuAGA.661090$nT1.467590@fx44.am4> <a92c6f37-e327-412a-8923-11ccfee76d54@googlegroups.com> <bQyHA.1006772$Pm3.858411@fx42.am4> <d3b64bc0-40c8-4f54-9381-387da6e6d7f4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="13360d95e95b581afe8d2d731341601b"; logging-data="15047"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QaOgooOlUfkOyeWB4rT3f"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:qnnXnIg6wATNva1Vkx3r0dlTTqw= sha1:BytzAzc6DNA2Y8uQrlFYFz3Kf04=
Xref csiph.com comp.lang.c:108095

Show key headers only | View raw


supercat@casperkitty.com writes:
[...]
> On a 16-bit system, given something like:
>
>     long mul(int x, int y) { return x*y; }
>
> it may be faster on some platforms for a compiler to return the
> numerically- correct 32-bit result than for it to sign-extend a 16-bit
> result, and I would suggest that programmers should not view
> numerically-correct results as "astonishing".  If what I wanted was a
> 16-bit result that was truncated and sign-extended, I would have made
> that intention clear via:
>
>     long mul(int x, int y) { return (int)(x*y); }
>
> The notion that a compiler might use the multiplication to make
> assumptions about x and y would never have occurred to me.

The notion that casting an expression that's already of type int to type
int would have some non-trivial effect would never have occurred to me.

An expression of type int yielding a "numerically-correct" result that's
outside the range INT_MIN..INT_MAX is certainly something I would find
astonishing -- until I realized that the evaluation has undefined
behavior.

And even if x*y somehow yielded a result outside the range
of int, casting that result to int would at best yield an
implementation-defined result (even ignoring the fact that the cast
logically does nothing).

If I wanted a 16-by-16-to-32 bit multiplication function, given 16-bit
int and 32-bit long, I wouldn't write either version of your mul
function.  I'd probably write:

    long mul(int x, int y) { return (long)x * y; }

(Or I might cast both operands just for symmetry, but the other
one will be promoted anyway.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 00:38 +0000
  Re: LLVM and Forth James Kuyper <jameskuyper@verizon.net> - 2017-04-09 22:46 -0400
    Re: LLVM and Forth Robert Wessel <robertwessel2@yahoo.com> - 2017-04-09 22:27 -0500
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 12:36 +0000
      Re: LLVM and Forth Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-10 14:09 +0100
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-10 13:07 +0000
      Re: LLVM and Forth Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-10 16:18 +0100
      Re: LLVM and Forth "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-10 11:51 -0400
        Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 21:32 +0000
          Re: LLVM and Forth "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-12 18:29 -0400
          Re: LLVM and Forth supercat@casperkitty.com - 2017-04-12 15:34 -0700
            Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 23:41 +0000
          Re: LLVM and Forth albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-13 02:55 +0200
  Re: LLVM and Forth supercat@casperkitty.com - 2017-04-10 15:12 -0700
    Re: LLVM and Forth Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 23:34 +0000
      Re: LLVM and Forth supercat@casperkitty.com - 2017-04-12 17:25 -0700
        Re: LLVM and Forth Keith Thompson <kst-u@mib.org> - 2017-04-12 20:04 -0700

csiph-web