Skip to content
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

change code to use addressing helpers in all opcodes #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion circuits/helpers/src/addressing_helper.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn is_acc(opcode: Field) -> bool {
res
}
pub fn is_imp(opcode: Field) -> bool {
let opcode_vec = [202, 136, 24, 216, 88, 184, 232, 200, 56, 248, 120, 170, 168, 138];
let opcode_vec = [202, 136, 24, 216, 88, 184, 232, 200, 56, 248, 120, 170, 168, 138,152];
let mut res = false;
for i in 0..opcode_vec.len() {
if opcode == opcode_vec[i] {
Expand Down
129 changes: 0 additions & 129 deletions circuits/helpers/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -254,55 +254,6 @@ pub fn set_interrupt_bit(mut status: Status) -> Status {
status
}

// code to call functions
// need to be removed after the logic has transaferred completely to helper
pub fn acc(op_sorted_addr: [Field; 1], op_sorted_val: [Field; 1], op_sorted_op_rw: [Field; 1]) {
addressing::acc(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn imp(op_sorted_addr: [Field; 2], op_sorted_val: [Field; 2], op_sorted_op_rw: [Field; 2]) {
addressing::imp(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn imm(op_sorted_addr: [Field; 2], op_sorted_val: [Field; 2], op_sorted_op_rw: [Field; 2]) -> Field {
addressing::imm(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn zpo(op_sorted_addr: [Field; 3], op_sorted_val: [Field; 3], op_sorted_op_rw: [Field; 3]) -> Field {
addressing::zpo(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn zpx_zpy(
mode: Field,
op_sorted_addr: [Field; 5],
op_sorted_val: [Field; 5],
op_sorted_op_rw: [Field; 5]
) -> Field {
addressing::zpx_zpy(mode, op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn rel(op_sorted_addr: [Field; 3], op_sorted_val: [Field; 3], op_sorted_op_rw: [Field; 3]) -> Field {
addressing::rel(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn abs(op_sorted_addr: [Field; 6], op_sorted_val: [Field; 6], op_sorted_op_rw: [Field; 6]) -> Field {
addressing::abs(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn abx_aby(
mode: Field,
op_sorted_addr: [Field; 8],
op_sorted_val: [Field; 8],
op_sorted_op_rw: [Field; 8]
) -> [Field; 2] {
addressing::abx_aby(mode, op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn ind(op_sorted_addr: [Field; 8], op_sorted_val: [Field; 8], op_sorted_op_rw: [Field; 8]) -> Field {
addressing::ind(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn idx(op_sorted_addr: [Field; 7], op_sorted_val: [Field; 7], op_sorted_op_rw: [Field; 7]) -> Field {
addressing::idx(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}
pub fn idy(
op_sorted_addr: [Field; 7],
op_sorted_val: [Field; 7],
op_sorted_op_rw: [Field; 7]
) -> [Field; 2] {
addressing::idy(op_sorted_addr, op_sorted_val, op_sorted_op_rw)
}

// addressing helper function to select the addressing based on the mode
pub fn addressing_helpers(
Expand Down Expand Up @@ -563,22 +514,6 @@ pub fn addressing_helpers(
}
}

pub fn compute_permutation_9(
r: Field,
op_sorted_step: [Field; 9],
op_sorted_addr: [Field; 9],
op_sorted_val: [Field; 9],
op_sorted_op_rw: [Field; 9]
) -> Field {
permutation::compute_9(
r,
op_sorted_step,
op_sorted_addr,
op_sorted_val,
op_sorted_op_rw
)
}

pub fn compute_permutation_21(
r: Field,
op_sorted_step: [Field; 21],
Expand All @@ -594,67 +529,3 @@ pub fn compute_permutation_21(
op_sorted_op_rw
)
}

pub fn compute_permutation_7(
r: Field,
op_sorted_step: [Field; 7],
op_sorted_addr: [Field; 7],
op_sorted_val: [Field; 7],
op_sorted_op_rw: [Field; 7]
) -> Field {
permutation::compute_7(
r,
op_sorted_step,
op_sorted_addr,
op_sorted_val,
op_sorted_op_rw
)
}

pub fn compute_permutation_17(
r: Field,
op_sorted_step: [Field; 17],
op_sorted_addr: [Field; 17],
op_sorted_val: [Field; 17],
op_sorted_op_rw: [Field; 17]
) -> Field {
permutation::compute_17(
r,
op_sorted_step,
op_sorted_addr,
op_sorted_val,
op_sorted_op_rw
)
}

pub fn compute_permutation_15(
r: Field,
op_sorted_step: [Field; 15],
op_sorted_addr: [Field; 15],
op_sorted_val: [Field; 15],
op_sorted_op_rw: [Field; 15]
) -> Field {
permutation::compute_15(
r,
op_sorted_step,
op_sorted_addr,
op_sorted_val,
op_sorted_op_rw
)
}

pub fn compute_permutation_18(
r: Field,
op_sorted_step: [Field; 18],
op_sorted_addr: [Field; 18],
op_sorted_val: [Field; 18],
op_sorted_op_rw: [Field; 18]
) -> Field {
permutation::compute_18(
r,
op_sorted_step,
op_sorted_addr,
op_sorted_val,
op_sorted_op_rw
)
}
54 changes: 0 additions & 54 deletions circuits/helpers/src/permutation.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,3 @@ pub fn compute_21(
0
}

pub fn compute_9(
_r: Field,
_op_sorted_step: [Field; 9],
_op_sorted_addr: [Field; 9],
_op_sorted_val: [Field; 9],
_op_sorted_op_rw: [Field; 9]
) -> Field {
// TODO: implement
0
}

pub fn compute_7(
_r: Field,
_op_sorted_step: [Field; 7],
_op_sorted_addr: [Field; 7],
_op_sorted_val: [Field; 7],
_op_sorted_op_rw: [Field; 7]
) -> Field {
// TODO: implement
0
}

pub fn compute_17(
_r: Field,
_op_sorted_step: [Field; 17],
_op_sorted_addr: [Field; 17],
_op_sorted_val: [Field; 17],
_op_sorted_op_rw: [Field; 17]
) -> Field {
// TODO: implement
0
}

pub fn compute_18(
_r: Field,
_op_sorted_step: [Field; 18],
_op_sorted_addr: [Field; 18],
_op_sorted_val: [Field; 18],
_op_sorted_op_rw: [Field; 18]
) -> Field {
// TODO: implement
0
}

pub fn compute_15(
_r: Field,
_op_sorted_step: [Field; 15],
_op_sorted_addr: [Field; 15],
_op_sorted_val: [Field; 15],
_op_sorted_op_rw: [Field; 15]
) -> Field {
// TODO: implement
0
}
80 changes: 43 additions & 37 deletions circuits/instr/and/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use dep::std;

fn main(
r: Field,
op_sorted_step: [Field; 18],
op_sorted_addr: [Field; 18],
op_sorted_val: [Field; 18],
op_sorted_op_rw: [Field; 18]
op_sorted_step: [Field; 21],
op_sorted_addr: [Field; 21],
op_sorted_val: [Field; 21],
op_sorted_op_rw: [Field; 21]
) -> pub Field {
//check the program counter
assert(op_sorted_addr[0] == 8203);
Expand Down Expand Up @@ -93,7 +93,13 @@ fn main(
assert(op_sorted_op_rw[17] == 1);
assert(op_sorted_val[17] == comp_status);

helpers::compute_permutation_18(
for i in 18..21 {
assert(op_sorted_addr[i] == 0);
assert(op_sorted_val[i] == 0);
assert(op_sorted_op_rw[i] == 0);
}

helpers::compute_permutation_21(
r,
op_sorted_step,
op_sorted_addr,
Expand All @@ -110,11 +116,11 @@ fn test_0() -> Field {
main(
1,
[
343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449
343432, 343433, 343434, 343435, 343436, 343437, 343438, 343439, 343440, 343441, 343442, 343443, 343444, 343445, 343446,343447, 343448 , 343449 , 343450 , 343451 , 343452
],
[8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8200,8205, 8205],
[49231, 41, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,67,34,2,36,36],
[0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,0,1,0, 1]
[8203, 79, 8203,8203,8203, 0, 0, 0, 0, 0,0,8203,8203,8204,8200,8200,8205,8205,0,0,0],
[49231, 41, 49232, 1, 49233, 0, 0, 0, 0, 0,0,49233,49234,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1, 0, 0, 0, 0, 0,0,0,1,0,0,1,0, 1,0,0,0]
)
}

Expand All @@ -123,11 +129,11 @@ fn test_1() -> Field {
main(
1,
[
343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509
343492, 343493, 343494, 343495, 343496, 343497, 343498, 343499, 343500, 343501, 343502, 343503, 343504, 343505, 343506, 343507, 343508 , 343509 , 343510 , 343511 , 343512
],
[8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8200,8205, 8205],
[49231, 37 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,67,34,2,36,36],
[0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,0,1,0, 1]
[8203, 79, 8203,8203,8203, 0, 0, 0,0,0,8203,49233,8203 ,8204,8200,8200,8205, 8205,0,0,0],
[49231, 37 , 49232, 1, 49233, 0, 0, 0,0,0, 49233,69,49234,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1, 0, 0, 0,0,0,0,0,1,0,0,1,0, 1,0,0,0]
)
}

Expand All @@ -136,11 +142,11 @@ fn test_2() -> Field {
main(
1,
[
343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569
343552, 343553, 343554, 343555, 343556, 343557, 343558, 343559, 343560, 343561, 343562, 343563, 343564, 343565, 343566, 343567, 343568 , 343569 , 343570 , 343571 , 343572
],
[8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8200,8205, 8205 ],
[49231, 53, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,67,34,2,36,36 ],
[0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,0,1,0, 1 ]
[8203, 79, 8203,8203,8203,0,0,0,8203,49233,8203,13,8202,8204,8200,8200,8205, 8205,0,0,0],
[49231, 53, 49232, 1, 49233,0,0,0,49233,13,49234,0,69,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1,0,0,0,0,0,1,0,0,0,0,1,0, 1,0,0,0]
)
}

Expand All @@ -149,11 +155,11 @@ fn test_3() -> Field {
main(
1,
[
343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629
343612, 343613, 343614, 343615, 343616, 343617, 343618, 343619, 343620, 343621, 343622, 343623, 343624, 343625, 343626, 343627, 343628 , 343629 , 343630 , 343631 , 343632
],
[8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8200,8205, 8205 ],
[49231, 45, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,67,34,2,36,36],
[0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,0,1,0, 1 ]
[8203, 79, 8203,8203,8203,0,0,8203,49233,8203,8203,49234, 8203,8204,8200,8200,8205, 8205 ,0,0,0],
[49231, 45, 49232, 1, 49233,0,0,49233,1,49234,49234,2,49235,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,0]
)
}

Expand All @@ -162,11 +168,11 @@ fn test_4() -> Field {
main(
1,
[
343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729
343712, 343713, 343714, 343715, 343716, 343717, 343718, 343719, 343720, 343721, 343722, 343723, 343724, 343725, 343726, 343727, 343728 , 343729 , 343730 , 343731 , 343732
],
[8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8200,8205, 8205 ],
[49231,61, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36],
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1 ]
[8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8201, 582,8204,8200,8200,8205, 8205,0,0,0],
[49231,61, 49232,0,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1,0,0,0]
)
}

Expand All @@ -175,11 +181,11 @@ fn test_5() -> Field {
main(
1,
[
343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829
343812, 343813, 343814, 343815, 343816, 343817, 343818, 343819, 343820, 343821, 343822, 343823, 343824, 343825, 343826, 343827, 343828 , 343829 , 343830 , 343831 , 343832
],
[8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8200,8205, 8205 ],
[49231,57, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36],
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0, 1 ]
[8203,79,8203,8203,8203,8203, 49233, 8203, 8203, 49234, 8203, 8202, 582,8204,8200,8200,8205, 8205,0,0,0],
[49231,57, 49232,1,49233,49233, 1, 49234, 49234, 2, 49235, 69, 80,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,0,0,1,0,1,0,0,0]
)
}

Expand All @@ -188,11 +194,11 @@ fn test_6() -> Field {
main(
1,
[
343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929
343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 , 343930 , 343931 , 343932
],
[8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8200,8205, 8205 ],
[49231,33, 49232,0,49233,0,49233,5675,5676,69,13,1,2,67,34,2,36,36],
[0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,0,1,0,1]
[8203,79,8203,8203,8203,0,8203,49233,8203,5675,8201,5688,5689,8204,8200,8200,8205, 8205,0,0,0],
[49231,33, 49232,0,49233,0,49233,5675,5676,69,13,1,2,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1,0,0,0,1,0,0,0,0 ,0,0,1,0,1,0,0,0]
)
}

Expand All @@ -201,10 +207,10 @@ fn test_7() -> Field {
main(
1,
[
343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929
343912, 343913, 343914, 343915, 343916, 343917, 343918, 343919, 343920, 343921, 343922, 343923, 343924, 343925, 343926, 343927, 343928 , 343929 , 343930 , 343931 , 343932
],
[8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8200,8205, 8205],
[49231,49, 49232,0,49233,0,49233,5675,5676,1,2,69,112,67,34,2,36,36],
[0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,0,1,0,1]
[8203,79,8203,8203,8203,0,8203,49233,8203,5675,5676,8202,582,8204,8200,8200,8205, 8205,0,0,0],
[49231,49, 49232,0,49233,0,49233,5675,5676,1,2,69,112,67,34,2,36,36,0,0,0],
[0, 0, 1, 0, 1,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0]
)
}
Loading