1b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#!/usr/bin/env perl
2b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
3b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ====================================================================
4b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
5b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# project. The module is, however, dual licensed under OpenSSL and
6b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# CRYPTOGAMS licenses depending on where you obtain it. For further
7b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# details see http://www.openssl.org/~appro/cryptogams/.
8b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ====================================================================
9b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
10b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# AES for MIPS
11b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
12b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# October 2010
13b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
14b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# Code uses 1K[+256B] S-box and on single-issue core [such as R5000]
15b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# spends ~68 cycles per byte processed with 128-bit key. This is ~16%
16b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# faster than gcc-generated code, which is not very impressive. But
17b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# recall that compressed S-box requires extra processing, namely
18b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# additional rotations. Rotations are implemented with lwl/lwr pairs,
19b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# which is normally used for loading unaligned data. Another cool
20b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# thing about this module is its endian neutrality, which means that
21b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# it processes data without ever changing byte order...
22b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
23b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic######################################################################
24b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# There is a number of MIPS ABI in use, O32 and N32/64 are most
25b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# widely used. Then there is a new contender: NUBI. It appears that if
26b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# one picks the latter, it's possible to arrange code in ABI neutral
27b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# manner. Therefore let's stick to NUBI register layout:
28b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
29b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($zero,$at,$t0,$t1,$t2)=map("\$$_",(0..2,24,25));
30b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11));
31b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8,$s9,$s10,$s11)=map("\$$_",(12..23));
32b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic($gp,$tp,$sp,$fp,$ra)=map("\$$_",(3,28..31));
33b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
34b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# The return value is placed in $a0. Following coding rules facilitate
35b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# interoperability:
36b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
37b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - never ever touch $tp, "thread pointer", former $gp;
38b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - copy return value to $t0, former $v0 [or to $a0 if you're adapting
39b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#   old code];
40b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# - on O32 populate $a4-$a7 with 'lw $aN,4*N($sp)' if necessary;
41b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
42b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# For reference here is register layout for N32/64 MIPS ABIs:
43b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
44b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($zero,$at,$v0,$v1)=map("\$$_",(0..3));
45b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7)=map("\$$_",(4..11));
46b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($t0,$t1,$t2,$t3,$t8,$t9)=map("\$$_",(12..15,24,25));
47b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($s0,$s1,$s2,$s3,$s4,$s5,$s6,$s7)=map("\$$_",(16..23));
48b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# ($gp,$sp,$fp,$ra)=map("\$$_",(28..31));
49b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
50b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$flavour = shift; # supported flavours are o32,n32,64,nubi32,nubi64
51b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
52b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif ($flavour =~ /64|n32/i) {
53b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD="dadd";	# incidentally works even on n32
54b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB="dsub";	# incidentally works even on n32
55b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S="sd";
56b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L="ld";
57b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SLL="dsll";	# incidentally works even on n32
58b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$SZREG=8;
59b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic} else {
60b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD="add";
61b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB="sub";
62b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S="sw";
63b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L="lw";
64b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SLL="sll";
65b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$SZREG=4;
66b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic}
67b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$pf = ($flavour =~ /nubi/i) ? $t0 : $t2;
68b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
69b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# <appro@openssl.org>
70b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#
71b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic######################################################################
72b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
73b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$big_endian=(`echo MIPSEL | $ENV{CC} -E -P -`=~/MIPSEL/)?1:0;
74b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
75b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicfor (@ARGV) {	$output=$_ if (/^\w[\w\-]*\.\w+$/);	}
76b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicopen STDOUT,">$output";
77b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
78b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicif (!defined($big_endian))
79b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic{    $big_endian=(unpack('L',pack('N',1))==1);   }
80b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
81b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicwhile (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
82b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicopen STDOUT,">$output";
83b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
84b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($MSB,$LSB)=(0,3);	# automatically converted to little-endian
85b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
86b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
87b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.text
88b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#ifdef OPENSSL_FIPSCANISTER
89b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# include <openssl/fipssyms.h>
90b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#endif
91b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
92b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#if !defined(__vxworks) || defined(__pic__)
93b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.option	pic2
94b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic#endif
95b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.set	noat
96b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
97b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
98b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic{{{
99b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy $FRAMESIZE=16*$SZREG;
100b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc0fff008 : 0xc0ff0000;
101b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
102b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($inp,$out,$key,$Tbl,$s0,$s1,$s2,$s3)=($a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7);
103b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($i0,$i1,$i2,$i3)=($at,$t0,$t1,$t2);
104b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($t0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) = map("\$$_",(12..23));
105b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($key0,$cnt)=($gp,$fp);
106b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
107b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# instuction ordering is "stolen" from output from MIPSpro assembler
108b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# invoked with -mips3 -O3 arguments...
109b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
110b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
111b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent	_mips_AES_encrypt
112b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic_mips_AES_encrypt:
113b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,0,$ra
114b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
115b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t0,0($key)
116b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t1,4($key)
117b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t2,8($key)
118b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t3,12($key)
119b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$cnt,240($key)
120b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key0,$key,16
121b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
122b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
123b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
124b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
125b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
126b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
127b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
128b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s1,16-2
129b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Loop_enc:
130b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s2,16-2
131b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s3,16-2
132b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s0,16-2
133b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
134b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
135b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
136b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
137b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
138b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
139b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
140b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
141b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t0,3($i0)		# Te1[s1>>16]
142b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t1,3($i1)		# Te1[s2>>16]
143b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t2,3($i2)		# Te1[s3>>16]
144b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t3,3($i3)		# Te1[s0>>16]
145b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t0,2($i0)		# Te1[s1>>16]
146b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t1,2($i1)		# Te1[s2>>16]
147b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t2,2($i2)		# Te1[s3>>16]
148b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t3,2($i3)		# Te1[s0>>16]
149b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
150b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s2,8-2
151b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s3,8-2
152b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s0,8-2
153b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s1,8-2
154b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
155b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
156b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
157b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
158b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
159b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
160b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
161b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
162b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t4,2($i0)		# Te2[s2>>8]
163b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t5,2($i1)		# Te2[s3>>8]
164b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t6,2($i2)		# Te2[s0>>8]
165b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t7,2($i3)		# Te2[s1>>8]
166b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t4,1($i0)		# Te2[s2>>8]
167b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t5,1($i1)		# Te2[s3>>8]
168b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t6,1($i2)		# Te2[s0>>8]
169b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t7,1($i3)		# Te2[s1>>8]
170b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
171b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s3,0-2
172b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s0,0-2
173b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s1,0-2
174b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s2,0-2
175b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
176b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
177b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
178b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
179b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
180b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
181b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
182b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
183b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t8,1($i0)		# Te3[s3]
184b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t9,1($i1)		# Te3[s0]
185b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t10,1($i2)		# Te3[s1]
186b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t11,1($i3)		# Te3[s2]
187b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t8,0($i0)		# Te3[s3]
188b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t9,0($i1)		# Te3[s0]
189b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t10,0($i2)		# Te3[s1]
190b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t11,0($i3)		# Te3[s2]
191b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
192b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s0,24-2
193b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s1,24-2
194b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s2,24-2
195b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s3,24-2
196b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
197b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
198b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
199b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
200b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
201b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
202b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
203b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
204b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
205b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
206b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
207b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
208b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t4,0($i0)		# Te0[s0>>24]
209b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t5,0($i1)		# Te0[s1>>24]
210b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t6,0($i2)		# Te0[s2>>24]
211b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t7,0($i3)		# Te0[s3>>24]
212b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
213b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s0,0($key0)
214b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s1,4($key0)
215b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s2,8($key0)
216b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s3,12($key0)
217b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
218b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t8
219b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t9
220b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t10
221b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t11
222b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
223b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
224b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
225b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
226b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
227b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
228b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
229b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key0,16
230b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
231b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
232b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
233b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
234b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
235b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bnez	$cnt,.Loop_enc
236b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s1,16-2
237b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
238b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
239b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s2,16-2
240b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s3,16-2
241b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s0,16-2
242b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
243b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
244b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
245b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
246b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
247b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
248b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
249b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
250b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t0,2($i0)		# Te4[s1>>16]
251b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t1,2($i1)		# Te4[s2>>16]
252b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t2,2($i2)		# Te4[s3>>16]
253b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t3,2($i3)		# Te4[s0>>16]
254b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
255b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s2,8-2
256b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s3,8-2
257b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s0,8-2
258b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s1,8-2
259b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
260b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
261b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
262b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
263b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
264b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
265b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
266b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
267b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t4,2($i0)		# Te4[s2>>8]
268b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t5,2($i1)		# Te4[s3>>8]
269b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t6,2($i2)		# Te4[s0>>8]
270b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t7,2($i3)		# Te4[s1>>8]
271b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
272b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s0,24-2
273b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s1,24-2
274b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s2,24-2
275b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s3,24-2
276b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
277b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
278b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
279b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
280b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
281b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
282b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
283b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
284b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t8,2($i0)		# Te4[s0>>24]
285b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t9,2($i1)		# Te4[s1>>24]
286b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t10,2($i2)		# Te4[s2>>24]
287b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t11,2($i3)		# Te4[s3>>24]
288b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
289b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s3,0-2
290b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s0,0-2
291b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s1,0-2
292b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s2,0-2
293b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
294b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
295b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
296b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
297b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
298b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t0,16
299b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t1,16
300b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t2,16
301b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t3,16
302b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
303b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t4,8
304b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t5,8
305b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t6,8
306b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t7,8
307b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
308b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
309b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
310b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
311b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
312b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
313b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
314b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
315b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
316b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
317b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t4,2($i0)		# Te4[s3]
318b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t5,2($i1)		# Te4[s0]
319b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t6,2($i2)		# Te4[s1]
320b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t7,2($i3)		# Te4[s2]
321b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
322b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t8,24
323b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t9,24
324b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t10,24
325b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t11,24
326b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
327b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s0,0($key0)
328b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s1,4($key0)
329b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s2,8($key0)
330b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s3,12($key0)
331b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
332b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t8
333b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t9
334b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t10
335b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t11
336b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
337b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t4,0
338b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t5,0
339b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t6,0
340b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t7,0
341b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
342b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
343b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
344b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
345b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
346b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
347b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
348b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
349b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
350b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
351b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
352b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
353b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end	_mips_AES_encrypt
354b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
355b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
356b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.globl	AES_encrypt
357b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent	AES_encrypt
358b83a02d94f9ba66fc5da46c2e27572674ea17931Petar JovanovicAES_encrypt:
359b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,$FRAMESIZE,$ra
360b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.mask	$SAVED_REGS_MASK,-$SZREG
361b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
362b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
363b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /o32/i);	# o32 PIC-ification
364b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpload	$pf
365b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
366b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
367b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $sp,$FRAMESIZE
368b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$ra,$FRAMESIZE-1*$SZREG($sp)
369b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$fp,$FRAMESIZE-2*$SZREG($sp)
370b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s11,$FRAMESIZE-3*$SZREG($sp)
371b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s10,$FRAMESIZE-4*$SZREG($sp)
372b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s9,$FRAMESIZE-5*$SZREG($sp)
373b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s8,$FRAMESIZE-6*$SZREG($sp)
374b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s7,$FRAMESIZE-7*$SZREG($sp)
375b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s6,$FRAMESIZE-8*$SZREG($sp)
376b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s5,$FRAMESIZE-9*$SZREG($sp)
377b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s4,$FRAMESIZE-10*$SZREG($sp)
378b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
379b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);	# optimize non-nubi prologue
380b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$15,$FRAMESIZE-11*$SZREG($sp)
381b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$14,$FRAMESIZE-12*$SZREG($sp)
382b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$13,$FRAMESIZE-13*$SZREG($sp)
383b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$12,$FRAMESIZE-14*$SZREG($sp)
384b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$gp,$FRAMESIZE-15*$SZREG($sp)
385b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
386b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour !~ /o32/i);	# non-o32 PIC-ification
387b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cplocal	$Tbl
388b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpsetup	$pf,$zero,AES_encrypt
389b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
390b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
391b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
392b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	la	$Tbl,AES_Te		# PIC-ified 'load address'
393b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
394b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s0,0+$MSB($inp)
395b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s1,4+$MSB($inp)
396b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s2,8+$MSB($inp)
397b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s3,12+$MSB($inp)
398b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s0,0+$LSB($inp)
399b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s1,4+$LSB($inp)
400b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s2,8+$LSB($inp)
401b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s3,12+$LSB($inp)
402b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
403b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bal	_mips_AES_encrypt
404b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
405b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s0,0+$LSB($out)
406b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s1,4+$LSB($out)
407b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s2,8+$LSB($out)
408b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s3,12+$LSB($out)
409b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s0,0+$MSB($out)
410b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s1,4+$MSB($out)
411b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s2,8+$MSB($out)
412b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s3,12+$MSB($out)
413b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
414b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
415b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$ra,$FRAMESIZE-1*$SZREG($sp)
416b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$fp,$FRAMESIZE-2*$SZREG($sp)
417b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s11,$FRAMESIZE-3*$SZREG($sp)
418b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s10,$FRAMESIZE-4*$SZREG($sp)
419b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s9,$FRAMESIZE-5*$SZREG($sp)
420b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s8,$FRAMESIZE-6*$SZREG($sp)
421b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s7,$FRAMESIZE-7*$SZREG($sp)
422b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s6,$FRAMESIZE-8*$SZREG($sp)
423b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s5,$FRAMESIZE-9*$SZREG($sp)
424b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s4,$FRAMESIZE-10*$SZREG($sp)
425b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
426b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);
427b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$15,$FRAMESIZE-11*$SZREG($sp)
428b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$14,$FRAMESIZE-12*$SZREG($sp)
429b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$13,$FRAMESIZE-13*$SZREG($sp)
430b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$12,$FRAMESIZE-14*$SZREG($sp)
431b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$gp,$FRAMESIZE-15*$SZREG($sp)
432b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
433b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
434b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
435b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $sp,$FRAMESIZE
436b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end	AES_encrypt
437b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
438b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
439b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
440b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
441b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent	_mips_AES_decrypt
442b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic_mips_AES_decrypt:
443b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,0,$ra
444b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
445b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t0,0($key)
446b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t1,4($key)
447b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t2,8($key)
448b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t3,12($key)
449b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$cnt,240($key)
450b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key0,$key,16
451b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
452b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
453b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
454b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
455b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
456b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
457b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
458b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s3,16-2
459b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Loop_dec:
460b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s0,16-2
461b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s1,16-2
462b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s2,16-2
463b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
464b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
465b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
466b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
467b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
468b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
469b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
470b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
471b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t0,3($i0)		# Td1[s3>>16]
472b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t1,3($i1)		# Td1[s0>>16]
473b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t2,3($i2)		# Td1[s1>>16]
474b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t3,3($i3)		# Td1[s2>>16]
475b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t0,2($i0)		# Td1[s3>>16]
476b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t1,2($i1)		# Td1[s0>>16]
477b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t2,2($i2)		# Td1[s1>>16]
478b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t3,2($i3)		# Td1[s2>>16]
479b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
480b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s2,8-2
481b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s3,8-2
482b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s0,8-2
483b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s1,8-2
484b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
485b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
486b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
487b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
488b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
489b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
490b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
491b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
492b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t4,2($i0)		# Td2[s2>>8]
493b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t5,2($i1)		# Td2[s3>>8]
494b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t6,2($i2)		# Td2[s0>>8]
495b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t7,2($i3)		# Td2[s1>>8]
496b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t4,1($i0)		# Td2[s2>>8]
497b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t5,1($i1)		# Td2[s3>>8]
498b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t6,1($i2)		# Td2[s0>>8]
499b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t7,1($i3)		# Td2[s1>>8]
500b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
501b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s1,0-2
502b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s2,0-2
503b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s3,0-2
504b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s0,0-2
505b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
506b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
507b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
508b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
509b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
510b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
511b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
512b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
513b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t8,1($i0)		# Td3[s1]
514b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t9,1($i1)		# Td3[s2]
515b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t10,1($i2)		# Td3[s3]
516b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$t11,1($i3)		# Td3[s0]
517b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t8,0($i0)		# Td3[s1]
518b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t9,0($i1)		# Td3[s2]
519b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t10,0($i2)		# Td3[s3]
520b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$t11,0($i3)		# Td3[s0]
521b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
522b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s0,24-2
523b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s1,24-2
524b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s2,24-2
525b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s3,24-2
526b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0x3fc
527b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0x3fc
528b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0x3fc
529b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0x3fc
530b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
531b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
532b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
533b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
534b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
535b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
536b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
537b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
538b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
539b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
540b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
541b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t4,0($i0)		# Td0[s0>>24]
542b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t5,0($i1)		# Td0[s1>>24]
543b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t6,0($i2)		# Td0[s2>>24]
544b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t7,0($i3)		# Td0[s3>>24]
545b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
546b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s0,0($key0)
547b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s1,4($key0)
548b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s2,8($key0)
549b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s3,12($key0)
550b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
551b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t8
552b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t9
553b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t10
554b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t11
555b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
556b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
557b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
558b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
559b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
560b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
561b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
562b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key0,16
563b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
564b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
565b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
566b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
567b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
568b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bnez	$cnt,.Loop_dec
569b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s3,16-2
570b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
571b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
572b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t4,1024($Tbl)		# prefetch Td4
573b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t5,1024+32($Tbl)
574b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t6,1024+64($Tbl)
575b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t7,1024+96($Tbl)
576b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t8,1024+128($Tbl)
577b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t9,1024+160($Tbl)
578b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t10,1024+192($Tbl)
579b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$t11,1024+224($Tbl)
580b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
581b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s3,16
582b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s0,16
583b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s1,16
584b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s2,16
585b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0xff
586b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
587b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0xff
588b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0xff
589b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
590b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
591b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
592b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
593b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t0,1024($i0)		# Td4[s3>>16]
594b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t1,1024($i1)		# Td4[s0>>16]
595b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t2,1024($i2)		# Td4[s1>>16]
596b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t3,1024($i3)		# Td4[s2>>16]
597b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
598b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s2,8
599b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s3,8
600b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s0,8
601b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s1,8
602b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0xff
603b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
604b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0xff
605b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,0xff
606b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
607b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
608b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
609b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
610b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t4,1024($i0)		# Td4[s2>>8]
611b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t5,1024($i1)		# Td4[s3>>8]
612b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t6,1024($i2)		# Td4[s0>>8]
613b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t7,1024($i3)		# Td4[s1>>8]
614b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
615b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s0,24
616b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s1,24
617b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s2,24
618b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s3,24
619b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
620b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
621b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
622b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
623b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t8,1024($i0)		# Td4[s0>>24]
624b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t9,1024($i1)		# Td4[s1>>24]
625b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t10,1024($i2)		# Td4[s2>>24]
626b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t11,1024($i3)		# Td4[s3>>24]
627b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
628b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i0,$s1,0
629b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i1,$s2,0
630b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i2,$s3,0
631b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_xtr	$i3,$s0,0
632b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
633b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t0,16
634b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t1,16
635b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t2,16
636b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t3,16
637b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
638b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t4,8
639b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t5,8
640b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t6,8
641b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t7,8
642b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
643b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
644b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
645b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
646b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
647b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
648b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
649b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
650b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
651b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
652b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t4,1024($i0)		# Td4[s1]
653b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t5,1024($i1)		# Td4[s2]
654b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t6,1024($i2)		# Td4[s3]
655b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$t7,1024($i3)		# Td4[s0]
656b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
657b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t8,24
658b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t9,24
659b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t10,24
660b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t11,24
661b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
662b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s0,0($key0)
663b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s1,4($key0)
664b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s2,8($key0)
665b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$s3,12($key0)
666b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
667b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t4,0
668b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t5,0
669b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t6,0
670b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ins	$t7,0
671b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
672b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
673b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t8
674b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t9
675b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t10
676b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t11
677b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
678b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t0,$t4
679b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t1,$t5
680b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t2,$t6
681b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$t3,$t7
682b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
683b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s0,$t0
684b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s1,$t1
685b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s2,$t2
686b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$s3,$t3
687b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
688b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
689b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end	_mips_AES_decrypt
690b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
691b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
692b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.globl	AES_decrypt
693b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent	AES_decrypt
694b83a02d94f9ba66fc5da46c2e27572674ea17931Petar JovanovicAES_decrypt:
695b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,$FRAMESIZE,$ra
696b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.mask	$SAVED_REGS_MASK,-$SZREG
697b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
698b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
699b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /o32/i);	# o32 PIC-ification
700b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpload	$pf
701b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
702b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
703b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $sp,$FRAMESIZE
704b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$ra,$FRAMESIZE-1*$SZREG($sp)
705b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$fp,$FRAMESIZE-2*$SZREG($sp)
706b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s11,$FRAMESIZE-3*$SZREG($sp)
707b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s10,$FRAMESIZE-4*$SZREG($sp)
708b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s9,$FRAMESIZE-5*$SZREG($sp)
709b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s8,$FRAMESIZE-6*$SZREG($sp)
710b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s7,$FRAMESIZE-7*$SZREG($sp)
711b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s6,$FRAMESIZE-8*$SZREG($sp)
712b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s5,$FRAMESIZE-9*$SZREG($sp)
713b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s4,$FRAMESIZE-10*$SZREG($sp)
714b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
715b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);	# optimize non-nubi prologue
716b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$15,$FRAMESIZE-11*$SZREG($sp)
717b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$14,$FRAMESIZE-12*$SZREG($sp)
718b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$13,$FRAMESIZE-13*$SZREG($sp)
719b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	\$12,$FRAMESIZE-14*$SZREG($sp)
720b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$gp,$FRAMESIZE-15*$SZREG($sp)
721b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
722b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour !~ /o32/i);	# non-o32 PIC-ification
723b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cplocal	$Tbl
724b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpsetup	$pf,$zero,AES_decrypt
725b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
726b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
727b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
728b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	la	$Tbl,AES_Td		# PIC-ified 'load address'
729b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
730b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s0,0+$MSB($inp)
731b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s1,4+$MSB($inp)
732b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s2,8+$MSB($inp)
733b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$s3,12+$MSB($inp)
734b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s0,0+$LSB($inp)
735b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s1,4+$LSB($inp)
736b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s2,8+$LSB($inp)
737b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$s3,12+$LSB($inp)
738b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
739b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bal	_mips_AES_decrypt
740b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
741b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s0,0+$LSB($out)
742b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s1,4+$LSB($out)
743b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s2,8+$LSB($out)
744b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swr	$s3,12+$LSB($out)
745b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s0,0+$MSB($out)
746b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s1,4+$MSB($out)
747b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s2,8+$MSB($out)
748b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	swl	$s3,12+$MSB($out)
749b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
750b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
751b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$ra,$FRAMESIZE-1*$SZREG($sp)
752b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$fp,$FRAMESIZE-2*$SZREG($sp)
753b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s11,$FRAMESIZE-3*$SZREG($sp)
754b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s10,$FRAMESIZE-4*$SZREG($sp)
755b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s9,$FRAMESIZE-5*$SZREG($sp)
756b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s8,$FRAMESIZE-6*$SZREG($sp)
757b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s7,$FRAMESIZE-7*$SZREG($sp)
758b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s6,$FRAMESIZE-8*$SZREG($sp)
759b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s5,$FRAMESIZE-9*$SZREG($sp)
760b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s4,$FRAMESIZE-10*$SZREG($sp)
761b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
762b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);
763b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$15,$FRAMESIZE-11*$SZREG($sp)
764b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$14,$FRAMESIZE-12*$SZREG($sp)
765b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$13,$FRAMESIZE-13*$SZREG($sp)
766b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	\$12,$FRAMESIZE-14*$SZREG($sp)
767b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$gp,$FRAMESIZE-15*$SZREG($sp)
768b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
769b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
770b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
771b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $sp,$FRAMESIZE
772b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end	AES_decrypt
773b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
774b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic}}}
775b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
776b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic{{{
777b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy $FRAMESIZE=8*$SZREG;
778b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy $SAVED_REGS_MASK = ($flavour =~ /nubi/i) ? 0xc000f008 : 0xc0000000;
779b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
780b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($inp,$bits,$key,$Tbl)=($a0,$a1,$a2,$a3);
781b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($rk0,$rk1,$rk2,$rk3,$rk4,$rk5,$rk6,$rk7)=($a4,$a5,$a6,$a7,$s0,$s1,$s2,$s3);
782b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($i0,$i1,$i2,$i3)=($at,$t0,$t1,$t2);
783b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($rcon,$cnt)=($gp,$fp);
784b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
785b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
786b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
787b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.ent	_mips_AES_set_encrypt_key
788b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic_mips_AES_set_encrypt_key:
789b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,0,$ra
790b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
791b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beqz	$inp,.Lekey_done
792b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,-1
793b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beqz	$key,.Lekey_done
794b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $rcon,$Tbl,1024+256
795b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
796b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
797b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk0,0+$MSB($inp)	# load 128 bits
798b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk1,4+$MSB($inp)
799b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk2,8+$MSB($inp)
800b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk3,12+$MSB($inp)
801b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$at,128
802b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk0,0+$LSB($inp)
803b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk1,4+$LSB($inp)
804b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk2,8+$LSB($inp)
805b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk3,12+$LSB($inp)
806b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
807b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beq	$bits,$at,.L128bits
808b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,10
809b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
810b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
811b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk4,16+$MSB($inp)	# load 192 bits
812b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk5,20+$MSB($inp)
813b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$at,192
814b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk4,16+$LSB($inp)
815b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk5,20+$LSB($inp)
816b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
817b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beq	$bits,$at,.L192bits
818b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,8
819b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
820b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
821b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk6,24+$MSB($inp)	# load 256 bits
822b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwl	$rk7,28+$MSB($inp)
823b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$at,256
824b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk6,24+$LSB($inp)
825b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lwr	$rk7,28+$LSB($inp)
826b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
827b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beq	$bits,$at,.L256bits
828b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,7
829b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
830b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	b	.Lekey_done
831b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,-2
832b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
833b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	4
834b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.L128bits:
835b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
836b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i0,$rk3,16
837b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i1,$rk3,8
838b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0xff
839b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
840b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,$rk3,0xff
841b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i3,$rk3,24
842b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
843b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
844b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
845b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
846b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i0,1024($i0)
847b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i1,1024($i1)
848b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i2,1024($i2)
849b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i3,1024($i3)
850b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
851b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($key)
852b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($key)
853b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($key)
854b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($key)
855b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
856b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key,16
857b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
858b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i0,24
859b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i1,16
860b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i2,8
861b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i3,0
862b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
863b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
864b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$i0,0($rcon)
865b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i1
866b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i2
867b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i3
868b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
869b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
870b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk1,$rk0
871b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk2,$rk1
872b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk3,$rk2
873b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
874b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
875b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bnez	$cnt,.L128bits
876b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $rcon,4
877b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
878b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($key)
879b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($key)
880b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($key)
881b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,10
882b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($key)
883b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,0
884b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$cnt,80($key)
885b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	b	.Lekey_done
886b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $key,10*16
887b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
888b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	4
889b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.L192bits:
890b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
891b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i0,$rk5,16
892b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i1,$rk5,8
893b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0xff
894b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
895b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,$rk5,0xff
896b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i3,$rk5,24
897b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
898b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
899b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
900b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
901b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i0,1024($i0)
902b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i1,1024($i1)
903b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i2,1024($i2)
904b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i3,1024($i3)
905b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
906b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($key)
907b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($key)
908b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($key)
909b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($key)
910b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk4,16($key)
911b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk5,20($key)
912b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
913b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key,24
914b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
915b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i0,24
916b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i1,16
917b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i2,8
918b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i3,0
919b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
920b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
921b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$i0,0($rcon)
922b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i1
923b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i2
924b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i3
925b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
926b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
927b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk1,$rk0
928b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk2,$rk1
929b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk3,$rk2
930b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk4,$rk3
931b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk5,$rk4
932b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
933b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
934b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bnez	$cnt,.L192bits
935b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $rcon,4
936b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
937b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($key)
938b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($key)
939b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($key)
940b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,12
941b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($key)
942b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,0
943b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$cnt,48($key)
944b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	b	.Lekey_done
945b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $key,12*16
946b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
947b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	4
948b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.L256bits:
949b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
950b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i0,$rk7,16
951b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i1,$rk7,8
952b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i0,0xff
953b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
954b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,$rk7,0xff
955b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i3,$rk7,24
956b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
957b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
958b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
959b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
960b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i0,1024($i0)
961b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i1,1024($i1)
962b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i2,1024($i2)
963b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i3,1024($i3)
964b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
965b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($key)
966b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($key)
967b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($key)
968b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($key)
969b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk4,16($key)
970b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk5,20($key)
971b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk6,24($key)
972b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk7,28($key)
973b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
974b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
975b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i0,24
976b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i1,16
977b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i2,8
978b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_bias	$i3,0
979b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
980b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
981b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$i0,0($rcon)
982b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i1
983b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i2
984b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i3
985b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk0,$i0
986b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
987b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk1,$rk0
988b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk2,$rk1
989b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk3,$rk2
990b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	beqz	$cnt,.L256bits_done
991b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
992b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i0,$rk3,24
993b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i1,$rk3,16
994b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$i2,$rk3,8
995b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i3,$rk3,0xff
996b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i1,0xff
997b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$i2,0xff
998b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i0,$Tbl
999b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i1,$Tbl
1000b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i2,$Tbl
1001b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $i3,$Tbl
1002b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i0,1024($i0)
1003b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i1,1024($i1)
1004b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i2,1024($i2)
1005b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lbu	$i3,1024($i3)
1006b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sll	$i0,24
1007b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sll	$i1,16
1008b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sll	$i2,8
1009b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1010b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk4,$i0
1011b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk4,$i1
1012b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk4,$i2
1013b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk4,$i3
1014b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1015b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk5,$rk4
1016b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk6,$rk5
1017b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$rk7,$rk6
1018b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1019b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key,32
1020b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
1021b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	b	.L256bits
1022b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $rcon,4
1023b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1024b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.L256bits_done:
1025b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,32($key)
1026b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,36($key)
1027b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,40($key)
1028b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$cnt,14
1029b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,44($key)
1030b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,0
1031b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$cnt,48($key)
1032b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $key,12*16
1033b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1034b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Lekey_done:
1035b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
1036b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	nop
1037b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.end	_mips_AES_set_encrypt_key
1038b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
10392178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.globl	private_AES_set_encrypt_key
10402178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.ent	private_AES_set_encrypt_key
10412178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearmanprivate_AES_set_encrypt_key:
1042b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,$FRAMESIZE,$ra
1043b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.mask	$SAVED_REGS_MASK,-$SZREG
1044b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
1045b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1046b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /o32/i);	# o32 PIC-ification
1047b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpload	$pf
1048b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1049b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1050b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $sp,$FRAMESIZE
1051b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$ra,$FRAMESIZE-1*$SZREG($sp)
1052b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$fp,$FRAMESIZE-2*$SZREG($sp)
1053b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1054b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);	# optimize non-nubi prologue
1055b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s3,$FRAMESIZE-3*$SZREG($sp)
1056b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s2,$FRAMESIZE-4*$SZREG($sp)
1057b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s1,$FRAMESIZE-5*$SZREG($sp)
1058b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s0,$FRAMESIZE-6*$SZREG($sp)
1059b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$gp,$FRAMESIZE-7*$SZREG($sp)
1060b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1061b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour !~ /o32/i);	# non-o32 PIC-ification
1062b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cplocal	$Tbl
10632178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman	.cpsetup	$pf,$zero,private_AES_set_encrypt_key
1064b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1065b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1066b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
1067b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	la	$Tbl,AES_Te		# PIC-ified 'load address'
1068b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1069b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bal	_mips_AES_set_encrypt_key
1070b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1071b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
1072b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	move	$a0,$t0
1073b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$ra,$FRAMESIZE-1*$SZREG($sp)
1074b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$fp,$FRAMESIZE-2*$SZREG($sp)
1075b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1076b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);
1077b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s3,$FRAMESIZE-11*$SZREG($sp)
1078b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s2,$FRAMESIZE-12*$SZREG($sp)
1079b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s1,$FRAMESIZE-13*$SZREG($sp)
1080b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s0,$FRAMESIZE-14*$SZREG($sp)
1081b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$gp,$FRAMESIZE-15*$SZREG($sp)
1082b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1083b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1084b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
1085b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $sp,$FRAMESIZE
10862178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.end	private_AES_set_encrypt_key
1087b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1088b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1089b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($head,$tail)=($inp,$bits);
1090b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($tp1,$tp2,$tp4,$tp8,$tp9,$tpb,$tpd,$tpe)=($a4,$a5,$a6,$a7,$s0,$s1,$s2,$s3);
1091b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicmy ($m,$x80808080,$x7f7f7f7f,$x1b1b1b1b)=($at,$t0,$t1,$t2);
1092b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1093b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	5
10942178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.globl	private_AES_set_decrypt_key
10952178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.ent	private_AES_set_decrypt_key
10962178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearmanprivate_AES_set_decrypt_key:
1097b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.frame	$sp,$FRAMESIZE,$ra
1098b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.mask	$SAVED_REGS_MASK,-$SZREG
1099b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
1100b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1101b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /o32/i);	# o32 PIC-ification
1102b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cpload	$pf
1103b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1104b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1105b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $sp,$FRAMESIZE
1106b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$ra,$FRAMESIZE-1*$SZREG($sp)
1107b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$fp,$FRAMESIZE-2*$SZREG($sp)
1108b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1109b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);	# optimize non-nubi prologue
1110b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s3,$FRAMESIZE-3*$SZREG($sp)
1111b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s2,$FRAMESIZE-4*$SZREG($sp)
1112b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s1,$FRAMESIZE-5*$SZREG($sp)
1113b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$s0,$FRAMESIZE-6*$SZREG($sp)
1114b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_S	$gp,$FRAMESIZE-7*$SZREG($sp)
1115b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1116b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour !~ /o32/i);	# non-o32 PIC-ification
1117b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.cplocal	$Tbl
11182178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman	.cpsetup	$pf,$zero,private_AES_set_decrypt_key
1119b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1120b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1121b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	reorder
1122b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	la	$Tbl,AES_Te		# PIC-ified 'load address'
1123b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1124b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bal	_mips_AES_set_encrypt_key
1125b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1126b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bltz	$t0,.Ldkey_done
1127b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1128b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sll	$at,$cnt,4
1129b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $head,$key,0
1130b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $tail,$key,$at
1131b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	4
1132b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Lswap:
1133b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk0,0($head)
1134b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk1,4($head)
1135b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk2,8($head)
1136b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk3,12($head)
1137b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk4,0($tail)
1138b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk5,4($tail)
1139b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk6,8($tail)
1140b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$rk7,12($tail)
1141b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk0,0($tail)
1142b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk1,4($tail)
1143b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk2,8($tail)
1144b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk3,12($tail)
1145b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $head,16
1146b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_SUB $tail,16
1147b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk4,-16($head)
1148b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk5,-12($head)
1149b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk6,-8($head)
1150b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$rk7,-4($head)
1151b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bne	$head,$tail,.Lswap
1152b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1153b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$tp1,16($key)		# modulo-scheduled
1154b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lui	$x80808080,0x8080
1155b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
1156b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	or	$x80808080,0x8080
1157b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sll	$cnt,2
1158b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key,16
1159b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lui	$x1b1b1b1b,0x1b1b
1160b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	nor	$x7f7f7f7f,$zero,$x80808080
1161b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	or	$x1b1b1b1b,0x1b1b
1162b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	4
1163b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Lmix:
1164b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$tp1,$x80808080
1165b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$tp2,$tp1,$x7f7f7f7f
1166b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$tp4,$m,7
1167b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	addu	$tp2,$tp2		# tp2<<1
1168b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	subu	$m,$tp4
1169b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$x1b1b1b1b
1170b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tp2,$m
1171b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1172b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$tp2,$x80808080
1173b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$tp4,$tp2,$x7f7f7f7f
1174b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$tp8,$m,7
1175b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	addu	$tp4,$tp4		# tp4<<1
1176b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	subu	$m,$tp8
1177b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$x1b1b1b1b
1178b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tp4,$m
1179b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1180b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$tp4,$x80808080
1181b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$tp8,$tp4,$x7f7f7f7f
1182b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	srl	$tp9,$m,7
1183b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	addu	$tp8,$tp8		# tp8<<1
1184b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	subu	$m,$tp9
1185b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	and	$m,$x1b1b1b1b
1186b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tp8,$m
1187b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1188b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tp9,$tp8,$tp1
1189b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp8,$tp4
1190b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpb,$tp9,$tp2
1191b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpd,$tp9,$tp4
1192b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1193b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp1,$tpd,16
1194b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	 xor	$tpe,$tp2
1195b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp2,$tpd,-16
1196b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp1
1197b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp1,$tp9,8
1198b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp2
1199b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp2,$tp9,-24
1200b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp1
1201b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp1,$tpb,24
1202b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp2
1203b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	_ror	$tp2,$tpb,-8
1204b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp1
1205b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	lw	$tp1,4($key)		# modulo-scheduled
1206b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	xor	$tpe,$tp2
1207b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sub	$cnt,1
1208b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	sw	$tpe,0($key)
1209b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $key,4
1210b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	bnez	$cnt,.Lmix
1211b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1212b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	li	$t0,0
1213b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.Ldkey_done:
1214b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	.set	noreorder
1215b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	move	$a0,$t0
1216b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$ra,$FRAMESIZE-1*$SZREG($sp)
1217b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$fp,$FRAMESIZE-2*$SZREG($sp)
1218b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1219b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___ if ($flavour =~ /nubi/i);
1220b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s3,$FRAMESIZE-11*$SZREG($sp)
1221b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s2,$FRAMESIZE-12*$SZREG($sp)
1222b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s1,$FRAMESIZE-13*$SZREG($sp)
1223b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$s0,$FRAMESIZE-14*$SZREG($sp)
1224b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$REG_L	$gp,$FRAMESIZE-15*$SZREG($sp)
1225b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1226b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1227b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	jr	$ra
1228b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	$PTR_ADD $sp,$FRAMESIZE
12292178392bec7b69d0f469bce29f653c9fbd09b614Chris Dearman.end	private_AES_set_decrypt_key
1230b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1231b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic}}}
1232b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1233b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic######################################################################
1234b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic# Tables are kept in endian-neutral manner
1235b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic$code.=<<___;
1236b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.rdata
1237b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	6
1238b83a02d94f9ba66fc5da46c2e27572674ea17931Petar JovanovicAES_Te:
1239b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc6,0x63,0x63,0xa5,	0xf8,0x7c,0x7c,0x84	# Te0
1240b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xee,0x77,0x77,0x99,	0xf6,0x7b,0x7b,0x8d
1241b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xff,0xf2,0xf2,0x0d,	0xd6,0x6b,0x6b,0xbd
1242b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xde,0x6f,0x6f,0xb1,	0x91,0xc5,0xc5,0x54
1243b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x60,0x30,0x30,0x50,	0x02,0x01,0x01,0x03
1244b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xce,0x67,0x67,0xa9,	0x56,0x2b,0x2b,0x7d
1245b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe7,0xfe,0xfe,0x19,	0xb5,0xd7,0xd7,0x62
1246b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x4d,0xab,0xab,0xe6,	0xec,0x76,0x76,0x9a
1247b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8f,0xca,0xca,0x45,	0x1f,0x82,0x82,0x9d
1248b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x89,0xc9,0xc9,0x40,	0xfa,0x7d,0x7d,0x87
1249b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xef,0xfa,0xfa,0x15,	0xb2,0x59,0x59,0xeb
1250b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8e,0x47,0x47,0xc9,	0xfb,0xf0,0xf0,0x0b
1251b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x41,0xad,0xad,0xec,	0xb3,0xd4,0xd4,0x67
1252b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5f,0xa2,0xa2,0xfd,	0x45,0xaf,0xaf,0xea
1253b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x23,0x9c,0x9c,0xbf,	0x53,0xa4,0xa4,0xf7
1254b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe4,0x72,0x72,0x96,	0x9b,0xc0,0xc0,0x5b
1255b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x75,0xb7,0xb7,0xc2,	0xe1,0xfd,0xfd,0x1c
1256b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3d,0x93,0x93,0xae,	0x4c,0x26,0x26,0x6a
1257b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6c,0x36,0x36,0x5a,	0x7e,0x3f,0x3f,0x41
1258b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf5,0xf7,0xf7,0x02,	0x83,0xcc,0xcc,0x4f
1259b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x68,0x34,0x34,0x5c,	0x51,0xa5,0xa5,0xf4
1260b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd1,0xe5,0xe5,0x34,	0xf9,0xf1,0xf1,0x08
1261b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe2,0x71,0x71,0x93,	0xab,0xd8,0xd8,0x73
1262b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x62,0x31,0x31,0x53,	0x2a,0x15,0x15,0x3f
1263b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x08,0x04,0x04,0x0c,	0x95,0xc7,0xc7,0x52
1264b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x46,0x23,0x23,0x65,	0x9d,0xc3,0xc3,0x5e
1265b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x30,0x18,0x18,0x28,	0x37,0x96,0x96,0xa1
1266b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0a,0x05,0x05,0x0f,	0x2f,0x9a,0x9a,0xb5
1267b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0e,0x07,0x07,0x09,	0x24,0x12,0x12,0x36
1268b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1b,0x80,0x80,0x9b,	0xdf,0xe2,0xe2,0x3d
1269b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xcd,0xeb,0xeb,0x26,	0x4e,0x27,0x27,0x69
1270b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x7f,0xb2,0xb2,0xcd,	0xea,0x75,0x75,0x9f
1271b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x12,0x09,0x09,0x1b,	0x1d,0x83,0x83,0x9e
1272b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x58,0x2c,0x2c,0x74,	0x34,0x1a,0x1a,0x2e
1273b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x36,0x1b,0x1b,0x2d,	0xdc,0x6e,0x6e,0xb2
1274b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb4,0x5a,0x5a,0xee,	0x5b,0xa0,0xa0,0xfb
1275b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa4,0x52,0x52,0xf6,	0x76,0x3b,0x3b,0x4d
1276b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb7,0xd6,0xd6,0x61,	0x7d,0xb3,0xb3,0xce
1277b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x52,0x29,0x29,0x7b,	0xdd,0xe3,0xe3,0x3e
1278b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5e,0x2f,0x2f,0x71,	0x13,0x84,0x84,0x97
1279b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa6,0x53,0x53,0xf5,	0xb9,0xd1,0xd1,0x68
1280b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x00,0x00,0x00,0x00,	0xc1,0xed,0xed,0x2c
1281b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x40,0x20,0x20,0x60,	0xe3,0xfc,0xfc,0x1f
1282b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x79,0xb1,0xb1,0xc8,	0xb6,0x5b,0x5b,0xed
1283b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd4,0x6a,0x6a,0xbe,	0x8d,0xcb,0xcb,0x46
1284b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x67,0xbe,0xbe,0xd9,	0x72,0x39,0x39,0x4b
1285b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x94,0x4a,0x4a,0xde,	0x98,0x4c,0x4c,0xd4
1286b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb0,0x58,0x58,0xe8,	0x85,0xcf,0xcf,0x4a
1287b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbb,0xd0,0xd0,0x6b,	0xc5,0xef,0xef,0x2a
1288b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x4f,0xaa,0xaa,0xe5,	0xed,0xfb,0xfb,0x16
1289b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x86,0x43,0x43,0xc5,	0x9a,0x4d,0x4d,0xd7
1290b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x66,0x33,0x33,0x55,	0x11,0x85,0x85,0x94
1291b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8a,0x45,0x45,0xcf,	0xe9,0xf9,0xf9,0x10
1292b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x04,0x02,0x02,0x06,	0xfe,0x7f,0x7f,0x81
1293b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa0,0x50,0x50,0xf0,	0x78,0x3c,0x3c,0x44
1294b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x25,0x9f,0x9f,0xba,	0x4b,0xa8,0xa8,0xe3
1295b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa2,0x51,0x51,0xf3,	0x5d,0xa3,0xa3,0xfe
1296b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x80,0x40,0x40,0xc0,	0x05,0x8f,0x8f,0x8a
1297b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3f,0x92,0x92,0xad,	0x21,0x9d,0x9d,0xbc
1298b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x70,0x38,0x38,0x48,	0xf1,0xf5,0xf5,0x04
1299b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x63,0xbc,0xbc,0xdf,	0x77,0xb6,0xb6,0xc1
1300b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xaf,0xda,0xda,0x75,	0x42,0x21,0x21,0x63
1301b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x20,0x10,0x10,0x30,	0xe5,0xff,0xff,0x1a
1302b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfd,0xf3,0xf3,0x0e,	0xbf,0xd2,0xd2,0x6d
1303b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x81,0xcd,0xcd,0x4c,	0x18,0x0c,0x0c,0x14
1304b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x26,0x13,0x13,0x35,	0xc3,0xec,0xec,0x2f
1305b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbe,0x5f,0x5f,0xe1,	0x35,0x97,0x97,0xa2
1306b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x88,0x44,0x44,0xcc,	0x2e,0x17,0x17,0x39
1307b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x93,0xc4,0xc4,0x57,	0x55,0xa7,0xa7,0xf2
1308b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfc,0x7e,0x7e,0x82,	0x7a,0x3d,0x3d,0x47
1309b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc8,0x64,0x64,0xac,	0xba,0x5d,0x5d,0xe7
1310b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x32,0x19,0x19,0x2b,	0xe6,0x73,0x73,0x95
1311b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc0,0x60,0x60,0xa0,	0x19,0x81,0x81,0x98
1312b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9e,0x4f,0x4f,0xd1,	0xa3,0xdc,0xdc,0x7f
1313b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x44,0x22,0x22,0x66,	0x54,0x2a,0x2a,0x7e
1314b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3b,0x90,0x90,0xab,	0x0b,0x88,0x88,0x83
1315b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8c,0x46,0x46,0xca,	0xc7,0xee,0xee,0x29
1316b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6b,0xb8,0xb8,0xd3,	0x28,0x14,0x14,0x3c
1317b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa7,0xde,0xde,0x79,	0xbc,0x5e,0x5e,0xe2
1318b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x16,0x0b,0x0b,0x1d,	0xad,0xdb,0xdb,0x76
1319b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xdb,0xe0,0xe0,0x3b,	0x64,0x32,0x32,0x56
1320b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x74,0x3a,0x3a,0x4e,	0x14,0x0a,0x0a,0x1e
1321b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x92,0x49,0x49,0xdb,	0x0c,0x06,0x06,0x0a
1322b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x48,0x24,0x24,0x6c,	0xb8,0x5c,0x5c,0xe4
1323b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9f,0xc2,0xc2,0x5d,	0xbd,0xd3,0xd3,0x6e
1324b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x43,0xac,0xac,0xef,	0xc4,0x62,0x62,0xa6
1325b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x39,0x91,0x91,0xa8,	0x31,0x95,0x95,0xa4
1326b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd3,0xe4,0xe4,0x37,	0xf2,0x79,0x79,0x8b
1327b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd5,0xe7,0xe7,0x32,	0x8b,0xc8,0xc8,0x43
1328b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6e,0x37,0x37,0x59,	0xda,0x6d,0x6d,0xb7
1329b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x01,0x8d,0x8d,0x8c,	0xb1,0xd5,0xd5,0x64
1330b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9c,0x4e,0x4e,0xd2,	0x49,0xa9,0xa9,0xe0
1331b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd8,0x6c,0x6c,0xb4,	0xac,0x56,0x56,0xfa
1332b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf3,0xf4,0xf4,0x07,	0xcf,0xea,0xea,0x25
1333b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xca,0x65,0x65,0xaf,	0xf4,0x7a,0x7a,0x8e
1334b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x47,0xae,0xae,0xe9,	0x10,0x08,0x08,0x18
1335b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6f,0xba,0xba,0xd5,	0xf0,0x78,0x78,0x88
1336b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x4a,0x25,0x25,0x6f,	0x5c,0x2e,0x2e,0x72
1337b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x38,0x1c,0x1c,0x24,	0x57,0xa6,0xa6,0xf1
1338b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x73,0xb4,0xb4,0xc7,	0x97,0xc6,0xc6,0x51
1339b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xcb,0xe8,0xe8,0x23,	0xa1,0xdd,0xdd,0x7c
1340b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe8,0x74,0x74,0x9c,	0x3e,0x1f,0x1f,0x21
1341b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x96,0x4b,0x4b,0xdd,	0x61,0xbd,0xbd,0xdc
1342b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0d,0x8b,0x8b,0x86,	0x0f,0x8a,0x8a,0x85
1343b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe0,0x70,0x70,0x90,	0x7c,0x3e,0x3e,0x42
1344b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x71,0xb5,0xb5,0xc4,	0xcc,0x66,0x66,0xaa
1345b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x90,0x48,0x48,0xd8,	0x06,0x03,0x03,0x05
1346b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf7,0xf6,0xf6,0x01,	0x1c,0x0e,0x0e,0x12
1347b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc2,0x61,0x61,0xa3,	0x6a,0x35,0x35,0x5f
1348b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xae,0x57,0x57,0xf9,	0x69,0xb9,0xb9,0xd0
1349b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x17,0x86,0x86,0x91,	0x99,0xc1,0xc1,0x58
1350b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3a,0x1d,0x1d,0x27,	0x27,0x9e,0x9e,0xb9
1351b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd9,0xe1,0xe1,0x38,	0xeb,0xf8,0xf8,0x13
1352b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2b,0x98,0x98,0xb3,	0x22,0x11,0x11,0x33
1353b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd2,0x69,0x69,0xbb,	0xa9,0xd9,0xd9,0x70
1354b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x07,0x8e,0x8e,0x89,	0x33,0x94,0x94,0xa7
1355b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2d,0x9b,0x9b,0xb6,	0x3c,0x1e,0x1e,0x22
1356b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x15,0x87,0x87,0x92,	0xc9,0xe9,0xe9,0x20
1357b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x87,0xce,0xce,0x49,	0xaa,0x55,0x55,0xff
1358b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x50,0x28,0x28,0x78,	0xa5,0xdf,0xdf,0x7a
1359b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x03,0x8c,0x8c,0x8f,	0x59,0xa1,0xa1,0xf8
1360b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x09,0x89,0x89,0x80,	0x1a,0x0d,0x0d,0x17
1361b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x65,0xbf,0xbf,0xda,	0xd7,0xe6,0xe6,0x31
1362b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x84,0x42,0x42,0xc6,	0xd0,0x68,0x68,0xb8
1363b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x82,0x41,0x41,0xc3,	0x29,0x99,0x99,0xb0
1364b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5a,0x2d,0x2d,0x77,	0x1e,0x0f,0x0f,0x11
1365b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x7b,0xb0,0xb0,0xcb,	0xa8,0x54,0x54,0xfc
1366b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6d,0xbb,0xbb,0xd6,	0x2c,0x16,0x16,0x3a
1367b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1368b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5	# Te4
1369b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76
1370b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0
1371b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0
1372b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc
1373b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15
1374b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a
1375b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75
1376b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0
1377b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84
1378b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b
1379b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf
1380b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85
1381b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8
1382b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5
1383b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2
1384b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17
1385b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73
1386b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88
1387b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb
1388b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c
1389b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79
1390b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9
1391b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08
1392b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6
1393b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a
1394b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e
1395b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e
1396b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94
1397b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf
1398b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68
1399b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
1400b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1401b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x01,0x00,0x00,0x00,	0x02,0x00,0x00,0x00	# rcon
1402b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x04,0x00,0x00,0x00,	0x08,0x00,0x00,0x00
1403b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x10,0x00,0x00,0x00,	0x20,0x00,0x00,0x00
1404b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x40,0x00,0x00,0x00,	0x80,0x00,0x00,0x00
1405b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1B,0x00,0x00,0x00,	0x36,0x00,0x00,0x00
1406b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1407b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.align	6
1408b83a02d94f9ba66fc5da46c2e27572674ea17931Petar JovanovicAES_Td:
1409b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x51,0xf4,0xa7,0x50,	0x7e,0x41,0x65,0x53	# Td0
1410b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1a,0x17,0xa4,0xc3,	0x3a,0x27,0x5e,0x96
1411b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3b,0xab,0x6b,0xcb,	0x1f,0x9d,0x45,0xf1
1412b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xac,0xfa,0x58,0xab,	0x4b,0xe3,0x03,0x93
1413b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x20,0x30,0xfa,0x55,	0xad,0x76,0x6d,0xf6
1414b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x88,0xcc,0x76,0x91,	0xf5,0x02,0x4c,0x25
1415b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x4f,0xe5,0xd7,0xfc,	0xc5,0x2a,0xcb,0xd7
1416b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x26,0x35,0x44,0x80,	0xb5,0x62,0xa3,0x8f
1417b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xde,0xb1,0x5a,0x49,	0x25,0xba,0x1b,0x67
1418b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x45,0xea,0x0e,0x98,	0x5d,0xfe,0xc0,0xe1
1419b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc3,0x2f,0x75,0x02,	0x81,0x4c,0xf0,0x12
1420b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8d,0x46,0x97,0xa3,	0x6b,0xd3,0xf9,0xc6
1421b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x03,0x8f,0x5f,0xe7,	0x15,0x92,0x9c,0x95
1422b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbf,0x6d,0x7a,0xeb,	0x95,0x52,0x59,0xda
1423b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd4,0xbe,0x83,0x2d,	0x58,0x74,0x21,0xd3
1424b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x49,0xe0,0x69,0x29,	0x8e,0xc9,0xc8,0x44
1425b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x75,0xc2,0x89,0x6a,	0xf4,0x8e,0x79,0x78
1426b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x99,0x58,0x3e,0x6b,	0x27,0xb9,0x71,0xdd
1427b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbe,0xe1,0x4f,0xb6,	0xf0,0x88,0xad,0x17
1428b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc9,0x20,0xac,0x66,	0x7d,0xce,0x3a,0xb4
1429b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x63,0xdf,0x4a,0x18,	0xe5,0x1a,0x31,0x82
1430b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x97,0x51,0x33,0x60,	0x62,0x53,0x7f,0x45
1431b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb1,0x64,0x77,0xe0,	0xbb,0x6b,0xae,0x84
1432b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfe,0x81,0xa0,0x1c,	0xf9,0x08,0x2b,0x94
1433b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x70,0x48,0x68,0x58,	0x8f,0x45,0xfd,0x19
1434b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x94,0xde,0x6c,0x87,	0x52,0x7b,0xf8,0xb7
1435b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xab,0x73,0xd3,0x23,	0x72,0x4b,0x02,0xe2
1436b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe3,0x1f,0x8f,0x57,	0x66,0x55,0xab,0x2a
1437b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb2,0xeb,0x28,0x07,	0x2f,0xb5,0xc2,0x03
1438b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x86,0xc5,0x7b,0x9a,	0xd3,0x37,0x08,0xa5
1439b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x30,0x28,0x87,0xf2,	0x23,0xbf,0xa5,0xb2
1440b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x02,0x03,0x6a,0xba,	0xed,0x16,0x82,0x5c
1441b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8a,0xcf,0x1c,0x2b,	0xa7,0x79,0xb4,0x92
1442b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf3,0x07,0xf2,0xf0,	0x4e,0x69,0xe2,0xa1
1443b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x65,0xda,0xf4,0xcd,	0x06,0x05,0xbe,0xd5
1444b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd1,0x34,0x62,0x1f,	0xc4,0xa6,0xfe,0x8a
1445b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x34,0x2e,0x53,0x9d,	0xa2,0xf3,0x55,0xa0
1446b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x05,0x8a,0xe1,0x32,	0xa4,0xf6,0xeb,0x75
1447b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0b,0x83,0xec,0x39,	0x40,0x60,0xef,0xaa
1448b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5e,0x71,0x9f,0x06,	0xbd,0x6e,0x10,0x51
1449b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3e,0x21,0x8a,0xf9,	0x96,0xdd,0x06,0x3d
1450b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xdd,0x3e,0x05,0xae,	0x4d,0xe6,0xbd,0x46
1451b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x91,0x54,0x8d,0xb5,	0x71,0xc4,0x5d,0x05
1452b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x04,0x06,0xd4,0x6f,	0x60,0x50,0x15,0xff
1453b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x19,0x98,0xfb,0x24,	0xd6,0xbd,0xe9,0x97
1454b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x89,0x40,0x43,0xcc,	0x67,0xd9,0x9e,0x77
1455b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb0,0xe8,0x42,0xbd,	0x07,0x89,0x8b,0x88
1456b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe7,0x19,0x5b,0x38,	0x79,0xc8,0xee,0xdb
1457b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa1,0x7c,0x0a,0x47,	0x7c,0x42,0x0f,0xe9
1458b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf8,0x84,0x1e,0xc9,	0x00,0x00,0x00,0x00
1459b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x09,0x80,0x86,0x83,	0x32,0x2b,0xed,0x48
1460b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1e,0x11,0x70,0xac,	0x6c,0x5a,0x72,0x4e
1461b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfd,0x0e,0xff,0xfb,	0x0f,0x85,0x38,0x56
1462b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3d,0xae,0xd5,0x1e,	0x36,0x2d,0x39,0x27
1463b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0a,0x0f,0xd9,0x64,	0x68,0x5c,0xa6,0x21
1464b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9b,0x5b,0x54,0xd1,	0x24,0x36,0x2e,0x3a
1465b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0c,0x0a,0x67,0xb1,	0x93,0x57,0xe7,0x0f
1466b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb4,0xee,0x96,0xd2,	0x1b,0x9b,0x91,0x9e
1467b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x80,0xc0,0xc5,0x4f,	0x61,0xdc,0x20,0xa2
1468b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5a,0x77,0x4b,0x69,	0x1c,0x12,0x1a,0x16
1469b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe2,0x93,0xba,0x0a,	0xc0,0xa0,0x2a,0xe5
1470b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3c,0x22,0xe0,0x43,	0x12,0x1b,0x17,0x1d
1471b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0e,0x09,0x0d,0x0b,	0xf2,0x8b,0xc7,0xad
1472b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2d,0xb6,0xa8,0xb9,	0x14,0x1e,0xa9,0xc8
1473b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x57,0xf1,0x19,0x85,	0xaf,0x75,0x07,0x4c
1474b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xee,0x99,0xdd,0xbb,	0xa3,0x7f,0x60,0xfd
1475b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf7,0x01,0x26,0x9f,	0x5c,0x72,0xf5,0xbc
1476b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x44,0x66,0x3b,0xc5,	0x5b,0xfb,0x7e,0x34
1477b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8b,0x43,0x29,0x76,	0xcb,0x23,0xc6,0xdc
1478b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb6,0xed,0xfc,0x68,	0xb8,0xe4,0xf1,0x63
1479b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd7,0x31,0xdc,0xca,	0x42,0x63,0x85,0x10
1480b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x13,0x97,0x22,0x40,	0x84,0xc6,0x11,0x20
1481b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x85,0x4a,0x24,0x7d,	0xd2,0xbb,0x3d,0xf8
1482b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xae,0xf9,0x32,0x11,	0xc7,0x29,0xa1,0x6d
1483b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1d,0x9e,0x2f,0x4b,	0xdc,0xb2,0x30,0xf3
1484b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x0d,0x86,0x52,0xec,	0x77,0xc1,0xe3,0xd0
1485b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2b,0xb3,0x16,0x6c,	0xa9,0x70,0xb9,0x99
1486b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x11,0x94,0x48,0xfa,	0x47,0xe9,0x64,0x22
1487b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa8,0xfc,0x8c,0xc4,	0xa0,0xf0,0x3f,0x1a
1488b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x56,0x7d,0x2c,0xd8,	0x22,0x33,0x90,0xef
1489b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x87,0x49,0x4e,0xc7,	0xd9,0x38,0xd1,0xc1
1490b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x8c,0xca,0xa2,0xfe,	0x98,0xd4,0x0b,0x36
1491b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa6,0xf5,0x81,0xcf,	0xa5,0x7a,0xde,0x28
1492b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xda,0xb7,0x8e,0x26,	0x3f,0xad,0xbf,0xa4
1493b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2c,0x3a,0x9d,0xe4,	0x50,0x78,0x92,0x0d
1494b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6a,0x5f,0xcc,0x9b,	0x54,0x7e,0x46,0x62
1495b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf6,0x8d,0x13,0xc2,	0x90,0xd8,0xb8,0xe8
1496b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2e,0x39,0xf7,0x5e,	0x82,0xc3,0xaf,0xf5
1497b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9f,0x5d,0x80,0xbe,	0x69,0xd0,0x93,0x7c
1498b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6f,0xd5,0x2d,0xa9,	0xcf,0x25,0x12,0xb3
1499b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc8,0xac,0x99,0x3b,	0x10,0x18,0x7d,0xa7
1500b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe8,0x9c,0x63,0x6e,	0xdb,0x3b,0xbb,0x7b
1501b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xcd,0x26,0x78,0x09,	0x6e,0x59,0x18,0xf4
1502b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xec,0x9a,0xb7,0x01,	0x83,0x4f,0x9a,0xa8
1503b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe6,0x95,0x6e,0x65,	0xaa,0xff,0xe6,0x7e
1504b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x21,0xbc,0xcf,0x08,	0xef,0x15,0xe8,0xe6
1505b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xba,0xe7,0x9b,0xd9,	0x4a,0x6f,0x36,0xce
1506b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xea,0x9f,0x09,0xd4,	0x29,0xb0,0x7c,0xd6
1507b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x31,0xa4,0xb2,0xaf,	0x2a,0x3f,0x23,0x31
1508b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc6,0xa5,0x94,0x30,	0x35,0xa2,0x66,0xc0
1509b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x74,0x4e,0xbc,0x37,	0xfc,0x82,0xca,0xa6
1510b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe0,0x90,0xd0,0xb0,	0x33,0xa7,0xd8,0x15
1511b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf1,0x04,0x98,0x4a,	0x41,0xec,0xda,0xf7
1512b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x7f,0xcd,0x50,0x0e,	0x17,0x91,0xf6,0x2f
1513b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x76,0x4d,0xd6,0x8d,	0x43,0xef,0xb0,0x4d
1514b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xcc,0xaa,0x4d,0x54,	0xe4,0x96,0x04,0xdf
1515b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9e,0xd1,0xb5,0xe3,	0x4c,0x6a,0x88,0x1b
1516b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc1,0x2c,0x1f,0xb8,	0x46,0x65,0x51,0x7f
1517b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9d,0x5e,0xea,0x04,	0x01,0x8c,0x35,0x5d
1518b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfa,0x87,0x74,0x73,	0xfb,0x0b,0x41,0x2e
1519b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb3,0x67,0x1d,0x5a,	0x92,0xdb,0xd2,0x52
1520b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe9,0x10,0x56,0x33,	0x6d,0xd6,0x47,0x13
1521b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9a,0xd7,0x61,0x8c,	0x37,0xa1,0x0c,0x7a
1522b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x59,0xf8,0x14,0x8e,	0xeb,0x13,0x3c,0x89
1523b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xce,0xa9,0x27,0xee,	0xb7,0x61,0xc9,0x35
1524b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe1,0x1c,0xe5,0xed,	0x7a,0x47,0xb1,0x3c
1525b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9c,0xd2,0xdf,0x59,	0x55,0xf2,0x73,0x3f
1526b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x18,0x14,0xce,0x79,	0x73,0xc7,0x37,0xbf
1527b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x53,0xf7,0xcd,0xea,	0x5f,0xfd,0xaa,0x5b
1528b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xdf,0x3d,0x6f,0x14,	0x78,0x44,0xdb,0x86
1529b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xca,0xaf,0xf3,0x81,	0xb9,0x68,0xc4,0x3e
1530b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x38,0x24,0x34,0x2c,	0xc2,0xa3,0x40,0x5f
1531b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x16,0x1d,0xc3,0x72,	0xbc,0xe2,0x25,0x0c
1532b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x28,0x3c,0x49,0x8b,	0xff,0x0d,0x95,0x41
1533b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x39,0xa8,0x01,0x71,	0x08,0x0c,0xb3,0xde
1534b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd8,0xb4,0xe4,0x9c,	0x64,0x56,0xc1,0x90
1535b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x7b,0xcb,0x84,0x61,	0xd5,0x32,0xb6,0x70
1536b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x48,0x6c,0x5c,0x74,	0xd0,0xb8,0x57,0x42
1537b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1538b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38	# Td4
1539b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb
1540b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87
1541b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb
1542b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d
1543b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e
1544b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2
1545b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25
1546b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16
1547b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92
1548b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda
1549b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84
1550b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a
1551b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06
1552b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02
1553b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b
1554b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea
1555b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73
1556b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85
1557b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e
1558b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89
1559b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b
1560b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20
1561b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4
1562b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31
1563b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f
1564b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d
1565b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef
1566b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0
1567b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61
1568b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26
1569b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic.byte	0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
1570b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic___
1571b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1572b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicforeach (split("\n",$code)) {
1573b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	s/\`([^\`]*)\`/eval $1/ge;
1574b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1575b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	# made-up _instructions, _xtr, _ins, _ror and _bias, cope
1576b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	# with byte order dependencies...
1577b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	if (/^\s+_/) {
1578b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/(_[a-z]+\s+)(\$[0-9]+),([^,]+)(#.*)*$/$1$2,$2,$3/;
1579b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1580b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/_xtr\s+(\$[0-9]+),(\$[0-9]+),([0-9]+(\-2)*)/
1581b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("srl\t$1,$2,%d",$big_endian ?	eval($3)
1582b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic					:		eval("24-$3"))/e or
1583b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/_ins\s+(\$[0-9]+),(\$[0-9]+),([0-9]+)/
1584b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("sll\t$1,$2,%d",$big_endian ?	eval($3)
1585b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic					:		eval("24-$3"))/e or
1586b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/_ror\s+(\$[0-9]+),(\$[0-9]+),(\-?[0-9]+)/
1587b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("srl\t$1,$2,%d",$big_endian ?	eval($3)
1588b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic					:		eval("$3*-1"))/e or
1589b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/_bias\s+(\$[0-9]+),(\$[0-9]+),([0-9]+)/
1590b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("sll\t$1,$2,%d",$big_endian ?	eval($3)
1591b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic					:		eval("($3-16)&31"))/e;
1592b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1593b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/srl\s+(\$[0-9]+),(\$[0-9]+),\-([0-9]+)/
1594b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("sll\t$1,$2,$3")/e				or
1595b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/srl\s+(\$[0-9]+),(\$[0-9]+),0/
1596b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("and\t$1,$2,0xff")/e				or
1597b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/(sll\s+\$[0-9]+,\$[0-9]+,0)/#$1/;
1598b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	}
1599b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1600b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	# convert lwl/lwr and swr/swl to little-endian order
1601b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	if (!$big_endian && /^\s+[sl]w[lr]\s+/) {
1602b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/([sl]wl.*)([0-9]+)\((\$[0-9]+)\)/
1603b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("$1%d($3)",eval("$2-$2%4+($2%4-1)&3"))/e	or
1604b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	    s/([sl]wr.*)([0-9]+)\((\$[0-9]+)\)/
1605b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic		sprintf("$1%d($3)",eval("$2-$2%4+($2%4+1)&3"))/e;
1606b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	}
1607b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1608b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic	print $_,"\n";
1609b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic}
1610b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovic
1611b83a02d94f9ba66fc5da46c2e27572674ea17931Petar Jovanovicclose STDOUT;
1612