zfsonlinux/zfs — pull request #2332 by tuxoko (2014-05-14 15:34:35+00:00)
Title: sha256 x86_64 optimization (RFC, prototype)

This was mentioned in #1618, but the thread wasn't update for a while.
So I did a fast prototype version.

This patch provides three optimization flavor:
sha256-ssse3-asm.S, sha256-avx-asm.S, sha256-avx2-asm.S.
They all come from linux-3.14, but since they are BSD dual licensed it should be OK.
ssse3 and avx versions are about 3 times the speed compare to unoptimized.
I don't have CPU with avx2 so it is not tested, use it with your own discretion.

This pull request is an RFC. It cannot be merged in its current state.
This might not even compile for everyone.
And there are some GPL code copied from kernel: linux/linkage.h and runtime cpu detection

1) Directory structure
I reuse the $(TARGET_ASM_DIR) for arch dependent files.
Header files are put in ```include/$(TARGET_ASM_DIR)/asm````
Source files are put in ```module/zfs/$(TARGET_ASM_DIR)```
I have add ```include/$(TARGET_ASM_DIR)``` to libzpool and module Makefile

2) asm instruction config
To detect compiler support for asm instruction.
I first check $TARGET_ARCH = x86_64 in user.m4
And jump into x86_64.m4 to test AVX and AVX2.
I add -DCONFIG_AS_AVX{,2} to user space CFLAGS and ASFLAGS becaus that how it is done in kernel Makefile.

3) Build target
For module, I add a Makefile in ```module/zfs/$(TARGET_ASM_DIR)```.
The module/zfs/Makefile will detect and include it.
For userspace, I haven't figure out how to do it properly. I just hard code them in.
That's why it won't compile for anything other than x86_64.

4) linux/linkage.h
The sha256-xxx-asm.S depends on it. So I copied it for userspace code.
This should be fixed.

5) runtime CPU feature detection
In sha256_x86.c, copied from linux and kernel space only.
For now, you need to set it manually for user space.

6) make tarball
Definitely won't work. I didn't even bother to try.