Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
d6d39d2
Upgrade to new syntax
Pratyush Aug 12, 2021
615b005
Fmt
Pratyush Aug 12, 2021
27d266e
add comments
Pratyush Aug 12, 2021
d89ed19
Fix build script
Pratyush Aug 12, 2021
3229826
Fix generated assembly
Pratyush Aug 12, 2021
3cf16da
Clean up assembly library
Pratyush Aug 14, 2021
16523e8
Clean context module
Pratyush Aug 14, 2021
eba4f5f
Fix
Pratyush Aug 14, 2021
84f44c3
Tweak
Pratyush Aug 14, 2021
f4faf7a
Fix
Pratyush Aug 14, 2021
93e479f
Fix formatting of registers
Pratyush Aug 14, 2021
89c182b
Merge branch 'master' into migrate-to-asm
Pratyush Aug 14, 2021
6b65552
Merge branch 'master' into migrate-to-asm
weikengchen Jan 7, 2022
0f01f56
Update arithmetic.rs
weikengchen Jan 7, 2022
e8143f1
Update arithmetic.rs
weikengchen Jan 7, 2022
c579e58
Update mod.rs
weikengchen Jan 7, 2022
a9691a8
Update lib.rs
weikengchen Jan 7, 2022
6cd9a6f
Update lib.rs
weikengchen Jan 7, 2022
781ff18
Update lib.rs
weikengchen Jan 7, 2022
ef5e27f
Declare P::MODULUS.0 and P::INV as constants
Pratyush Jan 7, 2022
f4f4584
Fix
Pratyush Jan 7, 2022
2d37a39
Add required features
Pratyush Jan 7, 2022
0b1c3c5
`const` generics for `Fp` & no Montgomery default
Pratyush Jan 10, 2022
56e5ecc
More powerful compile-time Fp configuration
Pratyush Jan 11, 2022
8a81ee7
Fix compilation errors in `ark-ec`
Pratyush Jan 11, 2022
5fb6ffb
Fix compilation errors in `ark-poly`
Pratyush Jan 11, 2022
e8558d7
Fix doctest
Pratyush Jan 11, 2022
2a47811
Fix CHANGELOG typos
Pratyush Jan 11, 2022
fbede63
Everything compiles
Pratyush Jan 12, 2022
7ea854b
Rename `Parameters` to `Config` for all fields
Pratyush Jan 12, 2022
dfeea4a
Update CHANGELOG and fix typos in README
Pratyush Jan 12, 2022
ec89e31
Clean up CHANGELOG further
Pratyush Jan 12, 2022
cc8cb91
Fix assembly
Pratyush Jan 12, 2022
266b37e
Fix indentation
Pratyush Jan 12, 2022
ad1bca7
Fix assembly
Pratyush Jan 12, 2022
23868df
Fix README lint
Pratyush Jan 12, 2022
7a76bd8
Fix import
Pratyush Jan 12, 2022
9ce6ce9
Fix match statement
Pratyush Jan 12, 2022
b5f3887
Fix match statement, and move no_carry check to constant
Pratyush Jan 12, 2022
923bb3f
Introduce `BigInt` macro
Pratyush Jan 12, 2022
61fcbaf
Fix `CAPACITY` bug
Pratyush Jan 12, 2022
2e083db
Make `QuadExt` and `CubicExt` macros more succinct
Pratyush Jan 12, 2022
054204b
Add documentation for macros
Pratyush Jan 12, 2022
a550389
fmt
Pratyush Jan 12, 2022
5f866fe
Use singular in CHANGELOG
Pratyush Jan 12, 2022
2964946
Clean up some documentation
Pratyush Jan 12, 2022
bce28d3
Merge branch 'upgrade-ff' of github.com:arkworks-rs/algebra into upgr…
Pratyush Jan 12, 2022
5b6642f
Update and format
Pratyush Jan 12, 2022
9f01c8b
Clean up doc test
Pratyush Jan 12, 2022
0d8fcd1
Clean up docs
Pratyush Jan 12, 2022
e4f111b
Merge `upgrade-ff`
Pratyush Jan 12, 2022
3eec142
Fix merge
Pratyush Jan 12, 2022
871bac1
Make CI provide more details
Pratyush Jan 12, 2022
862981e
Experiment with putting `INV` in register
Pratyush Jan 12, 2022
d2acce5
Update ci.yml
weikengchen Jan 13, 2022
f3b6903
Merge branch 'master' into migrate-to-asm
weikengchen Feb 5, 2022
a80a82a
fmt
weikengchen Feb 5, 2022
4eb0507
fmt
weikengchen Feb 5, 2022
cd934c5
Update ci.yml
weikengchen Feb 5, 2022
76fde44
Update ci.yml
weikengchen Feb 5, 2022
5411d70
movq_zero?
weikengchen Feb 5, 2022
6106f10
drop the z flag
weikengchen Feb 5, 2022
e1e993d
automatically use asm if it is in 1.59.0
weikengchen Feb 5, 2022
210f2ad
Update CHANGELOG.md
weikengchen Feb 5, 2022
2d33586
keep the asm feature
weikengchen Feb 5, 2022
c3dcded
simplify build.rs
weikengchen Feb 5, 2022
40f01e0
Update CHANGELOG.md
weikengchen Feb 5, 2022
dc9809b
Update CHANGELOG.md
weikengchen Feb 5, 2022
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@
- Remove `FftConfig`; move its contents to `FftField`.
- [\#383](https://github.com/arkworks-rs/algebra/pull/383) (arc-ff) Rename `BigInteger::add_nocarry` to `add_with_carry` and `sub_noborrow` to `sub_with_borrow`.


### Features

- [\#321](https://github.com/arkworks-rs/algebra/pull/321) (`ark-ff`) Change bigint conversions to impl `From` instead of `Into`.
- [\#301](https://github.com/arkworks-rs/algebra/pull/301) (`ark-ec`) Add `GLVParameters` trait definition.
- [\#312](https://github.com/arkworks-rs/algebra/pull/312) (`ark-ec`) Add `is_in_correct_subgroup_assuming_on_curve` for all `SWModelParameters`.
- [\#321](https://github.com/arkworks-rs/algebra/pull/321) (`ark-ff`) Change bigint conversions to impl `From` instead of `Into`.
- [\#348](https://github.com/arkworks-rs/algebra/pull/348) (`ark-ec`) Add `msm:{Fixed,Variable}Base:msm_checked_len`.
- [\#364](https://github.com/arkworks-rs/algebra/pull/364) (`ark-ec`) Add `ChunkedPippenger` to variable-base MSM.
- [\#371](https://github.com/arkworks-rs/algebra/pull/371) (`ark-serialize`) Add serialization impls for arrays

### Improvements

- [\#306](https://github.com/arkworks-rs/algebra/pull/306) (`ark-ff`, `ark-ff-asm`) Make the assembly backend available on `stable`.
- [\#339](https://github.com/arkworks-rs/algebra/pull/339) (`ark-ff`) Remove duplicated code from `test_field` module and replace its usage with `ark-test-curves` crate.
- [\#352](https://github.com/arkworks-rs/algebra/pull/352) (`ark-ff`) Update `QuadExtField::sqrt` for better performance.
- [\#357](https://github.com/arkworks-rs/algebra/pull/357) (`ark-poly`) Speedup division by vanishing polynomials for dense polynomials.
Expand Down
121 changes: 0 additions & 121 deletions ff-asm/src/context.rs

This file was deleted.

68 changes: 68 additions & 0 deletions ff-asm/src/context/data_structures.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::fmt;

#[derive(Clone)]
pub enum AssemblyVar {
Memory(String),
Variable(String),
Fixed(String),
}

impl AssemblyVar {
pub fn memory_access(&self, offset: usize) -> Option<AssemblyVar> {
match self {
Self::Variable(a) | Self::Fixed(a) => Some(Self::Memory(format!("{}({})", offset, a))),
_ => None,
}
}

pub fn memory_accesses(&self, range: usize) -> Vec<AssemblyVar> {
(0..range)
.map(|i| {
let offset = i * 8;
self.memory_access(offset).unwrap()
})
.collect()
}
}

impl fmt::Display for AssemblyVar {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
Self::Variable(a) | Self::Fixed(a) | Self::Memory(a) => write!(f, "{}", a),
}
}
}

impl<'a> From<Declaration<'a>> for AssemblyVar {
fn from(other: Declaration<'a>) -> Self {
Self::Variable(format!("{{{}}}", other.name))
}
}

impl<'a> From<Register<'a>> for AssemblyVar {
fn from(other: Register<'a>) -> Self {
Self::Fixed(format!("%{}", other.0))
}
}

#[derive(Copy, Clone, PartialEq, Eq)]
pub struct Register<'a>(pub &'a str);
impl fmt::Display for Register<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "\"{}\"", self.0)
}
}

#[derive(Copy, Clone)]
pub struct Declaration<'a> {
/// Name of the assembly template variable declared by `self`.
pub name: &'a str,
/// Rust expression whose value is declared in `self`.
pub expr: &'a str,
}

impl fmt::Display for Declaration<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{} = in(reg) {},", self.name, self.expr)
}
}
117 changes: 117 additions & 0 deletions ff-asm/src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
mod data_structures;
pub use data_structures::*;

#[derive(Clone)]
pub struct Context<'a> {
assembly_instructions: Vec<String>,
declarations: Vec<Declaration<'a>>,
used_registers: Vec<Register<'a>>,
}

impl<'a> Context<'a> {
pub const RAX: Register<'static> = Register("rax");
pub const RSI: Register<'static> = Register("rsi");
pub const RCX: Register<'static> = Register("rcx");
pub const RDX: Register<'static> = Register("rdx");

pub const R: [Register<'static>; 8] = [
Register("r8"),
Register("r9"),
Register("r10"),
Register("r11"),
Register("r12"),
Register("r13"),
Register("r14"),
Register("r15"),
];

pub fn new() -> Self {
Self {
assembly_instructions: Vec::new(),
declarations: Vec::new(),
used_registers: Vec::new(),
}
}

fn find(&self, name: &str) -> Option<&Declaration<'_>> {
self.declarations.iter().find(|item| item.name == name)
}

fn append(&mut self, other: &str) {
self.assembly_instructions.push(format!("\"{}\",", other));
}

fn instructions_to_string(&self) -> String {
self.assembly_instructions.join("\n")
}

fn get_decl_name(&self, name: &str) -> Option<&Declaration<'_>> {
self.find(name)
}

pub fn get_decl(&self, name: &str) -> Declaration<'_> {
*self.get_decl_name(name).unwrap()
}

pub fn get_decl_with_fallback(&self, name: &str, fallback_name: &str) -> Declaration<'_> {
self.get_decl_name(name)
.copied()
.unwrap_or_else(|| self.get_decl(fallback_name))
}

pub fn add_declaration(&mut self, name: &'a str, expr: &'a str) {
let declaration = Declaration { name, expr };
self.declarations.push(declaration);
}

pub fn add_buffer(&mut self, extra_reg: usize) {
self.append(&format!(
"let mut spill_buffer = core::mem::MaybeUninit::<[u64; {}]>::uninit();",
extra_reg
));
}

pub fn add_asm(&mut self, asm_instructions: &[String]) {
for instruction in asm_instructions {
self.append(instruction)
}
}

pub fn add_clobbers(&mut self, clobbers: impl Iterator<Item = Register<'a>>) {
for clobber in clobbers {
self.add_clobber(clobber)
}
}

pub fn add_clobber(&mut self, clobber: Register<'a>) {
self.used_registers.push(clobber);
}

pub fn build(self) -> String {
let declarations: String = self
.declarations
.iter()
.map(ToString::to_string)
.collect::<Vec<String>>()
.join("\n");
let clobbers = self
.used_registers
.iter()
.map(|l| format!("out({}) _,", l))
.collect::<Vec<String>>()
.join("\n");
let options = "options(att_syntax)".to_string();
let assembly = self.instructions_to_string();
[
"unsafe {".to_string(),
"ark_std::arch::asm!(".to_string(),
assembly,
declarations,
clobbers,
options,
")".to_string(),
"}".to_string(),
]
.join("\n")
}
}
Loading