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


Groups > comp.os.vms > #378666

Re: JLine for VMS

From cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups comp.os.vms
Subject Re: JLine for VMS
Date 2026-03-30 01:39 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <10qck92$52n$1@reader2.panix.com> (permalink)
References <10pu8oa$10r0f$1@dont-email.me> <10qbf37$gk$1@panix2.panix.com> <10qbvrn$1qse2$1@dont-email.me> <69c98574$0$668$14726298@news.sunsite.dk>

Show all headers | View raw


In article <69c98574$0$668$14726298@news.sunsite.dk>,
Arne Vajhøj  <arne@vajhoej.dk> wrote:
>On 3/29/2026 3:51 PM, Arne Vajhøj wrote:
>> And most prefer while over repeat until, because
>> using while instead of repeat until is safe
>> but using repeat until instead of while is
>> not safe.
>> 
>> https://www.linkedin.com/posts/sdalbera_geekhumor-becauseitsfriday- 
>> activity-7438097776862986241-Tmj0/
>
>Once upon a time it was said that a bottom test was
>faster than a top test.

This is still kind of true, but not in the form presented; the
idea is to reduce the total number of unconditional jumps.

That is, given a loop like,

	let mut i = 0;
	while i < 10 {
		// Do something....
		i += 1;
	}

The compiler will often rewrite this to:

	mov r0, #0
	jmp cond
top:	// Do whatever.
	// Presumably a few instructions.
	add r0, r0, #1
cond:
	cmp r0, #10
	blt top

That is, by jumping to the condition at the bottom of the loop
and testing it there, and then jumping back to the top, the body
stays on the forward path and the only conditional branch is at
the end.

Indeed, for a loop like this, the compiler can even omit the
`jmp cond` before the loop: it knows that `r0` must be less than
10, since it just set it to 0, so it can walk right into the
first iteration:

	mov r0, #0
top:	// Do whatever
	// Probably more than one instruction.
	add r0, r0, #1
	cmp r0, #10
	blt top

But this is a concern for the compiler's optimizer, not the
programmer.

>Supposedly the reason that many Fortran 66 implementations
>had minimum of one iteration for DO loops.
>
>       DO 100 I=START,END
>          ...
>100   CONTINUE
>
>START=1 and END=1:
>
>Fortran 66 => 1 iteration
>Fortran 77 => 1 iteration
>
>START=1 and END=0:
>
>Fortran 66 => 0 or 1 iteration
>Fortran 77 => 0 iteration
>
>And I guess it was true.
>
>        movl    #1,r1
>100$:  cmpl    r1,#N
>        bgtr    200$:
>        ...
>        incl    r1
>        brb     100$
>200$:
>
>vs:
>
>        movl    #1,r1
>100$:  ...
>        incl    r1
>        cmpl    r1,#N
>        bleq    100$
>
>But doesn't matter any more today.

Sure it does.  This is the sort of thing that is _de rigueur_
for optimizing compilers.  But most programmers don't have to
think about it.

	- Dan C.

Back to comp.os.vms | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-24 10:57 -0400
  Re: JLine for VMS Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2026-03-24 18:15 +0000
    Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-24 14:29 -0400
      Re: JLine for VMS "Craig A. Berry" <craigberry@nospam.mac.com> - 2026-03-24 15:13 -0500
        Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-24 16:34 -0400
      Re: JLine for VMS cross@spitfire.i.gajendra.net (Dan Cross) - 2026-03-25 01:46 +0000
        Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-24 22:07 -0400
          Re: JLine for VMS Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-25 04:40 +0000
            Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-25 11:02 -0400
          Re: JLine for VMS cross@spitfire.i.gajendra.net (Dan Cross) - 2026-03-25 10:54 +0000
            Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-25 11:12 -0400
              Re: JLine for VMS cross@spitfire.i.gajendra.net (Dan Cross) - 2026-03-25 18:43 +0000
          Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-25 20:40 -0400
            Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-27 12:41 -0400
              Re: JLine for VMS Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2026-03-27 18:18 +0000
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-27 14:41 -0400
                Re: JLine for VMS Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2026-03-27 18:54 +0000
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-27 15:12 -0400
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-27 15:14 -0400
                Re: JLine for VMS hb0815 <mw40171@mucweb.de> - 2026-03-28 21:39 +0100
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-28 17:33 -0400
                Re: JLine for VMS hb0815 <mw40171@mucweb.de> - 2026-03-28 23:25 +0100
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-28 21:24 -0400
                Re: JLine for VMS hb0815 <mw40171@mucweb.de> - 2026-03-29 12:34 +0200
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-28 21:27 -0400
                Re: JLine for VMS Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-29 03:19 +0000
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-29 10:13 -0400
                Re: JLine for VMS kludge@panix.com (Scott Dorsey) - 2026-03-29 11:05 -0400
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-29 15:51 -0400
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-29 16:03 -0400
                Re: JLine for VMS cross@spitfire.i.gajendra.net (Dan Cross) - 2026-03-30 01:39 +0000
                Re: JLine for VMS Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2026-03-30 12:25 +0000
                Re: JLine for VMS Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-29 22:44 +0000
                Re: JLine for VMS hb0815 <mw40171@mucweb.de> - 2026-03-29 12:41 +0200
                Re: JLine for VMS Arne Vajhøj <arne@vajhoej.dk> - 2026-03-29 08:03 -0400
                Re: JLine for VMS hb0815 <mw40171@mucweb.de> - 2026-03-30 10:50 +0200
                Re: JLine for VMS Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-29 22:46 +0000

csiph-web