diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c
index b81ba47521ee8fa9124153a30d52648e33a8cf7e..e41ea86e096614664f7632a3a96ec2efb2f6cdb9 100644
--- a/libavcodec/dsputil.c
+++ b/libavcodec/dsputil.c
@@ -48,6 +48,7 @@ uint32_t ff_square_tab[512] = { 0, };
 #undef BIT_DEPTH
 
 #define BIT_DEPTH 8
+#include "hpel_template.c"
 #include "tpel_template.c"
 #include "dsputil_template.c"
 
diff --git a/libavcodec/dsputil_template.c b/libavcodec/dsputil_template.c
index 56f41ad767b16d02d1842946e5921de516882617..c2b30d2b1e16fcc0a12f0ea586baca84a92e2398 100644
--- a/libavcodec/dsputil_template.c
+++ b/libavcodec/dsputil_template.c
@@ -97,10 +97,6 @@ static void FUNCC(clear_blocks)(int16_t *blocks)
 }
 #endif
 
-#if BIT_DEPTH == 8
-#include "hpel_template.c"
-#endif
-
 #define PIXOP2(OPNAME, OP)                                              \
 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst,     \
                                                       const uint8_t *src1, \
diff --git a/libavcodec/hpel_template.c b/libavcodec/hpel_template.c
index 0a8550a738d659d9d403b75d753e3c8c400331fb..fa7a614b8234d2bb529371b212a891887f0c9f48 100644
--- a/libavcodec/hpel_template.c
+++ b/libavcodec/hpel_template.c
@@ -21,6 +21,8 @@
 
 #include "pixels.h"
 
+#include "bit_depth_template.c"
+
 #define DEF_HPEL(OPNAME, OP)                                            \
 static inline void FUNC(OPNAME ## _pixels8_l2)(uint8_t *dst,            \
                                                const uint8_t *src1,     \