From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id DB2F03852761 for ; Tue, 16 May 2023 08:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB2F03852761 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3078d1c8828so10594371f8f.3 for ; Tue, 16 May 2023 01:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684226444; x=1686818444; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BmBoL/pCdwm4kXp6G5XWNVYrfUx84ZOCCdJmPwc/y+0=; b=Djt+vrBAthyHuwlyP4r4kbufTq4ZWpIAdNJFFd55o1YxH37SFHzNIz/UEglA+MFaSc DUCc2IIgzGpGSbsx5xm19jOfdhQEChfkvoTah94SsLd03Jt5coABqcn3mb8u8V907n7D 3xjWjTfyaSnUBmP+eOYimhAMbHHkQ3PC6FepmWk6aSxUNb8UJ9aO+BEC4VFx2ofVdO3D krhM9YhYwzyb9cxYGc5boiWWdoAiEdvlct39EflFTnq1ws99kEyKaZ3n/vc7pbJSqBij 5ZPyrTZjSVJxEEAlXa45WiMj1aWYfRX4J3J2wNwb12N26xfmqmVP7FdCQTT7C6urKjQV nXbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684226444; x=1686818444; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BmBoL/pCdwm4kXp6G5XWNVYrfUx84ZOCCdJmPwc/y+0=; b=GXJlgAFyZCrmzSYswNIKIoM3YJFX3keggunqKzB1GTD6DWg/NqutEY3/Uh4GabQ7eR R434pdEbcemERNQ3EZ8d7JgINPAIKlktxlZmwuoIaHSQR9Uw0PFwb/uBjDk5tnsg2sqW JYh8jPvdGYfPeJJGMvY4JlwgLP56NRxUb/zC8EA61RCnMMQdAIjBfv8u7tzjwBLGPbqc h9wGAMZDQ1U828jnYFj6vXZgInzq4Quy9cSUuibPa2n8sUzetR53KAQWLCrWiPc/TLVq MTXBNf4stEhfSRBM0aw1Rpcnt8Ur//4JOOztaFVkfevkzEcXe0CMLvftCgh9FqsSYO8p ynWA== X-Gm-Message-State: AC+VfDygFZXpwGahbH+7+A5EzxyfbTl5g2OT4CpMBoqFHBXsCBOCT+eg ufGCzmT9gtS80Jd+cSK+sKm6x6oAa1HnqlxBC3qR3w== X-Google-Smtp-Source: ACHHUZ4RowKYUcJLfW4Q+BfYFLV8XwvoSwmgz7sRNoa33neSaQs4pYDbD/uT3VqzyqkfaBt4i5gjgg== X-Received: by 2002:adf:e88a:0:b0:306:2cc8:a337 with SMTP id d10-20020adfe88a000000b003062cc8a337mr23426402wrm.45.1684226444661; Tue, 16 May 2023 01:40:44 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id f18-20020adfe912000000b00307d20546e6sm1783308wrm.27.2023.05.16.01.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:40:43 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Johannes Kliemann Subject: [COMMITTED] ada: Enable Support_Atomic_Primitives on PPC Linux Date: Tue, 16 May 2023 10:40:42 +0200 Message-Id: <20230516084042.1501739-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Johannes Kliemann gcc/ada/ * libgnat/system-linux-ppc.ads: Add Support_Atomic_Primitives. * libgnat/s-atopri__32.ads: Add 32 bit version of s-atopri.ads. * Makefile.rtl: Use s-atopro__32.ads for ppc-linux. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/Makefile.rtl | 1 + gcc/ada/libgnat/s-atopri__32.ads | 149 +++++++++++++++++++++++++++ gcc/ada/libgnat/system-linux-ppc.ads | 1 + 3 files changed, 151 insertions(+) create mode 100644 gcc/ada/libgnat/s-atopri__32.ads diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl index 96306f8cc9a..2cfdd8dc613 100644 --- a/gcc/ada/Makefile.rtl +++ b/gcc/ada/Makefile.rtl @@ -2185,6 +2185,7 @@ ifeq ($(strip $(filter-out powerpc% linux%,$(target_cpu) $(target_os))),) EXTRA_GNATRTL_NONTASKING_OBJS += $(GNATRTL_128BIT_OBJS) endif else + LIBGNAT_TARGET_PAIRS += s-atopri.ads. -- +-- -- +-- GNAT was originally developed by the GNAT team at New York University. -- +-- Extensive contributions were provided by Ada Core Technologies Inc. -- +-- -- +------------------------------------------------------------------------------ + +-- This package contains both atomic primitives defined from GCC built-in +-- functions and operations used by the compiler to generate the lock-free +-- implementation of protected objects. +-- This is the version that only contains primitives available on 32 bit +-- platforms. + +with Interfaces.C; + +package System.Atomic_Primitives is + pragma Pure; + + type uint is mod 2 ** Long_Integer'Size; + + type uint8 is mod 2**8 + with Size => 8; + + type uint16 is mod 2**16 + with Size => 16; + + type uint32 is mod 2**32 + with Size => 32; + + Relaxed : constant := 0; + Consume : constant := 1; + Acquire : constant := 2; + Release : constant := 3; + Acq_Rel : constant := 4; + Seq_Cst : constant := 5; + Last : constant := 6; + + subtype Mem_Model is Integer range Relaxed .. Last; + + ------------------------------------ + -- GCC built-in atomic primitives -- + ------------------------------------ + + generic + type Atomic_Type is mod <>; + function Atomic_Load + (Ptr : Address; + Model : Mem_Model := Seq_Cst) return Atomic_Type; + pragma Import (Intrinsic, Atomic_Load, "__atomic_load_n"); + + function Atomic_Load_8 is new Atomic_Load (uint8); + function Atomic_Load_16 is new Atomic_Load (uint16); + function Atomic_Load_32 is new Atomic_Load (uint32); + + generic + type Atomic_Type is mod <>; + function Atomic_Compare_Exchange + (Ptr : Address; + Expected : Address; + Desired : Atomic_Type; + Weak : Boolean := False; + Success_Model : Mem_Model := Seq_Cst; + Failure_Model : Mem_Model := Seq_Cst) return Boolean; + pragma Import + (Intrinsic, Atomic_Compare_Exchange, "__atomic_compare_exchange_n"); + + function Atomic_Compare_Exchange_8 is new Atomic_Compare_Exchange (uint8); + function Atomic_Compare_Exchange_16 is new Atomic_Compare_Exchange (uint16); + function Atomic_Compare_Exchange_32 is new Atomic_Compare_Exchange (uint32); + + function Atomic_Test_And_Set + (Ptr : System.Address; + Model : Mem_Model := Seq_Cst) return Boolean; + pragma Import (Intrinsic, Atomic_Test_And_Set, "__atomic_test_and_set"); + + procedure Atomic_Clear + (Ptr : System.Address; + Model : Mem_Model := Seq_Cst); + pragma Import (Intrinsic, Atomic_Clear, "__atomic_clear"); + + function Atomic_Always_Lock_Free + (Size : Interfaces.C.size_t; + Ptr : System.Address := System.Null_Address) return Boolean; + pragma Import + (Intrinsic, Atomic_Always_Lock_Free, "__atomic_always_lock_free"); + + -------------------------- + -- Lock-free operations -- + -------------------------- + + -- The lock-free implementation uses two atomic instructions for the + -- expansion of protected operations: + + -- * Lock_Free_Read atomically loads the value contained in Ptr (with the + -- Acquire synchronization mode). + + -- * Lock_Free_Try_Write atomically tries to write the Desired value into + -- Ptr if Ptr contains the Expected value. It returns true if the value + -- in Ptr was changed, or False if it was not, in which case Expected is + -- updated to the unexpected value in Ptr. Note that it does nothing and + -- returns true if Desired and Expected are equal. + + generic + type Atomic_Type is mod <>; + function Lock_Free_Read (Ptr : Address) return Atomic_Type; + + function Lock_Free_Read_8 is new Lock_Free_Read (uint8); + function Lock_Free_Read_16 is new Lock_Free_Read (uint16); + function Lock_Free_Read_32 is new Lock_Free_Read (uint32); + + generic + type Atomic_Type is mod <>; + function Lock_Free_Try_Write + (Ptr : Address; + Expected : in out Atomic_Type; + Desired : Atomic_Type) return Boolean; + + function Lock_Free_Try_Write_8 is new Lock_Free_Try_Write (uint8); + function Lock_Free_Try_Write_16 is new Lock_Free_Try_Write (uint16); + function Lock_Free_Try_Write_32 is new Lock_Free_Try_Write (uint32); + +private + pragma Inline (Lock_Free_Read); + pragma Inline (Lock_Free_Try_Write); +end System.Atomic_Primitives; diff --git a/gcc/ada/libgnat/system-linux-ppc.ads b/gcc/ada/libgnat/system-linux-ppc.ads index a24d6164da4..f5bb80187f1 100644 --- a/gcc/ada/libgnat/system-linux-ppc.ads +++ b/gcc/ada/libgnat/system-linux-ppc.ads @@ -142,6 +142,7 @@ private Stack_Check_Probes : constant Boolean := True; Stack_Check_Limits : constant Boolean := False; Support_Aggregates : constant Boolean := True; + Support_Atomic_Primitives : constant Boolean := True; Support_Composite_Assign : constant Boolean := True; Support_Composite_Compare : constant Boolean := True; Support_Long_Shifts : constant Boolean := True; -- 2.40.0