Skip to content

Document origins of the multiplication method being used here. #499

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

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion src/riscv.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
intrinsics! {
// Implementation from gcc
// Ancient Egyptian/Ethiopian/Russian multiplication method
// see https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
//
// This is a long-available stock algorithm; e.g. it is documented in
// Knuth's "The Art of Computer Programming" volume 2 (under the section
// "Evaluation of Powers") since at least the 2nd edition (1981).
//
// The main attraction of this method is that it implements (software)
// multiplication atop four simple operations: doubling, halving, checking
// if a value is even/odd, and addition. This is *not* considered to be the
// fastest multiplication method, but it may be amongst the simplest (and
// smallest with respect to code size).
//
// for reference, see also implementation from gcc
// https://raw.githubusercontent.com/gcc-mirror/gcc/master/libgcc/config/epiphany/mulsi3.c
pub extern "C" fn __mulsi3(a: u32, b: u32) -> u32 {
let (mut a, mut b) = (a, b);
Expand Down