1 /*
2  * Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "stdioInterf.h"
19 #include "fioMacros.h"
20 
21 /* local gather functions */
22 
23 static void
local_gather_INT1(int n,__INT1_T * dst,__INT1_T * src,int * gv)24 local_gather_INT1(int n, __INT1_T *dst, __INT1_T *src, int *gv)
25 {
26   int i;
27   for (i = 0; i < n; ++i)
28     dst[i] = src[gv[i]];
29 }
30 
31 static void
local_gather_INT2(int n,__INT2_T * dst,__INT2_T * src,int * gv)32 local_gather_INT2(int n, __INT2_T *dst, __INT2_T *src, int *gv)
33 {
34   int i;
35   for (i = 0; i < n; ++i)
36     dst[i] = src[gv[i]];
37 }
38 
39 static void
local_gather_INT4(int n,__INT4_T * dst,__INT4_T * src,int * gv)40 local_gather_INT4(int n, __INT4_T *dst, __INT4_T *src, int *gv)
41 {
42   int i;
43   for (i = 0; i < n; ++i)
44     dst[i] = src[gv[i]];
45 }
46 
47 static void
local_gather_INT8(int n,__INT8_T * dst,__INT8_T * src,int * gv)48 local_gather_INT8(int n, __INT8_T *dst, __INT8_T *src, int *gv)
49 {
50   int i;
51   for (i = 0; i < n; ++i)
52     dst[i] = src[gv[i]];
53 }
54 
55 static void
local_gather_LOG1(int n,__LOG1_T * dst,__LOG1_T * src,int * gv)56 local_gather_LOG1(int n, __LOG1_T *dst, __LOG1_T *src, int *gv)
57 {
58   int i;
59   for (i = 0; i < n; ++i)
60     dst[i] = src[gv[i]];
61 }
62 
63 static void
local_gather_LOG2(int n,__LOG2_T * dst,__LOG2_T * src,int * gv)64 local_gather_LOG2(int n, __LOG2_T *dst, __LOG2_T *src, int *gv)
65 {
66   int i;
67   for (i = 0; i < n; ++i)
68     dst[i] = src[gv[i]];
69 }
70 
71 static void
local_gather_LOG4(int n,__LOG4_T * dst,__LOG4_T * src,int * gv)72 local_gather_LOG4(int n, __LOG4_T *dst, __LOG4_T *src, int *gv)
73 {
74   int i;
75   for (i = 0; i < n; ++i)
76     dst[i] = src[gv[i]];
77 }
78 
79 static void
local_gather_LOG8(int n,__LOG8_T * dst,__LOG8_T * src,int * gv)80 local_gather_LOG8(int n, __LOG8_T *dst, __LOG8_T *src, int *gv)
81 {
82   int i;
83   for (i = 0; i < n; ++i)
84     dst[i] = src[gv[i]];
85 }
86 
87 static void
local_gather_REAL4(int n,__REAL4_T * dst,__REAL4_T * src,int * gv)88 local_gather_REAL4(int n, __REAL4_T *dst, __REAL4_T *src, int *gv)
89 {
90   int i;
91   for (i = 0; i < n; ++i)
92     dst[i] = src[gv[i]];
93 }
94 
95 static void
local_gather_REAL8(int n,__REAL8_T * dst,__REAL8_T * src,int * gv)96 local_gather_REAL8(int n, __REAL8_T *dst, __REAL8_T *src, int *gv)
97 {
98   int i;
99   for (i = 0; i < n; ++i)
100     dst[i] = src[gv[i]];
101 }
102 
103 static void
local_gather_REAL16(int n,__REAL16_T * dst,__REAL16_T * src,int * gv)104 local_gather_REAL16(int n, __REAL16_T *dst, __REAL16_T *src, int *gv)
105 {
106   int i;
107   for (i = 0; i < n; ++i)
108     dst[i] = src[gv[i]];
109 }
110 
111 static void
local_gather_CPLX8(int n,__CPLX8_T * dst,__CPLX8_T * src,int * gv)112 local_gather_CPLX8(int n, __CPLX8_T *dst, __CPLX8_T *src, int *gv)
113 {
114   int i;
115   for (i = 0; i < n; ++i)
116     dst[i] = src[gv[i]];
117 }
118 
119 static void
local_gather_CPLX16(int n,__CPLX16_T * dst,__CPLX16_T * src,int * gv)120 local_gather_CPLX16(int n, __CPLX16_T *dst, __CPLX16_T *src, int *gv)
121 {
122   int i;
123   for (i = 0; i < n; ++i)
124     dst[i] = src[gv[i]];
125 }
126 
127 static void
local_gather_CPLX32(int n,__CPLX32_T * dst,__CPLX32_T * src,int * gv)128 local_gather_CPLX32(int n, __CPLX32_T *dst, __CPLX32_T *src, int *gv)
129 {
130   int i;
131   for (i = 0; i < n; ++i)
132     dst[i] = src[gv[i]];
133 }
134 
135 void (*__fort_local_gather[__NTYPES])() = {
136     NULL,                /*     no type (absent optional argument) */
137     NULL,                /* C   signed short */
138     NULL,                /* C   unsigned short */
139     NULL,                /* C   signed int */
140     NULL,                /* C   unsigned int */
141     NULL,                /* C   signed long int */
142     NULL,                /* C   unsigned long int */
143     NULL,                /* C   float */
144     NULL,                /* C   double */
145     local_gather_CPLX8,  /*   F complex*8 (2x real*4) */
146     local_gather_CPLX16, /*   F complex*16 (2x real*8) */
147     NULL,                /* C   signed char */
148     NULL,                /* C   unsigned char */
149     NULL,                /* C   long double */
150     NULL,                /*   F character */
151     NULL,                /* C   long long */
152     NULL,                /* C   unsigned long long */
153     local_gather_LOG1,   /*   F logical*1 */
154     local_gather_LOG2,   /*   F logical*2 */
155     local_gather_LOG4,   /*   F logical*4 */
156     local_gather_LOG8,   /*   F logical*8 */
157     NULL,                /*   F typeless */
158     NULL,                /*   F double typeless */
159     NULL,                /*   F ncharacter - kanji */
160     local_gather_INT2,   /*   F integer*2 */
161     local_gather_INT4,   /*   F integer*4, integer */
162     local_gather_INT8,   /*   F integer*8 */
163     local_gather_REAL4,  /*   F real*4, real */
164     local_gather_REAL8,  /*   F real*8, double precision */
165     local_gather_REAL16, /*   F real*16 */
166     local_gather_CPLX32, /*   F complex*32 (2x real*16) */
167     NULL,                /*   F quad typeless */
168     local_gather_INT1,   /*   F integer*1 */
169     NULL                 /*   F derived type */
170 };
171