From patchwork Sat Sep 12 11:00:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1362811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=OZLD7REs; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BpV862Mb8z9sTC for ; Sat, 12 Sep 2020 21:02:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 766063870907; Sat, 12 Sep 2020 11:02:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 09D63384C004 for ; Sat, 12 Sep 2020 11:02:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 09D63384C004 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wr1-x42e.google.com with SMTP id g4so13856081wrs.5 for ; Sat, 12 Sep 2020 04:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=H3Xw9M2wx5n6JJJaH2r5/okyfznB09r3Gd1qHhFXHVA=; b=OZLD7REsvNhDA9lij7EoOOJOafQHabCPqL6y8g0jBpLKz3C0EP4sltz7zTsUgaDOMR EtPVFchv/vLKt6kfH9cEEiTasT2UgNuu3DLrliy+SiVonedhgMxUKGQC7cmMX+Me+Oyo d0xgPAcQG1VwpILe0PYEh8o2Z3y57AJF2MXqTzb4zUa81Eql3LjzOfk73RfuZsr0vFF/ CQ5DX1pq951kEu5YMk7H4jfIyPC+Mtk4UIyktXx2lZ3iMMYW/SQ3nlzJLHOvrPsc2GAV 1N31O6JqFAUpKmwvAp5ikqlK9bFDmmQAuUF8ogr7p2nfQW2OwMEPb5Mxx0fgn4rPd6jU 5qcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=H3Xw9M2wx5n6JJJaH2r5/okyfznB09r3Gd1qHhFXHVA=; b=rbyoCbpVppGboTBF5fXHT4ZyoNGBPupIKNSWFLq2+iRRrJJgcJDmc5LCx/JISGMSFc 5rzxqnLHjivNABntQx1oL0RDi6ETuVtS5XfM+P5O/jWrVOrdSy+GvyUfJvPW6iY5pnlk UIUka9SXbJMKZp+7JHPqcz4X8v5ldH+WJ0B+DORbLqC1SqGgonpRaJFj+snZCxsqlQ4G VEb4vxEBHUlAgkh4bPEI9pHazBYLkuNNVez8Xnpk3YyJG8c0SqJeRvj7ySMUUqBXMuUc +VAWR5bwh3R8pCbvP/ExWBZ+5rmqDotJvUcortm/H5KDB1637K34IPYqx2cq6LEBF6/d +AYg== X-Gm-Message-State: AOAM531lmz/nIWU6kT2/Qw7id+16RbufIWD6L4WVIInLger/IizufwxY NDOW7N3TAvHvBYYMAWdsePax2zc6zOqIQCqW X-Google-Smtp-Source: ABdhPJzHLa8GU3BG5CL3ROTAGlzFLdAJ/j9n6bhWXkUM7dsgFreh/SILKPB9a1fytRjLHRU8aSYAJA== X-Received: by 2002:adf:f88d:: with SMTP id u13mr6841798wrp.213.1599908539854; Sat, 12 Sep 2020 04:02:19 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:9230:7f82:53f4:769e:54b6]) by smtp.gmail.com with ESMTPSA id k6sm9342840wmf.30.2020.09.12.04.02.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 12 Sep 2020 04:02:19 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Add preliminary support for 128-bit integer types Date: Sat, 12 Sep 2020 13:00:10 +0200 Message-ID: <1823522.ZhmkvUMZHt@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This is only the gigi part, in preparation for the bulk of the implementation. Tested on x86_64-suse-linux, applied on the mainline. 2020-09-12 Eric Botcazou * gcc-interface/gigi.h (standard_datatypes): Add ADT_mulv128_decl. (mulv128_decl): New macro. (get_target_long_long_long_size): Declare. * gcc-interface/decl.c (gnat_to_gnu_entity): Use a maximum size of 128 bits for discrete types if Enable_128bit_Types is true. * gcc-interface/targtyps.c: Include target.h. (get_target_long_long_long_size): New function. * gcc-interface/trans.c (gigi): Initialize mulv128_decl if need be. (build_binary_op_trapv): Call it for 128-bit multiplication. * gcc-interface/utils.c (make_type_from_size): Enforce a maximum size of 128 bits if Enable_128bit_Types is true. diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h index 520301e4c3e..858a28acb8e 100644 --- a/gcc/ada/fe.h +++ b/gcc/ada/fe.h @@ -213,6 +213,7 @@ typedef enum { extern Ada_Version_Type Ada_Version; extern Boolean Back_End_Inlining; extern Boolean Debug_Generated_Code; +extern Boolean Enable_128bit_Types; extern Boolean Exception_Extra_Info; extern Boolean Exception_Locations_Suppressed; extern Exception_Mechanism_Type Exception_Mechanism; diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index d19f5aac81f..c9c2a95170f 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -524,7 +524,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) else if (IN (kind, Access_Kind)) max_esize = POINTER_SIZE * 2; else - max_esize = LONG_LONG_TYPE_SIZE; + max_esize = Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE; if (esize > max_esize) esize = max_esize; diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index e43b3db59a9..355178e284f 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -390,6 +390,9 @@ enum standard_datatypes /* Function decl node for 64-bit multiplication with overflow checking. */ ADT_mulv64_decl, + /* Function decl node for 128-bit multiplication with overflow checking. */ + ADT_mulv128_decl, + /* Identifier for the name of the _Parent field in tagged record types. */ ADT_parent_name_id, @@ -462,6 +465,7 @@ extern GTY(()) tree gnat_raise_decls_ext[(int) LAST_REASON_CODE + 1]; #define free_decl gnat_std_decls[(int) ADT_free_decl] #define realloc_decl gnat_std_decls[(int) ADT_realloc_decl] #define mulv64_decl gnat_std_decls[(int) ADT_mulv64_decl] +#define mulv128_decl gnat_std_decls[(int) ADT_mulv128_decl] #define parent_name_id gnat_std_decls[(int) ADT_parent_name_id] #define exception_data_name_id gnat_std_decls[(int) ADT_exception_data_name_id] #define jmpbuf_type gnat_std_decls[(int) ADT_jmpbuf_type] @@ -1035,6 +1039,7 @@ extern Pos get_target_short_size (void); extern Pos get_target_int_size (void); extern Pos get_target_long_size (void); extern Pos get_target_long_long_size (void); +extern Pos get_target_long_long_long_size (void); extern Pos get_target_pointer_size (void); extern Pos get_target_maximum_default_alignment (void); extern Pos get_target_system_allocator_alignment (void); diff --git a/gcc/ada/gcc-interface/targtyps.c b/gcc/ada/gcc-interface/targtyps.c index 9b2d24146a1..60a37e1463b 100644 --- a/gcc/ada/gcc-interface/targtyps.c +++ b/gcc/ada/gcc-interface/targtyps.c @@ -29,6 +29,7 @@ #include "system.h" #include "coretypes.h" #include "tm.h" +#include "target.h" #include "tree.h" #include "ada.h" @@ -94,6 +95,15 @@ get_target_long_long_size (void) return LONG_LONG_TYPE_SIZE; } +Pos +get_target_long_long_long_size (void) +{ + if (targetm.scalar_mode_supported_p (TImode)) + return GET_MODE_BITSIZE (TImode); + else + return LONG_LONG_TYPE_SIZE; +} + Pos get_target_pointer_size (void) { diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 39d4d28fa67..9be12952c5b 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -439,6 +439,19 @@ gigi (Node_Id gnat_root, NULL_TREE, is_default, true, true, true, false, false, NULL, Empty); + if (Enable_128bit_Types) + { + tree int128_type = gnat_type_for_size (128, 0); + mulv128_decl + = create_subprog_decl (get_identifier ("__gnat_mulv128"), NULL_TREE, + build_function_type_list (int128_type, + int128_type, + int128_type, + NULL_TREE), + NULL_TREE, is_default, true, true, true, false, + false, NULL, Empty); + } + /* Name of the _Parent field in tagged record types. */ parent_name_id = get_identifier (Get_Name_String (Name_uParent)); @@ -9388,6 +9401,15 @@ build_binary_op_trapv (enum tree_code code, tree gnu_type, tree left, convert (int64, rhs))); } + /* Likewise for a 128-bit mult and a 64-bit target. */ + else if (code == MULT_EXPR && precision == 128 && BITS_PER_WORD < 128) + { + tree int128 = gnat_type_for_size (128, 0); + return convert (gnu_type, build_call_n_expr (mulv128_decl, 2, + convert (int128, lhs), + convert (int128, rhs))); + } + enum internal_fn icode; switch (code) diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 3065fcb6260..048a0cf13b4 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -1343,7 +1343,7 @@ make_type_from_size (tree type, tree size_tree, bool for_biased) not already have the proper size and the size is not too large. */ if (BIT_PACKED_ARRAY_TYPE_P (type) || (TYPE_PRECISION (type) == size && biased_p == for_biased) - || size > LONG_LONG_TYPE_SIZE) + || size > (Enable_128bit_Types ? 128 : LONG_LONG_TYPE_SIZE)) break; biased_p |= for_biased;