Skip to content

Commit 45eecfb

Browse files
Ard Biesheuvelgregkh
authored andcommitted
arm64: introduce mov_q macro to move a constant into a 64-bit register
commit 30b5ba5 upstream. 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 <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9bb698b commit 45eecfb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,24 @@ lr .req x30 // link register
204204
.size __pi_##x, . - x; \
205205
ENDPROC(x)
206206

207+
/*
208+
* mov_q - move an immediate constant into a 64-bit register using
209+
* between 2 and 4 movz/movk instructions (depending on the
210+
* magnitude and sign of the operand)
211+
*/
212+
.macro mov_q, reg, val
213+
.if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff)
214+
movz \reg, :abs_g1_s:\val
215+
.else
216+
.if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff)
217+
movz \reg, :abs_g2_s:\val
218+
.else
219+
movz \reg, :abs_g3:\val
220+
movk \reg, :abs_g2_nc:\val
221+
.endif
222+
movk \reg, :abs_g1_nc:\val
223+
.endif
224+
movk \reg, :abs_g0_nc:\val
225+
.endm
226+
207227
#endif /* __ASM_ASSEMBLER_H */

0 commit comments

Comments
 (0)