diff mbox series

[v3,2/2] bpf, docs: Fix small typo and define semantics of sign extension

Message ID 20230805030921.52035-2-hawkinsw@obs.cr (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [v3,1/2] bpf, docs: Formalize type notation and function semantics in ISA standard | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on s390x with gcc
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 15 maintainers not CCed: daniel@iogearbox.net yonghong.song@linux.dev haoluo@google.com dthaler@microsoft.com linux-doc@vger.kernel.org void@manifault.com kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com song@kernel.org sdf@google.com andrii@kernel.org corbet@lwn.net jolsa@kernel.org ast@kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch warning WARNING: Missing commit description - Add an appropriate one
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Will Hawkins Aug. 5, 2023, 3:09 a.m. UTC
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
 .../bpf/standardization/instruction-set.rst   | 31 ++++++++++++++++---
 1 file changed, 26 insertions(+), 5 deletions(-)

Comments

David Vernet Aug. 5, 2023, 2:18 p.m. UTC | #1
On Fri, Aug 04, 2023 at 11:09:19PM -0400, Will Hawkins wrote:
> Signed-off-by: Will Hawkins <hawkinsw@obs.cr>

Hi Will,

Given that this is a separate patch, it should also have its own commit
summary as it would be merged as a separate commit to the kernel.

- David

> ---
>  .../bpf/standardization/instruction-set.rst   | 31 ++++++++++++++++---
>  1 file changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
> index fe296f35e5a7..6f3b34ef7b7c 100644
> --- a/Documentation/bpf/standardization/instruction-set.rst
> +++ b/Documentation/bpf/standardization/instruction-set.rst
> @@ -73,6 +73,27 @@ Functions
>    format and returns the equivalent number with the same bit width but
>    opposite endianness.
>  
> +
> +Definitions
> +-----------
> +
> +.. glossary::
> +
> +  Sign Extend
> +    To `sign extend an` ``X`` `-bit number, A, to a` ``Y`` `-bit number, B  ,` means to
> +
> +    #. Copy all ``X`` bits from `A` to the lower ``X`` bits of `B`.
> +    #. Set the value of the remaining ``Y`` - ``X`` bits of `B` to the value of
> +       the  most-significant bit of `A`.
> +
> +.. admonition:: Example
> +
> +  Sign extend an 8-bit number ``A`` to a 16-bit number ``B`` on a big-endian platform:
> +  ::
> +
> +    A:          10000110
> +    B: 11111111 10000110
> +
>  Registers and calling convention
>  ================================
>  
> @@ -263,17 +284,17 @@ where '(u32)' indicates that the upper 32 bits are zeroed.
>  Note that most instructions have instruction offset of 0. Only three instructions
>  (``BPF_SDIV``, ``BPF_SMOD``, ``BPF_MOVSX``) have a non-zero offset.
>  
> -The devision and modulo operations support both unsigned and signed flavors.
> +The division and modulo operations support both unsigned and signed flavors.
>  
>  For unsigned operations (``BPF_DIV`` and ``BPF_MOD``), for ``BPF_ALU``,
>  'imm' is interpreted as a 32-bit unsigned value. For ``BPF_ALU64``,
> -'imm' is first sign extended from 32 to 64 bits, and then interpreted as
> -a 64-bit unsigned value.
> +'imm' is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
> +interpreted as a 64-bit unsigned value.
>  
>  For signed operations (``BPF_SDIV`` and ``BPF_SMOD``), for ``BPF_ALU``,
>  'imm' is interpreted as a 32-bit signed value. For ``BPF_ALU64``, 'imm'
> -is first sign extended from 32 to 64 bits, and then interpreted as a
> -64-bit signed value.
> +is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
> +interpreted as a 64-bit signed value.
>  
>  The ``BPF_MOVSX`` instruction does a move operation with sign extension.
>  ``BPF_ALU | BPF_MOVSX`` sign extends 8-bit and 16-bit operands into 32

There are some other places where we say e.g. "sign extend", "sign
extending", etc. Can we link those places to your handy new section as
well, please?

Thanks,
David
Will Hawkins Aug. 6, 2023, 2:56 a.m. UTC | #2
On Sat, Aug 5, 2023 at 10:18 AM David Vernet <void@manifault.com> wrote:
>
> On Fri, Aug 04, 2023 at 11:09:19PM -0400, Will Hawkins wrote:
> > Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
>
> Hi Will,
>
> Given that this is a separate patch, it should also have its own commit
> summary as it would be merged as a separate commit to the kernel.

Agree -- sorry for adding it to this set. It was contingent on the
first going on so that there was not a merge conflict so I just added
it here. In v3 of the patch I will make the change!!

>
> - David
>
> > ---
> >  .../bpf/standardization/instruction-set.rst   | 31 ++++++++++++++++---
> >  1 file changed, 26 insertions(+), 5 deletions(-)
> >
> > diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
> > index fe296f35e5a7..6f3b34ef7b7c 100644
> > --- a/Documentation/bpf/standardization/instruction-set.rst
> > +++ b/Documentation/bpf/standardization/instruction-set.rst
> > @@ -73,6 +73,27 @@ Functions
> >    format and returns the equivalent number with the same bit width but
> >    opposite endianness.
> >
> > +
> > +Definitions
> > +-----------
> > +
> > +.. glossary::
> > +
> > +  Sign Extend
> > +    To `sign extend an` ``X`` `-bit number, A, to a` ``Y`` `-bit number, B  ,` means to
> > +
> > +    #. Copy all ``X`` bits from `A` to the lower ``X`` bits of `B`.
> > +    #. Set the value of the remaining ``Y`` - ``X`` bits of `B` to the value of
> > +       the  most-significant bit of `A`.
> > +
> > +.. admonition:: Example
> > +
> > +  Sign extend an 8-bit number ``A`` to a 16-bit number ``B`` on a big-endian platform:
> > +  ::
> > +
> > +    A:          10000110
> > +    B: 11111111 10000110
> > +
> >  Registers and calling convention
> >  ================================
> >
> > @@ -263,17 +284,17 @@ where '(u32)' indicates that the upper 32 bits are zeroed.
> >  Note that most instructions have instruction offset of 0. Only three instructions
> >  (``BPF_SDIV``, ``BPF_SMOD``, ``BPF_MOVSX``) have a non-zero offset.
> >
> > -The devision and modulo operations support both unsigned and signed flavors.
> > +The division and modulo operations support both unsigned and signed flavors.
> >
> >  For unsigned operations (``BPF_DIV`` and ``BPF_MOD``), for ``BPF_ALU``,
> >  'imm' is interpreted as a 32-bit unsigned value. For ``BPF_ALU64``,
> > -'imm' is first sign extended from 32 to 64 bits, and then interpreted as
> > -a 64-bit unsigned value.
> > +'imm' is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
> > +interpreted as a 64-bit unsigned value.
> >
> >  For signed operations (``BPF_SDIV`` and ``BPF_SMOD``), for ``BPF_ALU``,
> >  'imm' is interpreted as a 32-bit signed value. For ``BPF_ALU64``, 'imm'
> > -is first sign extended from 32 to 64 bits, and then interpreted as a
> > -64-bit signed value.
> > +is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
> > +interpreted as a 64-bit signed value.
> >
> >  The ``BPF_MOVSX`` instruction does a move operation with sign extension.
> >  ``BPF_ALU | BPF_MOVSX`` sign extends 8-bit and 16-bit operands into 32
>
> There are some other places where we say e.g. "sign extend", "sign
> extending", etc. Can we link those places to your handy new section as
> well, please?

Absolutely! Sorry that I missed them!

>
> Thanks,
> David
diff mbox series

Patch

diff --git a/Documentation/bpf/standardization/instruction-set.rst b/Documentation/bpf/standardization/instruction-set.rst
index fe296f35e5a7..6f3b34ef7b7c 100644
--- a/Documentation/bpf/standardization/instruction-set.rst
+++ b/Documentation/bpf/standardization/instruction-set.rst
@@ -73,6 +73,27 @@  Functions
   format and returns the equivalent number with the same bit width but
   opposite endianness.
 
+
+Definitions
+-----------
+
+.. glossary::
+
+  Sign Extend
+    To `sign extend an` ``X`` `-bit number, A, to a` ``Y`` `-bit number, B  ,` means to
+
+    #. Copy all ``X`` bits from `A` to the lower ``X`` bits of `B`.
+    #. Set the value of the remaining ``Y`` - ``X`` bits of `B` to the value of
+       the  most-significant bit of `A`.
+
+.. admonition:: Example
+
+  Sign extend an 8-bit number ``A`` to a 16-bit number ``B`` on a big-endian platform:
+  ::
+
+    A:          10000110
+    B: 11111111 10000110
+
 Registers and calling convention
 ================================
 
@@ -263,17 +284,17 @@  where '(u32)' indicates that the upper 32 bits are zeroed.
 Note that most instructions have instruction offset of 0. Only three instructions
 (``BPF_SDIV``, ``BPF_SMOD``, ``BPF_MOVSX``) have a non-zero offset.
 
-The devision and modulo operations support both unsigned and signed flavors.
+The division and modulo operations support both unsigned and signed flavors.
 
 For unsigned operations (``BPF_DIV`` and ``BPF_MOD``), for ``BPF_ALU``,
 'imm' is interpreted as a 32-bit unsigned value. For ``BPF_ALU64``,
-'imm' is first sign extended from 32 to 64 bits, and then interpreted as
-a 64-bit unsigned value.
+'imm' is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
+interpreted as a 64-bit unsigned value.
 
 For signed operations (``BPF_SDIV`` and ``BPF_SMOD``), for ``BPF_ALU``,
 'imm' is interpreted as a 32-bit signed value. For ``BPF_ALU64``, 'imm'
-is first sign extended from 32 to 64 bits, and then interpreted as a
-64-bit signed value.
+is first :term:`sign extended<Sign Extend>` from 32 to 64 bits, and then
+interpreted as a 64-bit signed value.
 
 The ``BPF_MOVSX`` instruction does a move operation with sign extension.
 ``BPF_ALU | BPF_MOVSX`` sign extends 8-bit and 16-bit operands into 32