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


Groups > comp.arch > #31581 > unrolled thread

Between CISC and RISC

Started byQuadibloc <jsavard@ecn.ab.ca>
First post2015-12-07 20:13 -0800
Last post2015-12-26 10:07 -0800
Articles 20 on this page of 134 — 26 participants

Back to article view | Back to comp.arch


Contents

  Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-07 20:13 -0800
    Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-08 01:50 -0800
      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-08 04:19 -0800
        Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-08 04:57 -0800
          Re: Between CISC and RISC algrant109@gmail.com - 2015-12-11 12:57 -0800
            Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-11 13:44 -0800
            Re: Between CISC and RISC Ivan Godard <ivan@millcomputing.com> - 2015-12-11 15:40 -0800
              Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-11 21:13 -0800
                Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-12 04:14 -0800
                  Re: Between CISC and RISC already5chosen@yahoo.com - 2015-12-12 12:59 -0800
              Re: Between CISC and RISC algrant109@gmail.com - 2015-12-14 08:44 -0800
          Re: Between CISC and RISC Exophase <exophase@gmail.com> - 2015-12-15 13:23 -0800
            Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-16 02:13 -0800
    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-08 04:17 -0800
      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-09 05:35 -0800
        Re: Between CISC and RISC jacko <jackokring@gmail.com> - 2015-12-09 08:56 -0800
        Re: Between CISC and RISC Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-12-09 10:30 -0800
          Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-09 11:06 -0800
            Re: Between CISC and RISC Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-12-09 12:17 -0800
              Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-09 12:56 -0800
                Re: Between CISC and RISC Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-12-10 11:44 -0800
                  Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-10 22:50 -0800
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-10 23:06 -0800
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-11 06:01 -0800
          Re: Between CISC and RISC David W Schroth <davidschroth@harrietmanor.com> - 2015-12-10 21:37 -0600
          Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-11 10:37 -0800
            Re: Between CISC and RISC Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-12-11 15:19 -0800
              Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-11 21:20 -0800
              Re: Between CISC and RISC David W Schroth <davidschroth@harrietmanor.com> - 2015-12-12 18:22 -0600
          Re: Between CISC and RISC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-12 23:20 +0000
            Re: Between CISC and RISC Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-13 07:48 +0100
              Re: Between CISC and RISC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-13 18:00 +0000
                Re: Between CISC and RISC Ivan Godard <ivan@millcomputing.com> - 2015-12-13 11:37 -0800
                Re: Between CISC and RISC Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-13 21:57 +0100
            Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-13 07:19 -0800
              Re: ones complement, was Between John Levine <johnl@iecc.com> - 2015-12-13 15:32 +0000
                Re: ones complement, was Between Quadibloc <jsavard@ecn.ab.ca> - 2015-12-13 08:32 -0800
                  Re: ones complement, was Between John Levine <johnl@iecc.com> - 2015-12-13 16:52 +0000
                    Re: ones complement, was Between Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-13 08:56 -0800
                      Re: ones complement, was Between John Levine <johnl@iecc.com> - 2015-12-13 17:03 +0000
                        Re: ones complement, was Between Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-12-13 10:12 -0700
                      Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-13 21:51 +0100
                        Re: ones complement, was Between Jan Coombs <jan_coombs@murmic.plus.com> - 2015-12-13 22:18 +0000
                Re: ones complement, was Between MitchAlsup <MitchAlsup@aol.com> - 2015-12-13 10:15 -0800
                  Re: ones complement, was Between Megol <golem960@gmail.com> - 2015-12-13 12:18 -0800
                  Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-13 22:00 +0100
                    Re: ones complement, was Between Ivan Godard <ivan@millcomputing.com> - 2015-12-13 13:07 -0800
                      Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-14 10:15 +0100
                        Re: ones complement, was Between Ivan Godard <ivan@millcomputing.com> - 2015-12-14 01:39 -0800
                        Re: ones complement, was Between already5chosen@yahoo.com - 2015-12-14 01:59 -0800
                          Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-14 14:21 +0100
                            Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-14 14:21 +0000
                            Re: ones complement, was Between already5chosen@yahoo.com - 2015-12-14 07:03 -0800
                              Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-14 15:50 +0000
                                Re: ones complement, was Between MitchAlsup <MitchAlsup@aol.com> - 2015-12-14 16:34 -0800
                                  Re: ones complement, was Between Ivan Godard <ivan@millcomputing.com> - 2015-12-14 18:42 -0800
                                    Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-15 09:13 +0000
                                    Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-15 09:25 +0000
                                  Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-15 08:53 +0000
                              Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-14 18:25 +0100
                                Re: ones complement, was Between Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-15 02:20 -0800
                                  Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-15 11:58 +0100
                                Re: ones complement, was Between already5chosen@yahoo.com - 2015-12-20 02:45 -0800
                                  Re: ones complement, was Between already5chosen@yahoo.com - 2015-12-20 03:11 -0800
                                  Re: ones complement, was Between nj_kruse@me.com (Niels Jørgen Kruse) - 2015-12-20 14:34 +0100
                                    Re: ones complement, was Between already5chosen@yahoo.com - 2015-12-20 05:57 -0800
                                      Re: ones complement, was Between MitchAlsup <MitchAlsup@aol.com> - 2015-12-20 12:12 -0800
                                        Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-21 15:33 +0100
                                          Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-21 14:58 +0000
                                            Re: ones complement, was Between Quadibloc <jsavard@ecn.ab.ca> - 2015-12-21 10:06 -0800
                                            Re: ones complement, was Between MitchAlsup <MitchAlsup@aol.com> - 2015-12-21 15:48 -0800
                                              Re: ones complement, was Between Ivan Godard <ivan@millcomputing.com> - 2015-12-21 17:13 -0800
                                  Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-20 17:47 +0100
                                    Re: ones complement, was Between jacko <jackokring@gmail.com> - 2015-12-20 10:09 -0800
                                    Re: ones complement, was Between Jean-Marc Bourguet <jm@bourguet.org> - 2015-12-20 20:09 +0100
                                  Re: ones complement, was Between Chris Gray <cg@GraySage.COM> - 2015-12-20 11:02 -0700
                                    Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-21 14:11 +0000
                                      Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-21 16:08 +0100
                                        Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-21 16:03 +0000
                                          Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-21 16:18 +0000
                                            Re: ones complement, was Between nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-21 17:53 +0000
                                          Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-21 21:29 +0100
                                        Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-21 15:57 +0000
                                          Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-21 21:25 +0100
                    Re: ones complement, was Between John Levine <johnl@iecc.com> - 2015-12-14 02:11 +0000
                      Re: ones complement, was Between Quadibloc <jsavard@ecn.ab.ca> - 2015-12-14 00:27 -0800
                  Re: ones complement, was Between Quadibloc <jsavard@ecn.ab.ca> - 2015-12-13 17:16 -0800
                    Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-14 10:20 +0100
                      Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-14 10:29 +0000
                        Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-14 12:17 +0000
                          Re: ones complement, was Between MitchAlsup <MitchAlsup@aol.com> - 2015-12-14 06:40 -0800
                        Re: ones complement, was Between Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-14 14:26 +0100
                  Re: ones complement, was Between anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-14 08:09 +0000
            Re: Between CISC and RISC mrs@kithrup.com (Mike Stump) - 2015-12-14 00:11 +0000
        Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2015-12-09 17:30 -0800
      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-14 00:17 -0800
        Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-14 05:48 -0800
    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-15 15:32 -0800
      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-21 12:57 -0800
        Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-21 19:00 -0800
          Re: Between CISC and RISC Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-22 10:26 +0100
            Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-22 06:39 -0800
            Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-23 10:17 -0800
              Re: Between CISC and RISC Jean-Marc Bourguet <jm@bourguet.org> - 2015-12-23 19:55 +0100
                Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-23 17:15 -0800
                  Re: Between CISC and RISC Terje Mathisen <terje.mathisen@tmsw.no> - 2015-12-24 10:27 +0100
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 04:50 -0800
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 07:37 -0800
                      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 09:47 -0800
                        Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 11:47 -0800
                          Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 12:48 -0800
                            Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 18:56 -0800
                              Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-25 09:34 -0800
                            Re: Between CISC and RISC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-12-25 17:57 +0000
                              Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-25 10:42 -0800
                                Re: Between CISC and RISC Bruce Hoult <bruce.hoult@gmail.com> - 2015-12-26 03:29 -0800
                                Re: Between CISC and RISC Jakob Brundin <jakbru@gmail.com> - 2015-12-26 07:23 -0800
                                  Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-26 09:54 -0800
                                Re: Between CISC and RISC Anne & Lynn Wheeler <lynn@garlic.com> - 2015-12-26 16:18 -0800
                            Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2016-01-31 10:17 -0800
                              Re: Between CISC and RISC paul wallich <pw@panix.com> - 2016-01-31 13:39 -0500
                                Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2016-01-31 19:16 -0800
                              Re: Between CISC and RISC anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-02-01 12:43 +0000
                                Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2016-02-01 06:44 -0800
                    Re: Between CISC and RISC Ivan Godard <ivan@millcomputing.com> - 2015-12-24 13:03 -0800
                      Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-24 16:35 -0800
                        Re: Between CISC and RISC Ivan Godard <ivan@millcomputing.com> - 2015-12-24 16:45 -0800
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2016-01-31 07:14 -0800
                  Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2015-12-25 07:21 -0800
                    Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-25 07:39 -0800
                    Re: Between CISC and RISC George Neuner <gneuner2@comcast.net> - 2015-12-25 11:53 -0500
                      Re: Between CISC and RISC MitchAlsup <MitchAlsup@aol.com> - 2016-01-31 10:10 -0800
                        Re: Between CISC and RISC Robert Wessel <robertwessel2@yahoo.com> - 2016-01-31 23:34 -0600
            Re: Between CISC and RISC Quadibloc <jsavard@ecn.ab.ca> - 2015-12-26 10:07 -0800

Page 4 of 7 — ← Prev page 1 2 3 [4] 5 6 7  Next page →


#31876 — Re: ones complement, was Between

FromBruce Hoult <bruce.hoult@gmail.com>
Date2015-12-15 02:20 -0800
SubjectRe: ones complement, was Between
Message-ID<baa2886f-e147-44ef-8343-192aab45cf7e@googlegroups.com>
In reply to#31855
On Monday, December 14, 2015 at 8:25:27 PM UTC+3, Terje Mathisen wrote:
> When I do need integers then it would be nice if I could have a 
> user-level trap to catch overflows and automatically convert the result 
> to a bigint style extended/arbitrary precision variable instead.

Well and good, but then how does subsequent code know it's got a bigint, not a regular int?

That gets you into tagging, in which case you either need 1) full hardware support for bigints, or 2) at least trapping if one of the operands is a bigint, or 3) explicit checks of the tag in which case you might as well check the overflow yourself also...

[toc] | [prev] | [next] | [standalone]


#31878 — Re: ones complement, was Between

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-12-15 11:58 +0100
SubjectRe: ones complement, was Between
Message-ID<n4oro1$c30$1@speranza.aioe.org>
In reply to#31876
Bruce Hoult wrote:
> On Monday, December 14, 2015 at 8:25:27 PM UTC+3, Terje Mathisen
> wrote:
>> When I do need integers then it would be nice if I could have a
>> user-level trap to catch overflows and automatically convert the
>> result to a bigint style extended/arbitrary precision variable
>> instead.
>
> Well and good, but then how does subsequent code know it's got a
> bigint, not a regular int?
>
> That gets you into tagging, in which case you either need 1) full
> hardware support for bigints, or 2) at least trapping if one of the
> operands is a bigint, or 3) explicit checks of the tag in which case
> you might as well check the overflow yourself also...
>

Yes to all of those? :-)

Having (2) would work OK actually.

I.e. my example wasn't the best but I am sure I have written code which 
could have been _much_ simpler if the exception handling could have been 
moved external to the mainline code.

Terje
-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32012 — Re: ones complement, was Between

Fromalready5chosen@yahoo.com
Date2015-12-20 02:45 -0800
SubjectRe: ones complement, was Between
Message-ID<c8108207-ea80-410f-9573-9686cf6cc416@googlegroups.com>
In reply to#31855
On Monday, December 14, 2015 at 7:25:27 PM UTC+2, Terje Mathisen wrote:
> already5chosen@yahoo.com wrote:
> > On Monday, December 14, 2015 at 3:21:40 PM UTC+2, Terje Mathisen
> > wrote:
> >> already5chosen@yahoo.com wrote:
> >>> I'd guess, by Ivan's classification it's called "to not care
> >>> about overflow". "To care about overflow" = to make an operation
> >>> that checks overflow as cheap as the the operation that does not
> >>> check overflow.
> >>
> >> The key issue here isn't really checking overflow, but how to
> >> handle exceptions at user level!
> >>
> >> I.e. if you can make user level trap handling cheap enough then you
> >> can use straight-line code for the normal case and depend on
> >> getting traps when something bad happens.
> >>
> >
> > I don't see why "make user level trap handling cheap enough" is
> > particularly desirable. That is, yes, cheap is better than expensive,
> > but speed of the trap delivery should be our least important concern.
> > By far. If trap delivery by means of slow trip to kernel and back
> > makes anything else even a little bit faster, smaller or easier, than
> > it shell be chosen over alternatives.
> 
> Sure.
> 
> >
> >> If you have to implement this with explicit test/branch after
> >> every operation (using branch prediction slots etc) then the cost
> >> is so high that most people have decided they would rather take a
> >> chance and ignore the problem.
> >
> > I think, Ivan is coming from the school in which even addition of
> > single-byte opcode, like x86 INTO, is already considered too
> > expensive. He want literally the same cost for checked and unchecked
> > arithmetic options. But, of course, Ivan can speak for himself.
> 
> Ivan and I mostly agree, that's one of the reasons why I'm working on 
> his Mill.
> >
> > I, personally, is coming from the school that is not willing to do
> > [automatic] overflow checks of signed integer arithmetic regardless
> > of its cost. We (I) tend to think that such checks are harmful much
> > more often than they are helpful. And, of course, we like to point to
> > $7B Ariane 5 mission failure as a proof.
> 
> I'm from the 'C integers are badly broken, so don't ever use them unless 
> you absolutely have to' school.
> 
> I have very seldom seen integer code that wouldn't work 
> better/faster/more portably using unsigned instead.
>

It's not the first time you are saying that. But I'd prefer more elaborate explanation, because without explanation it simply does not make sense to me.
To me it seems rather obvious that see 'int' type is much closer to people's intuitive (well, not really intuitive, let's say tough in school. from practical perspective it's the same as intuitive) perception of the number.
For example, it is very non-intuitive when (a-b<c) does not follow from (a < b+c).
It is very non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i) ..."

You can say that even for 'int' (a-b<c) is not an exact equivalent of (a < b+c). That's true theoretically, but not in practice, because in practice numbers with magnitude > 2**30 are very rare.

> When I do need integers then it would be nice if I could have a 
> user-level trap to catch overflows and automatically convert the result 
> to a bigint style extended/arbitrary precision variable instead.

As Bruce said, that's only possible in "dynamically-typed" languages. And when we are already in "dynamic" land, I am not sure that overflow trap is the best way to achieve the desired effect even under assumption that user-level exceptions are fast.
I don't have opinion of my own, because I don't know enough about implementation options for such languages. Intuitively I think that overflow trap can be the best option from performance perspective in [most common] situation when overflow is extremely rare. But when it comes to performance, even well trained programmer's intuition sucks badly; untrained intuition, like mine, probably sucks even worse.


> 
> Terje
> -- 
> - <Terje.Mathisen at tmsw.no>
> "almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32014 — Re: ones complement, was Between

Fromalready5chosen@yahoo.com
Date2015-12-20 03:11 -0800
SubjectRe: ones complement, was Between
Message-ID<b25c071e-af79-4322-bb0e-92f4a6c4eb5c@googlegroups.com>
In reply to#32012
On Sunday, December 20, 2015 at 12:45:37 PM UTC+2, already...@yahoo.com wrote:
> On Monday, December 14, 2015 at 7:25:27 PM UTC+2, Terje Mathisen wrote:
> > already5chosen@yahoo.com wrote:
> > > On Monday, December 14, 2015 at 3:21:40 PM UTC+2, Terje Mathisen
> > > wrote:
> > >> already5chosen@yahoo.com wrote:
> > >>> I'd guess, by Ivan's classification it's called "to not care
> > >>> about overflow". "To care about overflow" = to make an operation
> > >>> that checks overflow as cheap as the the operation that does not
> > >>> check overflow.
> > >>
> > >> The key issue here isn't really checking overflow, but how to
> > >> handle exceptions at user level!
> > >>
> > >> I.e. if you can make user level trap handling cheap enough then you
> > >> can use straight-line code for the normal case and depend on
> > >> getting traps when something bad happens.
> > >>
> > >
> > > I don't see why "make user level trap handling cheap enough" is
> > > particularly desirable. That is, yes, cheap is better than expensive,
> > > but speed of the trap delivery should be our least important concern.
> > > By far. If trap delivery by means of slow trip to kernel and back
> > > makes anything else even a little bit faster, smaller or easier, than
> > > it shell be chosen over alternatives.
> > 
> > Sure.
> > 
> > >
> > >> If you have to implement this with explicit test/branch after
> > >> every operation (using branch prediction slots etc) then the cost
> > >> is so high that most people have decided they would rather take a
> > >> chance and ignore the problem.
> > >
> > > I think, Ivan is coming from the school in which even addition of
> > > single-byte opcode, like x86 INTO, is already considered too
> > > expensive. He want literally the same cost for checked and unchecked
> > > arithmetic options. But, of course, Ivan can speak for himself.
> > 
> > Ivan and I mostly agree, that's one of the reasons why I'm working on 
> > his Mill.
> > >
> > > I, personally, is coming from the school that is not willing to do
> > > [automatic] overflow checks of signed integer arithmetic regardless
> > > of its cost. We (I) tend to think that such checks are harmful much
> > > more often than they are helpful. And, of course, we like to point to
> > > $7B Ariane 5 mission failure as a proof.
> > 
> > I'm from the 'C integers are badly broken, so don't ever use them unless 
> > you absolutely have to' school.
> > 
> > I have very seldom seen integer code that wouldn't work 
> > better/faster/more portably using unsigned instead.
> >
> 
> It's not the first time you are saying that. But I'd prefer more elaborate explanation, because without explanation it simply does not make sense to me.
> To me it seems rather obvious that see 'int' type is much closer to people's intuitive (well, not really intuitive, let's say tough in school. from practical perspective it's the same as intuitive) perception of the number.

Here I meant to say:
"To me it seems rather obvious that C 'int' type is much closer to people's intuitive (well, not really intuitive, let's say taught in school. from practical perspective it's the same as intuitive) perception of the number."

> For example, it is very non-intuitive when (a-b<c) does not follow from (a < b+c).
> It is very non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i) ..."
> 
> You can say that even for 'int' (a-b<c) is not an exact equivalent of (a < b+c). That's true theoretically, but not in practice, because in practice numbers with magnitude > 2**30 are very rare.
> 
> > When I do need integers then it would be nice if I could have a 
> > user-level trap to catch overflows and automatically convert the result 
> > to a bigint style extended/arbitrary precision variable instead.
> 
> As Bruce said, that's only possible in "dynamically-typed" languages. And when we are already in "dynamic" land, I am not sure that overflow trap is the best way to achieve the desired effect even under assumption that user-level exceptions are fast.
> I don't have opinion of my own, because I don't know enough about implementation options for such languages. Intuitively I think that overflow trap can be the best option from performance perspective in [most common] situation when overflow is extremely rare. But when it comes to performance, even well trained programmer's intuition sucks badly; untrained intuition, like mine, probably sucks even worse.
> 
> 
> > 
> > Terje
> > -- 
> > - <Terje.Mathisen at tmsw.no>
> > "almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32019 — Re: ones complement, was Between

Fromnj_kruse@me.com (Niels Jørgen Kruse)
Date2015-12-20 14:34 +0100
SubjectRe: ones complement, was Between
Message-ID<1mfqge5.kc01v71hjor0gN%nj_kruse@me.com>
In reply to#32012
<already5chosen@yahoo.com> wrote:

> You can say that even for 'int' (a-b<c) is not an exact equivalent of
> (a < b+c). That's true theoretically, but not in practice, because in
> practice numbers with magnitude > 2**30 are very rare.

If you are not concerned with rare events, you can't write correct code.

-- 
Mvh./Regards,    Niels Jørgen Kruse,    Vanløse, Denmark

[toc] | [prev] | [next] | [standalone]


#32020 — Re: ones complement, was Between

Fromalready5chosen@yahoo.com
Date2015-12-20 05:57 -0800
SubjectRe: ones complement, was Between
Message-ID<04290f1f-2d69-479e-b9d7-38b384afdd48@googlegroups.com>
In reply to#32019
On Sunday, December 20, 2015 at 3:34:44 PM UTC+2, Niels Jørgen Kruse wrote:
> <already5chosen@yahoo.com> wrote:
> 
> > You can say that even for 'int' (a-b<c) is not an exact equivalent of
> > (a < b+c). That's true theoretically, but not in practice, because in
> > practice numbers with magnitude > 2**30 are very rare.
> 
> If you are not concerned with rare events, you can't write correct code.
> 
> -- 
> Mvh./Regards,    Niels Jørgen Kruse,    Vanløse, Denmark

Human language. It is imprecise :(
"rare" in this context does not mean "it occurs with very low probability for any given variable that is defined as 'int' in all C programs in the world", but rather "does not occur (and can be proven so) for overwhelming majority of variables that are defined as 'int' in all C programs in the world".

On the other hand, I claim that situations in which both a and b are certainly small (i.e. < 2^30) positive integers and programmer does not know for sure which one of them is bigger, but thinks that he knows, are less rare, for the same definition of 'rare'. And that's one, but not the only reason why I think that C 'unsigned' numbers are inherently more error-prone than 'int'.

[toc] | [prev] | [next] | [standalone]


#32030 — Re: ones complement, was Between

FromMitchAlsup <MitchAlsup@aol.com>
Date2015-12-20 12:12 -0800
SubjectRe: ones complement, was Between
Message-ID<bbf44676-e3e9-47c9-b48b-ade1128724c6@googlegroups.com>
In reply to#32020
On Sunday, December 20, 2015 at 7:57:08 AM UTC-6, already...@yahoo.com wrote:

> On the other hand, I claim that situations in which both a and b are certainly small (i.e. < 2^30) positive integers and programmer does not know for sure which one of them is bigger, but thinks that he knows, are less rare, for the same definition of 'rare'. And that's one, but not the only reason why I think that C 'unsigned' numbers are inherently more error-prone than 'int'.

The most error prone declarative statement in C is the one that declares
a variable to have the properties of int without that variable requiring
an ability to have a negative value.

I have programmed for decades without using int for anything (except for
values passed to library function that were misdeclared as int to begin
with.) I use unsigned almost exclusively for non floating point non 
pointer variables. This has dramatically decreased my surprise factor when
using C.

[toc] | [prev] | [next] | [standalone]


#32045 — Re: ones complement, was Between

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-12-21 15:33 +0100
SubjectRe: ones complement, was Between
Message-ID<n592j5$348$2@speranza.aioe.org>
In reply to#32030
MitchAlsup wrote:
> On Sunday, December 20, 2015 at 7:57:08 AM UTC-6, already...@yahoo.com wrote:
>
> The most error prone declarative statement in C is the one that declares
> a variable to have the properties of int without that variable requiring
> an ability to have a negative value.

Or quite often: It is an int just because the code needs the zero to -1 
stage to signal loop termination, i.e. just a (bad) replacement for 
carry detection using unsigned variables in asm.
>
> I have programmed for decades without using int for anything (except for
> values passed to library function that were misdeclared as int to begin
> with.) I use unsigned almost exclusively for non floating point non
> pointer variables. This has dramatically decreased my surprise factor when
> using C.
>
Thank you Mitch, it is good to know that I am not alone. :-)

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32047 — Re: ones complement, was Between

Fromnmm@wheeler.UUCP (Nick Maclaren)
Date2015-12-21 14:58 +0000
SubjectRe: ones complement, was Between
Message-ID<n5942k$eio$1@dont-email.me>
In reply to#32045
In article <n592j5$348$2@speranza.aioe.org>,
Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
>MitchAlsup wrote:
>>
>> The most error prone declarative statement in C is the one that declares
>> a variable to have the properties of int without that variable requiring
>> an ability to have a negative value.
>
>Or quite often: It is an int just because the code needs the zero to -1 
>stage to signal loop termination, i.e. just a (bad) replacement for 
>carry detection using unsigned variables in asm.

While I agree that is a ghastly feature, I have seen many more
errors due to people using unsigned ints without that variable
requiring the property of wrap-around.  At BOTH ends.  But see my
last paragraph.

>> I have programmed for decades without using int for anything (except for
>> values passed to library function that were misdeclared as int to begin
>> with.) I use unsigned almost exclusively for non floating point non
>> pointer variables. This has dramatically decreased my surprise factor when
>> using C.
>>
>Thank you Mitch, it is good to know that I am not alone. :-)

And I dramatically decreased my surprise factor when using C by
avoiding 'unsigned' as if it were toxic, except when forced to by
the demented specifications.  I.e. I have tried using the most
natural, using unsigned as you and Mitch do, and then decided to
use signed except when forced away from it.

It depends entirely on what sort of code you write.  I have written
codes where unsigned works best, but not often.  What seems to be a
complete disaster area is any mixture (even using the 'natural'
forms), because of C's demented conversion and mixture rules.


Regards,
Nick Maclaren.

[toc] | [prev] | [next] | [standalone]


#32061 — Re: ones complement, was Between

FromQuadibloc <jsavard@ecn.ab.ca>
Date2015-12-21 10:06 -0800
SubjectRe: ones complement, was Between
Message-ID<b61b3fa6-1bbe-4f55-adc7-6a172a9f41da@googlegroups.com>
In reply to#32047
On Monday, December 21, 2015 at 8:01:04 AM UTC-7, Nick Maclaren wrote:
> In article <n592j5$348$2@speranza.aioe.org>,
> Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
> >MitchAlsup wrote:

> >> I have programmed for decades without using int for anything (except for
> >> values passed to library function that were misdeclared as int to begin
> >> with.) I use unsigned almost exclusively for non floating point non
> >> pointer variables. This has dramatically decreased my surprise factor when
> >> using C.

> >Thank you Mitch, it is good to know that I am not alone. :-)

> And I dramatically decreased my surprise factor when using C by
> avoiding 'unsigned' as if it were toxic, except when forced to by
> the demented specifications.  I.e. I have tried using the most
> natural, using unsigned as you and Mitch do, and then decided to
> use signed except when forced away from it.

> It depends entirely on what sort of code you write.  I have written
> codes where unsigned works best, but not often.  What seems to be a
> complete disaster area is any mixture (even using the 'natural'
> forms), because of C's demented conversion and mixture rules.

I'm surprised by this discussion.

I would tend to agree that in most programs that use integer variables, the 
integers are likely to only take positive values, and so unsigned would work 
just as well.

However, whether the variables used are declared "integer" or "unsigned" should 
usually not matter - unless the extended positive range provided by unsigned is 
important. Because if the values the variables can take as the program works 
can only be positive... they would only become negative if an _error_ took 
place!

Now I can see what the reply to this would be. Nobody is so perfect as to write 
programs without bugs! And if the program is large and complicated, then a bug 
that makes an integer negative... could either result in an _immediate_ 
failure, or, if the variable is allowed to be negative, then it could result in 
a failure in some later, far-distant part of the program, making it impossible 
to find.

And I agree, that makes perfect sense, except...

This assumes that the unsigned int type in C comes with automatic range checking, however. I wasn't aware that C was that sort of language.

However, if you have a compiler switch that turns C into Pascal with bounds-checked arrays and all the other niceness, then declaring your variables unsigned might actually buy you something.

John Savard

[toc] | [prev] | [next] | [standalone]


#32082 — Re: ones complement, was Between

FromMitchAlsup <MitchAlsup@aol.com>
Date2015-12-21 15:48 -0800
SubjectRe: ones complement, was Between
Message-ID<958f48b4-cd71-4e3b-b4c9-402a1df5259e@googlegroups.com>
In reply to#32047
On Monday, December 21, 2015 at 9:01:04 AM UTC-6, Nick Maclaren wrote:
> In article <n592j5$348$2@speranza.aioe.org>,
> Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
> >MitchAlsup wrote:
> >>
> >> The most error prone declarative statement in C is the one that declares
> >> a variable to have the properties of int without that variable requiring
> >> an ability to have a negative value.
> >
> >Or quite often: It is an int just because the code needs the zero to -1 
> >stage to signal loop termination, i.e. just a (bad) replacement for 
> >carry detection using unsigned variables in asm.
> 
> While I agree that is a ghastly feature, I have seen many more
> errors due to people using unsigned ints without that variable
> requiring the property of wrap-around.  At BOTH ends.  But see my
> last paragraph.
> 
> >> I have programmed for decades without using int for anything (except for
> >> values passed to library function that were misdeclared as int to begin
> >> with.) I use unsigned almost exclusively for non floating point non
> >> pointer variables. This has dramatically decreased my surprise factor when
> >> using C.
> >>
> >Thank you Mitch, it is good to know that I am not alone. :-)
> 
> And I dramatically decreased my surprise factor when using C by
> avoiding 'unsigned' as if it were toxic, except when forced to by
> the demented specifications.  I.e. I have tried using the most
> natural, using unsigned as you and Mitch do, and then decided to
> use signed except when forced away from it.
> 
> It depends entirely on what sort of code you write.  I have written
> codes where unsigned works best, but not often.  What seems to be a
> complete disaster area is any mixture (even using the 'natural'
> forms), because of C's demented conversion and mixture rules.

Most of the code I write deals with HW bit-fields in containers of 
conventional sizes. Except for bookeeping, I hardly use integer (S or U) 
or floating point data types. Half the time I am using FP, I need access 
to the exponent and fraction bits in raw form. And almost always
I am programming on one machine to emulate a different machine with 
different ISA and different data types.

A lot of my code smells like:
......if( p->state == STATE1 ) 
......{
...........p->STATE ^= (STATE1 | STATE2)......// from current to new state
with some attendant pointer manipulations.
......}

Most of my code is mimicking the pipeline control of a processor,
with the barest fraction mimicking the actual calculations.

In my latest ISA, I create the notion of a signless type of data.
Signless data does not have the notions of:
a) a series of binary values
b) a sign or the lack thereof
c) a memory/register location is just a container of bits
and instruction to deal with these uses of a contiguous field of bits.

With respect to alternate uses of MAXimums, there is a simple way
to check for <signed> NEGMAX and for <unsigned> POSMAX that does not
require comparisons. So if the application or the language wants
to special case them, it has low cost access to that feature.

Rarely to I have a count-based loop, much more often it is a dereferencing 
loop that terminates at NULL.

[toc] | [prev] | [next] | [standalone]


#32084 — Re: ones complement, was Between

FromIvan Godard <ivan@millcomputing.com>
Date2015-12-21 17:13 -0800
SubjectRe: ones complement, was Between
Message-ID<n5a7ud$t0a$1@dont-email.me>
In reply to#32082
On 12/21/2015 3:48 PM, MitchAlsup wrote:

> In my latest ISA, I create the notion of a signless type of data.
> Signless data does not have the notions of:
> a) a series of binary values
> b) a sign or the lack thereof
> c) a memory/register location is just a container of bits
> and instruction to deal with these uses of a contiguous field of bits.

Great minds... :-)

This corresponds to the "logical" domain in the Mill ISA; it is 
different from the signedIntegral, unsignedIntegral, signedFixed, and 
unsignedFixed that are also supported (as are binary and decimal FP). 
Each language maps its datatype notions onto these domains.

Some languages have a ranged type notion, sometying like:
	range<1901, 2000> twentiethCentury;
This is essentially a numeric form of enumeration, with overflow 
checking; the C hierarchy is then just a selection of predeclared range 
types. The difficulty is doing the overflow check when the range is not 
a natural power of two....

> With respect to alternate uses of MAXimums, there is a simple way
> to check for <signed> NEGMAX and for <unsigned> POSMAX that does not
> require comparisons. So if the application or the language wants
> to special case them, it has low cost access to that feature.
>
> Rarely to I have a count-based loop, much more often it is a dereferencing
> loop that terminates at NULL.
>

for(year thru twentiethCentury) do ...

[toc] | [prev] | [next] | [standalone]


#32024 — Re: ones complement, was Between

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-12-20 17:47 +0100
SubjectRe: ones complement, was Between
Message-ID<n56m2p$ubn$1@speranza.aioe.org>
In reply to#32012
already5chosen@yahoo.com wrote:
> On Monday, December 14, 2015 at 7:25:27 PM UTC+2, Terje Mathisen
>> I'm from the 'C integers are badly broken, so don't ever use them
>> unless you absolutely have to' school.
>>
>> I have very seldom seen integer code that wouldn't work
>> better/faster/more portably using unsigned instead.
>>
>
> It's not the first time you are saying that. But I'd prefer more
> elaborate explanation, because without explanation it simply does not
> make sense to me. To me it seems rather obvious that see 'int' type
> is much closer to people's intuitive (well, not really intuitive,
> let's say tough in school. from practical perspective it's the same
> as intuitive) perception of the number. For example, it is very
> non-intuitive when (a-b<c) does not follow from (a < b+c). It is very
> non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i)
> ..."

Decrementing counted loops are one of the uglier cases, I write those 
either offset by one or (if I know that n will be positive) as a do while.

>
> You can say that even for 'int' (a-b<c) is not an exact equivalent of
> (a < b+c). That's true theoretically, but not in practice, because in
> practice numbers with magnitude > 2**30 are very rare.

Very rare errors like that is a perfect conduit for hacks and cracks. :-(

>
>> When I do need integers then it would be nice if I could have a
>> user-level trap to catch overflows and automatically convert the
>> result to a bigint style extended/arbitrary precision variable
>> instead.
>
> As Bruce said, that's only possible in "dynamically-typed" languages.
> And when we are already in "dynamic" land, I am not sure that
> overflow trap is the best way to achieve the desired effect even
> under assumption that user-level exceptions are fast. I don't have
> opinion of my own, because I don't know enough about implementation
> options for such languages. Intuitively I think that overflow trap
> can be the best option from performance perspective in [most common]
> situation when overflow is extremely rare. But when it comes to
> performance, even well trained programmer's intuition sucks badly;
> untrained intuition, like mine, probably sucks even worse.

"Always measure, never assume" - Mike Abrash

I believe my intuition re the actual performance of a given algorithm is 
probably better than most, but as you say, most programmers suck badly. :-(

It is only after I have written a complete implementation myself, either 
in asm or low-level C (i.e. using C as a portable assembler), that I get 
a real feel for how long it should take.

Scaling is actually easier since I automatically think in Big-O 
notation. :-)

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32027 — Re: ones complement, was Between

Fromjacko <jackokring@gmail.com>
Date2015-12-20 10:09 -0800
SubjectRe: ones complement, was Between
Message-ID<a9273f2e-ad48-4e3b-800f-03eac5dd02fc@googlegroups.com>
In reply to#32024
> Scaling is actually easier since I automatically think in Big-O 
> notation. :-)

As an aside, I develop programs in the following manor.

1) get it to work using the implemented algorithm.
2) make it readable and maintainable.
2.5) manager says release the product.
3) optimize using algorithms not first thought obvious, and repeat.

[toc] | [prev] | [next] | [standalone]


#32028 — Re: ones complement, was Between

FromJean-Marc Bourguet <jm@bourguet.org>
Date2015-12-20 20:09 +0100
SubjectRe: ones complement, was Between
Message-ID<87k2o9vswy.fsf@news.bourguet.org>
In reply to#32024
Terje Mathisen <terje.mathisen@tmsw.no> writes:


> It's not the first time you are saying that. But I'd prefer more
>> elaborate explanation, because without explanation it simply does not
>> make sense to me. To me it seems rather obvious that see 'int' type
>> is much closer to people's intuitive (well, not really intuitive,
>> let's say tough in school. from practical perspective it's the same
>> as intuitive) perception of the number. For example, it is very
>> non-intuitive when (a-b<c) does not follow from (a < b+c). It is very
>> non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i)
>> ..."
>
> Decrementing counted loops are one of the uglier cases, I write those
> either offset by one or (if I know that n will be positive) as a do while.

C usually uses half-open range. AFAIK, the four idiomatic formats are

for (i = l; i < h; ++i)   [l, h)
for (i = l; i++ < h; )    (l, h]
for (i = h; i-- > l; )    (h, l]
for (i = h; i > l; --i)   [h, l)

and work for signed and unsigned types (<pedantic>i++ < h and i-- > l are
overflows for int if h is INT_MAX and l is INT_MIN</pedantic>).

Yours,

-- 
Jean-Marc

[toc] | [prev] | [next] | [standalone]


#32026 — Re: ones complement, was Between

FromChris Gray <cg@GraySage.COM>
Date2015-12-20 11:02 -0700
SubjectRe: ones complement, was Between
Message-ID<877fk9ov6r.fsf@GraySage.COM>
In reply to#32012
already5chosen@yahoo.com writes:

> To me it seems rather obvious that see 'int' type is much closer to people's intuitive (well, not really intuitive, let's say tough in school. from practical perspective it's the same as intuitive) perception of the number.
> For example, it is very non-intuitive when (a-b<c) does not follow from (a < b+c).
> It is very non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i) ..."

> You can say that even for 'int' (a-b<c) is not an exact equivalent of (a < b+c). That's true theoretically, but not in practice, because in practice numbers with magnitude > 2**30 are very rare.

Personally, I think the preference could strongly relate to the background of
the programmer, and to the nature of the programs they deal with.

Myself, I mostly program system level stuff, compiler toolsets, and mostly
non-graphic game stuff. In these things, nearly all "ints" are used as
counters and array indexes. In both such situations a negative value is an
error. I like array bounds checking, and if you are allowing signed values
as indexes, you have to check for negative as well as too-large values (And
yes, I know that you can often combine the two in actual code.)

The only place I can think of that I've encountered in the last couple of
years where negative values are expected is in the co-ordinate system for
GUI windows, etc.

Floating point values representing simulation values, etc. will often be
negative, but I find it rare that I want integral values to be negative.

The old practice, like on Unix system call return values, where negative is
a negated error code and non-negative is a "normal" return value is not
something I like to do. It saved code back in the old days, but it is
mostly a source of bugs and hacking targets now, I think.

-- 
Chris Gray

[toc] | [prev] | [next] | [standalone]


#32044 — Re: ones complement, was Between

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-12-21 14:11 +0000
SubjectRe: ones complement, was Between
Message-ID<2015Dec21.151132@mips.complang.tuwien.ac.at>
In reply to#32026
Chris Gray <cg@GraySage.COM> writes:
>already5chosen@yahoo.com writes:
[unsigned instead of int]
>> It is very non-intuitive when we can't code a loop as "for (i = n; i >= 0; --i) ..."
...
>Personally, I think the preference could strongly relate to the background of
>the programmer, and to the nature of the programs they deal with.
>
>Myself, I mostly program system level stuff, compiler toolsets, and mostly
>non-graphic game stuff. In these things, nearly all "ints" are used as
>counters and array indexes. In both such situations a negative value is an
>error.

Or it's the boundary condition, as in the loop above.

Now, we could code the loop above as

for (i=n; i<=n; i--) ...

and it will perform the intended iterations, but this is harder to
understand, the generated code might be slower (the compiler may
preserve n, and may fail to use counted-loop instructions), and the
code is just as unsigned-specific as the other variant is
signed-specific.  Overall, not that great.

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


#32048 — Re: ones complement, was Between

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-12-21 16:08 +0100
SubjectRe: ones complement, was Between
Message-ID<n594kr$9kv$1@speranza.aioe.org>
In reply to#32044
Anton Ertl wrote:
> Now, we could code the loop above as
>
> for (i=n; i<=n; i--) ...

I.e.

unsigned n = ...;
for (unsigned i = n; i <= n; i--) {}

This works for all n except n == MAXUNSIGNED where it becomes an 
infinite loop.

n is of course iteration_count-1, so it cannot work if the count could 
be zero.

Writing

   for (unsigned i = n-1; i < (unsigned) (-1); i--) {}

makes it a bit more obvious that we are using wraparound from zero as 
the termination criteria.

>
> and it will perform the intended iterations, but this is harder to
> understand, the generated code might be slower (the compiler may
> preserve n, and may fail to use counted-loop instructions), and the
> code is just as unsigned-specific as the other variant is
> signed-specific.  Overall, not that great.

It is only in C(++) that this code is significantly better and that is 
because of all those undefined/implementation-defined C gotchas for ints.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#32050 — Re: ones complement, was Between

Fromnmm@wheeler.UUCP (Nick Maclaren)
Date2015-12-21 16:03 +0000
SubjectRe: ones complement, was Between
Message-ID<n597t1$u5l$1@dont-email.me>
In reply to#32048
In article <n594kr$9kv$1@speranza.aioe.org>,
Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
>Anton Ertl wrote:
>> Now, we could code the loop above as
>>
>> for (i=n; i<=n; i--) ...
>
>I.e.
>
>unsigned n = ...;
>for (unsigned i = n; i <= n; i--) {}
>
>This works for all n except n == MAXUNSIGNED where it becomes an 
>infinite loop.

Now try:

    for (unsigned i = 0; i < n; ++i)
        for (unsigned j = 0; j < n-1; ++j) {}

Oops.  what happens if n == 0?

The point is that loops like that are widespread in numerical code,
sorting algorithms, etc., etc.  Even programmers like you and I will
occasionally miss one and everything goes splat.  It's particularly
horrible when n == 0 is impossible in versions 1 to 9, but becomes
possible under difficult-to-create-to-order circumstances in later
versions.


Regards,
Nick Maclaren.

[toc] | [prev] | [next] | [standalone]


#32053 — Re: ones complement, was Between

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-12-21 16:18 +0000
SubjectRe: ones complement, was Between
Message-ID<2015Dec21.171818@mips.complang.tuwien.ac.at>
In reply to#32050
nmm@wheeler.UUCP (Nick Maclaren) writes:
>Now try:
>
>    for (unsigned i = 0; i < n; ++i)
>        for (unsigned j = 0; j < n-1; ++j) {}
>
>Oops.  what happens if n == 0?

The outer loop has 0 iterations.  Where is the problem?

Anyway, the problem we were discussing is how to write a
count-down-to-zero loop with an unsigned index.

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


Page 4 of 7 — ← Prev page 1 2 3 [4] 5 6 7  Next page →

Back to top | Article view | comp.arch


csiph-web