LCOV - code coverage report
Current view: top level - src/port - pg_crc32c_armv8.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 100.0 % 34 34
Test Date: 2026-01-26 10:56:24 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 20 20

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * pg_crc32c_armv8.c
       4                 :             :  *        Compute CRC-32C checksum using ARMv8 CRC Extension 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_armv8.c
      12                 :             :  *
      13                 :             :  *-------------------------------------------------------------------------
      14                 :             :  */
      15                 :             : #include "c.h"
      16                 :             : 
      17                 :             : #ifdef _MSC_VER
      18                 :             : #include <intrin.h>
      19                 :             : #else
      20                 :             : #include <arm_acle.h>
      21                 :             : #endif
      22                 :             : 
      23                 :             : #include "port/pg_crc32c.h"
      24                 :             : 
      25                 :             : pg_crc32c
      26                 :    11102120 : pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
      27                 :             : {
      28                 :    11102120 :         const unsigned char *p = data;
      29                 :    11102120 :         const unsigned char *pend = p + len;
      30                 :             : 
      31                 :             :         /*
      32                 :             :          * ARMv8 doesn't require alignment, but aligned memory access is
      33                 :             :          * significantly faster. Process leading bytes so that the loop below
      34                 :             :          * starts with a pointer aligned to eight bytes.
      35                 :             :          */
      36   [ +  +  +  + ]:    11102120 :         if (!PointerIsAligned(p, uint16) &&
      37                 :     1155112 :                 p + 1 <= pend)
      38                 :             :         {
      39                 :     1154758 :                 crc = __crc32cb(crc, *p);
      40                 :     1154758 :                 p += 1;
      41                 :     1154758 :         }
      42   [ +  +  +  + ]:    11102120 :         if (!PointerIsAligned(p, uint32) &&
      43                 :     1234713 :                 p + 2 <= pend)
      44                 :             :         {
      45                 :     1230968 :                 crc = __crc32ch(crc, *(uint16 *) p);
      46                 :     1230968 :                 p += 2;
      47                 :     1230968 :         }
      48   [ +  +  +  + ]:    11102120 :         if (!PointerIsAligned(p, uint64) &&
      49                 :     1234242 :                 p + 4 <= pend)
      50                 :             :         {
      51                 :       88130 :                 crc = __crc32cw(crc, *(uint32 *) p);
      52                 :       88130 :                 p += 4;
      53                 :       88130 :         }
      54                 :             : 
      55                 :             :         /* Process eight bytes at a time, as far as we can. */
      56         [ +  + ]:    51328261 :         while (p + 8 <= pend)
      57                 :             :         {
      58                 :    40226141 :                 crc = __crc32cd(crc, *(uint64 *) p);
      59                 :    40226141 :                 p += 8;
      60                 :             :         }
      61                 :             : 
      62                 :             :         /* Process remaining 0-7 bytes. */
      63         [ +  + ]:    11102120 :         if (p + 4 <= pend)
      64                 :             :         {
      65                 :     5696006 :                 crc = __crc32cw(crc, *(uint32 *) p);
      66                 :     5696006 :                 p += 4;
      67                 :     5696006 :         }
      68         [ +  + ]:    11102120 :         if (p + 2 <= pend)
      69                 :             :         {
      70                 :     5854459 :                 crc = __crc32ch(crc, *(uint16 *) p);
      71                 :     5854459 :                 p += 2;
      72                 :     5854459 :         }
      73         [ +  + ]:    11102120 :         if (p < pend)
      74                 :             :         {
      75                 :     2463318 :                 crc = __crc32cb(crc, *p);
      76                 :     2463318 :         }
      77                 :             : 
      78                 :    22204240 :         return crc;
      79                 :    11102120 : }
        

Generated by: LCOV version 2.3.2-1