Skip to content

Commit

Permalink
Add mulmod
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiyou committed Dec 9, 2023
1 parent a345d03 commit 5da31db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- [Linear Recurrence (Constant Coefficient)](rec.md)
- [Constant Division / Modulo](cdiv.md)
- [Number Theoretic Transform](ntt.md)
- [Mulmod](mulmod.md)

# Geometry

Expand Down
21 changes: 21 additions & 0 deletions src/mulmod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Mulmod

Computes 64bit a times b mod c, returning quotient and remainder

```rs
fn mulmod(a: u64, b: u64, c: u64) -> (u64, u64) {
let (quot, rem);
unsafe {
std::arch::asm!(
"mul {b}",
"div {c}",
inout("rax") a => quot,
b = in(reg) b,
c = in(reg) c,
out("rdx") rem,
options(nomem, pure)
)
};
(quot, rem)
}
```

0 comments on commit 5da31db

Please sign in to comment.