Merge trunk version 204345 into gupc branch.
[official-gcc.git] / libgupc / smp / upc_mem.h
blob6f6669d5c52782818ac8507cff00c8e7d6040404
1 /* Copyright (C) 2006-2013 Free Software Foundation, Inc.
2 This file is part of the UPC runtime library.
3 Written by Gary Funck <gary@intrepid.com>
4 and Nenad Vukicevic <nenad@intrepid.com>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
28 #ifndef _UPC_MEM_H_
29 #define _UPC_MEM_H_
31 /* The following memory-to-memory operations have been
32 factored into this file because they are needed both
33 by upc_access.c and upc_mem.c */
35 //begin lib_inline_mem_sup
37 __attribute__((__always_inline__))
38 static inline
39 void
40 __upc_memcpy (upc_shared_ptr_t dest, upc_shared_ptr_t src, size_t n)
42 if (GUPCR_PTS_IS_NULL (src))
43 __upc_fatal ("Invalid access via null shared pointer");
44 if (GUPCR_PTS_IS_NULL (dest))
45 __upc_fatal ("Invalid access via null shared pointer");
46 for (;;)
48 char *srcp = (char *)__upc_sptr_to_addr (src);
49 size_t s_offset = GUPCR_PTS_OFFSET(src);
50 size_t ps_offset = (s_offset & GUPCR_VM_OFFSET_MASK);
51 size_t ns_copy = GUPCR_VM_PAGE_SIZE - ps_offset;
52 char *destp = (char *)__upc_sptr_to_addr (dest);
53 size_t d_offset = GUPCR_PTS_OFFSET(dest);
54 size_t pd_offset = (d_offset & GUPCR_VM_OFFSET_MASK);
55 size_t nd_copy = GUPCR_VM_PAGE_SIZE - pd_offset;
56 size_t n_copy = GUPCR_MIN (GUPCR_MIN (ns_copy, nd_copy), n);
57 memcpy (destp, srcp, n_copy);
58 n -= n_copy;
59 if (!n)
60 break;
61 GUPCR_PTS_INCR_VADDR (src, n_copy);
62 GUPCR_PTS_INCR_VADDR (dest, n_copy);
66 __attribute__((__always_inline__))
67 static inline
68 void
69 __upc_memget (void *dest, upc_shared_ptr_t src, size_t n)
71 if (!dest)
72 __upc_fatal ("Invalid access via null shared pointer");
73 if (GUPCR_PTS_IS_NULL (src))
74 __upc_fatal ("Invalid access via null shared pointer");
75 for (;;)
77 char *srcp = (char *)__upc_sptr_to_addr (src);
78 size_t offset = GUPCR_PTS_OFFSET(src);
79 size_t p_offset = (offset & GUPCR_VM_OFFSET_MASK);
80 size_t n_copy = GUPCR_MIN (GUPCR_VM_PAGE_SIZE - p_offset, n);
81 memcpy (dest, srcp, n_copy);
82 n -= n_copy;
83 if (!n)
84 break;
85 GUPCR_PTS_INCR_VADDR (src, n_copy);
86 dest = (char *) dest + n_copy;
90 __attribute__((__always_inline__))
91 static inline
92 void
93 __upc_memput (upc_shared_ptr_t dest, const void *src, size_t n)
95 if (!src)
96 __upc_fatal ("Invalid access via null shared pointer");
97 if (GUPCR_PTS_IS_NULL (dest))
98 __upc_fatal ("Invalid access via null shared pointer");
99 for (;;)
101 char *destp = (char *)__upc_sptr_to_addr (dest);
102 size_t offset = GUPCR_PTS_OFFSET(dest);
103 size_t p_offset = (offset & GUPCR_VM_OFFSET_MASK);
104 size_t n_copy = GUPCR_MIN (GUPCR_VM_PAGE_SIZE - p_offset, n);
105 memcpy (destp, src, n_copy);
106 n -= n_copy;
107 if (!n)
108 break;
109 GUPCR_PTS_INCR_VADDR (dest, n_copy);
110 src = (char *) src + n_copy;
114 __attribute__((__always_inline__))
115 static inline
116 void
117 __upc_memset (upc_shared_ptr_t dest, int c, size_t n)
119 if (GUPCR_PTS_IS_NULL (dest))
120 __upc_fatal ("Invalid access via null shared pointer");
121 for (;;)
123 char *destp = (char *)__upc_sptr_to_addr (dest);
124 size_t offset = GUPCR_PTS_OFFSET(dest);
125 size_t p_offset = (offset & GUPCR_VM_OFFSET_MASK);
126 size_t n_set = GUPCR_MIN (GUPCR_VM_PAGE_SIZE - p_offset, n);
127 memset (destp, c, n_set);
128 n -= n_set;
129 if (!n)
130 break;
131 GUPCR_PTS_INCR_VADDR (dest, n_set);
134 //end lib_inline_mem_sup
136 #endif /* _UPC_MEM_H_ */