1 /*
2 Copyright (c) 1990 The Regents of the University of California.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 by the University of California, Berkeley.  The name of the
11 University may not be used to endorse or promote products derived
12 from this software without specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #include <picolibc.h>
19 
20 union u
21 {
22   struct
23     {
24       short int msw;
25       unsigned short lsw;
26     } w;
27   long l;
28 };
29 
30 union us
31 {
32   struct
33     {
34       short int msw;
35       unsigned short lsw;
36     } w;
37   long l;
38 };
39 
40 int
__cmpsi2(long arga,short int msw_b,unsigned short int lsw_b)41 __cmpsi2(long arga,
42 	 short int msw_b, unsigned short int lsw_b)
43 {
44   union u u;
45   u.l = arga;
46 
47   if (u.w.msw != msw_b)
48     {
49       if (u.w.msw < msw_b) return 0;
50       return 2;
51     }
52   if (u.w.lsw != lsw_b)
53     {
54       if (u.w.lsw < lsw_b) return 0;
55       return 2;
56     }
57   return 1;
58 }
59 
60 
61 int
__ucmpsi2(unsigned long arga,unsigned short int msw_b,unsigned short int lsw_b)62 __ucmpsi2(unsigned long arga,
63 	 unsigned short int msw_b, unsigned short int lsw_b)
64 {
65   union us u;
66   u.l = arga;
67 
68   if (u.w.msw != msw_b)
69     {
70       if (u.w.msw < msw_b) return 0;
71       return 2;
72     }
73   if (u.w.lsw != lsw_b)
74     {
75       if (u.w.lsw < lsw_b) return 0;
76       return 2;
77     }
78   return 1;
79 }
80 
81 
82 union pu
83 {
84   struct {
85     char ignore;
86     signed char msb;
87     unsigned short lsw;
88   } w;
89   long l;
90 };
91 
92 union pun
93 {
94   struct {
95     char ignore;
96     unsigned char msb;
97     unsigned short lsw;
98   } w;
99   long l;
100 };
101 
102 
103 int
__cmppsi2(long arga,long argb)104 __cmppsi2(long arga, long argb)
105 {
106   union pu a;
107   union pu b;
108   a.l = arga;
109   b.l = argb;
110 
111   if (a.w.msb != b.w.msb)
112     {
113       if (a.w.msb < b.w.msb) return 0;
114       return 2;
115     }
116   if (a.w.lsw != b.w.lsw)
117     {
118       if (a.w.lsw < b.w.lsw) return 0;
119       return 2;
120     }
121   return 1;
122 }
123 
124 
125 int
__ucmppsi2(long arga,long argb)126 __ucmppsi2(long arga, long argb)
127 {
128   union pun a;
129   union pun b;
130   a.l = arga;
131   b.l = argb;
132 
133   if (a.w.msb != b.w.msb)
134     {
135       if (a.w.msb < b.w.msb) return 0;
136       return 2;
137     }
138   if (a.w.lsw != b.w.lsw)
139     {
140       if (a.w.lsw < b.w.lsw) return 0;
141       return 2;
142     }
143   return 1;
144 }
145