115 lines
3.3 KiB
NASM
Raw Normal View History

2022-10-17 11:02:24 -04:00
global test_mul_Fp12:
// stack: f, f', g, g'
%store_fp6(0)
%store_fp6(6)
%store_fp6(12)
%store_fp6(18)
PUSH return_on_stack
// stack: return_on_stack
%jump(mul_Fp12)
return_on_stack:
// stack:
%load_fp6(30)
%load_fp6(24)
2022-10-17 11:02:24 -04:00
// stack: h, h'
%jump(0xdeadbeef)
2022-10-13 20:06:19 -04:00
2022-10-07 15:41:46 -07:00
2022-10-18 11:23:43 -04:00
/// macro | num | ops | cost
/// -------------------------
2022-10-18 12:47:31 -04:00
/// load | 8 | 40 | 320
/// store | 5 | 40 | 200
/// dup | 5 | 6 | 30
/// swap | 4 | 16 | 64
/// add | 3 | 16 | 48
/// sub | 2 | 17 | 34
/// mul | 3 | 156 | 468
/// i9 | 1 | 9 | 9
/// jump | 1 | 1 | 1
2022-10-18 11:23:43 -04:00
///
/// TOTAL: 1174
/// F = f + f'z
/// G = g + g'z
///
/// H = h + h'z = FG
///
/// h = fg + sh(f'g')
/// h' = (f+f')(g+g') - fg - f'g'
///
2022-10-20 11:55:05 -04:00
/// Note: f, f', g, g' consist of six terms on the stack
2022-10-18 11:23:43 -04:00
2022-10-17 11:02:24 -04:00
global mul_Fp12:
2022-10-20 11:55:05 -04:00
// stack: in1, in2, out
DUP1 %add_const(6) %load_fp6
// stack: f', in1, in2, out
DUP7 %add_const(6) %load_fp6
// stack: g', f', in1, in2, out
PUSH post_mul_1
DUP13 DUP13 DUP13 DUP13 DUP13 DUP13
// stack: f', post_mul_1, g', f', in1, in2, out
DUP13 DUP13 DUP13 DUP13 DUP13 DUP13
// stack: g', f', post_mul_1, g', f', in1, in2, out
%jump(mul_fp6)
post_mul_1:
// stack: f'g', g' , f', in1, in2, out
2022-10-07 15:41:46 -07:00
%dup1_fp6
2022-10-20 11:55:05 -04:00
// stack: f'g', f'g', g' , f', in1, in2, out
2022-10-07 15:41:46 -07:00
%store_fp6_sh(36)
2022-10-20 11:55:05 -04:00
// stack: f'g', g' , f', in1, in2, out
2022-10-07 15:41:46 -07:00
%store_fp6(42)
2022-10-20 11:55:05 -04:00
// stack: g' , f', in1, in2, out
DUP13
// stack: in1, g' , f', in1, in2, out
DUP15 %load_fp6
// stack: g , in1, g' , f', in1, in2, out
%swap_fp6_hole
// stack: g', in1, g , f', in1, in2, out
DUP13 DUP13 DUP13 DUP13 DUP13 DUP13
// stack: g,g', in1, g , f', in1, in2, out
2022-10-07 15:41:46 -07:00
%add_fp6
2022-10-20 11:55:05 -04:00
// stack: g+g', in1, g , f', in1, in2, out
%swap_fp6_hole
// stack: g, in1, g+g', f', in1, in2, out
PUSH post_mul_2
SWAP7
%load_fp6
// stack: f, g, post_mul_2, g+g', f', in1, in2, out
%jump(mul_fp6)
post_mul_2:
// stack: fg, g+g', f', in1, in2, out
2022-10-07 15:41:46 -07:00
%store_fp6(48)
2022-10-20 11:55:05 -04:00
// stack: g+g', f', in1, in2, out
2022-10-07 15:41:46 -07:00
%swap_fp6
2022-10-20 11:55:05 -04:00
// stack: f', g+g', in1, in2, out
PUSH post_mul_3
SWAP13 %load_fp6
// stack: f,f', g+g', post_mul_3, in2, out
2022-10-07 15:41:46 -07:00
%add_fp6
2022-10-20 11:55:05 -04:00
// stack: f+f', g+g', post_mul_3, in2, out
%jump(mul_fp6)
post_mul_3:
// stack: (f+f')(g+g'), in2, out
2022-10-07 15:41:46 -07:00
%load_fp6(42)
2022-10-20 11:55:05 -04:00
// stack: f'g', (f+f')(g+g'), in2, out
2022-10-20 10:56:55 -04:00
%subr_fp6
2022-10-20 11:55:05 -04:00
// stack: (f+f')(g+g') - f'g', in2, out
2022-10-07 15:41:46 -07:00
%load_fp6(48)
2022-10-20 11:55:05 -04:00
// stack: fg, (f+f')(g+g') - f'g', in2, out
2022-10-07 15:41:46 -07:00
%swap_fp6
2022-10-20 11:55:05 -04:00
// stack: (f+f')(g+g') - f'g', fg, in2, out
2022-10-07 15:41:46 -07:00
%dup2_fp6
2022-10-20 11:55:05 -04:00
// stack: fg, (f+f')(g+g') - f'g', fg, in2, out
2022-10-20 10:56:55 -04:00
%subr_fp6
2022-10-20 11:55:05 -04:00
// stack: (f+f')(g+g') - f'g' - fg, fg, in2, out
DUP14 add_const(6) %store_fp6
// stack: fg, in2, out
2022-10-07 15:41:46 -07:00
%load_fp6(36)
2022-10-20 11:55:05 -04:00
// stack: sh(f'g') , fg, in2, out
2022-10-07 15:41:46 -07:00
%add_fp6
2022-10-20 11:55:05 -04:00
// stack: sh(f'g') + fg, in2, out
DUP8 %store_fp6(24)
// stack: in2, out
%pop2 JUMP