Language:
switch to room list switch to menu My folders
Go to page: First ... 99 100 101 102 [103] 104 105 106 107 ... Last
[#] Wed Jun 01 2011 18:56:14 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I think Duff actually mentions that some optimizing compilers may be able to recognize what a rolled-up loop structure is doing and pick the fastest assembly code. In which case, using his technique may not get you any performance gains.

[#] Wed Jun 01 2011 18:19:27 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

and if you're going to use labels, you're sorta defeating the purpose of structured procedural programming.

The way I heard it the first time was that duffs device allows you to jump into the middle of a loop so you don't have to handle a start/end case pile of code before or after the loop.
That sounds great from a pretty programming point of view, but duffs device isn't terribly pretty to look at, and what really matters is what it compiles into, which I haven't actually seen, so maybe it's a better deal.
Seems to me an optimizer would detect a copy of some code handling the after-loop case and end up with the same result as if you had written duffs device.

[#] Wed Jun 01 2011 20:03:32 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

 

Wed Jun 01 2011 16:17:32 EDT from Spell Binder @ Uncensored
In a way, the case's in a switch statement are essentially go-to labels, so any situation that might require the flexibility of a label could probably be made somewhat more organized by using a switch statement instead.

For me, though, the more bizarre part is the way it continues within the loop... it's like jumping to the middle of the loop without even looking at the 'while' or 'for' statement, yet still working within the loop.  While I know better, my mind kind of feels like the evaluation is 'set up' at the beginning, and must be viewed before working within the loop's block.



[#] Wed Jun 01 2011 22:58:21 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I think Duff actually mentions that some optimizing compilers may be

able to recognize what a rolled-up loop structure is doing and pick the


gcc -O3 -funroll-loops/-funroll-all-loops

[#] Wed Jun 01 2011 22:57:47 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


Which is why, IIRC, the loop in duff's device is usually a do {} while ();

[#] Mon Jun 06 2011 17:42:33 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I think Duff actually mentions that some optimizing compilers may be

able to recognize what a rolled-up loop structure is doing and pick the

fastest assembly code. In which case, using his technique may not get

you any performance gains.

Also keep in mind duff wrote that in 1988 or something, and optimizing compilers have come a long way in 23 years.

[#] Mon Jun 06 2011 17:46:57 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Optimize-Options.html

So I started reading that.
my god. I'm old.

[#] Mon Jun 06 2011 18:19:24 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Jun 1 2011 3:38pm from fleeb @uncnsrd
Well... it is useful in a very, very specific way.  You can
implement coroutines in C/C++ with them.  So the problems solved
best by co-routines are best solved with Duff's Device.


co-routines, at least in the context of the Simon Tatham link mentioned previousluy, appear equivalent to the generators construct in languages like Python, Scala and Erlang.


Far preferable to have first-class language support for that sort of thing.

[#] Mon Jun 06 2011 20:56:01 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I definitely agree with that.  Explicit language support for any particular comp-sci technique is far preferable to trickery.



[#] Mon Jun 06 2011 23:06:00 EDT from IGnatius T Foobar @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I suppose that the caller/callee conundrum would also be mitigated if the program is event driven.

(LS's favorite State Machine poem is included herein by reference.)

[#] Tue Jun 07 2011 18:42:10 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


<toothy grin>

[#] Tue Jun 07 2011 19:47:08 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

It's possible to fake generators in Java, as well - using exceptions for flow control (a trick that's used by at least one JVM-hosted higher-level language.)

This allows one to write lazy iterators using an unusual, but comprehensible idiom:

public final class Generator
extends HateMachine<Integer>
{
private int i;

@Override
protected void generate()
{
for (; i <= 3; i++ )
{
yield( i );
}
}
}

yield() is internally implemented, in base class HateMachine, as

protected final void yield( T value )
{
throw new YieldException( value );
}

... the rest of the base class is simple enough, yet totally revolting, and therefore left as an exercise to the reader.

[#] Wed Jun 08 2011 00:06:13 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


SPOT THE BUG!

[#] Wed Jun 08 2011 07:47:09 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

you didn't init i.

[#] Wed Jun 08 2011 07:48:20 EDT from Ford II @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I see what that example does, but I don't see the point.
you call generate, and an exception gets thrown that nobody nearby catches... so?

[#] Wed Jun 08 2011 11:42:47 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


;) It's pretty horrible, eh? But no, you don't need to init i.

[#] Wed Jun 08 2011 12:03:23 EDT from Spell Binder @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

Is the bug the fact that generate() was declared with a void return type?

As I understand it, the idea of a generator is that each time it gets invoked, it returns the next value, so it would be called something like this.

Generator gen = new Generator();
int x = gen.generate(); // x == 0
x = gen.generate(); // x == 1
...

If I'm understand it properly, generate() should be declared to return int.
Java Binder

[#] Wed Jun 08 2011 13:26:57 EDT from LoanShark @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]


the bug is that I never should have posted it (and that it needs to be yield (++i) instead of yield(i) otherwise increment never happens)

For a *proper* example of using exceptions for flow control in order to fake state machines, see Scala's actors library:

http://www.scala-lang.org/node/242

[#] Wed Jun 08 2011 13:57:21 EDT from fleeb @ Uncensored

[Reply] [ReplyQuoted] [Headers] [Print]

I did not realize today is IPV6 day.

Which is a good thing.



[#] Thu Jun 09 2011 03:07:01 EDT from Nite*Star @ Uncensored

Subject: Re:

[Reply] [ReplyQuoted] [Headers] [Print]

Feb 9 2011 9:51pm from IGnatius T Foobar @uncnsrd in Tech Area>
Subject: Re:
Keep saying the word "freeware" a lot. Maybe it'll make RMS's head
explode.

So a site like one of my clients, http://freewarehome.com/ would probably give RMS a stroke? o.O

Go to page: First ... 99 100 101 102 [103] 104 105 106 107 ... Last