Changeset View
Changeset View
Standalone View
Standalone View
sys/libkern/x86/crc32_sse42.c
Show All 23 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
/* | /* | ||||
* This file is compiled in userspace in order to run ATF unit tests. | * This file is compiled in userspace in order to run ATF unit tests. | ||||
*/ | */ | ||||
#ifdef USERSPACE_TESTING | #ifndef _KERNEL | ||||
delphij: Unrelated to your change, but maybe we can change this to #if(n)def _KERNEL (along with the… | |||||
Done Inline ActionsNow, I get kib's _KERNEL question at last. I adjusted and ran 'make -c tests/sys/kern' to test. ota_j.email.ne.jp: Now, I get kib's _KERNEL question at last.
I adjusted and ran 'make -c tests/sys/kern' to test. | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#else | #else | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#endif | #endif | ||||
#include <sys/gsb_crc32.h> | |||||
static __inline uint32_t | static __inline uint32_t | ||||
_mm_crc32_u8(uint32_t x, uint8_t y) | _mm_crc32_u8(uint32_t x, uint8_t y) | ||||
{ | { | ||||
/* | /* | ||||
* clang (at least 3.9.[0-1]) pessimizes "rm" (y) and "m" (y) | * clang (at least 3.9.[0-1]) pessimizes "rm" (y) and "m" (y) | ||||
* significantly and "r" (y) a lot by copying y to a different | * significantly and "r" (y) a lot by copying y to a different | ||||
* local variable (on the stack or in a register), so only use | * local variable (on the stack or in a register), so only use | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return (zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^ | return (zeros[0][crc & 0xff] ^ zeros[1][(crc >> 8) & 0xff] ^ | ||||
zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24]); | zeros[2][(crc >> 16) & 0xff] ^ zeros[3][crc >> 24]); | ||||
} | } | ||||
/* Initialize tables for shifting crcs. */ | /* Initialize tables for shifting crcs. */ | ||||
static void | static void | ||||
#ifdef USERSPACE_TESTING | #ifndef _KERNEL | ||||
__attribute__((__constructor__)) | __attribute__((__constructor__)) | ||||
#endif | #endif | ||||
crc32c_init_hw(void) | crc32c_init_hw(void) | ||||
{ | { | ||||
crc32c_zeros(crc32c_long, LONG); | crc32c_zeros(crc32c_long, LONG); | ||||
crc32c_zeros(crc32c_2long, 2 * LONG); | crc32c_zeros(crc32c_2long, 2 * LONG); | ||||
crc32c_zeros(crc32c_short, SHORT); | crc32c_zeros(crc32c_short, SHORT); | ||||
crc32c_zeros(crc32c_2short, 2 * SHORT); | crc32c_zeros(crc32c_2short, 2 * SHORT); | ||||
} | } | ||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
SYSINIT(crc32c_sse42, SI_SUB_LOCK, SI_ORDER_ANY, crc32c_init_hw, NULL); | SYSINIT(crc32c_sse42, SI_SUB_LOCK, SI_ORDER_ANY, crc32c_init_hw, NULL); | ||||
#endif | #endif | ||||
/* Compute CRC-32C using the Intel hardware instruction. */ | /* Compute CRC-32C using the Intel hardware instruction. */ | ||||
#ifdef USERSPACE_TESTING | |||||
uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned); | |||||
#endif | |||||
uint32_t | uint32_t | ||||
sse42_crc32c(uint32_t crc, const unsigned char *buf, unsigned len) | sse42_crc32c(uint32_t crc, const unsigned char *buf, unsigned len) | ||||
{ | { | ||||
#ifdef __amd64__ | #ifdef __amd64__ | ||||
const size_t align = 8; | const size_t align = 8; | ||||
#else | #else | ||||
const size_t align = 4; | const size_t align = 4; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |
Unrelated to your change, but maybe we can change this to #if(n)def _KERNEL (along with the comment above) and simply drop USERSPACE_TESTING in tests/sys/kern/Makefile?