lib/crc/s390/crc32le-vx.c

Source file repositories/reference/linux-study-clean/lib/crc/s390/crc32le-vx.c

File Facts

System
Linux kernel
Corpus path
lib/crc/s390/crc32le-vx.c
Extension
.c
Size
7764 bytes
Lines
241
Domain
Kernel Services
Bucket
lib
Inferred role
Kernel Services: implementation source
Status
source implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

#include <linux/types.h>
#include <asm/fpu.h>
#include "crc32-vx.h"

/* Vector register range containing CRC-32 constants */
#define CONST_PERM_LE2BE	9
#define CONST_R2R1		10
#define CONST_R4R3		11
#define CONST_R5		12
#define CONST_RU_POLY		13
#define CONST_CRC_POLY		14

/*
 * The CRC-32 constant block contains reduction constants to fold and
 * process particular chunks of the input data stream in parallel.
 *
 * For the CRC-32 variants, the constants are precomputed according to
 * these definitions:
 *
 *	R1 = [(x4*128+32 mod P'(x) << 32)]' << 1
 *	R2 = [(x4*128-32 mod P'(x) << 32)]' << 1
 *	R3 = [(x128+32 mod P'(x) << 32)]'   << 1
 *	R4 = [(x128-32 mod P'(x) << 32)]'   << 1
 *	R5 = [(x64 mod P'(x) << 32)]'	    << 1
 *	R6 = [(x32 mod P'(x) << 32)]'	    << 1
 *
 *	The bitreflected Barret reduction constant, u', is defined as
 *	the bit reversal of floor(x**64 / P(x)).
 *
 *	where P(x) is the polynomial in the normal domain and the P'(x) is the
 *	polynomial in the reversed (bitreflected) domain.
 *
 * CRC-32 (IEEE 802.3 Ethernet, ...) polynomials:
 *
 *	P(x)  = 0x04C11DB7
 *	P'(x) = 0xEDB88320
 *
 * CRC-32C (Castagnoli) polynomials:
 *
 *	P(x)  = 0x1EDC6F41
 *	P'(x) = 0x82F63B78
 */

static unsigned long constants_CRC_32_LE[] = {
	0x0f0e0d0c0b0a0908, 0x0706050403020100,	/* BE->LE mask */
	0x1c6e41596, 0x154442bd4,		/* R2, R1 */
	0x0ccaa009e, 0x1751997d0,		/* R4, R3 */
	0x0, 0x163cd6124,			/* R5 */
	0x0, 0x1f7011641,			/* u' */
	0x0, 0x1db710641			/* P'(x) << 1 */
};

static unsigned long constants_CRC_32C_LE[] = {
	0x0f0e0d0c0b0a0908, 0x0706050403020100,	/* BE->LE mask */
	0x09e4addf8, 0x740eef02,		/* R2, R1 */
	0x14cd00bd6, 0xf20c0dfe,		/* R4, R3 */
	0x0, 0x0dd45aab8,			/* R5 */
	0x0, 0x0dea713f1,			/* u' */
	0x0, 0x105ec76f0			/* P'(x) << 1 */
};

/**
 * crc32_le_vgfm_generic - Compute CRC-32 (LE variant) with vector registers
 * @crc: Initial CRC value, typically ~0.
 * @buf: Input buffer pointer, performance might be improved if the
 *	 buffer is on a doubleword boundary.
 * @size: Size of the buffer, must be 64 bytes or greater.
 * @constants: CRC-32 constant pool base pointer.
 *
 * Register usage:
 *	V0:	  Initial CRC value and intermediate constants and results.
 *	V1..V4:	  Data for CRC computation.
 *	V5..V8:	  Next data chunks that are fetched from the input buffer.
 *	V9:	  Constant for BE->LE conversion and shift operations
 *	V10..V14: CRC-32 constants.
 */
static u32 crc32_le_vgfm_generic(u32 crc, unsigned char const *buf, size_t size, unsigned long *constants)
{
	/* Load CRC-32 constants */
	fpu_vlm(CONST_PERM_LE2BE, CONST_CRC_POLY, constants);

	/*
	 * Load the initial CRC value.
	 *
	 * The CRC value is loaded into the rightmost word of the
	 * vector register and is later XORed with the LSB portion
	 * of the loaded input data.
	 */
	fpu_vzero(0);			/* Clear V0 */
	fpu_vlvgf(0, crc, 3);		/* Load CRC into rightmost word */

Annotation

Implementation Notes