root/arch/sparc/lib/memset.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. memset

   1 /* linux/arch/sparc/lib/memset.c
   2  *
   3  * This is from GNU libc.
   4  */
   5 
   6 #include <linux/types.h>
   7 
   8 #define op_t unsigned long int
   9 #define OPSIZ (sizeof(op_t))
  10 
  11 typedef unsigned char byte;
  12 
  13 void *memset(void *dstpp, char c, size_t len)
     /* [previous][next][first][last][top][bottom][index][help] */
  14 {
  15         long int dstp = (long int) dstpp;
  16 
  17         if (len >= 8) {
  18                         size_t xlen;
  19                         op_t cccc;
  20 
  21                         cccc = (unsigned char) c;
  22                         cccc |= cccc << 8;
  23                         cccc |= cccc << 16;
  24 
  25                         /* There are at least some bytes to set.
  26                            No need to test for LEN == 0 in this alignment loop.  */
  27                         while (dstp % OPSIZ != 0) {
  28                                 ((byte *) dstp)[0] = c;
  29                                 dstp += 1;
  30                                 len -= 1;
  31                         }
  32 
  33                         /* Write 8 `op_t' per iteration until less
  34                          * than 8 `op_t' remain.
  35                          */
  36                         xlen = len / (OPSIZ * 8);
  37                         while (xlen > 0) {
  38                                 ((op_t *) dstp)[0] = cccc;
  39                                 ((op_t *) dstp)[1] = cccc;
  40                                 ((op_t *) dstp)[2] = cccc;
  41                                 ((op_t *) dstp)[3] = cccc;
  42                                 ((op_t *) dstp)[4] = cccc;
  43                                 ((op_t *) dstp)[5] = cccc;
  44                                 ((op_t *) dstp)[6] = cccc;
  45                                 ((op_t *) dstp)[7] = cccc;
  46                                 dstp += 8 * OPSIZ;
  47                                 xlen -= 1;
  48                         }
  49                         len %= OPSIZ * 8;
  50 
  51                         /* Write 1 `op_t' per iteration until less than
  52                          * OPSIZ bytes remain.
  53                          */
  54                         xlen = len / OPSIZ;
  55                         while (xlen > 0) {
  56                                 ((op_t *) dstp)[0] = cccc;
  57                                 dstp += OPSIZ;
  58                                 xlen -= 1;
  59                         }
  60                         len %= OPSIZ;
  61         }
  62 
  63         /* Write the last few bytes.  */
  64         while (len > 0) {
  65                 ((byte *) dstp)[0] = c;
  66                 dstp += 1;
  67                 len -= 1;
  68         }
  69 
  70         return dstpp;
  71 }

/* [previous][next][first][last][top][bottom][index][help] */