From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#41615: [feature/native-comp] Dump prettier C code. Date: Mon, 01 Jun 2020 20:28:59 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="112250"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 41615@debbugs.gnu.org To: Nicolas =?UTF-8?Q?B=C3=A9rtolo?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 01 22:30:14 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfr4W-000T6Y-Rx for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Jun 2020 22:30:12 +0200 Original-Received: from localhost ([::1]:48724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jfr4V-0007tX-Te for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Jun 2020 16:30:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfr4N-0007sY-8O for bug-gnu-emacs@gnu.org; Mon, 01 Jun 2020 16:30:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jfr4M-0005CN-Ug for bug-gnu-emacs@gnu.org; Mon, 01 Jun 2020 16:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jfr4M-0006zx-PB for bug-gnu-emacs@gnu.org; Mon, 01 Jun 2020 16:30:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Jun 2020 20:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41615 X-GNU-PR-Package: emacs Original-Received: via spool by 41615-submit@debbugs.gnu.org id=B41615.159104334526820 (code B ref 41615); Mon, 01 Jun 2020 20:30:02 +0000 Original-Received: (at 41615) by debbugs.gnu.org; 1 Jun 2020 20:29:05 +0000 Original-Received: from localhost ([127.0.0.1]:37107 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfr3R-0006yW-E5 for submit@debbugs.gnu.org; Mon, 01 Jun 2020 16:29:05 -0400 Original-Received: from mx.sdf.org ([205.166.94.20]:62190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfr3O-0006yB-QI for 41615@debbugs.gnu.org; Mon, 01 Jun 2020 16:29:03 -0400 Original-Received: from sdf.org (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 051KT0gE003673 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Mon, 1 Jun 2020 20:29:01 GMT Original-Received: (from akrl@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 051KSxAp008937; Mon, 1 Jun 2020 20:28:59 GMT In-Reply-To: ("Nicolas =?UTF-8?Q?B=C3=A9rtolo?="'s message of "Mon, 1 Jun 2020 09:25:18 -0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181378 Archived-At: Nicolas B=C3=A9rtolo writes: > I rewrote the "cast with functions" patch and added a few more patches. > - Implement cast to bool as !!x instead of (x & 0xFF). > - Throw an ICE when asked to perform sign extension. I didn't see any > issues with this one. So for now it is not necessary to implement them. > > Nico. > > From 39b8d7b0bbcda4f4f34759b02cc2cf30523536ff Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Nicol=3DC3=3DA1s=3D20B=3DC3=3DA9rtolo?=3D > Date: Sun, 31 May 2020 17:24:03 -0300 > Subject: [PATCH 3/4] Implement casts to bool using double negation like i= n C. As I commented early I think this would be not ideal. The trick of the negation is done already in emit_cond_jump and regarding the cast operation I think is important to keep the C semantic (that is the one we have). I pushed the others with some very minor change, have a look. > From 435ed84c6df4911b238f67c79492533e0c71ca46 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Nicol=3DC3=3DA1s=3D20B=3DC3=3DA9rtolo?=3D > Date: Sun, 31 May 2020 18:09:12 -0300 > Subject: [PATCH 4/4] Throw an ICE when asked to emit a cast with sign > extension. > > * src/comp.c (cast_kind_of_type): Enum that specifies the kind of type > in the cast enum (unsigned, signed, pointer). > (emit_coerce): Throw an ICE when asked to emit a cast with sign > extension. > (define_cast_from_to): Return NULL for casts involving sign extension. > (define_cast_functions): Specify the kind of each type in the cast > union. > --- > src/comp.c | 58 ++++++++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 43 insertions(+), 15 deletions(-) > [...] > typedef struct { > @@ -514,6 +521,7 @@ #define NUM_CAST_TYPES 15 > member. */ > gcc_jit_type *cast_types[NUM_CAST_TYPES+1]; > size_t cast_type_sizes[NUM_CAST_TYPES+1]; > + enum cast_kind_of_type cast_type_kind[NUM_CAST_TYPES+1]; I've just added the spaces around + (here and for the other). > From ec7af221c7dbf9b9fc551ef38d6e70a1bf09d4e8 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Nicol=3DC3=3DA1s=3D20B=3DC3=3DA9rtolo?=3D > Date: Sun, 31 May 2020 15:55:18 -0300 > Subject: [PATCH 1/4] Remove unnecessary DLL load of > gcc_jit_block_add_assignment_op. I've jsut added a bare ChangeLog entry, pushed. > From 91189343ccd6943eafc2f3dc8b3b19b8ea879903 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Nicol=3DC3=3DA1s=3D20B=3DC3=3DA9rtolo?=3D > Date: Sat, 30 May 2020 18:33:58 -0300 > Subject: [PATCH 2/4] Define casts using functions. > > This is to dump prettier C files. > This does not affect compilation times in my tests. > > * src/comp.c: Define a 15x15 cast matrix. Use it in emit_coerce(). [...] > static gcc_jit_rvalue * > @@ -1090,7 +1041,7 @@ emit_rvalue_from_long_long (gcc_jit_type *type, lon= g long n) > gcc_jit_context_new_rvalue_from_int (comp.ctxt, > comp.unsigned_long_long_type, > 32)), > - low)); > + low)); I guess this was involuntary, I removed this change. > } > > static gcc_jit_rvalue * > @@ -1132,7 +1083,7 @@ emit_rvalue_from_unsigned_long_long (gcc_jit_type *= type, unsigned long long n) > gcc_jit_context_new_rvalue_from_int (comp.ctxt, > comp.unsigned_long_l= ong_type, > 32)), > - low)); > + low)); Likewise > +static void > +define_cast_functions (void) > +{ > + struct cast_type cast_types[NUM_CAST_TYPES] > + =3D { { comp.bool_type, "bool", sizeof (bool) }, > + { comp.char_ptr_type, "char_ptr", sizeof (char *) }, > + { comp.int_type, "int", sizeof (int) }, > + { comp.lisp_cons_ptr_type, "cons_ptr", sizeof (struct Lisp_Cons = *) }, > + { comp.lisp_obj_ptr_type, "lisp_obj_ptr", sizeof (Lisp_Object *)= }, > + { comp.lisp_word_tag_type, "lisp_word_tag", sizeof (Lisp_Word_ta= g) }, > + { comp.lisp_word_type, "lisp_word", sizeof (Lisp_Word) }, > + { comp.long_long_type, "long_long", sizeof (long long) }, > + { comp.long_type, "long", sizeof (long) }, > + { comp.ptrdiff_type, "ptrdiff", sizeof (ptrdiff_t) }, > + { comp.uintptr_type, "uintptr", sizeof (uintptr_t) }, > + { comp.unsigned_long_long_type, "unsigned_long_long", > + sizeof (unsigned long long) }, > + { comp.unsigned_long_type, "unsigned_long", sizeof (unsigned lon= g) }, > + { comp.unsigned_type, "unsigned", sizeof (unsigned) }, > + { comp.void_ptr_type, "void_ptr", sizeof (void*) } }; Fine for now, but I don't like to have all this information sparse. We should take what is now cast_type (add the sign information) call it something like comp_type and use it allover. So that when we initialize a type all the information is in one place and is not duplicated. If you like to pick this task would be very welcome. [...] > comp.cast_union_type =3D > gcc_jit_context_new_union_type (comp.ctxt, > NULL, > "cast_union", > - ARRAYELTS (cast_union_fields), > - cast_union_fields); > + NUM_CAST_TYPES+1, Spaces around + > + comp.cast_union_fields); > + > + /* Define the cast functions using a matrix. */ > + for (int i =3D 0; i < NUM_CAST_TYPES; ++i) > + for (int j =3D 0; j < NUM_CAST_TYPES; ++j) > + comp.cast_functions_from_to[i][j] Okay so the three pushed. Thanks Andrea -- akrl@sdf.org