PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
pg_crc32c_loongarch.c
Go to the documentation of this file.
1
/*-------------------------------------------------------------------------
2
*
3
* pg_crc32c_loongarch.c
4
* Compute CRC-32C checksum using LoongArch CRCC instructions
5
*
6
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
8
*
9
*
10
* IDENTIFICATION
11
* src/port/pg_crc32c_loongarch.c
12
*
13
*-------------------------------------------------------------------------
14
*/
15
#include "
c.h
"
16
17
#include "
port/pg_crc32c.h
"
18
19
pg_crc32c
20
pg_comp_crc32c_loongarch
(
pg_crc32c
crc
,
const
void
*
data
,
size_t
len
)
21
{
22
const
unsigned
char
*p =
data
;
23
const
unsigned
char
*
pend
= p +
len
;
24
25
/*
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.
29
*/
30
if
(!
PointerIsAligned
(p,
uint16
) &&
31
p + 1 <=
pend
)
32
{
33
crc
=
__builtin_loongarch_crcc_w_b_w
(*p,
crc
);
34
p += 1;
35
}
36
if
(!
PointerIsAligned
(p,
uint32
) &&
37
p + 2 <=
pend
)
38
{
39
crc
=
__builtin_loongarch_crcc_w_h_w
(*(
uint16
*) p,
crc
);
40
p += 2;
41
}
42
if
(!
PointerIsAligned
(p,
uint64
) &&
43
p + 4 <=
pend
)
44
{
45
crc
=
__builtin_loongarch_crcc_w_w_w
(*(
uint32
*) p,
crc
);
46
p += 4;
47
}
48
49
/* Process eight bytes at a time, as far as we can. */
50
while
(p + 8 <=
pend
)
51
{
52
crc
=
__builtin_loongarch_crcc_w_d_w
(*(
uint64
*) p,
crc
);
53
p += 8;
54
}
55
56
/* Process remaining 0-7 bytes. */
57
if
(p + 4 <=
pend
)
58
{
59
crc
=
__builtin_loongarch_crcc_w_w_w
(*(
uint32
*) p,
crc
);
60
p += 4;
61
}
62
if
(p + 2 <=
pend
)
63
{
64
crc
=
__builtin_loongarch_crcc_w_h_w
(*(
uint16
*) p,
crc
);
65
p += 2;
66
}
67
if
(p <
pend
)
68
{
69
crc
=
__builtin_loongarch_crcc_w_b_w
(*p,
crc
);
70
}
71
72
return
crc
;
73
}
c.h
PointerIsAligned
#define PointerIsAligned(pointer, type)
Definition
c.h:782
uint64
uint64_t uint64
Definition
c.h:547
uint16
uint16_t uint16
Definition
c.h:545
uint32
uint32_t uint32
Definition
c.h:546
pg_crc32c.h
pg_crc32c
uint32 pg_crc32c
Definition
pg_crc32c.h:38
pg_comp_crc32c_loongarch
pg_crc32c pg_comp_crc32c_loongarch(pg_crc32c crc, const void *data, size_t len)
Definition
pg_crc32c_loongarch.c:20
len
const void size_t len
Definition
pg_crc32c_sse42.c:28
data
const void * data
Definition
pg_crc32c_sse42.c:27
crc
return crc
Definition
pg_crc32c_sse42.c:72
pend
const unsigned char * pend
Definition
pg_crc32c_sse42.c:30
fb
static int fb(int x)
Definition
preproc-init.c:92
src
port
pg_crc32c_loongarch.c
Generated on Sun Feb 1 2026 12:13:17 for PostgreSQL Source Code by
1.9.8