From 7c91df5e50e5161ca9ad373cf0f83562e840e740 Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Thu, 9 Jun 2016 12:55:59 -0700 Subject: [PATCH] igzip: add macros for shrx, shlx, and bzhi instructions on old architectures Signed-off-by: Roy Oursler Reviewed-by: Greg Tucker --- igzip/stdmac.asm | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/igzip/stdmac.asm b/igzip/stdmac.asm index a4c2b6f..a9e24e9 100644 --- a/igzip/stdmac.asm +++ b/igzip/stdmac.asm @@ -205,3 +205,69 @@ ssc: mov rbx, rax ret %endm + +;; Implement BZHI instruction on older architectures +;; Clobbers rcx, unless rcx is %%index +%macro BZHI 4 +%define %%dest %1 +%define %%src %2 +%define %%index %3 +%define %%tmp1 %4 + +%ifdef USE_HSWNI + bzhi %%src, %%dest, %%index +%else +%ifnidn %%index, rcx + mov rcx, %%index +%endif + mov %%tmp1, 1 + shl %%tmp1, cl + sub %%tmp1, 1 + +%ifnidn %%src, %%dest + mov %%dest, %%src +%endif + + and %%dest, %%tmp1 +%endif +%endm + +;; Implement shrx instruction on older architectures +;; Clobbers rcx, unless rcx is %%index +%macro SHRX 3 +%define %%dest %1 +%define %%src %2 +%define %%index %3 + +%ifdef USE_HSWNI + shrx %%dest, %%src, %%index +%else +%ifnidn %%src, %%dest + mov %%dest, %%src +%endif +%ifnidn %%index, rcx + mov rcx, %%index +%endif + shr %%dest, cl +%endif +%endm + +;; Implement shlx instruction on older architectures +;; Clobbers rcx, unless rcx is %%index +%macro SHLX 3 +%define %%dest %1 +%define %%src %2 +%define %%index %3 + +%ifdef USE_HSWNI + shlx %%dest, %%src, %%index +%else +%ifnidn %%src, %%dest + mov %%dest, %%src +%endif +%ifnidn %%index, rcx + mov rcx, %%index +%endif + shl %%dest, cl +%endif +%endm