www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Functions, intrinsics, flexibility

reply bearophile <bearophileHUGS lycos.com> writes:
I don't know what is the right design in this case. Intrinsics are useful
because they sometimes give more performance, but normal functions are
sometimes more handy because they allow more flexibility, like taking their
address ("first class functions"):


import std.math;
void main() {
    auto a = [&sin, &cos];
}


DMD 2.055:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test) 
 Error 42: Symbol Undefined _D3std4math3sinFNaNbNfeZe
test.obj(test) 
 Error 42: Symbol Undefined _D3std4math3cosFNaNbNfeZe

Isn't it possible to find some middle way that allows me to use std.math.sin as
true functions, while keeping the advantages of intrinsics?

(Currently I define wrapper functions like mysin, mycos, etc).

Bye,
bearophile
Sep 18 2011
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 09/18/2011 08:57 PM, bearophile wrote:
 I don't know what is the right design in this case. Intrinsics are useful
because they sometimes give more performance, but normal functions are
sometimes more handy because they allow more flexibility, like taking their
address ("first class functions"):


 import std.math;
 void main() {
      auto a = [&sin,&cos];
 }


 DMD 2.055:

 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 test.obj(test)
   Error 42: Symbol Undefined _D3std4math3sinFNaNbNfeZe
 test.obj(test)
   Error 42: Symbol Undefined _D3std4math3cosFNaNbNfeZe

 Isn't it possible to find some middle way that allows me to use std.math.sin
as true functions, while keeping the advantages of intrinsics?

 (Currently I define wrapper functions like mysin, mycos, etc).

 Bye,
 bearophile
+1, the compiler should just rewrite your example so that it 'just works'. An alternative to your fix is to create an object file that contains the appropriate symbols.
Sep 18 2011
parent reply =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 18-09-2011 21:47, Timon Gehr wrote:
 On 09/18/2011 08:57 PM, bearophile wrote:
 I don't know what is the right design in this case. Intrinsics are
 useful because they sometimes give more performance, but normal
 functions are sometimes more handy because they allow more
 flexibility, like taking their address ("first class functions"):


 import std.math;
 void main() {
 auto a = [&sin,&cos];
 }


 DMD 2.055:

 OPTLINK (R) for Win32 Release 8.00.12
 Copyright (C) Digital Mars 1989-2010 All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 test.obj(test)
 Error 42: Symbol Undefined _D3std4math3sinFNaNbNfeZe
 test.obj(test)
 Error 42: Symbol Undefined _D3std4math3cosFNaNbNfeZe

 Isn't it possible to find some middle way that allows me to use
 std.math.sin as true functions, while keeping the advantages of
 intrinsics?

 (Currently I define wrapper functions like mysin, mycos, etc).

 Bye,
 bearophile
+1, the compiler should just rewrite your example so that it 'just works'. An alternative to your fix is to create an object file that contains the appropriate symbols.
You could write a wrapper function that calls the intrinsic, but I suppose this defeats the purpose... - Alex
Sep 19 2011
parent Ary Manzana <ary esperanto.org.ar> writes:
On 9/19/11 3:32 PM, Alex Rønne Petersen wrote:
 On 18-09-2011 21:47, Timon Gehr wrote:
 On 09/18/2011 08:57 PM, bearophile wrote:
 I don't know what is the right design in this case. Intrinsics are
 useful because they sometimes give more performance, but normal
 functions are sometimes more handy because they allow more
 flexibility, like taking their address ("first class functions"):


 import std.math;
 void main() {
 auto a = [&sin,&cos];
 }


 DMD 2.055:

 OPTLINK (R) for Win32 Release 8.00.12
 Copyright (C) Digital Mars 1989-2010 All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 test.obj(test)
 Error 42: Symbol Undefined _D3std4math3sinFNaNbNfeZe
 test.obj(test)
 Error 42: Symbol Undefined _D3std4math3cosFNaNbNfeZe

 Isn't it possible to find some middle way that allows me to use
 std.math.sin as true functions, while keeping the advantages of
 intrinsics?

 (Currently I define wrapper functions like mysin, mycos, etc).

 Bye,
 bearophile
+1, the compiler should just rewrite your example so that it 'just works'. An alternative to your fix is to create an object file that contains the appropriate symbols.
You could write a wrapper function that calls the intrinsic, but I suppose this defeats the purpose... - Alex
Or maybe you could define a wrapper function that calls the intrinsic...
Sep 19 2011