Skip to content

Commit 1a16481

Browse files
autotools: add AVX512VL + AVX512DQ detection
Binary john needs AVX512VL's XOP-like bit rotates for faster Salsa20 in yescrypt. Without `VL` enabled compilers don't use mnemonics at all. As it stands now, the possible binaries are: - AVX512BW + AVX512VL + AVX512DQ - AVX512F - AVX2 - And so on. There is no AVX512BW only binary. See: openwall#5691. Signed-off-by: Claudio André <[email protected]>
1 parent 3bd67e4 commit 1a16481

File tree

6 files changed

+100
-18
lines changed

6 files changed

+100
-18
lines changed

doc/NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ Major changes from 1.9.0-jumbo-1 (May 2019) in this bleeding-edge version:
420420
- Add Oubliette Password Manager support (two formats and oubliette2john.py).
421421
[DavideDG; 2025]
422422

423+
- Use AVX512VL XOP-like bit rotates for scrypt's Salsa20. [Solar; 2025]
424+
425+
- When we use AVX512BW, also enable usage of AVX512VL and AVX512DQ. [Claudio André; 2025]
426+
423427

424428
Major changes from 1.8.0-jumbo-1 (December 2014) to 1.9.0-jumbo-1 (May 2019):
425429

src/configure

+65-9
Original file line numberDiff line numberDiff line change
@@ -9224,7 +9224,62 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
92249224

92259225
SIMD_NAME="Altivec2"
92269226
;;
9227-
mmx|sse*|ssse3|avx*|xop*)
9227+
avx512|avx512bw)
9228+
SIMD_NAME="avx512bw"
9229+
{ $as_echo "$as_me:${as_lineno-$LINENO}: Trying to force $SIMD_NAME using default method (--enable-simd=$simd)." >&5
9230+
$as_echo "$as_me: Trying to force $SIMD_NAME using default method (--enable-simd=$simd)." >&6;}
9231+
if test 2 -gt 0; then :
9232+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -mavx512bw -mavx512vl -mavx512dq w/ linking" >&5
9233+
$as_echo_n "checking if $CC supports -mavx512bw -mavx512vl -mavx512dq w/ linking... " >&6; }
9234+
fi
9235+
ac_ext=c
9236+
ac_cpp='$CPP $CPPFLAGS'
9237+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
9238+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
9239+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
9240+
9241+
ac_saved_cflags="$CFLAGS"
9242+
CFLAGS="-Werror -mavx512bw -mavx512vl -mavx512dq"
9243+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
9244+
/* end confdefs.h. */
9245+
9246+
int
9247+
main ()
9248+
{
9249+
9250+
;
9251+
return 0;
9252+
}
9253+
_ACEOF
9254+
if ac_fn_c_try_link "$LINENO"; then :
9255+
if test "2" -gt 0; then :
9256+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
9257+
$as_echo "yes" >&6; }
9258+
fi
9259+
CFLAGS_EX="$CFLAGS_EX -mavx512bw -mavx512vl -mavx512dq"
9260+
9261+
else
9262+
if test 2 -gt 0; then :
9263+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
9264+
$as_echo "no" >&6; }
9265+
fi
9266+
if test "2" = 2; then :
9267+
as_fn_error $? "Not supported by compiler/linker" "$LINENO" 5
9268+
fi
9269+
9270+
fi
9271+
rm -f core conftest.err conftest.$ac_objext \
9272+
conftest$ac_exeext conftest.$ac_ext
9273+
CFLAGS="$ac_saved_cflags"
9274+
ac_ext=c
9275+
ac_cpp='$CPP $CPPFLAGS'
9276+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
9277+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
9278+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
9279+
9280+
9281+
;;
9282+
mmx|sse*|ssse3|avx*|xop*)
92289283
SIMD_NAME=`echo $simd | tr a-z A-Z`
92299284
{ $as_echo "$as_me:${as_lineno-$LINENO}: Trying to force $SIMD_NAME using default method (--enable-simd=$simd)." >&5
92309285
$as_echo "$as_me: Trying to force $SIMD_NAME using default method (--enable-simd=$simd)." >&6;}
@@ -11485,10 +11540,10 @@ fi
1148511540

1148611541
if test "x$CPU_NOTFOUND" = x0; then :
1148711542

11488-
CFLAGS="$CFLAGS_BACKUP -mavx512bw -P $EXTRA_AS_FLAGS $CPPFLAGS $CFLAGS_EXTRA $CPUID_ASM"
11543+
CFLAGS="$CFLAGS_BACKUP -mavx512bw -mavx512vl -mavx512dq -P $EXTRA_AS_FLAGS $CPPFLAGS $CFLAGS_EXTRA $CPUID_ASM"
1148911544

11490-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX512BW" >&5
11491-
$as_echo_n "checking for AVX512BW... " >&6; }
11545+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX512BW + AVX512VL + AVX512DQ" >&5
11546+
$as_echo_n "checking for AVX512BW + AVX512VL + AVX512DQ... " >&6; }
1149211547
if test "$cross_compiling" = yes; then :
1149311548
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
1149411549
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
@@ -11503,7 +11558,7 @@ extern int CPU_detect(void); extern char CPU_req_name[];
1150311558

1150411559
_ACEOF
1150511560
if ac_fn_c_try_run "$LINENO"; then :
11506-
CPU_BEST_FLAGS="-mavx512bw"
11561+
CPU_BEST_FLAGS="-mavx512bw -mavx512vl -mavx512dq"
1150711562
SIMD_NAME="AVX512BW"
1150811563
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1150911564
$as_echo "yes" >&6; }
@@ -11810,20 +11865,21 @@ fi
1181011865

1181111866
if test "x$CPU_NOTFOUND" = x0; then :
1181211867

11813-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX512BW" >&5
11814-
$as_echo_n "checking for AVX512BW... " >&6; }
11868+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for AVX512BW + AVX512VL + AVX512DQ" >&5
11869+
$as_echo_n "checking for AVX512BW + AVX512VL + AVX512DQ... " >&6; }
1181511870
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1181611871
/* end confdefs.h. */
1181711872

1181811873
#include <immintrin.h>
1181911874
#include <stdio.h>
1182011875
extern void exit(int);
11821-
int main(){__m512i t=_mm512_slli_epi16(_mm512_set1_epi16(1),1);exit(!(_mm_cvtsi128_si64x(_mm512_extracti32x4_epi32(t,0))==0x2000200020002ULL));}
11876+
int main(){__m512i t=_mm512_slli_epi16(_mm512_set1_epi16(1),1);__int64_t ret_value=(!(_mm_cvtsi128_si64x(_mm512_extracti32x4_epi32(t,0))==0x2000200020002ULL));
11877+
__m128i u, t1;*((long long*)&u)=1;t1=u;u=_mm_rol_epi32(t1,1);if((*(long long*)&t)==88)printf(".");exit(ret_value);}
1182211878

1182311879

1182411880
_ACEOF
1182511881
if ac_fn_c_try_link "$LINENO"; then :
11826-
CPU_BEST_FLAGS="-mavx512bw"
11882+
CPU_BEST_FLAGS="-mavx512bw -mavx512vl -mavx512dq"
1182711883
SIMD_NAME="AVX512BW"
1182811884
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
1182911885
$as_echo "yes" >&6; }

src/configure.ac

+5
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ case "$simd" in
439439
SIMD_NAME="Altivec2"
440440
;;
441441
dnl Handle known cases of --enable-simd=foo --> -mfoo
442+
avx512|avx512bw)
443+
SIMD_NAME="avx512bw"
444+
AC_MSG_NOTICE([Trying to force $SIMD_NAME using default method (--enable-simd=$simd).])
445+
JTR_FLAG_CHECK_LINK([-mavx512bw -mavx512vl -mavx512dq], 2)
446+
;;
442447
mmx|sse*|ssse3|avx*|xop*)
443448
SIMD_NAME=`echo $simd | tr a-z A-Z`
444449
AC_MSG_NOTICE([Trying to force $SIMD_NAME using default method (--enable-simd=$simd).])

src/m4/jtr_x86_logic.m4

+7-6
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ if test "x$simd" != xno; then
268268
269269
AS_IF([test "x$CPU_NOTFOUND" = x0],
270270
[
271-
CFLAGS="$CFLAGS_BACKUP -mavx512bw -P $EXTRA_AS_FLAGS $CPPFLAGS $CFLAGS_EXTRA $CPUID_ASM"
271+
CFLAGS="$CFLAGS_BACKUP -mavx512bw -mavx512vl -mavx512dq -P $EXTRA_AS_FLAGS $CPPFLAGS $CFLAGS_EXTRA $CPUID_ASM"
272272
273-
AC_MSG_CHECKING([for AVX512BW])
273+
AC_MSG_CHECKING([for AVX512BW + AVX512VL + AVX512DQ])
274274
AC_RUN_IFELSE([AC_LANG_SOURCE(
275275
[[extern int CPU_detect(void); extern char CPU_req_name[];
276276
unsigned int nt_buffer8x[4], output8x[4];
277277
int main(int argc, char **argv) { return !CPU_detect(); }
278278
]])],
279-
[CPU_BEST_FLAGS="-mavx512bw"]
279+
[CPU_BEST_FLAGS="-mavx512bw -mavx512vl -mavx512dq"]
280280
[SIMD_NAME="AVX512BW"]
281281
[AC_MSG_RESULT([yes])]
282282
,[AC_MSG_RESULT([no])]
@@ -464,16 +464,17 @@ dnl ======================================================================
464464
465465
AS_IF([test "x$CPU_NOTFOUND" = x0],
466466
[
467-
AC_MSG_CHECKING([for AVX512BW])
467+
AC_MSG_CHECKING([for AVX512BW + AVX512VL + AVX512DQ])
468468
AC_LINK_IFELSE(
469469
[
470470
AC_LANG_SOURCE(
471471
[[#include <immintrin.h>
472472
#include <stdio.h>
473473
extern void exit(int);
474-
int main(){__m512i t=_mm512_slli_epi16(_mm512_set1_epi16(1),1);exit(!(_mm_cvtsi128_si64x(_mm512_extracti32x4_epi32(t,0))==0x2000200020002ULL));}]]
474+
int main(){__m512i t=_mm512_slli_epi16(_mm512_set1_epi16(1),1);__int64_t ret_value=(!(_mm_cvtsi128_si64x(_mm512_extracti32x4_epi32(t,0))==0x2000200020002ULL));
475+
__m128i u, t1;*((long long*)&u)=1;t1=u;u=_mm_rol_epi32(t1,1);if((*(long long*)&t)==88)printf(".");exit(ret_value);}]]
475476
)]
476-
,[CPU_BEST_FLAGS="-mavx512bw"]
477+
,[CPU_BEST_FLAGS="-mavx512bw -mavx512vl -mavx512dq"]
477478
[SIMD_NAME="AVX512BW"]
478479
[AC_MSG_RESULT([yes])]
479480
,[AC_MSG_RESULT([no])]

src/x86-64.S

+16-2
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,15 @@ DES_bs_crypt_plain_loop:
16511651
#define CX_XOP $0x00000800
16521652

16531653
/* Leaf 7 */
1654+
// 0x00010000 /* AVX512 foundation */
1655+
// 0x00020000 /* AVX512 Doubleword and Quadword Instructions */
1656+
// 0x40000000 /* AVX512BW */
1657+
// 0x80000000 /* AVX512VL */
16541658
#define C7_AVX2 $0x00000020 /* AVX2 */
16551659
#define C7_AVX512F $0x00010000
16561660
#define C7_AVX512BW $0x40010000 /* AVX512BW + AVX512F */
1661+
#define C7_AVX512VL $0xC0010000 /* AVX512BW + AVX512VL + AVX512F */
1662+
#define C7_AVX512DQ $0xC0030000 /* AVX512BW + AVX512DQ + AVX512VL + AVX512F */
16571663

16581664
.text
16591665

@@ -1713,7 +1719,7 @@ CPU_detect:
17131719
#endif
17141720

17151721
/* Finally, leaf 7 tests (if required) */
1716-
#if CPU_REQ_AVX2 || CPU_REQ_AVX512F || CPU_REQ_AVX512BW
1722+
#if CPU_REQ_AVX2 || CPU_REQ_AVX512F || CPU_REQ_AVX512BW || CPU_REQ_AVX512VL || CPU_REQ_AVX512DQ
17171723
xorl %eax,%eax
17181724
cpuid
17191725
movl $7,%edx
@@ -1722,7 +1728,15 @@ CPU_detect:
17221728
xchgl %edx,%eax
17231729
xorl %ecx,%ecx
17241730
cpuid
1725-
#if CPU_REQ_AVX512BW
1731+
#if CPU_REQ_AVX512DQ
1732+
andl C7_AVX512DQ,%ebx
1733+
cmpl C7_AVX512DQ,%ebx
1734+
jne CPU_detect_fail
1735+
#elif CPU_REQ_AVX512VL
1736+
andl C7_AVX512VL,%ebx
1737+
cmpl C7_AVX512VL,%ebx
1738+
jne CPU_detect_fail
1739+
#elif CPU_REQ_AVX512BW
17261740
andl C7_AVX512BW,%ebx
17271741
cmpl C7_AVX512BW,%ebx
17281742
jne CPU_detect_fail

src/x86-64.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
#define CPU_DETECT 1
7979
#define CPU_REQ 1
8080
#define CPU_REQ_AVX512BW 1
81-
#define CPU_NAME "AVX512BW"
81+
#define CPU_REQ_AVX512VL 1
82+
#define CPU_REQ_AVX512DQ 1
83+
#define CPU_NAME "AVX512(BW+VL+DQ)"
8284
#if CPU_FALLBACK && !defined(CPU_FALLBACK_BINARY)
8385
#define CPU_FALLBACK_BINARY "john-non-avx512bw"
8486
#define CPU_FALLBACK_BINARY_DEFAULT

0 commit comments

Comments
 (0)