public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1462] [Ada] Clarify the semantics of signed intrinsic shift operations
Date: Tue, 15 Jun 2021 10:21:42 +0000 (GMT)	[thread overview]
Message-ID: <20210615102142.475B3398B168@sourceware.org> (raw)

https://gcc.gnu.org/g:688fb8553bd589d6cfc71de467f38ae725199da9

commit r12-1462-g688fb8553bd589d6cfc71de467f38ae725199da9
Author: Yannick Moy <moy@adacore.com>
Date:   Fri Feb 5 15:19:57 2021 +0100

    [Ada] Clarify the semantics of signed intrinsic shift operations
    
    gcc/ada/
    
            * doc/gnat_rm/intrinsic_subprograms.rst: More details on shift
            operations for signed types. Also add the missing Import and
            Convention on the example.
            * gnat_rm.texi: Regenerate.

Diff:
---
 gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst | 14 ++++++++------
 gcc/ada/gnat_rm.texi                          | 14 ++++++++------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst b/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
index e448816572f..355b1399b2f 100644
--- a/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
+++ b/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
@@ -203,7 +203,8 @@ type (signed or modular), as in this example:
 
      function Shift_Left
        (Value  : T;
-        Amount : Natural) return T;
+        Amount : Natural) return T
+     with Import, Convention => Intrinsic;
 
 
 The function name must be one of
@@ -215,11 +216,12 @@ The result type must be the same as the type of ``Value``.
 The shift amount must be Natural.
 The formal parameter names can be anything.
 
-A more convenient way of providing these shift operators is to use
-the Provide_Shift_Operators pragma, which provides the function declarations
-and corresponding pragma Import's for all five shift functions. Note that in
-using these provided shift operations, shifts performed on negative numbers
-will result in modification of the sign bit.
+A more convenient way of providing these shift operators is to use the
+Provide_Shift_Operators pragma, which provides the function declarations and
+corresponding pragma Import's for all five shift functions. For signed types
+the semantics of these operators is to interpret the bitwise result of the
+corresponding operator for modular type. In particular, shifting a negative
+number may change its sign bit to positive.
 
 .. _Source_Location:
 
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 68729da05df..8f0a370f684 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -17917,7 +17917,8 @@ type (signed or modular), as in this example:
 @example
 function Shift_Left
   (Value  : T;
-   Amount : Natural) return T;
+   Amount : Natural) return T
+with Import, Convention => Intrinsic;
 @end example
 
 The function name must be one of
@@ -17929,11 +17930,12 @@ The result type must be the same as the type of @code{Value}.
 The shift amount must be Natural.
 The formal parameter names can be anything.
 
-A more convenient way of providing these shift operators is to use
-the Provide_Shift_Operators pragma, which provides the function declarations
-and corresponding pragma Import's for all five shift functions. Note that in
-using these provided shift operations, shifts performed on negative numbers
-will result in modification of the sign bit.
+A more convenient way of providing these shift operators is to use the
+Provide_Shift_Operators pragma, which provides the function declarations and
+corresponding pragma Import's for all five shift functions. For signed types
+the semantics of these operators is to interpret the bitwise result of the
+corresponding operator for modular type. In particular, shifting a negative
+number may change its sign bit to positive.
 
 @node Source_Location,,Shifts and Rotates,Intrinsic Subprograms
 @anchor{gnat_rm/intrinsic_subprograms source-location}@anchor{274}@anchor{gnat_rm/intrinsic_subprograms id13}@anchor{275}


                 reply	other threads:[~2021-06-15 10:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210615102142.475B3398B168@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).