Tidied up the build, install, and regression tests.
[fw/sdcc] / support / regression / tests / libmullong.c
1 /* Test _mullong.c from library
2
3     type: asm, c
4  */
5 #include <testfwk.h>
6
7 #define type_{type}
8
9 #if defined(PORT_HOST)
10 #  include "../../../../../sdccconf.h"
11 #  if defined(type_c) && !defined(WORDS_BIGENDIAN)
12 #    define _SDCC_NO_ASM_LIB_FUNCS 1
13 #    define near
14 #    define long int
15 #    include "../../../../../device/lib/_mullong.c"
16 #    define mullong(a,b) mullong_wrapper(a,b)
17 #  else
18 #    define mullong(a,b) mullong_wrapper(a,b)
19 #  endif
20 #else
21 #  if defined(type_c)
22 #    define _SDCC_NO_ASM_LIB_FUNCS 1
23 #  endif
24 #  include "../../../../../device/lib/_mullong.c"
25 #  define mullong _mullong
26 #endif
27
28 /* gcc 2.95.2 on usf-cf-x86-linux-1 (debian 2.2) has a bug with
29  * packing structs
30  */
31 #if defined(PORT_HOST)
32
33 #if defined(type_c) && !defined(WORDS_BIGENDIAN)
34 struct
35 {
36   char c1;
37   short i;
38   char c2;
39 } pack_test;
40         
41 long
42 mullong_wrapper (long a, long b)
43 {
44   if (sizeof(pack_test) == 4)
45     /* length of struct ok: use SDCC library */
46     return _mullong (a, b);
47   else
48   {
49       /* buggy gcc: use generic multiplication */
50       return a * b;
51   }
52 }
53 #endif
54
55 #if defined(WORDS_BIGENDIAN)
56
57 long
58 mullong_wrapper (long a, long b)
59 {
60     return a * b;
61 }
62
63 #endif
64
65 #endif
66
67 void
68 testlibmullong(void)
69 {
70   ASSERT(mullong (         0,          0) ==          0);
71   ASSERT(mullong (     0x100,      0x100) ==    0x10000);
72   ASSERT(mullong (0x01020304,          3) == 0x0306090c);
73   ASSERT(mullong (         3, 0x01020304) == 0x0306090c);
74   ASSERT(mullong (0x000000ff,          2) == 0x000001fe);
75   ASSERT(mullong (         2, 0x000000ff) == 0x000001fe);
76   ASSERT(mullong (0x00007fff,          4) == 0x0001fffc);
77   ASSERT(mullong (         4, 0x00007fff) == 0x0001fffc);
78   ASSERT(mullong (0x003fffff,          8) == 0x01fffff8);
79   ASSERT(mullong (         8, 0x003fffff) == 0x01fffff8);
80
81   ASSERT(mullong (      0x33,       0x34) == 0x00000a5c);
82   ASSERT(mullong (      0x34,       0x33) == 0x00000a5c);
83   ASSERT(mullong (    0x3334,     0x3536) == 0x0aa490f8);
84   ASSERT(mullong (    0x3536,     0x3334) == 0x0aa490f8);
85   ASSERT(mullong (  0x333435,   0x363738) == 0x0e98ce98);
86   ASSERT(mullong (  0x363738,   0x333435) == 0x0e98ce98);
87   ASSERT(mullong (0x33343536, 0x3738393a) == 0x777d143c);
88   ASSERT(mullong (0x3738393a, 0x33343536) == 0x777d143c);
89
90   ASSERT(mullong (      0xff,       0xfe) == 0x0000fd02);
91   ASSERT(mullong (      0xfe,       0xff) == 0x0000fd02);
92   ASSERT(mullong (    0xfffe,     0xfdfc) == 0xfdfa0408);
93   ASSERT(mullong (    0xfdfc,     0xfffe) == 0xfdfa0408);
94   ASSERT(mullong (  0xfffefd,   0xfcfbfa) == 0xfa0d1212);
95   ASSERT(mullong (  0xfcfbfa,   0xfffefd) == 0xfa0d1212);
96   ASSERT(mullong (0xfffefdfc, 0xfbfaf9f8) == 0x20282820);
97   ASSERT(mullong (0xfbfaf9f8, 0xfffefdfc) == 0x20282820);
98
99   ASSERT(mullong (0xff000000, 0xff000000) ==          0);
100   ASSERT(mullong (0xffff0000, 0xffff0000) ==          0);
101   ASSERT(mullong (0xfffffe00, 0xfffffd00) == 0x00060000);
102   ASSERT(mullong (0xfffffd00, 0xfffffe00) == 0x00060000);
103   ASSERT(mullong (0xfffffefd, 0xfffffcfb) == 0x00030e0f);
104   ASSERT(mullong (0xfffffcfb, 0xfffffefd) == 0x00030e0f);
105
106   ASSERT(mullong (0xffffffff, 0xffffffff) ==          1);
107 }