plonky2/evm/src/cpu/kernel/asm/ripemd/subroutines.asm

135 lines
2.6 KiB
NASM
Raw Normal View History

2022-08-09 15:11:18 -07:00
/// def ROL(n, x):
/// return (u32(x << n)) | (x >> (32 - n))
2022-08-23 12:03:06 -07:00
global ROL:
2022-07-27 14:34:00 -04:00
jumpdest
2022-07-29 13:24:11 -04:00
// stack: n, x, retdest
swap1
// stack: x, n, retdest
2022-07-27 14:34:00 -04:00
dup1
2022-07-29 13:24:11 -04:00
// stack: x, x, n, retdest
dup3
// stack: n, x, x, n, retdest
2022-07-27 14:34:00 -04:00
push 32
2022-07-29 13:24:11 -04:00
// stack: 32, n, x, x, n, retdest
2022-07-27 14:34:00 -04:00
sub
2022-07-29 13:24:11 -04:00
// stack: 32-n, x, x, n, retdest
2022-07-27 14:34:00 -04:00
shr
2022-07-30 14:21:06 -04:00
// stack: x >> (32-n), x, n, retdest
2022-07-27 14:34:00 -04:00
swap2
2022-07-30 14:21:06 -04:00
// stack: n, x, x >> (32-n), retdest
2022-07-27 14:34:00 -04:00
shl
2022-07-30 14:21:06 -04:00
// stack: x << n, x >> (32-n), retdest
2022-07-29 13:24:11 -04:00
push 0xffffffff
2022-07-30 14:21:06 -04:00
// stack: 0xffffffff, (x << n), x >> (32-n), retdest
2022-07-27 14:34:00 -04:00
and
2022-07-30 14:21:06 -04:00
// stack: (x << n) & 0xffffffff, x >> (32-n), retdest
2022-07-27 14:34:00 -04:00
or
2022-07-30 14:21:06 -04:00
// stack: ((x << n) & 0xffffffff) | (x >> (32-n)), retdest
2022-07-29 13:24:11 -04:00
swap1
2022-07-30 14:21:06 -04:00
// stack: retdest, ((x << n) & 0xffffffff) | (x >> (32-n))
2022-07-27 14:34:00 -04:00
jump
2022-07-29 13:24:11 -04:00
2022-08-09 15:11:18 -07:00
/// def F0(x, y, z):
/// return x ^ y ^ z
2022-07-27 14:34:00 -04:00
global F0:
jumpdest
2022-07-29 13:24:11 -04:00
// stack: x, y, z, retdest
2022-07-27 14:34:00 -04:00
xor
2022-07-29 13:24:11 -04:00
// stack: x ^ y, z, retdest
2022-07-27 14:34:00 -04:00
xor
2022-07-29 13:24:11 -04:00
// stack: x ^ y ^ z, retdest
swap1
// stack: retdest, x ^ y ^ z
2022-07-27 14:34:00 -04:00
jump
2022-08-09 15:11:18 -07:00
/// def F1(x, y, z):
/// return (x & y) | (u32(~x) & z)
2022-07-27 14:34:00 -04:00
global F1:
jumpdest
2022-07-29 13:24:11 -04:00
// stack: x, y, z, retdest
2022-07-27 14:34:00 -04:00
dup1
2022-07-29 13:24:11 -04:00
// stack: x, x, y, z, retdest
2022-07-27 14:34:00 -04:00
swap2
2022-07-29 13:24:11 -04:00
// stack: y, x, x, z, retdest
2022-07-27 14:34:00 -04:00
and
2022-07-29 13:24:11 -04:00
// stack: y & x, x, z, retdest
2022-07-27 14:34:00 -04:00
swap2
2022-07-29 13:24:11 -04:00
// stack: z, x, y & x, retdest
2022-07-27 14:34:00 -04:00
swap1
2022-07-29 13:24:11 -04:00
// stack: x, z, y & x, retdest
2022-08-09 15:11:18 -07:00
%not_32
2022-07-29 13:24:11 -04:00
// stack: ~x, z, y & x, retdest
2022-07-27 14:34:00 -04:00
and
2022-07-29 13:24:11 -04:00
// stack: ~x & z, y & x, retdest
2022-07-27 14:34:00 -04:00
or
2022-07-29 13:24:11 -04:00
// stack: (~x & z) | (y & x), retdest
swap1
// stack: retdest, (~x & z) | (y & x)
2022-07-27 14:34:00 -04:00
jump
2022-08-09 15:11:18 -07:00
/// def F2(x, y, z):
/// return (x | u32(~y)) ^ z
2022-07-27 14:34:00 -04:00
global F2:
jumpdest
2022-07-29 13:24:11 -04:00
// stack: x, y, z, retdest
2022-07-27 14:34:00 -04:00
swap1
2022-07-29 13:24:11 -04:00
// stack: y, x, z, retdest
2022-08-09 15:11:18 -07:00
%not_32
2022-07-29 13:24:11 -04:00
// stack: ~y, x, z, retdest
2022-07-27 14:34:00 -04:00
or
2022-07-29 13:24:11 -04:00
// stack: ~y | x, z, retdest
2022-07-27 14:34:00 -04:00
xor
2022-08-09 15:11:18 -07:00
// stack: (~y | x) ^ z, retdest
2022-07-29 13:24:11 -04:00
swap1
// stack: retdest, (~y | x) ^ z
2022-07-27 14:34:00 -04:00
jump
2022-08-09 15:11:18 -07:00
/// def F3(x, y, z):
/// return (x & z) | (u32(~z) & y)
2022-07-27 14:34:00 -04:00
global F3:
jumpdest
2022-07-29 13:24:11 -04:00
// stack: x, y, z, retdest
2022-07-27 14:34:00 -04:00
dup3
2022-07-29 13:24:11 -04:00
// stack: z, x, y, z, retdest
2022-07-27 14:34:00 -04:00
and
2022-07-29 13:24:11 -04:00
// stack: z & x, y, z, retdest
2022-07-27 14:34:00 -04:00
swap2
2022-07-29 13:24:11 -04:00
// stack: z, y, z & x, retdest
2022-08-09 15:11:18 -07:00
%not_32
2022-07-29 13:24:11 -04:00
// stack: ~z, y, z & x, retdest
2022-07-27 14:34:00 -04:00
and
2022-07-29 13:24:11 -04:00
// stack: ~z & y, z & x, retdest
2022-07-27 14:34:00 -04:00
or
2022-07-29 13:24:11 -04:00
// stack: (~z & y) | (z & x), retdest
swap1
// stack: retdest, (~z & y) | (z & x)
2022-07-27 14:34:00 -04:00
jump
2022-08-09 15:11:18 -07:00
/// def F4(x, y, z):
/// return x ^ (y | u32(~z))
2022-07-27 14:34:00 -04:00
global F4:
jumpdest
2022-07-29 13:24:11 -04:00
// stack: x, y, z, retdest
2022-07-27 14:34:00 -04:00
swap2
2022-07-29 13:24:11 -04:00
// stack: z, y, x, retdest
2022-08-09 15:11:18 -07:00
%not_32
2022-07-29 13:24:11 -04:00
// stack: ~z, y, x, retdest
2022-07-27 14:34:00 -04:00
or
2022-07-29 13:24:11 -04:00
// stack: ~z | y, x, retdest
2022-07-27 14:34:00 -04:00
xor
2022-07-29 13:24:11 -04:00
// stack: (~z | y) ^ x, retdest
swap1
// stack: retdest, (~z | y) ^ x
jump