Skip to content

Commit 0333c0e

Browse files
committed
Support 64-bit limbs on no-asm platforms
Currently, platforms without assembler support always use 32-bit limbs, but the Rust bindings always assume 64-bit limbs. This breaks on big-endian platforms like our IBM Z (s390x). This patch enables 64-bit limbs on 64-bit platforms even if there is no hand-written assembler, by using a 128-bit integer type in the C implementation (this is an extension that is widely supported on 64-bit platforms with GCC or LLVM). This fixes the broken Rust bindings on IBM Z, and also improves performance by a factor or 3 or more, because compiler-generated code handling __int128 already uses the 64x64->128 multiply instruction our ISA provides. To improve performance of compiler-generated code a bit more, this also switches to the -O3 optimization level, which helps with unrolling of the Montgomery multiply core loop.
1 parent f2380d2 commit 0333c0e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

bindings/rust/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ fn main() {
116116
.flag_if_supported("-Wno-unused-function")
117117
.flag_if_supported("-Wno-unused-command-line-argument");
118118
if !cfg!(debug_assertions) {
119-
cc.opt_level(2);
119+
if target_arch.eq("s390x") {
120+
cc.opt_level(3);
121+
} else {
122+
cc.opt_level(2);
123+
}
120124
}
121125
cc.files(&file_vec).compile("libblst.a");
122126

src/no_asm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#if LIMB_T_BITS==32
88
typedef unsigned long long llimb_t;
9+
#else
10+
typedef unsigned __int128 llimb_t;
911
#endif
1012

1113
#if defined(__clang__)

src/vect.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef unsigned long long limb_t;
1818
typedef unsigned __int64 limb_t;
1919
# define LIMB_T_BITS 64
2020

21-
#elif defined(__BLST_NO_ASM__) || defined(__wasm64__)
21+
#elif defined(__wasm64__)
2222
typedef unsigned int limb_t;
2323
# define LIMB_T_BITS 32
2424
# ifndef __BLST_NO_ASM__
@@ -31,8 +31,10 @@ typedef unsigned long limb_t;
3131
# define LIMB_T_BITS 64
3232
# else
3333
# define LIMB_T_BITS 32
34-
# define __BLST_NO_ASM__
3534
# endif
35+
# ifndef __BLST_NO_ASM__
36+
# define __BLST_NO_ASM__
37+
# endif
3638
#endif
3739

3840
/*

0 commit comments

Comments
 (0)