From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: cwitty@newtonlabs.com (Carl R. Witty) Newsgroups: gmane.lisp.guile.devel Subject: Re: gcc optimisation breaks guile floating point Date: 11 Sep 2002 18:46:47 -0700 Sender: guile-devel-admin@gnu.org Message-ID: References: <200208272110.OAA20247@onyx.he.net> <15723.64888.759743.439428@blauw.xs4all.nl> <8765xuzq57.fsf@zagadka.ping.de> <15725.21637.516981.623205@blauw.xs4all.nl> <200208301751.KAA21818@onyx.he.net> <15735.51280.569410.22724@blauw.xs4all.nl> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII X-Trace: main.gmane.org 1031795408 14277 127.0.0.1 (12 Sep 2002 01:50:08 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 12 Sep 2002 01:50:08 +0000 (UTC) Cc: Gary Houston , mvo@zagadka.ping.de, guile-devel@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17pJ7M-0003i0-00 for ; Thu, 12 Sep 2002 03:50:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17pJ7P-0000PA-00; Wed, 11 Sep 2002 21:50:07 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17pJ6f-0008GG-00 for guile-devel@gnu.org; Wed, 11 Sep 2002 21:49:21 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17pJ6d-0008DM-00 for guile-devel@gnu.org; Wed, 11 Sep 2002 21:49:20 -0400 Original-Received: from sense-newton-80.oz.net ([216.39.161.80] helo=quasar.newtonlabs.com) by monty-python.gnu.org with esmtp (Exim 4.10) id 17pJ6c-0007ZR-00 for guile-devel@gnu.org; Wed, 11 Sep 2002 21:49:18 -0400 Original-Received: from bogomips.newtonlabs.com (bogomips216 [216.39.155.135]) by quasar.newtonlabs.com (8.9.3/8.9.3/Debian/GNU) with ESMTP id SAA22049; Wed, 11 Sep 2002 18:46:48 -0700 Original-Received: (from cwitty@localhost) by bogomips.newtonlabs.com (8.9.3/8.9.3/Debian/GNU) id SAA01566; Wed, 11 Sep 2002 18:46:47 -0700 Original-To: hanwen@cs.uu.nl In-Reply-To: Han-Wen Nienhuys's message of "Thu, 5 Sep 2002 23:10:40 +0200" Original-Lines: 41 X-Mailer: Gnus v5.4.61/Emacs 19.34 Errors-To: guile-devel-admin@gnu.org X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.devel:1330 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:1330 Han-Wen Nienhuys writes: > ghouston@arglist.com writes: > > > > However scm_double_cell itself probably needs to be fixed, otherwise > > this problem will turn up again some day, or in user code (I'll look > > at it myself if it's still a problem in a couple of weeks.) > > I think the proper solution is some kind of asm/gcc statement that > prevents the reordering. Any C gurus that know a portable way of > ensuring that? A function call like scm_remember() from > scm_[double_]cell() defeats the purpose of inlining scm_[double_]cell. Under gcc, the following statement: asm volatile ("" : : : "memory"); is approximately what you want. This specifies the empty string as inline assembly (so nothing is actually inserted into the assembly output), but tells gcc that the instruction may read and write memory in arbitrary ways. Thus, gcc will not reorder memory reads or writes past this statement. Of course, this does have other undesirable effects on optimization -- gcc cannot reorder other, unrelated memory reads or writes past this statement either, and it also cannot keep values from memory cached in registers across the statement. It also only works with gcc. I'm unfamiliar with the exact definition of ANSI C, but I wonder if something like this might be correct: typedef union { long l; double d; } long_or_double; ... *((long_or_double *)z).l = 0; *((long_or_double *)z).d = x; Carl Witty _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel