LCOV - code coverage report
Current view: top level - libc/string - memset.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 15 15 100.0 %
Date: 2024-01-02 21:04:04 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Copyright (c) 2004, 2008 IBM Corporation
       3                 :            :  * All rights reserved.
       4                 :            :  * This program and the accompanying materials
       5                 :            :  * are made available under the terms of the BSD License
       6                 :            :  * which accompanies this distribution, and is available at
       7                 :            :  * http://www.opensource.org/licenses/bsd-license.php
       8                 :            :  *
       9                 :            :  * Contributors:
      10                 :            :  *     IBM Corporation - initial implementation
      11                 :            :  *****************************************************************************/
      12                 :            : 
      13                 :            : #define CACHE_LINE_SIZE 128
      14                 :            : 
      15                 :            : #include <stddef.h>
      16                 :            : 
      17                 :            : void *memset(void *dest, int c, size_t size);
      18                 :         20 : void *memset(void *dest, int c, size_t size)
      19                 :            : {
      20                 :         20 :         unsigned char *d = (unsigned char *)dest;
      21                 :         20 :         unsigned long big_c = 0;
      22                 :            : 
      23                 :            : #if defined(__powerpc__) || defined(__powerpc64__)
      24                 :            :         if (size > CACHE_LINE_SIZE && c==0) {
      25                 :            :                 while ((unsigned long long)d % CACHE_LINE_SIZE) {
      26                 :            :                         *d++ = (unsigned char)c;
      27                 :            :                         size--;
      28                 :            :                 }
      29                 :            :                 while (size >= CACHE_LINE_SIZE) {
      30                 :            :                         asm volatile ("dcbz 0,%0\n" : : "r"(d) : "memory");
      31                 :            :                         d+= CACHE_LINE_SIZE;
      32                 :            :                         size-= CACHE_LINE_SIZE;
      33                 :            :                 }
      34                 :            :         }
      35                 :            : #endif
      36                 :            : 
      37                 :         20 :         if (c) {
      38                 :          5 :                 big_c = c;
      39                 :          5 :                 big_c |= (big_c << 8) | big_c;
      40                 :          5 :                 big_c |= (big_c << 16) | big_c;
      41                 :          5 :                 big_c |= (big_c << 32) | big_c;
      42                 :            :         }
      43                 :        815 :         while (size >= 8 && c == 0) {
      44                 :        795 :                 *((unsigned long *)d) = big_c;
      45                 :        795 :                 d+=8;
      46                 :        795 :                 size-=8;
      47                 :            :         }
      48                 :            : 
      49                 :        555 :         while (size-- > 0) {
      50                 :        535 :                 *d++ = (unsigned char)c;
      51                 :            :         }
      52                 :            : 
      53                 :         20 :         return dest;
      54                 :            : }

Generated by: LCOV version 1.14