1 /*
2  * Copyright (c) 1994-2018, 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 "ftni64.h"
19 
20 _ULONGLONG_T
ftn_i_kishft(_ULONGLONG_T op,int count)21 ftn_i_kishft(_ULONGLONG_T op, int count)
22 {
23   /*
24           logical shift:
25               cnt < 0 ==> shift op1 left by |cnt|
26               cnt > 0 ==> shift op1 right by cnt
27               |cnt| >= 64 ==> result is 0
28   */
29 
30   if (count >= 0) {
31     if (count >= 64)
32       return 0;
33     return op << count;
34   }
35   if (count <= -64)
36     return 0;
37   return op >> -count;
38 }
39 
40 __I8RET_T
ftn_i_xori64(int op1,int op2,int op3,int op4)41 ftn_i_xori64(int op1, int op2, int op3, int op4)
42 {
43   DBLINT64 u1;
44   DBLINT64 u2;
45 
46   u1[0] = op2;
47   u1[1] = op1;
48   u2[0] = op4;
49   u2[1] = op3;
50   u1[0] ^= u2[0];
51   u1[1] ^= u2[1];
52   UTL_I_I64RET(u1[0], u1[1]);
53 }
54 
55 __I8RET_T
ftn_i_xnori64(int op1,int op2,int op3,int op4)56 ftn_i_xnori64(int op1, int op2, int op3, int op4)
57 {
58   DBLINT64 u1;
59   DBLINT64 u2;
60 
61   u1[0] = op2;
62   u1[1] = op1;
63   u2[0] = op4;
64   u2[1] = op3;
65   u1[0] = ~(u1[0] ^ u2[0]);
66   u1[1] = ~(u1[1] ^ u2[1]);
67   UTL_I_I64RET(u1[0], u1[1]);
68 }
69 
70 int
ftn_i_kr2ir(int op1,int op2)71 ftn_i_kr2ir(int op1, int op2)
72 {
73   DBLINT64 u1;
74   /*
75       result is first element of int[2] which is union u'd with dp if little
76       endian; if big endian, result is second element.
77   */
78   u1[0] = op1;
79   u1[1] = op2;
80   return I64_LSH(u1);
81 }
82 
83 float
ftn_i_kr2sp(int op1,int op2)84 ftn_i_kr2sp(int op1, int op2)
85 {
86   DBLINT64 u1;
87   int i;
88 
89   u1[0] = op1;
90   u1[1] = op2;
91   i = I64_LSH(u1);
92   return (float)i;
93 }
94 
95 double
ftn_i_kr2dp(int op1,int op2)96 ftn_i_kr2dp(int op1, int op2)
97 {
98   INT64D u1;
99 
100   u1.i[0] = op1;
101   u1.i[1] = op2;
102   return u1.d;
103 }
104