Skip to content

Commit

Permalink
Toolchain updates for bitmanip 1.0+0.93 support
Browse files Browse the repository at this point in the history
For all toolchains:

- GCC 10.20
- binutils 2.35

For the bitmanip toolchains (rv32imcb):

- GCC and binutils with bitmanip 1.0+0.93 forks/patches
- LLVM 13.0.1-rc3. Supports most of bitmanip 0.93 with 1.0-compatible encodings.
  The only exception is the shift ones instructions (slo, sloi, sro, sroi).
  • Loading branch information
luismarques committed Jan 27, 2022
1 parent da3259f commit 8ff8f02
Show file tree
Hide file tree
Showing 10 changed files with 531 additions and 3,272 deletions.
29 changes: 9 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,14 @@ How to do a release
will be uploaded to
[GitHub releases](https://github.com/lowRISC/lowrisc-toolchains/releases).

How to generate the bitmanip patches
How to generate the bitmanip patch
------------------------------------

1. Generate the binutils patch:

```
git clone https://github.com/riscv/riscv-binutils-gdb.git
cd riscv-binutils-gdb
git checkout riscv-bitmanip
# 612aac65 is our upstream baseline
git diff 612aac65 > $TOP/patches/binutils/git-612aac65/001-bitmanip.patch
```

2. Generate the GCC patch:

```
git clone https://github.com/riscv/riscv-gcc.git
cd riscv-gcc
git checkout riscv-bitmanip
# 49f75e008c0 is our upstream baseline
git diff 49f75e008c0 > $TOP/patches/gcc/git-49f75e00/001-bitmanip.patch
```
```
git clone https://github.com/riscv-collab/riscv-binutils-gdb.git
cd riscv-binutils-gdb
# checkout Pirmin's bitmanip 1.00+0.93 PR (https://github.com/riscv-collab/riscv-binutils-gdb/pull/267)
gh pr checkout 267
# 7c9dd840 (riscv-binutils-2.35-rvb) is our baseline
git diff 7c9dd840 > $TOP/patches/lowrisc-toolchain-gcc-rv32imcb/binutils/git-7c9dd840/001-bitmanip.patch
```
31 changes: 6 additions & 25 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:

- job: "Toolchains_RV32IMCB"
displayName: "Toolchains targeting Ibex with 'Balanced' Bit-manipulation"
# These builds are using the 'Balanced' bit-manipulation subset identified in
# https://github.com/lowRISC/opentitan/issues/2708, and formatted for the
# correct versions as implemented by clang (B 0.92).
# These builds are using the ratified bitmanip extensions, version 1.0: Zba,
# Zbb, Zbc, and Zbs. For the current version of Clang we need to specify them
# as version 0.93, but they should be equivalent.
pool:
vmImage: "ubuntu-20.04"
container: lowrisc/lowrisc-base-centos6:latest
Expand All @@ -73,31 +73,12 @@ jobs:
displayName: "Prepare toolchain destination directory"
- bash: |
# HACK: GCC does not allow you to compile with just a subset of the B
# extension using `-march=`, but it does assemble separately.
#
# So, we pass a more acceptable `-march=` to the assembler with `-Wa`.
#
# However, gcc will emit an assembly directive describing the arch it
# wanted when it compiled, which the assembler will use in spite of the
# `-march=` flag. So, we have to turn this off, using
# `-mno-riscv-attribute`.
#
# The end result is: The compiler will not introduce B extension
# instructions when compiling, but the assembler will understand them, so
# they can be used in inline assembly.
#
# If you update the patches in `patches/lowrisc-toolchain-gcc-rv32imcb`,
# you will need to revalidate that this behaviour works. A good testcase
# is a file with a `pcnt` instruction in inline assembly.
#
./build-gcc-with-args.sh \
"lowrisc-toolchain-gcc-rv32imcb" \
"riscv32-unknown-elf" \
"/tools/riscv" \
"-march=rv32imc" "-mabi=ilp32" "-mcmodel=medany" \
"-Wa,-march=rv32imczbb0p92_zbf0p92_zbs0p92_zbt0p92" \
"-mno-riscv-attribute"
"-march=rv32imc_zba_zbb_zbc_zbs" \
"-mabi=ilp32" "-mcmodel=medany"
displayName: 'Build GCC toolchain'
env:
ARTIFACT_STAGING_DIR: $(Build.ArtifactStagingDirectory)
Expand All @@ -108,7 +89,7 @@ jobs:
"lowrisc-toolchain-rv32imcb" \
"riscv32-unknown-elf" \
"/tools/riscv" \
"-march=rv32imczbb0p92_zbf0p92_zbs0p92_zbt0p92" \
"-march=rv32imc_zba0p93_zbb0p93_zbc0p93_zbs0p93" \
"-mabi=ilp32" "-mcmodel=medany" "-menable-experimental-extensions"
displayName: "Build Clang toolchain"
env:
Expand Down
12 changes: 9 additions & 3 deletions build-clang-with-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ build_top_dir="${PWD}"
# shellcheck source=sw-versions.sh
source "${build_top_dir}/sw-versions.sh"

if [[ "${toolchain_name}" == *-rv32imcb ]]; then
llvm_version="${LLVM_BITMANIP_VERSION}"
else
llvm_version="${LLVM_VERSION}"
fi

tag_name="${RELEASE_TAG:-HEAD}"
toolchain_full_name="${toolchain_name}-${tag_name}"

Expand All @@ -55,7 +61,7 @@ if [ ! -d "${llvm_dir}" ]; then
fi
cd "${llvm_dir}"
git fetch origin
git checkout --force "${LLVM_VERSION}"
git checkout --force "${llvm_version}"

# Clang Symlinks
clang_links_to_create="clang++"
Expand Down Expand Up @@ -155,7 +161,7 @@ lowRISC toolchain version: ${tag_name}
Clang version:
${clang_version_string}
(git: ${LLVM_URL} ${LLVM_VERSION})
(git: ${LLVM_URL} ${llvm_version})
GCC version:
${gcc_version_string}
Expand All @@ -177,7 +183,7 @@ tee "${toolchain_dest}/buildinfo.json" <<BUILDINFO_JSON
"version": "${tag_name}",
"clang_version": "${clang_version_string}",
"clang_url": "${LLVM_URL}",
"clang_git": "${LLVM_VERSION}",
"clang_git": "${llvm_version}",
"gcc_version": "${gcc_version_string}",
"crosstool-ng_version": "${ct_ng_version_string}",
"crosstool-ng_url": "${CROSSTOOL_NG_URL}",
Expand Down
16 changes: 12 additions & 4 deletions lowrisc-toolchain-gcc-rv32imc.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ CT_ARCH_RISCV=y
# are built with. It should specify the minimum RISC-V extensions that need to
# be implemented by any processor that this toolchain will compile programs for.
#
# 2020-03-26: We have added B extension (v0.92) support to the compiler using
# experimental patches, but we still want to support Ibex without
# the B extension, so this remains "rv32imc".
#
CT_ARCH_ARCH="rv32imc"

# CT_ARCH_ABI controls the specific ABI that the toolchain's libraries are built
Expand Down Expand Up @@ -48,5 +44,17 @@ CT_PREFIX_DIR="/tools/riscv"
# Don't chmod the CT_PREFIX_DIR read-only after the install.
# CT_PREFIX_DIR_RO is not set

# Binutils 2.35 (tag binutils-2_35, commit 2cb5c79dad3)
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_VCS_git=y
CT_BINUTILS_DEVEL_URL="https://github.com/bminor/binutils-gdb.git"
CT_BINUTILS_DEVEL_REVISION="2cb5c79dad39dd438fb0f7372ac04cf5aa2a7db7"

# GCC 10.2.0 (tag releases/gcc-10.2.0, commit ee5c3db6c5b)
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_VCS_git=y
CT_GCC_DEVEL_URL="https://gcc.gnu.org/git/gcc.git"
CT_GCC_DEVEL_REVISION="ee5c3db6c5b2c3332912fb4c9cfa2864569ebd9a"

# The build script appends a definition of CT_LOCAL_PATCH_DIR down here, that
# points to the repo's patch directory.
31 changes: 22 additions & 9 deletions lowrisc-toolchain-gcc-rv32imcb.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ CT_ARCH_RISCV=y
# are built with. It should specify the minimum RISC-V extensions that need to
# be implemented by any processor that this toolchain will compile programs for.
#
# 2020-03-26: We have added B extension (v0.92) support to the compiler using
# experimental patches, but we still want to support Ibex without
# the B extension, so this remains "rv32imc".
# 2022-01-13: We can now generally assume that Ibex supports bitmanip, so we can
# compile the toolchain libraries with bitmanip 1.0 support.
#
# N.B. OpenTitan still requires support for Ibex without bitmanip
# (in the English Breakfast toplevel design) but OpenTitan is
# freestanding, so it shouldn't use these libraries.
#
# Unfortunately, when we tried to enable the ratified bitmanip
# subset here by specifying `CT_ARCH_ARCH=rv32imc_zba_zbb_zbc_zbs`
# the toolchain failed to compile, saying that `rol` (from Zbb)
# wasn't a recognized instruction. Until this is solved we don't
# compile the libraries with bitmanip. This doesn't really matter
# for our current use cases.
#
CT_ARCH_ARCH="rv32imc"

Expand Down Expand Up @@ -48,17 +58,20 @@ CT_PREFIX_DIR="/tools/riscv"
# Don't chmod the CT_PREFIX_DIR read-only after the install.
# CT_PREFIX_DIR_RO is not set

# We apply the binutils bitmanip patches on top of git commit 612aac65
# Binutils 2.35, RISC-V bitmanip fork (branch riscv-binutils-2.35-rvb,
# commit 7c9dd840fb from 2021-03-10).
# A bitmanip 1.0+0.93 patch will be applied on top.
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_VCS_git=y
CT_BINUTILS_DEVEL_URL="https://github.com/bminor/binutils-gdb.git"
CT_BINUTILS_DEVEL_REVISION="612aac65e690387c963c34a31dd1fb138d88a45c"
CT_BINUTILS_DEVEL_URL="https://github.com/riscv-collab/riscv-binutils-gdb.git"
CT_BINUTILS_DEVEL_REVISION="7c9dd840fbb6a1171a51feb08afb859288615137"

# We apply the gcc bitmanip patches on top of git commit 49f75e008c0
# GCC 10.2.0, RISC-V bitmanip fork (branch riscv-gcc-10.2.0-rvb,
# commit 73055647d33 from 2021-07-09)
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_VCS_git=y
CT_GCC_DEVEL_URL="https://github.com/riscv/riscv-gcc.git"
CT_GCC_DEVEL_REVISION="49f75e008c0809eb3c74a163297b4aa8925c9f1c"
CT_GCC_DEVEL_URL="https://github.com/riscv-collab/riscv-gcc"
CT_GCC_DEVEL_REVISION="73055647d33c0b63a3125c372019d1dac0f8ac34"

# The build script appends a definition of CT_LOCAL_PATCH_DIR down here, that
# points to the repo's patch directory.
12 changes: 12 additions & 0 deletions lowrisc-toolchain-gcc-rv64imac.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,17 @@ CT_PREFIX_DIR="/tools/riscv"
# Don't chmod the CT_PREFIX_DIR read-only after the install.
# CT_PREFIX_DIR_RO is not set

# Binutils 2.35 (tag binutils-2_35, commit 2cb5c79dad3)
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_VCS_git=y
CT_BINUTILS_DEVEL_URL="https://github.com/bminor/binutils-gdb.git"
CT_BINUTILS_DEVEL_REVISION="2cb5c79dad39dd438fb0f7372ac04cf5aa2a7db7"

# GCC 10.2.0 (tag releases/gcc-10.2.0, commit ee5c3db6c5b)
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_VCS_git=y
CT_GCC_DEVEL_URL="https://gcc.gnu.org/git/gcc.git"
CT_GCC_DEVEL_REVISION="ee5c3db6c5b2c3332912fb4c9cfa2864569ebd9a"

# The build script appends a definition of CT_LOCAL_PATCH_DIR down here, that
# points to the repo's patch directory.
Loading

0 comments on commit 8ff8f02

Please sign in to comment.