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