Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions .github/workflows/loongarch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Rust

on: [pull_request, workflow_dispatch]

env:
TOOLCHAIN_HOME: /opt/cross-tools
TARGET: loongarch64-unknown-linux-gnu
DEBIAN_FRONTEND: noninteractive

jobs:
loongarch:
name: LoongArch64
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.rust == 'nightly' }}
strategy:
matrix:
rust:
- stable
- nightly

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Linux Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: "${TARGET}"

- name: Install Cross Toolchain
run: |
# NOTE: Update this periodically
release="2025.08.08"
filename="loongarch64.tar.xz"
url="https://github.com/loongson/build-tools/releases/download/${release}/x86_64-cross-tools-loongarch64-binutils_2.45-gcc_15.1.0-glibc_2.42.tar.xz"

wget "${url}" -O "${filename}"
tar -xf "${filename}"
sudo mv "cross-tools" "${TOOLCHAIN_HOME}"
rm "${filename}"

"${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc" --version

- name: Install Qemu Runner
run: |
sudo apt update && sudo apt install qemu-user -y --no-install-recommends
qemu-loongarch64 --version

- name: Build and Test Library
run: |
export CC_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc"
export CXX_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-g++"
export AR_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc-ar"
export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc"
export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-loongarch64 -L ${TOOLCHAIN_HOME}/target"

# NOTE: The qemu runner does not seem to work for this architecture.
cargo build --target "${TARGET}"
cargo test --target "${TARGET}"

cd devel
cargo build --target "${TARGET}"
cargo test --target "${TARGET}"
4 changes: 1 addition & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ jobs:
uses: actions/checkout@v4

- name: Linux Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.75.0
uses: dtolnay/rust-toolchain@stable

- name: Build, Check, and Test
run: |
Expand Down
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
fn main() {
let version = rustc_version::version().unwrap();
let version_meta = rustc_version::version_meta().unwrap();
let support_unstable = version_meta.channel == rustc_version::Channel::Nightly;

if version >= rustc_version::Version::parse("1.63.0").unwrap() {
println!("cargo:rustc-cfg=has_aarch64_intrinsics");
Expand All @@ -8,4 +10,8 @@ fn main() {
if version >= rustc_version::Version::parse("1.70.0").unwrap() {
println!("cargo:rustc-cfg=has_x86_intrinsics");
}

if support_unstable && version >= rustc_version::Version::parse("1.89.0").unwrap() {
println!("cargo:rustc-cfg=has_loongarch_intrinsics");
}
}
2 changes: 2 additions & 0 deletions src/binary16/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ macro_rules! convert_fn {
$aarch64
}
else if #[cfg(all(
has_loongarch_intrinsics,
target_arch = "loongarch64",
target_feature = "lsx"
))] {
Expand Down Expand Up @@ -65,6 +66,7 @@ macro_rules! convert_fn {
}
}
else if #[cfg(all(
has_loongarch_intrinsics,
feature = "std",
target_arch = "loongarch64",
))] {
Expand Down
3 changes: 3 additions & 0 deletions src/binary16/arch/loongarch64.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![cfg(has_loongarch_intrinsics)]
#![allow(unknown_lints)]

#[cfg(target_arch = "loongarch64")]
use core::arch::loongarch64::{lsx_vfcvt_h_s, lsx_vfcvtl_s_h, m128, m128i};
use core::{mem::MaybeUninit, ptr};
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
//! [`std`]: https://doc.rust-lang.org/std/
//! [`binary16`]: https://en.wikipedia.org/wiki/Half-precision_floating-point_format
//! [`bfloat16`]: https://en.wikipedia.org/wiki/Bfloat16_floating-point_format

#![allow(clippy::verbose_bit_mask, clippy::cast_lossless, unexpected_cfgs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(all(target_arch = "loongarch64", has_loongarch_intrinsics), feature(stdarch_loongarch))]
#![doc(html_root_url = "https://docs.rs/float16/0.1.6")]
#![doc(test(attr(deny(warnings), allow(unused))))]
// Until updated to use newly stabilized `from_bits`, disable new lint warning about the transmutes
Expand Down
Loading