Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extension fast track] extra vector crypto instructions, Zvbc32e/Zvkgs #362

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4a59d4b
[Zv fast track] prototyping vclmul* changes
nibrunieAtSi5 Aug 14, 2023
a1bfcfc
[Zv fast track] prototyping vg* changes
nibrunieAtSi5 Aug 14, 2023
bc7f527
Completing vghsh.vs/vgmul.vs descriptions
nibrunieAtSi5 Aug 14, 2023
6b8eadb
adding directory with vector-crypto extra skeleton
nibrunieAtSi5 Aug 27, 2023
c10f745
Revert "Completing vghsh.vs/vgmul.vs descriptions"
nibrunieAtSi5 Aug 27, 2023
4e70f70
Revert "[Zv fast track] prototyping vg* changes"
nibrunieAtSi5 Aug 27, 2023
b0af277
Revert "[Zv fast track] prototyping vclmul* changes"
nibrunieAtSi5 Aug 27, 2023
72084cd
refactoring Zvkgs and vghsh.vs specifications
nibrunieAtSi5 Aug 27, 2023
8c5a9f2
fixing vghsh.vs/vgmul.vs descriptions
nibrunieAtSi5 Aug 28, 2023
056dd04
adding vclmul/vclmulh instruction specification for Zve32e
nibrunieAtSi5 Aug 28, 2023
11bd8af
moving vghsh.vs/vgmul.vs spec from doc/vector-extra to doc/vector-ext…
nibrunieAtSi5 Aug 28, 2023
5e836da
adding instruction table
nibrunieAtSi5 Aug 28, 2023
c986a6f
main document for vector extra
nibrunieAtSi5 Aug 28, 2023
4ae2021
renaming vclmul/vclmulh 32e spec files
nibrunieAtSi5 Aug 28, 2023
0083833
fixing vector-extra build issues
nibrunie Aug 31, 2023
21479fd
Fixing reserved encoding description for vclmulh
nibrunieAtSi5 Aug 31, 2023
e96eabc
Fixing title page
nibrunieAtSi5 Aug 31, 2023
8b5dab8
Fixing Zvbc32e description
nibrunieAtSi5 Aug 31, 2023
34a114e
adding vector-extra copy of images/risc-v_logo.png
nibrunieAtSi5 Aug 31, 2023
ea3471a
vclmul description
nibrunieAtSi5 Aug 31, 2023
ed8f89e
fixing a few typos + clarification
nibrunieAtSi5 Jan 18, 2024
1bfa9e3
[vector-crypto-extra] typo fix and improvements
nibrunieAtSi5 Feb 1, 2024
eff2e90
[vector-extra] updating revnumber to v0.0.3
nibrunie Feb 1, 2024
4ce6a83
[v0.0.4] applying internal review feedback
nibrunie Feb 7, 2024
acaf911
Apply suggestions from code review
nibrunieAtSi5 Feb 7, 2024
38d0834
Fixing typos / corrections / introducing Zvbc32e inst table
nibrunie Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions doc/vector-extra/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Makefile for RISC-V Doc Template
#
# This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
# International License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
#
# SPDX-License-Identifier: CC-BY-SA-4.0
#
# Description:
#
# This Makefile is designed to automate the process of building and packaging
# the Doc Template for RISC-V Extensions.

DOCKER_RUN := docker run --rm -v ${PWD}:/build -w /build \
riscvintl/riscv-docs-base-container-image:latest
HEADER_SOURCE := riscv-crypto-spec-vector-extra.adoc
PDF_RESULT := riscv-crypto-spec-vector-extra.pdf
SPEC_COMMIT= git-commit.adoc
ASCIIDOCTOR_PDF := asciidoctor-pdf
OPTIONS := --trace \
-a compress \
-a mathematical-format=svg \
-a pdf-fontsdir=resources/fonts \
-a pdf-style=resources/themes/risc-v_spec-pdf.yml \
-a toc \
--failure-level=ERROR
REQUIRES := --require=asciidoctor-bibtex \
--require=asciidoctor-diagram \
--require=asciidoctor-mathematical

.PHONY: all build clean build-container build-no-container

all: build

cp_bib:
@cp ../riscv-crypto-spec.bib ./

$(SPEC_COMMIT):
@git rev-parse --abbrev-ref HEAD > ${@}
@echo "@" >> ${@}
@git log --pretty=format:'%H' -n 1 >> ${@}

build: cp_bib $(SPEC_COMMIT)
@echo "Checking if Docker is available..."
@if command -v docker &> /dev/null ; then \
echo "Docker is available, building inside Docker container..."; \
$(MAKE) build-container; \
else \
echo "Docker is not available, building without Docker..."; \
$(MAKE) build-no-container; \
fi

build-container:
@echo "Starting build inside Docker container..."
$(DOCKER_RUN) /bin/sh -c "$(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) --out-file=$(PDF_RESULT) $(HEADER_SOURCE)"
@echo "Build completed successfully inside Docker container."

build-no-container:
@echo "Starting build..."
$(ASCIIDOCTOR_PDF) $(OPTIONS) $(REQUIRES) --out-file=$(PDF_RESULT) $(HEADER_SOURCE)
@echo "Build completed successfully."

clean:
@echo "Cleaning up generated files..."
rm -f $(PDF_RESULT)
@echo "Cleanup completed."
104 changes: 104 additions & 0 deletions doc/vector-extra/insns/vclmul-32e.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[[insns-vclmul-32e, Vector Carry-less Multiply]]
= vclmul.[vv,vx]

Synopsis::
Vector Carry-less Multiply by vector or scalar - returning low half of product.

Mnemonic::
vclmul.vv vd, vs2, vs1, vm +
vclmul.vx vd, vs2, rs1, vm

Encoding (Vector-Vector)::
[wavedrom, , svg]
....
{reg:[
{bits: 7, name: 'OP-V'},
{bits: 5, name: 'vd'},
{bits: 3, name: 'OPMVV'},
{bits: 5, name: 'vs1'},
{bits: 5, name: 'vs2'},
{bits: 1, name: 'vm'},
{bits: 6, name: '001100'},
]}
....

Encoding (Vector-Scalar)::
[wavedrom, , svg]
....
{reg:[
{bits: 7, name: 'OP-V'},
{bits: 5, name: 'vd'},
{bits: 3, name: 'OPMVX'},
{bits: 5, name: 'rs1'},
{bits: 5, name: 'vs2'},
{bits: 1, name: 'vm'},
{bits: 6, name: '001100'},
]}
....
Reserved Encodings::
* `SEW` is any value other than 32 (`Zvbc32e` only)
* `SEW` is any value other than 64 (`Zvbc` only)
* `SEW` is any value other than 32 or 64 (`Zvbc` and `Zvbc32e`)

Arguments::

[%autowidth]
[%header,cols="4,2,2"]
|===
|Register
|Direction
|Definition

| Vs1/Rs1 | input | multiplier
| Vs2 | input | multiplicand
| Vd | output | carry-less product low
|===

[NOTE]
====
`vclmul` instruction was initially defined in `Zvbc` with only `SEW=64-bit` support, this page describes how the specification is extended in `Zvbc32e` to support `SEW=32 bits`.
====

Description::
Produces the low half of 128-bit carry-less product.

Each SEW-bit element in the `vs2` vector register is carry-less multiplied by
either each SEW-bit element in `vs1` (vector-vector), or the SEW-bit value
from integer register `rs1` (vector-scalar). The result is the least
significant SEW bits of the carry-less product.

[NOTE]
====
The 64-bit carryless multiply instructions can be used for implementing GCM in the absence of the `zvkg` extension.
We do not make these instructions exclusive as the 64-bit carryless multiply is readily derived from the
instructions in the `zvkg` extension and can have utility in other areas.
====

Operation::
[source,sail]
--


function clause execute (VCLMUL(vs2, vs1, vd, suffix)) = {

foreach (i from vstart to vl-1) {
let op1 : bits (SEW) = if suffix =="vv" then get_velem(vs1, i)
else zext_or_truncate_to_sew(X(vs1));
let op2 : bits (SEW) = get_velem(vs2, i);
let product : bits (SEW) = clmul(op1, op2, SEW);
set_velem(vd, i, product);
}
RETIRE_SUCCESS
}

function clmul(x, y, width) = {
let result : bits(width) = zeros();
foreach (i from 0 to (width - 1)) {
if y[i] == 1 then result = result ^ (x << i);
}
result
}
--

Included in::
<<zvbc32e>>
98 changes: 98 additions & 0 deletions doc/vector-extra/insns/vclmulh-32e.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[[insns-vclmulh, Vector Carry-less Multiply Return High Half]]
= vclmulh.[vv,vx]

Synopsis::
Vector Carry-less Multiply by vector or scalar - returning high half of product.

Mnemonic::
vclmulh.vv vd, vs2, vs1, vm +
vclmulh.vx vd, vs2, rs1, vm

Encoding (Vector-Vector)::
[wavedrom, , svg]
....
{reg:[
{bits: 7, name: 'OP-V'},
{bits: 5, name: 'vd'},
{bits: 3, name: 'OPMVV'},
{bits: 5, name: 'vs1'},
{bits: 5, name: 'vs2'},
{bits: 1, name: 'vm'},
{bits: 6, name: '001101'},
]}
....

Encoding (Vector-Scalar)::
[wavedrom, , svg]
....
{reg:[
{bits: 7, name: 'OP-V'},
{bits: 5, name: 'vd'},
{bits: 3, name: 'OPMVX'},
{bits: 5, name: 'rs1'},
{bits: 5, name: 'vs2'},
{bits: 1, name: 'vm'},
{bits: 6, name: '001101'},
]}
....
Reserved Encodings::
* `SEW` is any value other than 64 (`Zvbcb`)
* `SEW` is any value other than 32 or 64 (`Zvbcb`)
nibrunieAtSi5 marked this conversation as resolved.
Show resolved Hide resolved

Arguments::

[%autowidth]
[%header,cols="4,2,2"]
|===
|Register
|Direction
|Definition

| Vs1 | input | multiplier
| Vs2 | input | multiplicand
| Vd | output | carry-less product high
|===

[NOTE]
====
`vclmulh` instruction was initially defined in `Zvbc`, this page describes how the specification is extended in `Zvbc32e` to support `SEW=32 bits`.
====

Description::
Produces the high half of 128-bit carry-less product.

Each SEW-bit element in the `vs2` vector register is carry-less multiplied by
either each SEW-bit element in `vs1` (vector-vector), or the SEW-bit value
from integer register `rs1` (vector-scalar). The result is the most
significant SEW bits of the carry-less product.

// This instruction must always be implemented such that its execution latency does not depend
// on the data being operated upon.

Operation::
[source,sail]
--
function clause execute (VCLMULH(vs2, vs1, vd, suffix)) = {

foreach (i from vstart to vl-1) {
let op1 : bits (SEW) = if suffix =="vv" then get_velem(vs1,i)
else zext_or_truncate_to_sew(X(vs1));
let op2 : bits (SEW) = get_velem(vs2, i);
let product : bits (SEW) = clmulh(op1, op2, SEW);
set_velem(vd, i, product);
}
RETIRE_SUCCESS
}

function clmulh(x, y, width) = {
let result : bits(width) = 0;
foreach (i from 1 to (width - 1)) {
if y[i] == 1 then result = result ^ (x >> (width - i));
}
result
}

--

Included in::
<<zvbc>>, <<zvbcb>>, <<zvknc>>, <<zvksc>>
nibrunieAtSi5 marked this conversation as resolved.
Show resolved Hide resolved
Loading