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


Groups > comp.lang.python > #57903 > unrolled thread

Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea.

Started by"Skybuck Flying" <Windows7IsOK@DreamPC2006.com>
First post2013-10-29 12:37 +0100
Last post2013-11-03 15:17 +1100
Articles 7 on this page of 27 — 10 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2013-10-29 12:37 +0100
    Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-29 14:08 +0000
      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-10-29 13:00 -0700
        Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve@pearwood.info> - 2013-10-30 10:22 +0000
          Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-10-30 19:48 -0700
            Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve@pearwood.info> - 2013-10-31 08:41 +0000
              Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-10-31 21:41 -0700
                Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-01 05:41 +0000
                  Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-11-01 18:50 -0700
                    Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-02 03:52 +0000
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-11-03 09:46 -0800
                  Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Joshua Landau <joshua@landau.ws> - 2013-11-02 18:22 +0000
                    Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-03 05:17 +0000
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-03 10:45 +0100
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-11-03 09:50 -0800
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-03 19:49 +0100
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Ben Finney <ben+python@benfinney.id.au> - 2013-11-04 09:11 +1100
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-04 09:38 +0100
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Ben Finney <ben+python@benfinney.id.au> - 2013-11-04 20:07 +1100
                      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-04 10:38 +0100
                  Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-02 18:36 +0000
                Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-01 13:50 +0100
                  Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. rurpy@yahoo.com - 2013-11-01 18:51 -0700
                    Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-11-02 12:15 +0100
    Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Bernhard Schornak <schornak@web.de> - 2013-11-01 00:53 +0100
      Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. "Skybuck Flying" <Windows7IsOK@DreamPC2006.com> - 2013-11-02 20:49 +0100
        Re: Possibly better loop construct, also labels+goto important and on the fly compiler idea. Chris Angelico <rosuav@gmail.com> - 2013-11-03 15:17 +1100

Page 2 of 2 — ← Prev page 1 [2]


#58342

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-11-02 18:36 +0000
Message-ID<mailman.1957.1383417435.18130.python-list@python.org>
In reply to#58240
On 02/11/2013 18:22, Joshua Landau wrote:
> On 1 November 2013 05:41, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> On Thu, 31 Oct 2013 21:41:32 -0700, rurpy wrote:
>>
>>> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>>>> On Wed, 30 Oct 2013 19:48:55 -0700, rurpy wrote:
>>>>> On 10/30/2013 04:22 AM, Steven D'Aprano wrote:
>>>>>> Skybuck's experience at programming *is relevant* to the question of
>>>>>> whether or not he understands what he is talking about.
>>>>> No.  You claimed his proposition "made no sense" based on your
>>>>> analysis of it.
>>>>
>>>> I said absolutely nothing of the sort. You're making that quote up --
>>>> not just misinterpreting what I said, or taking my words in the worst
>>>> possible way, but completely inventing things I never said.
>>>
>>> Yes, on rereading you are correct, you did not say his proposition made
>>> no sense, you disagreed with him that "putting this exit condition on
>>> the top makes no sense" and claimed he had no business making such a
>>> statement
>>
>> I said nothing of the sort.
>
> Personally, rurpy's reading seems like a reasonable one to me. Maybe
> not correct in a technical sense, but at least reasonable.
>
> Particularly, the phrase
>
> "Wait until you actually start programming before deciding what makes
> sense or doesn't."
>
> seems especially harsh, and would be furthermore so should Skybuck be
> a professional programmer. That's a phrase easy to take badly,
> especially over this medium.
>
> Sure, you in all probability didn't mean it like that but rurpy isn't
> uncalled for in raising the concern. Really I just want to remind you
> that you're both on the same side here.
>

Coming from me this is probably a classic case of pot calling the kettle 
black, but how about reading the Spike Milligan story The White Flag 
before this also escalates out of control.

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

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


#58259

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-01 13:50 +0100
Message-ID<mailman.1925.1383310281.18130.python-list@python.org>
In reply to#58239
Op 01-11-13 05:41, rurpy@yahoo.com schreef:
> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
> 
>> I don't know whether you are deliberately lying, or whether you're just 
>> such a careless reader that you have attributed words actually written by 
>> Skybuck to me, but either way I expect an apology from you for putting 
>> false words into my mouth.
> 
> An apology is due when someone does some damage to things 
> or people (including reputation or feelings) that should 
> have been avoided.
> 
> My overstating your disagreement with Skybuck was inadvertent, 
> does not change the points I was making (it does not matter 
> whether you thought he was wrong or nutty) and did no 
> significant damage to you or your reputation.  

It seems rather obvious from Steven's reaction, your overstatement
hurt (damaged) his feelings. Since you ackowleged that damaged
feelings are cause for an apology, it seems by your own words
an apology is due.

-- 
Antoon Pardon

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


#58308

Fromrurpy@yahoo.com
Date2013-11-01 18:51 -0700
Message-ID<5f4a4fee-4dcd-41de-bbb3-58244ce81a01@googlegroups.com>
In reply to#58259
On 11/01/2013 06:50 AM, Antoon Pardon wrote:
> Op 01-11-13 05:41, rurpy@yahoo.com schreef:
>> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>> 
>>> I don't know whether you are deliberately lying, or whether you're just 
>>> such a careless reader that you have attributed words actually written by 
>>> Skybuck to me, but either way I expect an apology from you for putting 
>>> false words into my mouth.
>> 
>> An apology is due when someone does some damage to things 
>> or people (including reputation or feelings) that should 
>> have been avoided.
>> 
>> My overstating your disagreement with Skybuck was inadvertent, 
>> does not change the points I was making (it does not matter 
>> whether you thought he was wrong or nutty) and did no 
>> significant damage to you or your reputation.  
> 
> It seems rather obvious from Steven's reaction, your overstatement
> hurt (damaged) his feelings. 

It it not obvious to me at all.

> Since you ackowleged that damaged
> feelings are cause for an apology, it seems by your own words
> an apology is due.

I explained why an apology was not appropriate previously.

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


#58321

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-11-02 12:15 +0100
Message-ID<mailman.1948.1383391189.18130.python-list@python.org>
In reply to#58308
Op 02-11-13 02:51, rurpy@yahoo.com schreef:
> On 11/01/2013 06:50 AM, Antoon Pardon wrote:
>> Op 01-11-13 05:41, rurpy@yahoo.com schreef:
>>> On 10/31/2013 02:41 AM, Steven D'Aprano wrote:
>>>
>>>> I don't know whether you are deliberately lying, or whether you're just 
>>>> such a careless reader that you have attributed words actually written by 
>>>> Skybuck to me, but either way I expect an apology from you for putting 
>>>> false words into my mouth.
>>>
>>> An apology is due when someone does some damage to things 
>>> or people (including reputation or feelings) that should 
>>> have been avoided.
>>>
>>> My overstating your disagreement with Skybuck was inadvertent, 
>>> does not change the points I was making (it does not matter 
>>> whether you thought he was wrong or nutty) and did no 
>>> significant damage to you or your reputation.  
>>
>> It seems rather obvious from Steven's reaction, your overstatement
>> hurt (damaged) his feelings. 
> 
> It it not obvious to me at all.

Shouldn't you be erring on the safe side? Rather issue an appology
when it may not be really needed than refuse to give one when it
may be appropiate?

>> Since you ackowleged that damaged
>> feelings are cause for an apology, it seems by your own words
>> an apology is due.
> 
> I explained why an apology was not appropriate previously.

No you didn't. What you did was trying to minimize your contribution.

-- 
Antoon Pardon

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


#58218

FromBernhard Schornak <schornak@web.de>
Date2013-11-01 00:53 +0100
Message-ID<l4uqik$qt2$1@dont-email.me>
In reply to#57903
Skybuck Flying wrote:


 >> Because it's logical.
 >
 > "
 > What is logical?
 > "
 >
 > To put the exit condition at the bottom is logical.


As "logical" as to put it anywhere else inside the loop body. As long as we write code
on machine language level, we are asked to choose the most efficient instruction chain
we can find. The decision where to place which instructions is up to the programmers -
not to a counter-productive "Universal Law".


 > The exit condition glues the loop to the code that will be executed next which is also at the bottom.
 >
 > Example:
 >
 > Loop
 >
 > NextCode


Yes. As you should know, jump targets should be aligned to 32 byte boundaries to avoid
prefetch stalls. Hence, it is absolutely illogical to let a loop run into a set of NOP
instructions at the bottom of the loop's body. Therefore, we had to end each loop with
a jump to the next label to avoid the execution of a couple of extra NOP instructions.
This is as illogical as the attempt to declare some artificial restrictions as the new
Non-Plus-Ultra of programming.


 > Placing the exit ondition near next code makes more sense at least in situation where I was
 > programming.
 >
 > I will give you an example:
 >
 >
 >
 > LoopBegin( Step = 10 )
 >
 >     if ButtonExists then
 >     begin
 >         ClickButton()
 >     end;
 >
 > LoopEnd( ButtonClicked )
 >
 > Execute next code...
 >
 > This loop waits for the button to appear, once it's found it is clicked and then the loop exits to
 > continue the next code.
 >
 > Putting this exit condition on the top makes no sense.


Ever thought about how a compiler might translate this construct? Here are 2 partially
optimised results:

ButtonExists  = bit 0 in RCX
ButtonClicked = bit 1 in RCX

       ...
       movl  $0x0A, %ebp
       testl $0x01, %ecx        # does button exist?
       je    1f
       jmp   0f

       .p2align 5,,31
     0:decl  %ebp
       je    1f
       call  _ClickButton
       jmp   0b

       .p2align 5,,31
      1:orl  $0x02, %ecx        # button was clicked ten times...
       ...


Alternative:

       ...
       movl  $0x0A, %ebp
       testl $0x01, %ecx        # does button exist?
       je    1f
       jmp   0f

       .p2align 5,,31
     0:call  _ClickButton
       decl  %ebp
       jne   0b
       jmp   1f

       .p2align 5,,31
      1:orl  $0x02, %ecx        # button was clicked ten times...
       ...


The code with the conditional branch at top is faster than the alternative code,
because putting calls at places used as branch target, even if properly aligned,
is punished with some penalty cycles. As the loop ends at the bottom, we have to
insert a second jump to bypass the second set of NOPs.

Placing an exit condition at the top possibly looks odd for HLL programmers, but
it's faster in many cases. Placing all exit conditions at the bottom of the loop
body can never be faster, but often will be the slower solution.

You should translate your HLL constructs into simple machine language before you
start to declare "Universal Laws" which are none.

I am still wondering why you post to alt.lang.asm if you do not accept that your
proposals are analysed and their flaws are revealed. ;)


BTW: If this button ever existed, it'll exist throughout the runtime of the loop
without disappearing.  Hence, it is not necessary to query its existence in each
iteration, because it costs a lot of precious time. The best solution is the one
above - check if the button exists, then start the loop.


Greetings from Augsburg

Bernhard Schornak

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


#58361

From"Skybuck Flying" <Windows7IsOK@DreamPC2006.com>
Date2013-11-02 20:49 +0100
Message-ID<6724c$5275cd26$5419b3e4$20097@cache80.multikabel.net>
In reply to#58218
For those programmers that want to write clear/understandable/less buggy 
code instead of the fastest it could be interesting.

Also ultimately compilers are free to implement it they way they want it ;) 
Thus freeing the programmer from strange assembler instruction orders as 
usual ;)

If you ever would like to write your own compiler you are free to implement 
it the way you want it and thus hopefully your assembler analysis makes 
sense ;)

Bye,
  Skybuck.

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


#58362

FromChris Angelico <rosuav@gmail.com>
Date2013-11-03 15:17 +1100
Message-ID<mailman.1966.1383452259.18130.python-list@python.org>
In reply to#58361
On Sun, Nov 3, 2013 at 6:49 AM, Skybuck Flying
<Windows7IsOK@dreampc2006.com> wrote:
> For those programmers that want to write clear/understandable/less buggy
> code instead of the fastest it could be interesting.

"it", without context? What could be interesting? You're not quoting
any text, so I have no idea what you're referring to. Correspondingly
in your other paragraphs.

ChrisA

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web