]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/crc32c_ppc.c
1 /* Copyright (C) 2017 International Business Machines Corp.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
11 #include "include/int_types.h"
12 #include "crc32c_ppc_constants.h"
18 #define VMX_ALIGN_MASK (VMX_ALIGN-1)
21 static unsigned int crc32_align(unsigned int crc
, unsigned char const *p
,
25 crc
= crc_table
[(crc
^ *p
++) & 0xff] ^ (crc
>> 8);
29 static unsigned int crc32_align(unsigned int crc
, unsigned char const *p
,
33 crc
= crc_table
[((crc
>> 24) ^ *p
++) & 0xff] ^ (crc
<< 8);
40 unsigned int __crc32_vpmsum(unsigned int crc
, unsigned char const *p
,
43 static uint32_t crc32_vpmsum(uint32_t crc
, unsigned char const *data
,
46 unsigned int prealign
;
53 if (len
< VMX_ALIGN
+ VMX_ALIGN_MASK
) {
54 crc
= crc32_align(crc
, data
, (unsigned long)len
);
58 if ((unsigned long)data
& VMX_ALIGN_MASK
) {
59 prealign
= VMX_ALIGN
- ((unsigned long)data
& VMX_ALIGN_MASK
);
60 crc
= crc32_align(crc
, data
, prealign
);
65 crc
= __crc32_vpmsum(crc
, data
, (unsigned long)len
& ~VMX_ALIGN_MASK
);
67 tail
= len
& VMX_ALIGN_MASK
;
69 data
+= len
& ~VMX_ALIGN_MASK
;
70 crc
= crc32_align(crc
, data
, tail
);
81 /* This wrapper function works around the fact that crc32_vpmsum
82 * does not gracefully handle the case where the data pointer is NULL. There
83 * may be room for performance improvement here.
85 uint32_t ceph_crc32c_ppc(uint32_t crc
, unsigned char const *data
, unsigned len
)
92 crc
= crc32_vpmsum(crc
, buf2
, len
);
95 crc
= crc32_vpmsum(crc
, data
, (unsigned long)len
);
100 #else /* HAVE_POWER8 */
102 /* This symbol has to exist on non-ppc architectures (and on legacy
103 * ppc systems using power7 or below) in order to compile properly
104 * there, even though it won't be called.
106 uint32_t ceph_crc32c_ppc(uint32_t crc
, unsigned char const *data
, unsigned len
)
111 #endif /* HAVE_POWER8 */