1 /*-------------------------------------------------------------------------
3 * pg_crc32c_loongarch.c
4 * Compute CRC-32C checksum using LoongArch CRCC instructions
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/port/pg_crc32c_loongarch.c
13 *-------------------------------------------------------------------------
17 #include "port/pg_crc32c.h"
20 pg_comp_crc32c_loongarch(pg_crc32c crc
, const void *data
, size_t len
)
22 const unsigned char *p
= data
;
23 const unsigned char *pend
= p
+ len
;
26 * LoongArch doesn't require alignment, but aligned memory access is
27 * significantly faster. Process leading bytes so that the loop below
28 * starts with a pointer aligned to eight bytes.
30 if (!PointerIsAligned(p
, uint16
) &&
33 crc
= __builtin_loongarch_crcc_w_b_w(*p
, crc
);
36 if (!PointerIsAligned(p
, uint32
) &&
39 crc
= __builtin_loongarch_crcc_w_h_w(*(uint16
*) p
, crc
);
42 if (!PointerIsAligned(p
, uint64
) &&
45 crc
= __builtin_loongarch_crcc_w_w_w(*(uint32
*) p
, crc
);
49 /* Process eight bytes at a time, as far as we can. */
52 crc
= __builtin_loongarch_crcc_w_d_w(*(uint64
*) p
, crc
);
56 /* Process remaining 0-7 bytes. */
59 crc
= __builtin_loongarch_crcc_w_w_w(*(uint32
*) p
, crc
);
64 crc
= __builtin_loongarch_crcc_w_h_w(*(uint16
*) p
, crc
);
69 crc
= __builtin_loongarch_crcc_w_b_w(*p
, crc
);