From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27102 invoked by alias); 27 Apr 2012 14:53:45 -0000 Received: (qmail 27085 invoked by uid 22791); 27 Apr 2012 14:53:44 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ob0-f175.google.com (HELO mail-ob0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Apr 2012 14:53:31 +0000 Received: by obhx4 with SMTP id x4so30855obh.20 for ; Fri, 27 Apr 2012 07:53:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding:x-system-of-record :x-gm-message-state; bh=eq3964g00xIqF7DlsXud+X0XTXEUOQvUiM5E8n1gjLE=; b=iIIbL5vKBZWVFmnH0BfH562mdj0HyDG2C+0jN12bXtZmEXY8y/4asc4Fm+WlRTgtPt RiUZisVSxJuC/Md4xmkmV/zPbyPX2oEsdQe/DNITUwgHo9yVph5sOqz5GHCxWxbh5cKH aVJjZoa15yQyNo17q3o0fpySdMnqFc82d4fdHabzctghosznunKT5o2lmJMWFLSWu8pc 2dsoeMm7yPyjwbCVFB+eh/EELJoH2hI7lMCwRzbfR+0sHBJwPPi4147SYkdOSMP/rBx4 MZLXMQ5H6tGYKOPlx3mlrE2nlOyvU8IpZ4Hez3Czr0Io4dhRjqInpCYWaWU6TaPxdsO5 OpZw== Received: by 10.182.112.41 with SMTP id in9mr14926972obb.40.1335538410407; Fri, 27 Apr 2012 07:53:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.112.41 with SMTP id in9mr14926950obb.40.1335538410266; Fri, 27 Apr 2012 07:53:30 -0700 (PDT) Received: by 10.182.147.104 with HTTP; Fri, 27 Apr 2012 07:53:30 -0700 (PDT) In-Reply-To: References: <20120307004630.A503DB21B6@azwildcat.mtv.corp.google.com> Date: Fri, 27 Apr 2012 14:53:00 -0000 Message-ID: Subject: Re: User directed Function Multiversioning via Function Overloading (issue5752064) From: Sriraman Tallam To: "H.J. Lu" Cc: Richard Guenther , Jan Hubicka , Uros Bizjak , reply@codereview.appspotmail.com, gcc-patches@gcc.gnu.org, David Li Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-Gm-Message-State: ALoCoQlMc71VRjunwp9BEH3vUAxpLoD+OoXe0eLkyLbYftkfbC+Mss/ZUSnWRE6gEwNDSA2p1nuc2cHEETGINtTCe5WDTbf8HfQMU6NwwlUp+UEsBrXu7yeboOZg15AIUWvMJUuRa/v3VRv/hHIkydBsgO5R1kcM4A== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg01776.txt.bz2 On Fri, Apr 27, 2012 at 7:38 AM, H.J. Lu wrote: > On Fri, Apr 27, 2012 at 7:35 AM, Sriraman Tallam wr= ote: >> On Fri, Apr 27, 2012 at 6:38 AM, H.J. Lu wrote: >>> On Thu, Apr 26, 2012 at 10:08 PM, Sriraman Tallam = wrote: >>>> Hi, >>>> >>>> =A0 I have made the following changes in this new patch which is attac= hed: >>>> >>>> * Use target attribute itself to create function versions. >>>> * Handle any number of ISA names and arch=3D =A0args to target attribu= te, >>>> generating the right dispatchers. >>>> * Integrate with the CPU runtime detection checked in this week. >>>> * Overload resolution: If the caller's target matches any of the >>>> version function's target, then a direct call to the version is >>>> generated, no need to go through the dispatching. >>>> >>>> Patch also available for review here: >>>> http://codereview.appspot.com/5752064 >>>> >>> >>> Does it work with >>> >>> int foo (); >>> int foo () __attribute__ ((targetv("arch=3Dcorei7"))); >>> >>> int (*foo_p) () =3D foo? >> >> Yes, this will work. foo_p will be the address of the dispatcher >> function and hence doing (*foo_p)() will call the right version. > > Even when foo_p is a global variable and compiled with -fPIC? I am not sure I understand what the complication is here, but FWIW, I tried this example and it works int foo () { return 0; } int __attribute__ ((target ("arch=3Dcorei7))) foo () { return 1; } int (*foo_p)() =3D foo; int main () { return (*foo_p)(); } g++ -fPIC -O2 example.cc Did you have something else in mind? Could you please elaborate if you a have a particular case in mind. The way I handle function pointers is straightforward. When the front-end sees a pointer to a function that is versioned, it returns the pointer to the dispatcher instead. Thanks, -Sri. > > Thanks. > > -- > H.J.