Skip to content

Commit de145ea

Browse files
author
Ard Biesheuvel
committed
arm64: introduce mov_q macro to move a constant into a 64-bit register
Implement a macro mov_q that can be used to move an immediate constant into a 64-bit register, using between 2 and 4 movz/movk instructions (depending on the operand) Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit 30b5ba5cf333cc650e474eaf2cc1ae91bc7cf89f) Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
1 parent d481227 commit de145ea

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

arch/arm64/include/asm/assembler.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,24 @@ lr .req x30 // link register
233233
.long \sym\()_hi32
234234
.endm
235235

236+
/*
237+
* mov_q - move an immediate constant into a 64-bit register using
238+
* between 2 and 4 movz/movk instructions (depending on the
239+
* magnitude and sign of the operand)
240+
*/
241+
.macro mov_q, reg, val
242+
.if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff)
243+
movz \reg, :abs_g1_s:\val
244+
.else
245+
.if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff)
246+
movz \reg, :abs_g2_s:\val
247+
.else
248+
movz \reg, :abs_g3:\val
249+
movk \reg, :abs_g2_nc:\val
250+
.endif
251+
movk \reg, :abs_g1_nc:\val
252+
.endif
253+
movk \reg, :abs_g0_nc:\val
254+
.endm
255+
236256
#endif /* __ASM_ASSEMBLER_H */

0 commit comments

Comments
 (0)