]> git.cryptolib.org Git - avr-crypto-lib.git/blob - keccak/rotate64.S
optimizing norx32
[avr-crypto-lib.git] / keccak / rotate64.S
1 /* rotate64.S */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 .global rotate64_1bit_left
21 rotate64_1bit_left:
22         bst r25, 7
23         rol r18
24         rol r19
25         rol r20
26         rol r21
27         rol r22
28         rol r23
29         rol r24
30         rol r25
31         bld r18, 0
32         ret
33
34 .global rotate64_1bit_right
35 rotate64_1bit_right:
36         bst r18, 0
37         ror r25
38         ror r24
39         ror r23
40         ror r22
41         ror r21
42         ror r20
43         ror r19
44         ror r18
45         bld r25, 7
46         ret
47
48 .global rotate64_nbit_autodir
49 rotate64_nbit_autodir:
50         lsr r16
51         brcc rotate64_nbit_left
52 .global rotate64_nbit_right
53 rotate64_nbit_right:
54         ldi r30, pm_lo8(rotate64_1bit_right)
55         ldi r31, pm_hi8(rotate64_1bit_right)
56         rjmp icall_r16_times
57 .global rotate64_nbit_left
58 rotate64_nbit_left:
59         ldi r30, pm_lo8(rotate64_1bit_left)
60         ldi r31, pm_hi8(rotate64_1bit_left)
61 icall_r16_times:
62 1:      dec r16
63         brmi 2f
64         icall
65         rjmp 1b
66 2:
67         pop r16
68     ret
69
70 rotate64_1byte_left:
71         mov r0, r25
72         mov r25, r24
73         mov r24, r23
74         mov r23, r22
75         mov r22, r21
76         mov r21, r20
77         mov r20, r19
78         mov r19, r18
79         mov r18, r0
80         ret
81
82 rotate64_2byte_left:
83         movw r0, r24
84         movw r24, r22
85         movw r22, r20
86         movw r20, r18
87         movw r18, r0
88         ret
89
90 rotate64_3byte_left:
91         mov r0, r25
92         mov r25, r22
93         mov r22, r19
94         mov r19, r24
95         mov r24, r21
96         mov r21, r18
97         mov r18, r23
98         mov r23, r20
99         mov r20, r0
100         ret
101
102 rotate64_4byte_left:
103         movw r0, r24
104         movw r24, r20
105         movw r20, r0
106         movw r0, r22
107         movw r22, r18
108         movw r18, r0
109         ret
110
111 rotate64_5byte_left:
112         mov r0, r25
113         mov r25, r20
114         mov r20, r23
115         mov r23, r18
116         mov r18, r21
117         mov r21, r24
118         mov r24, r19
119         mov r19, r22
120         mov r22, r0
121         ret
122
123 rotate64_6byte_left:
124         movw r0, r18
125         movw r18, r20
126         movw r20, r22
127         movw r22, r24
128         movw r24, r0
129         ret
130
131 rotate64_7byte_left:
132         mov r0, r18
133         mov r18, r19
134         mov r19, r20
135         mov r20, r21
136         mov r21, r22
137         mov r22, r23
138         mov r23, r24
139         mov r24, r25
140         mov r25, r0
141         ret
142
143
144 byte_rot_jmp_table:
145         ret
146         rjmp rotate64_1byte_left
147         rjmp rotate64_2byte_left
148         rjmp rotate64_3byte_left
149         rjmp rotate64_4byte_left
150         rjmp rotate64_5byte_left
151         rjmp rotate64_6byte_left
152         rjmp rotate64_7byte_left
153
154 .global rotate64left_code
155 rotate64left_code:
156         ldi r30, pm_lo8(byte_rot_jmp_table)
157         ldi r31, pm_hi8(byte_rot_jmp_table)
158         push r16
159         mov r0, r16
160         andi r16, 0x70
161         swap r16
162         add r30, r16
163         adc r31, r1
164         mov r16, r0
165         andi r16, 0x0f
166         icall
167         clr r1
168         rjmp rotate64_nbit_autodir