Skip to content

Commit f444a5f

Browse files
aeglsuryasaimadhu
authored andcommitted
x86/cpufeatures: Add support for fast short REP; MOVSB
>From the Intel Optimization Reference Manual: 3.7.6.1 Fast Short REP MOVSB Beginning with processors based on Ice Lake Client microarchitecture, REP MOVSB performance of short operations is enhanced. The enhancement applies to string lengths between 1 and 128 bytes long. Support for fast-short REP MOVSB is enumerated by the CPUID feature flag: CPUID [EAX=7H, ECX=0H).EDX.FAST_SHORT_REP_MOVSB[bit 4] = 1. There is no change in the REP STOS performance. Add an X86_FEATURE_FSRM flag for this. memmove() avoids REP MOVSB for short (< 32 byte) copies. Check FSRM and use REP MOVSB for short copies on systems that support it. [ bp: Massage and add comment. ] Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 50cc02e commit f444a5f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@
357357
/* Intel-defined CPU features, CPUID level 0x00000007:0 (EDX), word 18 */
358358
#define X86_FEATURE_AVX512_4VNNIW (18*32+ 2) /* AVX-512 Neural Network Instructions */
359359
#define X86_FEATURE_AVX512_4FMAPS (18*32+ 3) /* AVX-512 Multiply Accumulation Single precision */
360+
#define X86_FEATURE_FSRM (18*32+ 4) /* Fast Short Rep Mov */
360361
#define X86_FEATURE_AVX512_VP2INTERSECT (18*32+ 8) /* AVX-512 Intersect for D/Q */
361362
#define X86_FEATURE_MD_CLEAR (18*32+10) /* VERW clears CPU buffers */
362363
#define X86_FEATURE_TSX_FORCE_ABORT (18*32+13) /* "" TSX_FORCE_ABORT */

arch/x86/lib/memmove_64.S

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
SYM_FUNC_START_ALIAS(memmove)
3030
SYM_FUNC_START(__memmove)
3131

32-
/* Handle more 32 bytes in loop */
3332
mov %rdi, %rax
34-
cmp $0x20, %rdx
35-
jb 1f
3633

3734
/* Decide forward/backward copy mode */
3835
cmp %rdi, %rsi
@@ -42,7 +39,9 @@ SYM_FUNC_START(__memmove)
4239
cmp %rdi, %r8
4340
jg 2f
4441

42+
/* FSRM implies ERMS => no length checks, do the copy directly */
4543
.Lmemmove_begin_forward:
44+
ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM
4645
ALTERNATIVE "", "movq %rdx, %rcx; rep movsb; retq", X86_FEATURE_ERMS
4746

4847
/*
@@ -114,6 +113,8 @@ SYM_FUNC_START(__memmove)
114113
*/
115114
.p2align 4
116115
2:
116+
cmp $0x20, %rdx
117+
jb 1f
117118
cmp $680, %rdx
118119
jb 6f
119120
cmp %dil, %sil

0 commit comments

Comments
 (0)