#include "../../../cmd/ld/textflag.h"
data = 0
const = 1
a = 2
b = 3
c = 4
d = 5
e = 6
t0 = 7
t1 = 8
t2 = 11
ctr = 12
w = 14
p_end = -4
p_data = p_end - 4
w_buf = p_data - 4*80
saved = w_buf - 4*5
#define LOAD(e) \
MOVBU 2(R(data)), R(t0) ; \
MOVBU 3(R(data)), R(t1) ; \
MOVBU 1(R(data)), R(t2) ; \
ORR R(t0)<<8, R(t1), R(t0) ; \
MOVBU.P 4(R(data)), R(t1) ; \
ORR R(t2)<<16, R(t0), R(t0) ; \
ORR R(t1)<<24, R(t0), R(t0) ; \
MOVW.P R(t0), 4(R(w)) ; \
ADD R(t0), R(e), R(e)
#define SHUFFLE(e) \
MOVW (-16*4)(R(w)), R(t0) ; \
MOVW (-14*4)(R(w)), R(t1) ; \
MOVW (-8*4)(R(w)), R(t2) ; \
EOR R(t0), R(t1), R(t0) ; \
MOVW (-3*4)(R(w)), R(t1) ; \
EOR R(t2), R(t0), R(t0) ; \
EOR R(t0), R(t1), R(t0) ; \
MOVW R(t0)@>(32-1), R(t0) ; \
MOVW.P R(t0), 4(R(w)) ; \
ADD R(t0), R(e), R(e)
#define FUNC1(a, b, c, d, e) \
MVN R(b), R(t1) ; \
AND R(b), R(c), R(t0) ; \
AND R(d), R(t1), R(t1) ; \
ORR R(t0), R(t1), R(t1)
#define FUNC2(a, b, c, d, e) \
EOR R(b), R(c), R(t1) ; \
EOR R(d), R(t1), R(t1)
#define FUNC3(a, b, c, d, e) \
ORR R(b), R(c), R(t0) ; \
AND R(b), R(c), R(t1) ; \
AND R(d), R(t0), R(t0) ; \
ORR R(t0), R(t1), R(t1)
#define FUNC4 FUNC2
#define MIX(a, b, c, d, e) \
ADD R(t1), R(e), R(e) ; \
MOVW R(b)@>(32-30), R(b) ; \
ADD R(a)@>(32-5), R(e), R(e) ; \
ADD R(const), R(e), R(e)
#define ROUND1(a, b, c, d, e) \
LOAD(e) ; \
FUNC1(a, b, c, d, e) ; \
MIX(a, b, c, d, e)
#define ROUND1x(a, b, c, d, e) \
SHUFFLE(e) ; \
FUNC1(a, b, c, d, e) ; \
MIX(a, b, c, d, e)
#define ROUND2(a, b, c, d, e) \
SHUFFLE(e) ; \
FUNC2(a, b, c, d, e) ; \
MIX(a, b, c, d, e)
#define ROUND3(a, b, c, d, e) \
SHUFFLE(e) ; \
FUNC3(a, b, c, d, e) ; \
MIX(a, b, c, d, e)
#define ROUND4(a, b, c, d, e) \
SHUFFLE(e) ; \
FUNC4(a, b, c, d, e) ; \
MIX(a, b, c, d, e)
TEXT ·block(SB), 0, $352-16
MOVW p+4(FP), R(data)
MOVW p_len+8(FP), R(t0)
ADD R(data), R(t0)
MOVW R(t0), p_end(SP)
MOVW dig+0(FP), R(t0)
MOVM.IA (R(t0)), [R(a),R(b),R(c),R(d),R(e)]
loop:
MOVM.IB [R(a),R(b),R(c),R(d),R(e)], (R13)
MOVW $w_buf(SP), R(w)
MOVW $0x5A827999, R(const)
MOVW $3, R(ctr)
loop1: ROUND1(a, b, c, d, e)
ROUND1(e, a, b, c, d)
ROUND1(d, e, a, b, c)
ROUND1(c, d, e, a, b)
ROUND1(b, c, d, e, a)
SUB.S $1, R(ctr)
BNE loop1
ROUND1(a, b, c, d, e)
ROUND1x(e, a, b, c, d)
ROUND1x(d, e, a, b, c)
ROUND1x(c, d, e, a, b)
ROUND1x(b, c, d, e, a)
MOVW $0x6ED9EBA1, R(const)
MOVW $4, R(ctr)
loop2: ROUND2(a, b, c, d, e)
ROUND2(e, a, b, c, d)
ROUND2(d, e, a, b, c)
ROUND2(c, d, e, a, b)
ROUND2(b, c, d, e, a)
SUB.S $1, R(ctr)
BNE loop2
MOVW $0x8F1BBCDC, R(const)
MOVW $4, R(ctr)
loop3: ROUND3(a, b, c, d, e)
ROUND3(e, a, b, c, d)
ROUND3(d, e, a, b, c)
ROUND3(c, d, e, a, b)
ROUND3(b, c, d, e, a)
SUB.S $1, R(ctr)
BNE loop3
MOVW $0xCA62C1D6, R(const)
MOVW $4, R(ctr)
loop4: ROUND4(a, b, c, d, e)
ROUND4(e, a, b, c, d)
ROUND4(d, e, a, b, c)
ROUND4(c, d, e, a, b)
ROUND4(b, c, d, e, a)
SUB.S $1, R(ctr)
BNE loop4
MOVM.IB (R13), [R(t0),R(t1),R(t2),R(ctr),R(w)]
ADD R(t0), R(a)
ADD R(t1), R(b)
ADD R(t2), R(c)
ADD R(ctr), R(d)
ADD R(w), R(e)
MOVW p_end(SP), R(t0)
CMP R(t0), R(data)
BLO loop
MOVW dig+0(FP), R(t0)
MOVM.IA [R(a),R(b),R(c),R(d),R(e)], (R(t0))
RET