1 /* cc_test.c -- examine compiler-generated library calls
2 
3    This file is part of the UPX executable compressor.
4 
5    Copyright (C) 2006-2020 Markus Franz Xaver Johannes Oberhumer
6    All Rights Reserved.
7 
8    UPX and the UCL library are free software; you can redistribute them
9    and/or modify them under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2 of
11    the License, or (at your option) any later version.
12 
13    This program 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 General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; see the file COPYING.
20    If not, write to the Free Software Foundation, Inc.,
21    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23    Markus F.X.J. Oberhumer
24    <markus@oberhumer.com>
25  */
26 
27 
28 #if 0 && defined(__WATCOMC__)
29 #define __cdecl __watcall
30 #endif
31 
32 
33 /*************************************************************************
34 //
35 **************************************************************************/
36 
37 typedef short           int16_t;
38 typedef unsigned short  uint16_t;
39 typedef long            int32_t;
40 typedef unsigned long   uint32_t;
41 
42 #if 1
43 // simulated 32-bit pointer
44 typedef char __huge*    hptr;
45 typedef long            hptrdiff_t;
46 typedef unsigned long   hsize_t;
47 #elif 1
48 // ignore segment overflow
49 typedef char __far*     hptr;
50 typedef long            hptrdiff_t;
51 typedef unsigned long   hsize_t;
52 #else
53 // no segment
54 typedef char __near*    hptr;
55 typedef short           hptrdiff_t;
56 typedef unsigned short  hsize_t;
57 #endif
58 
59 // pia - pointer add
pia(hptr a,hsize_t d)60 hptr __cdecl pia(hptr a, hsize_t d) { return a + d; }
pia1(hptr a)61 hptr __cdecl pia1(hptr a)           { return a + 1; }
62 
63 // pis - pointer subtract
pis(hptr a,hsize_t d)64 hptr __cdecl pis(hptr a, hsize_t d) { return a - d; }
pis1(hptr a)65 hptr __cdecl pis1(hptr a)           { return a - 1; }
66 
67 // pts - pointer diff
pts(hptr a,hptr b)68 hptrdiff_t __cdecl pts(hptr a, hptr b) { return a - b; }
69 
70 // ptc - pointer compare (__PTC sets zero and carry flags)
ptc_eq(hptr a,hptr b)71 int __cdecl ptc_eq(hptr a, hptr b) { return a == b; }
ptc_ne(hptr a,hptr b)72 int __cdecl ptc_ne(hptr a, hptr b) { return a != b; }
ptc_lt(hptr a,hptr b)73 int __cdecl ptc_lt(hptr a, hptr b) { return a < b; }
ptc_le(hptr a,hptr b)74 int __cdecl ptc_le(hptr a, hptr b) { return a <= b; }
ptc_gt(hptr a,hptr b)75 int __cdecl ptc_gt(hptr a, hptr b) { return a > b; }
ptc_ge(hptr a,hptr b)76 int __cdecl ptc_ge(hptr a, hptr b) { return a >= b; }
77 
78 // u4m - unsigned multiplication
u4m(uint32_t a,uint32_t b)79 uint32_t __cdecl u4m(uint32_t a, uint32_t b) { return a * b; }
u4m_p(uint32_t a,uint32_t b)80 uint32_t __pascal u4m_p(uint32_t a, uint32_t b) { return b * a; }
81 
82 // i4m - signed multiplication
i4m(int32_t a,int32_t b)83 int32_t  __cdecl i4m(int32_t  a, int32_t  b) { return a * b; }
i4m_p(int32_t a,int32_t b)84 int32_t  __pascal i4m_p(int32_t a, int32_t b) { return b * a; }
85 
86 // just for testing
u2m(uint16_t a,uint16_t b)87 uint16_t __cdecl u2m(uint16_t a, uint16_t b) { return a * b; }
i2m(int16_t a,int16_t b)88 int16_t  __cdecl i2m(int16_t  a, int16_t  b) { return a * b; }
u2m4(uint16_t a,uint16_t b)89 uint32_t __cdecl u2m4(uint16_t a, uint16_t b) { return a * b; }
i2m4(int16_t a,int16_t b)90 int32_t  __cdecl i2m4(int16_t  a, int16_t  b) { return a * b; }
91 
u2shl8(uint16_t a)92 uint16_t __cdecl u2shl8 (uint16_t a) { return a <<  8; }
u4shl8(uint32_t a)93 uint32_t __cdecl u4shl8 (uint32_t a) { return a <<  8; }
u2shl12(uint16_t a)94 uint16_t __cdecl u2shl12(uint16_t a) { return a << 12; }
u4shl12(uint32_t a)95 uint32_t __cdecl u4shl12(uint32_t a) { return a << 12; }
u4shl16(uint32_t a)96 uint32_t __cdecl u4shl16(uint32_t a) { return a << 16; }
u4shl24(uint32_t a)97 uint32_t __cdecl u4shl24(uint32_t a) { return a << 24; }
u2shlv(uint16_t a,unsigned v)98 uint16_t __cdecl u2shlv(uint16_t a, unsigned v) { return a << v; }
u4shlv(uint32_t a,unsigned v)99 uint32_t __cdecl u4shlv(uint32_t a, unsigned v) { return a << v; }
100 
p4nshlv_v(unsigned char v,uint32_t __near * a)101 void __pascal p4nshlv_v(unsigned char v, uint32_t __near *a) { *a <<= v; }
p4fshlv_v(unsigned char v,uint32_t __far * a)102 void __pascal p4fshlv_v(unsigned char v, uint32_t __far *a) { *a <<= v; }
p4nshlv(unsigned char v,uint32_t __near * a)103 uint32_t __pascal p4nshlv(unsigned char v, uint32_t __near *a) { return *a <<= v; }
p4fshlv(unsigned char v,uint32_t __far * a)104 uint32_t __pascal p4fshlv(unsigned char v, uint32_t __far *a) { return *a <<= v; }
105 
hptr2int(hptr a)106 hptrdiff_t __cdecl hptr2int(hptr a) { return (hptrdiff_t) a; }
int2hptr(hptrdiff_t a)107 hptr __cdecl int2hptr(hptrdiff_t a) { return (hptr) a; }
108 
109 
110 /* vim:set ts=4 et: */
111