2 * Macro used to simplify coding multi-line assembler.
3 * Some of the bit test macro can simplify down to one line
4 * depending on the mask value.
6 * Copyright (C) 2004 Microtronix Datacom Ltd.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
22 #ifndef _ASM_NIOS2_ASMMACROS_H
23 #define _ASM_NIOS2_ASMMACROS_H
25 * ANDs reg2 with mask and places the result in reg1.
27 * You cannnot use the same register for reg1 & reg2.
30 .macro ANDI32 reg1, reg2, mask
32 .if \mask & 0xffff0000
33 movhi \reg1, %hi(\mask)
34 movui \reg1, %lo(\mask)
35 and \reg1, \reg1, \reg2
37 andi \reg1, \reg2, %lo(\mask)
40 andhi \reg1, \reg2, %hi(\mask)
45 * ORs reg2 with mask and places the result in reg1.
47 * It is safe to use the same register for reg1 & reg2.
50 .macro ORI32 reg1, reg2, mask
52 .if \mask & 0xffff0000
53 orhi \reg1, \reg2, %hi(\mask)
54 ori \reg1, \reg2, %lo(\mask)
56 ori \reg1, \reg2, %lo(\mask)
59 orhi \reg1, \reg2, %hi(\mask)
64 * XORs reg2 with mask and places the result in reg1.
66 * It is safe to use the same register for reg1 & reg2.
69 .macro XORI32 reg1, reg2, mask
71 .if \mask & 0xffff0000
72 xorhi \reg1, \reg2, %hi(\mask)
73 xori \reg1, \reg1, %lo(\mask)
75 xori \reg1, \reg2, %lo(\mask)
78 xorhi \reg1, \reg2, %hi(\mask)
83 * This is a support macro for BTBZ & BTBNZ. It checks
84 * the bit to make sure it is valid 32 value.
86 * It is safe to use the same register for reg1 & reg2.
89 .macro BT reg1, reg2, bit
94 andi \reg1, \reg2, (1 << \bit)
96 andhi \reg1, \reg2, (1 << (\bit - 16))
102 * Tests the bit in reg2 and branches to label if the
103 * bit is zero. The result of the bit test is stored in reg1.
105 * It is safe to use the same register for reg1 & reg2.
108 .macro BTBZ reg1, reg2, bit, label
109 BT \reg1, \reg2, \bit
110 beq \reg1, r0, \label
114 * Tests the bit in reg2 and branches to label if the
115 * bit is non-zero. The result of the bit test is stored in reg1.
117 * It is safe to use the same register for reg1 & reg2.
120 .macro BTBNZ reg1, reg2, bit, label
121 BT \reg1, \reg2, \bit
122 bne \reg1, r0, \label
126 * Tests the bit in reg2 and then compliments the bit in reg2.
127 * The result of the bit test is stored in reg1.
129 * It is NOT safe to use the same register for reg1 & reg2.
132 .macro BTC reg1, reg2, bit
137 andi \reg1, \reg2, (1 << \bit)
138 xori \reg2, \reg2, (1 << \bit)
140 andhi \reg1, \reg2, (1 << (\bit - 16))
141 xorhi \reg2, \reg2, (1 << (\bit - 16))
147 * Tests the bit in reg2 and then sets the bit in reg2.
148 * The result of the bit test is stored in reg1.
150 * It is NOT safe to use the same register for reg1 & reg2.
153 .macro BTS reg1, reg2, bit
158 andi \reg1, \reg2, (1 << \bit)
159 ori \reg2, \reg2, (1 << \bit)
161 andhi \reg1, \reg2, (1 << (\bit - 16))
162 orhi \reg2, \reg2, (1 << (\bit - 16))
168 * Tests the bit in reg2 and then resets the bit in reg2.
169 * The result of the bit test is stored in reg1.
171 * It is NOT safe to use the same register for reg1 & reg2.
174 .macro BTR reg1, reg2, bit
179 andi \reg1, \reg2, (1 << \bit)
180 andi \reg2, \reg2, %lo(~(1 << \bit))
182 andhi \reg1, \reg2, (1 << (\bit - 16))
183 andhi \reg2, \reg2, %lo(~(1 << (\bit - 16)))
189 * Tests the bit in reg2 and then compliments the bit in reg2.
190 * The result of the bit test is stored in reg1. If the
191 * original bit was zero it branches to label.
193 * It is NOT safe to use the same register for reg1 & reg2.
196 .macro BTCBZ reg1, reg2, bit, label
197 BTC \reg1, \reg2, \bit
198 beq \reg1, r0, \label
202 * Tests the bit in reg2 and then compliments the bit in reg2.
203 * The result of the bit test is stored in reg1. If the
204 * original bit was non-zero it branches to label.
206 * It is NOT safe to use the same register for reg1 & reg2.
209 .macro BTCBNZ reg1, reg2, bit, label
210 BTC \reg1, \reg2, \bit
211 bne \reg1, r0, \label
215 * Tests the bit in reg2 and then sets the bit in reg2.
216 * The result of the bit test is stored in reg1. If the
217 * original bit was zero it branches to label.
219 * It is NOT safe to use the same register for reg1 & reg2.
222 .macro BTSBZ reg1, reg2, bit, label
223 BTS \reg1, \reg2, \bit
224 beq \reg1, r0, \label
228 * Tests the bit in reg2 and then sets the bit in reg2.
229 * The result of the bit test is stored in reg1. If the
230 * original bit was non-zero it branches to label.
232 * It is NOT safe to use the same register for reg1 & reg2.
235 .macro BTSBNZ reg1, reg2, bit, label
236 BTS \reg1, \reg2, \bit
237 bne \reg1, r0, \label
241 * Tests the bit in reg2 and then resets the bit in reg2.
242 * The result of the bit test is stored in reg1. If the
243 * original bit was zero it branches to label.
245 * It is NOT safe to use the same register for reg1 & reg2.
248 .macro BTRBZ reg1, reg2, bit, label
249 BTR \reg1, \reg2, \bit
250 bne \reg1, r0, \label
254 * Tests the bit in reg2 and then resets the bit in reg2.
255 * The result of the bit test is stored in reg1. If the
256 * original bit was non-zero it branches to label.
258 * It is NOT safe to use the same register for reg1 & reg2.
261 .macro BTRBNZ reg1, reg2, bit, label
262 BTR \reg1, \reg2, \bit
263 bne \reg1, r0, \label
267 * Tests the bits in mask against reg2 stores the result in reg1.
268 * If the all the bits in the mask are zero it branches to label.
270 * It is safe to use the same register for reg1 & reg2.
273 .macro TSTBZ reg1, reg2, mask, label
274 ANDI32 \reg1, \reg2, \mask
275 beq \reg1, r0, \label
279 * Tests the bits in mask against reg2 stores the result in reg1.
280 * If the any of the bits in the mask are 1 it branches to label.
282 * It is safe to use the same register for reg1 & reg2.
285 .macro TSTBNZ reg1, reg2, mask, label
286 ANDI32 \reg1, \reg2, \mask
287 bne \reg1, r0, \label
291 * Pushes reg onto the stack.
300 * Pops the top of the stack into reg.
309 #endif /* _ASM_NIOS2_ASMMACROS_H */