struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / libmullong.c.in
blob3afb231e9884e3331c5de133214ce748c3bae2d0
1 /* Test _mullong.c from library
3 type: asm, c
4 */
5 #include <testfwk.h>
7 #ifndef PORT_HOST // No longer works
9 #if !defined(__SDCC_pdk14) // Lack of memory
10 #define type_{type}
12 #if defined(PORT_HOST)
13 # include "sdccconf.h"
14 # define mullong(a,b) mullong_wrapper(a,b)
15 # if defined(type_c) && !defined(WORDS_BIGENDIAN)
16 # define _SDCC_NO_ASM_LIB_FUNCS 1
17 # define __near
18 # define long int
19 # include "device/lib/_mullong.c"
20 # endif
21 #else
22 # if defined(type_c)
23 # define _SDCC_NO_ASM_LIB_FUNCS 1
24 # endif
25 # include "device/lib/_mullong.c"
26 # define mullong _mullong
27 #endif
29 /* gcc 2.95.2 on usf-cf-x86-linux-1 (debian 2.2) has a bug with
30 * packing structs
32 #if defined(PORT_HOST)
34 #define TYPE_TARGET_CHAR TYPE_BYTE
35 #define TYPE_TARGET_INT TYPE_WORD
36 #define TYPE_TARGET_LONG TYPE_DWORD
37 #define TYPE_TARGET_UCHAR TYPE_UBYTE
38 #define TYPE_TARGET_UINT TYPE_UWORD
39 #define TYPE_TARGET_ULONG TYPE_UDWORD
41 #if defined(type_c) && !defined(WORDS_BIGENDIAN)
42 struct
44 char c1;
45 short i;
46 char c2;
47 } pack_test;
49 TYPE_TARGET_LONG
50 mullong_wrapper (TYPE_TARGET_LONG a, TYPE_TARGET_LONG b)
52 if (sizeof(pack_test) == 4)
53 /* length of struct ok: use SDCC library */
54 return _mullong (a, b);
55 else
57 /* buggy gcc: use generic multiplication */
58 return a * b;
62 #else
64 TYPE_TARGET_LONG
65 mullong_wrapper (TYPE_TARGET_LONG a, TYPE_TARGET_LONG b)
67 return a * b;
70 #endif
72 #endif
74 #endif
76 #endif
78 void
79 testlibmullong(void)
81 #ifndef PORT_HOST
82 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
83 ASSERT(mullong ( 0, 0) == 0);
84 ASSERT(mullong ( 0x100, 0x100) == 0x10000);
85 ASSERT(mullong (0x01020304, 3) == 0x0306090c);
86 ASSERT(mullong ( 3, 0x01020304) == 0x0306090c);
87 ASSERT(mullong (0x000000ff, 2) == 0x000001fe);
88 ASSERT(mullong ( 2, 0x000000ff) == 0x000001fe);
89 ASSERT(mullong (0x00007fff, 4) == 0x0001fffc);
90 ASSERT(mullong ( 4, 0x00007fff) == 0x0001fffc);
91 ASSERT(mullong (0x003fffff, 8) == 0x01fffff8);
92 ASSERT(mullong ( 8, 0x003fffff) == 0x01fffff8);
94 ASSERT(mullong ( 0x33, 0x34) == 0x00000a5c);
95 ASSERT(mullong ( 0x34, 0x33) == 0x00000a5c);
96 ASSERT(mullong ( 0x3334, 0x3536) == 0x0aa490f8);
97 ASSERT(mullong ( 0x3536, 0x3334) == 0x0aa490f8);
98 ASSERT(mullong ( 0x333435, 0x363738) == 0x0e98ce98);
99 ASSERT(mullong ( 0x363738, 0x333435) == 0x0e98ce98);
100 ASSERT(mullong (0x33343536, 0x3738393a) == 0x777d143c);
101 ASSERT(mullong (0x3738393a, 0x33343536) == 0x777d143c);
103 ASSERT(mullong ( 0xff, 0xfe) == 0x0000fd02);
104 ASSERT(mullong ( 0xfe, 0xff) == 0x0000fd02);
105 ASSERT(mullong ( 0xfffe, 0xfdfc) == 0xfdfa0408);
106 ASSERT(mullong ( 0xfdfc, 0xfffe) == 0xfdfa0408);
107 ASSERT(mullong ( 0xfffefd, 0xfcfbfa) == 0xfa0d1212);
108 ASSERT(mullong ( 0xfcfbfa, 0xfffefd) == 0xfa0d1212);
109 ASSERT(mullong (0xfffefdfc, 0xfbfaf9f8) == 0x20282820);
110 ASSERT(mullong (0xfbfaf9f8, 0xfffefdfc) == 0x20282820);
112 ASSERT(mullong (0xff000000, 0xff000000) == 0);
113 ASSERT(mullong (0xffff0000, 0xffff0000) == 0);
114 ASSERT(mullong (0xfffffe00, 0xfffffd00) == 0x00060000);
115 ASSERT(mullong (0xfffffd00, 0xfffffe00) == 0x00060000);
116 ASSERT(mullong (0xfffffefd, 0xfffffcfb) == 0x00030e0f);
117 ASSERT(mullong (0xfffffcfb, 0xfffffefd) == 0x00030e0f);
119 ASSERT(mullong (0xffffffff, 0xffffffff) == 1);
120 #endif
121 #endif