OSDN Git Service

6b02f95f3f7a3a17cbe6890fea10d8f7dc7073eb
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / dotprod_c4.c
1 /* Implementation of the DOT_PRODUCT intrinsic
2    Copyright 2002 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
4    and Feng Wang <fengwang@nudt.edu.cn>
5
6 This file is part of the GNU Fortran 95 runtime library (libgfor).
7
8 Libgfortran is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 Libgfortran 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 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with libgfor; see the file COPYING.LIB.  If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 #include "config.h"
24 #include <stdlib.h>
25 #include <assert.h>
26 #include "libgfortran.h"
27
28 typedef GFC_ARRAY_DESCRIPTOR(GFC_MAX_DIMENSIONS, char) char_array;
29
30 extern GFC_COMPLEX_4 dot_product_c4 (gfc_array_c4 * a, gfc_array_c4 * b);
31 export_proto(dot_product_c4);
32
33 /* Both parameters will already have been converted to the result type.  */
34 GFC_COMPLEX_4
35 dot_product_c4 (gfc_array_c4 * a, gfc_array_c4 * b)
36 {
37   GFC_COMPLEX_4 *pa;
38   GFC_COMPLEX_4 *pb;
39   GFC_COMPLEX_4 res;
40   GFC_COMPLEX_4 conjga;
41   index_type count;
42   index_type astride;
43   index_type bstride;
44
45   assert (GFC_DESCRIPTOR_RANK (a) == 1
46           && GFC_DESCRIPTOR_RANK (b) == 1);
47
48   if (a->dim[0].stride == 0)
49     a->dim[0].stride = 1;
50   if (b->dim[0].stride == 0)
51     b->dim[0].stride = 1;
52
53   astride = a->dim[0].stride;
54   bstride = b->dim[0].stride;
55   count = a->dim[0].ubound + 1 - a->dim[0].lbound;
56   res = 0;
57   pa = a->data;
58   pb = b->data;
59
60   while (count--)
61     {
62       COMPLEX_ASSIGN(conjga, REALPART (*pa), -IMAGPART (*pa));
63       res += conjga * *pb;
64       pa += astride;
65       pb += bstride;
66     }
67
68   return res;
69 }