]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/config/gcn/lib2-vec_divmod-di.c
1 /* Copyright (C) 2012-2024 Free Software Foundation, Inc.
2 Contributed by Altera and Mentor Graphics, Inc.
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3, or (at your option) any
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 Under Section 7 of GPL version 3, you are granted additional
15 permissions described in the GCC Runtime Library Exception, version
16 3.1, as published by the Free Software Foundation.
18 You should have received a copy of the GNU General Public License and
19 a copy of the GCC Runtime Library Exception along with this program;
20 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 <http://www.gnu.org/licenses/>. */
25 /* 64-bit V64SI divide and modulo as used in gcn.
26 This is a simple conversion from lib2-divmod.c. */
28 #define MASKMODE v64di
29 #include "amdgcn_veclib.h"
32 __udivmodv64di4_aux (v64udi num
, v64udi den
, v64di __mask
)
34 v64udi bit
= VECTOR_INIT (1UL);
35 v64udi res
= VECTOR_INIT (0UL);
37 VECTOR_WHILE ((den
< num
) & (bit
!= 0) & ((den
& (1L<<31)) == 0),
39 VECTOR_COND_MOVE (den
, den
<< 1, cond
);
40 VECTOR_COND_MOVE (bit
, bit
<< 1, cond
);
42 VECTOR_WHILE (bit
!= 0, loopcond
, NO_COND
)
43 VECTOR_IF2 (num
>= den
, ifcond
, loopcond
)
44 VECTOR_COND_MOVE (num
, num
- den
, ifcond
);
45 VECTOR_COND_MOVE (res
, res
| bit
, ifcond
);
47 VECTOR_COND_MOVE (bit
, bit
>> 1, loopcond
);
48 VECTOR_COND_MOVE (den
, den
>> 1, loopcond
);
51 return PACK_DI_PAIR (res
, num
);
55 __divmodv64di4_aux (v64di a
, v64di b
, v64di __mask
)
57 v64di nega
= VECTOR_INIT (0L);
58 v64di negb
= VECTOR_INIT (0L);
60 VECTOR_IF (a
< 0, cond
)
61 VECTOR_COND_MOVE (a
, -a
, cond
);
65 VECTOR_IF (b
< 0, cond
)
66 VECTOR_COND_MOVE (b
, -b
, cond
);
70 v64udi ua
= __builtin_convertvector (a
, v64udi
);
71 v64udi ub
= __builtin_convertvector (b
, v64udi
);
72 v64uti pair
= __udivmodv64di4_aux (ua
, ub
, __mask
);
74 v64di quot
= UNPACK_DI_LOW (v64di
, pair
);
75 v64di rem
= UNPACK_DI_HIGH (v64di
, pair
);
76 VECTOR_COND_MOVE (quot
, -quot
, nega
^ negb
);
77 VECTOR_COND_MOVE (rem
, -rem
, nega
);
78 pair
= PACK_DI_PAIR (quot
, rem
);
85 __divv64di3_aux (v64di a
, v64di b
, v64di __mask
)
87 v64uti pair
= __divmodv64di4_aux (a
, b
, __mask
);
88 return UNPACK_DI_LOW (v64di
, pair
);
92 __modv64di3_aux (v64di a
, v64di b
, v64di __mask
)
94 v64uti pair
= __divmodv64di4_aux (a
, b
, __mask
);
95 return UNPACK_DI_HIGH (v64di
, pair
);
100 __udivv64di3_aux (v64udi a
, v64udi b
, v64di __mask
)
102 v64uti pair
= __udivmodv64di4_aux (a
, b
, __mask
);
103 return UNPACK_DI_LOW (v64udi
, pair
);
107 __umodv64di3_aux (v64udi a
, v64udi b
, v64di __mask
)
109 v64uti pair
= __udivmodv64di4_aux (a
, b
, __mask
);
110 return UNPACK_DI_HIGH (v64udi
, pair
);
113 DEF_VARIANTS (__div
, di3
, di
)
114 DEF_VARIANTS (__mod
, di3
, di
)
115 DEF_VARIANTS_B (__divmod
, di4
, uti
, di
)
116 DEF_VARIANTS (__udiv
, di3
, udi
)
117 DEF_VARIANTS (__umod
, di3
, udi
)
118 DEF_VARIANTS_B (__udivmod
, di4
, uti
, udi
)