Blame view

arch/microblaze/lib/memset.c 2.37 KB
322ae8eb9   Michal Simek   microblaze_v8: su...
1
2
3
4
5
6
7
8
9
10
11
  /*
   * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
   * Copyright (C) 2008-2009 PetaLogix
   * Copyright (C) 2007 John Williams
   *
   * Reasonably optimised generic C-code for memset on Microblaze
   * This is generic C code to do efficient, alignment-aware memcpy.
   *
   * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
   * http://www.embedded.com/showArticle.jhtml?articleID=19205567
   *
af901ca18   AndrĂ© Goddard Rosa   tree-wide: fix as...
12
   * Attempts were made, unsuccessfully, to contact the original
322ae8eb9   Michal Simek   microblaze_v8: su...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   * author of this code (Michael Morrow, Intel).  Below is the original
   * copyright notice.
   *
   * This software has been developed by Intel Corporation.
   * Intel specifically disclaims all warranties, express or
   * implied, and all liability, including consequential and
   * other indirect damages, for the use of this program, including
   * liability for infringement of any proprietary rights,
   * and including the warranties of merchantability and fitness
   * for a particular purpose. Intel does not assume any
   * responsibility for and errors which may appear in this program
   * not any responsibility to update it.
   */
  
  #include <linux/types.h>
  #include <linux/stddef.h>
  #include <linux/compiler.h>
  #include <linux/module.h>
  #include <linux/string.h>
  
  #ifdef __HAVE_ARCH_MEMSET
93e2e8513   Michal Simek   microblaze: Separ...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #ifndef CONFIG_OPT_LIB_FUNCTION
  void *memset(void *v_src, int c, __kernel_size_t n)
  {
  	char *src = v_src;
  
  	/* Truncate c to 8 bits */
  	c = (c & 0xFF);
  
  	/* Simple, byte oriented memset or the rest of count. */
  	while (n--)
  		*src++ = c;
  
  	return v_src;
  }
  #else /* CONFIG_OPT_LIB_FUNCTION */
322ae8eb9   Michal Simek   microblaze_v8: su...
49
50
  void *memset(void *v_src, int c, __kernel_size_t n)
  {
322ae8eb9   Michal Simek   microblaze_v8: su...
51
  	char *src = v_src;
322ae8eb9   Michal Simek   microblaze_v8: su...
52
  	uint32_t *i_src;
78ebfa884   Michal Simek   microblaze: Addin...
53
  	uint32_t w32 = 0;
93e2e8513   Michal Simek   microblaze: Separ...
54

322ae8eb9   Michal Simek   microblaze_v8: su...
55
56
  	/* Truncate c to 8 bits */
  	c = (c & 0xFF);
78ebfa884   Michal Simek   microblaze: Addin...
57
58
59
60
61
62
  	if (unlikely(c)) {
  		/* Make a repeating word out of it */
  		w32 = c;
  		w32 |= w32 << 8;
  		w32 |= w32 << 16;
  	}
322ae8eb9   Michal Simek   microblaze_v8: su...
63

78ebfa884   Michal Simek   microblaze: Addin...
64
  	if (likely(n >= 4)) {
322ae8eb9   Michal Simek   microblaze_v8: su...
65
  		/* Align the destination to a word boundary */
25985edce   Lucas De Marchi   Fix common misspe...
66
  		/* This is done in an endian independent manner */
322ae8eb9   Michal Simek   microblaze_v8: su...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  		switch ((unsigned) src & 3) {
  		case 1:
  			*src++ = c;
  			--n;
  		case 2:
  			*src++ = c;
  			--n;
  		case 3:
  			*src++ = c;
  			--n;
  		}
  
  		i_src  = (void *)src;
  
  		/* Do as many full-word copies as we can */
  		for (; n >= 4; n -= 4)
  			*i_src++ = w32;
  
  		src  = (void *)i_src;
  	}
93e2e8513   Michal Simek   microblaze: Separ...
87

322ae8eb9   Michal Simek   microblaze_v8: su...
88
89
90
91
92
93
  	/* Simple, byte oriented memset or the rest of count. */
  	while (n--)
  		*src++ = c;
  
  	return v_src;
  }
93e2e8513   Michal Simek   microblaze: Separ...
94
  #endif /* CONFIG_OPT_LIB_FUNCTION */
322ae8eb9   Michal Simek   microblaze_v8: su...
95
96
  EXPORT_SYMBOL(memset);
  #endif /* __HAVE_ARCH_MEMSET */