2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / config / spu / multi3.c
blob6998ed026f86b4ee9a8f64f32bf8ee6f748d14f6
1 /* Copyright (C) 2008 Free Software Foundation, Inc.
3 This file is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option)
6 any later version.
8 This file is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 for more details.
13 You should have received a copy of the GNU General Public License
14 along with this file; see the file COPYING. If not, write to the Free
15 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
16 02110-1301, USA. */
18 /* As a special exception, if you link this library with files compiled with
19 GCC to produce an executable, this does not cause the resulting executable
20 to be covered by the GNU General Public License. The exception does not
21 however invalidate any other reasons why the executable file might be covered
22 by the GNU General Public License. */
24 #include <spu_intrinsics.h>
26 typedef int TItype __attribute__ ((mode (TI)));
28 /* A straight forward vectorization and unrolling of
29 * short l[8], r[8];
30 * TItype total = 0;
31 * for (i = 0; i < 8; i++)
32 * for (j = 0; j < 8; j++)
33 * total += (TItype)((l[7-i] * r[7-j]) << (16 * (i + j)));
35 TItype
36 __multi3 (TItype l, TItype r)
38 qword u = *(qword *) & l;
39 qword v = *(qword *) & r;
40 qword splat0 = si_shufb (v, v, si_ilh (0x0001));
41 qword splat1 = si_shufb (v, v, si_ilh (0x0203));
42 qword splat2 = si_shufb (v, v, si_ilh (0x0405));
43 qword splat3 = si_shufb (v, v, si_ilh (0x0607));
44 qword splat4 = si_shufb (v, v, si_ilh (0x0809));
45 qword splat5 = si_shufb (v, v, si_ilh (0x0a0b));
46 qword splat6 = si_shufb (v, v, si_ilh (0x0c0d));
47 qword splat7 = si_shufb (v, v, si_ilh (0x0e0f));
49 qword part0l = si_shlqbyi (si_mpyu (u, splat0), 14);
50 qword part1h = si_shlqbyi (si_mpyhhu (u, splat1), 14);
51 qword part1l = si_shlqbyi (si_mpyu (u, splat1), 12);
52 qword part2h = si_shlqbyi (si_mpyhhu (u, splat2), 12);
53 qword part2l = si_shlqbyi (si_mpyu (u, splat2), 10);
54 qword part3h = si_shlqbyi (si_mpyhhu (u, splat3), 10);
55 qword part3l = si_shlqbyi (si_mpyu (u, splat3), 8);
56 qword part4h = si_shlqbyi (si_mpyhhu (u, splat4), 8);
57 qword part4l = si_shlqbyi (si_mpyu (u, splat4), 6);
58 qword part5h = si_shlqbyi (si_mpyhhu (u, splat5), 6);
59 qword part5l = si_shlqbyi (si_mpyu (u, splat5), 4);
60 qword part6h = si_shlqbyi (si_mpyhhu (u, splat6), 4);
61 qword part6l = si_shlqbyi (si_mpyu (u, splat6), 2);
62 qword part7h = si_shlqbyi (si_mpyhhu (u, splat7), 2);
63 qword part7l = si_mpyu (u, splat7);
65 qword carry, total0, total1, total2, total3, total4;
66 qword total5, total6, total7, total8, total9, total10;
67 qword total;
69 total0 = si_a (si_a (si_a (part0l, part1h), si_a (part1l, part2h)), part7l);
70 total1 = si_a (part2l, part3h);
71 total2 = si_a (part3l, part4h);
72 total3 = si_a (part4l, part5h);
73 total4 = si_a (part5l, part6h);
74 total5 = si_a (part6l, part7h);
75 total6 = si_a (total0, total1);
76 total7 = si_a (total2, total3);
77 total8 = si_a (total4, total5);
78 total9 = si_a (total6, total7);
79 total10 = si_a (total8, total9);
81 carry = si_cg (part2l, part3h);
82 carry = si_a (carry, si_cg (part3l, part4h));
83 carry = si_a (carry, si_cg (part4l, part5h));
84 carry = si_a (carry, si_cg (part5l, part6h));
85 carry = si_a (carry, si_cg (part6l, part7h));
86 carry = si_a (carry, si_cg (total0, total1));
87 carry = si_a (carry, si_cg (total2, total3));
88 carry = si_a (carry, si_cg (total4, total5));
89 carry = si_a (carry, si_cg (total6, total7));
90 carry = si_a (carry, si_cg (total8, total9));
91 carry = si_shlqbyi (carry, 4);
93 total = si_cg (total10, carry);
94 total = si_shlqbyi (total, 4);
95 total = si_cgx (total10, carry, total);
96 total = si_shlqbyi (total, 4);
97 total = si_addx (total10, carry, total);
98 return *(TItype *) & total;