Returning tuples from functions
Don Clugston
dac at nospam.com.au
Tue May 1 23:22:57 PDT 2007
Jari-Matti Mäkelä wrote:
> Jari-Matti Mäkelä wrote:
>
>> BCS wrote:
>>
>>> niovol wrote:
>>>> When will it be possible? I have almost no experience in programming on
>>>> D. But I can't imagine how to solve my problem without using tuples.
>>> Here's a nasty hack I came up with a while ago
>>>
>> <snipped the nasty hack>
>>
>> The only problem is that the struct version is 27 opcodes or 150% longer
>> that the inout/ref version at least on DMD/Linux. These hacks aren't very
>> useful until the optimizer gets better or something else great happens.
>
> It would also help the expression template code. I tried to come up with an
> optimal version of adding matrices with a regular D syntax, but the
> compiler couldn't remove some of the intermediate structs. I then tried the
> example code from Don's BLADE, but even it didn't produce optimal code. Has
> anyone found a solution to this?
It's a problem; the generated tuple handling code is horrible. I've
abandoned the idea of using tuples and expression templates.
I don't think an improved optimizer is
> enough, there should be a way to pass these 'AST references' at compile
> time.
I agree. My latest BLADE experiments use text mixins instead. There are
a lot of advantages to doing it this way.
So far, I haven't hooked up the asm code generation, but right now it
generates D code in-line. (No function call overhead whatsoever).
Incidentally, I'm also coming to the conclusion that operator
overloading is a bit of a flawed concept. For almost every case where
you'd want to use them, the code generation is terrible. You really want
to see the whole expression before you generate code.
(eg, a = b + a; can almost always be done more efficiently as a+=b).
More information about the Digitalmars-d
mailing list