Skip to content

Commit 54d00e1

Browse files
authored
Merge pull request #499 from pnkfelix/ancient-history
2 parents 5af23aa + 530baa4 commit 54d00e1

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/riscv.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
intrinsics! {
2-
// Implementation from gcc
2+
// Ancient Egyptian/Ethiopian/Russian multiplication method
3+
// see https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
4+
//
5+
// This is a long-available stock algorithm; e.g. it is documented in
6+
// Knuth's "The Art of Computer Programming" volume 2 (under the section
7+
// "Evaluation of Powers") since at least the 2nd edition (1981).
8+
//
9+
// The main attraction of this method is that it implements (software)
10+
// multiplication atop four simple operations: doubling, halving, checking
11+
// if a value is even/odd, and addition. This is *not* considered to be the
12+
// fastest multiplication method, but it may be amongst the simplest (and
13+
// smallest with respect to code size).
14+
//
15+
// for reference, see also implementation from gcc
316
// https://raw.githubusercontent.com/gcc-mirror/gcc/master/libgcc/config/epiphany/mulsi3.c
17+
//
18+
// and from LLVM (in relatively readable RISC-V assembly):
19+
// https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
420
pub extern "C" fn __mulsi3(a: u32, b: u32) -> u32 {
521
let (mut a, mut b) = (a, b);
622
let mut r = 0;

0 commit comments

Comments
 (0)