From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.devel Subject: Re: Redundant type checking in window.c and w32menu.c Date: Wed, 20 Jun 2007 18:12:26 +0400 Message-ID: <467935CA.9020808@yandex.ru> References: <4677EBCA.7020405@yandex.ru> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040000090403050909070602" X-Trace: sea.gmane.org 1182348899 8024 80.91.229.12 (20 Jun 2007 14:14:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 20 Jun 2007 14:14:59 +0000 (UTC) Cc: Ken Raeburn To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 20 16:14:58 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I10xO-0000fr-OR for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2007 16:14:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I10xN-0002v4-C3 for ged-emacs-devel@m.gmane.org; Wed, 20 Jun 2007 10:14:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I10xG-0002uE-4R for emacs-devel@gnu.org; Wed, 20 Jun 2007 10:14:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I10xF-0002tm-3M for emacs-devel@gnu.org; Wed, 20 Jun 2007 10:14:41 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I10xE-0002tf-TE for emacs-devel@gnu.org; Wed, 20 Jun 2007 10:14:40 -0400 Original-Received: from smtp3.yandex.ru ([213.180.200.14]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I10x5-0007tY-Ha; Wed, 20 Jun 2007 10:14:34 -0400 Original-Received: from rtsoft2.corbina.net ([85.21.88.2]:18401 "EHLO [192.168.1.172]" smtp-auth: "dmantipov" TLS-CIPHER: TLS-PEER-CN1: ) by mail.yandex.ru with ESMTP id S4748075AbXFTOO0 (ORCPT + 1 other); Wed, 20 Jun 2007 18:14:26 +0400 X-Comment: RFC 2476 MSA function at smtp3.yandex.ru logged sender identity as: dmantipov User-Agent: Thunderbird 1.5.0.7 (X11/20061008) In-Reply-To: X-detected-kernel: Linux 2.6 (newer, 1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:73427 Archived-At: This is a multi-part message in MIME format. --------------040000090403050909070602 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Ken Raeburn wrote: > On Jun 19, 2007, at 10:44, Dmitry Antipov wrote: >> If we pass CHECK_CONS(), we don't need CONSP()s in Fcar() and Fcdr() >> and may use XCAR() >> and XCDR() instead. > > Makes sense. Whoops, probably not for GNU C :-). At least with -O1 and -O2, GCC (I've tested with 4.1.2) emits an almost identical and optimal (i.e. with the only branch ends with a call of wrong_type_argument ()) code for both cases CHECK_CONS (obj); x = CAR (obj); y = CDR (obj); and CHECK_CONS (obj); x = XCAR (obj); y = XCDR (obj); Have no ideas about other compilers. > You could make Fcar a static inline function in lisp.h (conditional on > GCC, or maybe C99). If the optimizer's good at its job, it should > eliminate the redundant CONSP checks. Using an inline function avoids > having to check all Fcar uses for arguments that have function calls or > side effects. (A quick grep shows several of those. In fact, if your > test used the simple macro version, inline functions may result in less > code size expansion because of this.) And personally, I think inline > functions are often more readable than macros, if they're not very > simple macros. I agree, and here is the stuff I'm trying now. Reordering of data.c looks ugly, but I have no ideas on how to avoid them :-(. Dmitry --------------040000090403050909070602 Content-Type: text/plain; name="inline_cons_fns.patch" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="inline_cons_fns.patch" SW5kZXg6IGRhdGEuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvc291cmNlcy9lbWFjcy9l bWFjcy9zcmMvZGF0YS5jLHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjI3MQpkaWZmIC11IC1y MS4yNzEgZGF0YS5jCi0tLSBkYXRhLmMJMjYgTWF5IDIwMDcgMTc6MjE6MTQgLTAwMDAJMS4y NzEKKysrIGRhdGEuYwkyMCBKdW4gMjAwNyAxNDoxMTowMCAtMDAwMApAQCAtNTA2LDQ5ICs1 MDYsNiBAQAogICByZXR1cm4gUW5pbDsKIH0KIAotDAotLyogRXh0cmFjdCBhbmQgc2V0IGNv bXBvbmVudHMgb2YgbGlzdHMgKi8KLQotREVGVU4gKCJjYXIiLCBGY2FyLCBTY2FyLCAxLCAx LCAwLAotICAgICAgIGRvYzogLyogUmV0dXJuIHRoZSBjYXIgb2YgTElTVC4gIElmIGFyZyBp cyBuaWwsIHJldHVybiBuaWwuCi1FcnJvciBpZiBhcmcgaXMgbm90IG5pbCBhbmQgbm90IGEg Y29ucyBjZWxsLiAgU2VlIGFsc28gYGNhci1zYWZlJy4KLQotU2VlIEluZm8gbm9kZSBgKGVs aXNwKUNvbnMgQ2VsbHMnIGZvciBhIGRpc2N1c3Npb24gb2YgcmVsYXRlZCBiYXNpYwotTGlz cCBjb25jZXB0cyBzdWNoIGFzIGNhciwgY2RyLCBjb25zIGNlbGwgYW5kIGxpc3QuICAqLykK LSAgICAgKGxpc3QpCi0gICAgIHJlZ2lzdGVyIExpc3BfT2JqZWN0IGxpc3Q7Ci17Ci0gIHJl dHVybiBDQVIgKGxpc3Qp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YWZl KGMpIF9GQ0FSX1NBRkUgKGMpCisjZGVmaW5lIEZjZHIoYykgX0ZDRFIgKGMpCisjZGVmaW5l IEZjZHJfc2FmZShjKSBfRkNEUl9TQUZFIChjKQorCisjdW5kZWYgQ09OU0ZOCisKKyNlbHNl CisKIEVYRlVOIChGY2FyLCAxKTsKIEVYRlVOIChGY2FyX3NhZmUsIDEpOwogRVhGVU4gKEZj ZHIsIDEpOwogRVhGVU4gKEZjZHJfc2FmZSwgMSk7CisKKyNlbmRpZiAvKiBfX0dOVUNfXyAm JiBfX09QVElNSVpFX18gJiYgIV9fT1BUSU1JWkVfU0laRV9fICovCisKIEVYRlVOIChGc2V0 Y2FyLCAyKTsKIEVYRlVOIChGc2V0Y2RyLCAyKTsKIEVYRlVOIChGYm91bmRwLCAxKTsK --------------040000090403050909070602 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --------------040000090403050909070602--