diff --git a/libavcodec/x86/hevc_sao.asm b/libavcodec/x86/hevc_sao.asm
index 4c1173028271a4d8636d83e029c87dae9f4c305a..05855290f5978d89b7a722beec5c8c96d0804230 100644
--- a/libavcodec/x86/hevc_sao.asm
+++ b/libavcodec/x86/hevc_sao.asm
@@ -209,6 +209,7 @@ HEVC_SAO_BAND_FILTER_FUNCS
 INIT_XMM avx
 HEVC_SAO_BAND_FILTER_FUNCS
 
+%if HAVE_AVX2_EXTERNAL
 INIT_XMM avx2
 HEVC_SAO_BAND_FILTER_8       8, 0
 HEVC_SAO_BAND_FILTER_8      16, 1
@@ -236,3 +237,4 @@ HEVC_SAO_BAND_FILTER_16 12, 48, 1
 INIT_YMM avx2
 HEVC_SAO_BAND_FILTER_16 12, 64, 2
 %endif
+%endif