author | Claus Gittinger <cg@exept.de> |
Thu, 25 Mar 1999 17:29:38 +0100 | |
changeset 4073 | 21939187f19c |
parent 4065 | c0b7689b3a49 |
child 4167 | 15e0629ba1f1 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
214 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
13 |
'From Smalltalk/X, Version:3.4.1 on 13-feb-1998 at 15:51:34' ! |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
14 |
|
1 | 15 |
Integer subclass:#SmallInteger |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
16 |
instanceVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
17 |
classVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
18 |
poolDictionaries:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
19 |
category:'Magnitude-Numbers' |
1 | 20 |
! |
21 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
22 |
!SmallInteger class methodsFor:'documentation'! |
1 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
214 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
68 | 38 |
documentation |
39 |
" |
|
88 | 40 |
SmallIntegers are Integers in the range of at least +/- 2^30 |
2785 | 41 |
(i.e. 31 bits, which is not a guaranteed: on an alpha, 63 bits are used, |
42 |
if the system was configured for 64bit mode). |
|
88 | 43 |
|
68 | 44 |
These are no real objects - they have no instances (not even storage !!) |
45 |
and cannot be subclassed. |
|
46 |
The reason is to save both storage and runtime by not collecting |
|
47 |
SmallIntegers in the system. SmallInts are marked by having the TAG_INT |
|
88 | 48 |
bit set, in contrast to all other objects which do not. |
49 |
Since this knowledge is hardwired into the system (and there is no |
|
50 |
class-field stored with SmallIntegers) there can be no subclass of |
|
51 |
SmallInteger (sorry). |
|
52 |
||
53 |
If you really need this kind of thing, create a subclass of Integer, |
|
54 |
with an instance variable holding the value. |
|
1295 | 55 |
|
56 |
[author:] |
|
2216 | 57 |
Claus Gittinger |
1556 | 58 |
|
59 |
[see also:] |
|
2216 | 60 |
Number |
61 |
Float Fraction FixedPoint |
|
62 |
LargeInteger |
|
68 | 63 |
" |
64 |
! ! |
|
1 | 65 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
66 |
!SmallInteger class methodsFor:'instance creation'! |
1 | 67 |
|
68 |
basicNew |
|
69 |
"catch instance creation |
|
70 |
- SmallIntegers cannot be created with new" |
|
71 |
||
72 |
self error:'instances of SmallInteger cannot be created with new' |
|
73 |
! |
|
74 |
||
75 |
basicNew:size |
|
76 |
"catch instance creation |
|
77 |
- SmallIntegers cannot be created with new" |
|
78 |
||
79 |
self error:'instances of SmallInteger cannot be created with new' |
|
80 |
! ! |
|
81 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
82 |
!SmallInteger class methodsFor:'bit mask constants'! |
701 | 83 |
|
84 |
bitMaskFor:index |
|
85 |
"return a bitmask for the index's bit (index starts at 1)" |
|
86 |
||
87 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
88 |
^ self error:'index out of bounds' |
|
89 |
]. |
|
90 |
^ 1 bitShift:(index - 1) |
|
91 |
! ! |
|
92 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
93 |
!SmallInteger class methodsFor:'constants'! |
1 | 94 |
|
95 |
maxBits |
|
68 | 96 |
"return the number of bits in instances of me. |
97 |
For very special uses only - not constant across implementations" |
|
1 | 98 |
|
99 |
%{ /* NOCONTEXT */ |
|
1133 | 100 |
RETURN ( __MKSMALLINT(N_INT_BITS) ); |
1 | 101 |
%} |
2 | 102 |
|
103 |
"SmallInteger maxBits" |
|
1 | 104 |
! |
105 |
||
106 |
maxBytes |
|
68 | 107 |
"return the number of bytes in instances of me. |
108 |
For very special uses only - not constant across implementations" |
|
1 | 109 |
|
110 |
%{ /* NOCONTEXT */ |
|
1133 | 111 |
RETURN ( __MKSMALLINT(N_INT_BITS / 8 + 1) ); |
1 | 112 |
%} |
2 | 113 |
|
3684 | 114 |
" |
115 |
SmallInteger maxBytes |
|
116 |
" |
|
1 | 117 |
! |
118 |
||
119 |
maxVal |
|
68 | 120 |
"return the largest Integer representable as SmallInteger. |
121 |
For very special uses only - not constant across implementations" |
|
1 | 122 |
|
123 |
%{ /* NOCONTEXT */ |
|
1133 | 124 |
RETURN ( __MKSMALLINT(_MAX_INT) ); |
1 | 125 |
%} |
2 | 126 |
|
127 |
"SmallInteger maxVal" |
|
701 | 128 |
! |
129 |
||
130 |
minVal |
|
131 |
"return the smallest Integer representable as SmallInteger. |
|
132 |
For very special uses only - not constant across implementations" |
|
133 |
||
134 |
%{ /* NOCONTEXT */ |
|
1133 | 135 |
RETURN ( __MKSMALLINT(_MIN_INT) ); |
701 | 136 |
%} |
137 |
||
138 |
"SmallInteger minVal" |
|
1 | 139 |
! ! |
140 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
141 |
!SmallInteger class methodsFor:'queries'! |
3 | 142 |
|
50 | 143 |
canBeSubclassed |
144 |
"return true, if its allowed to create subclasses of the receiver. |
|
3914 | 145 |
Return false here - since it is NOT possible for SmallInteger |
146 |
(due to the tagged representation of SmallIntegers)" |
|
50 | 147 |
|
148 |
^ false |
|
3914 | 149 |
|
150 |
"Modified: / 5.11.1998 / 16:11:27 / cg" |
|
1 | 151 |
! |
152 |
||
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
153 |
hasImmediateInstances |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
154 |
"return true if this class has immediate instances. |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
155 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
156 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
157 |
^ true |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
158 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
159 |
"Created: 3.6.1997 / 12:01:26 / cg" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
160 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
161 |
|
701 | 162 |
isBuiltInClass |
1264 | 163 |
"return true if this class is known by the run-time-system. |
164 |
Here, true is returned." |
|
1 | 165 |
|
166 |
^ true |
|
1264 | 167 |
|
168 |
"Modified: 23.4.1996 / 16:00:33 / cg" |
|
1 | 169 |
! ! |
170 |
||
171 |
!SmallInteger methodsFor:'arithmetic'! |
|
172 |
||
173 |
* aNumber |
|
174 |
"return the product of the receivers value and the arguments value" |
|
175 |
||
176 |
%{ /* NOCONTEXT */ |
|
177 |
||
68 | 178 |
INT myValue, otherValue; |
179 |
unsigned INT productLow, productHi; |
|
180 |
int negative; |
|
181 |
||
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
182 |
# define low16Bits(foo) ((foo) & 0xFFFF) |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
183 |
# define hi16Bits(foo) ((foo) >> 16) |
2785 | 184 |
# define low32Bits(foo) ((foo) & 0xFFFFFFFFL) |
185 |
# define hi32Bits(foo) ((foo) >> 32) |
|
95 | 186 |
|
187 |
/* |
|
188 |
* can we use long long arithmetic ? |
|
189 |
*/ |
|
190 |
#if defined(__GNUC__) && (__GNUC__ >= 2) |
|
191 |
/* |
|
192 |
* commented, since long-long arithmetic seems to |
|
193 |
* be buggy in some implementations (sparc) ... |
|
194 |
* (took me a while to find this out :-( |
|
195 |
*/ |
|
196 |
# ifdef NOTDEF |
|
2785 | 197 |
# define USE_LONGLONG |
95 | 198 |
# endif |
199 |
#endif |
|
1 | 200 |
|
252 | 201 |
if (__isSmallInteger(aNumber)) { |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
202 |
myValue = __intVal(self); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
203 |
otherValue = __intVal(aNumber); |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
204 |
|
2953 | 205 |
#if defined(INT64) |
2785 | 206 |
# if !defined(alpha64) |
207 |
# define USE_LONGLONG |
|
208 |
# else |
|
209 |
# undef USE_LONGLONG |
|
210 |
# endif |
|
211 |
#endif |
|
212 |
||
213 |
#if defined(USE_LONGLONG) |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
214 |
{ |
2785 | 215 |
# if defined(alpha) && !defined(alpha64) |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
216 |
# define LONGLONG INT64 |
2785 | 217 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
218 |
# define LONGLONG long long |
2785 | 219 |
# endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
220 |
LONGLONG product; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
221 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
222 |
product = (LONGLONG)myValue * (LONGLONG)otherValue; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
223 |
if ((product >= (LONGLONG)_MIN_INT) |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
224 |
&& (product <= (LONGLONG)_MAX_INT)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
225 |
RETURN ( __MKSMALLINT((INT)product) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
226 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
227 |
if (product < 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
228 |
negative = -1; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
229 |
product = -product; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
230 |
} else { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
231 |
negative = 1; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
232 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
233 |
productHi = product >> 32; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
234 |
productLow = product & 0xFFFFFFFFL; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
235 |
} |
13 | 236 |
#else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
237 |
negative = 1; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
238 |
if (myValue < 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
239 |
negative = -1; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
240 |
myValue = -myValue; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
241 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
242 |
if (otherValue < 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
243 |
negative = -negative; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
244 |
otherValue = -otherValue; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
245 |
} |
68 | 246 |
|
247 |
# if defined(__GNUC__) && defined(mc68k) |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
248 |
asm ("mulu%.l %3,%1:%0" |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
249 |
: "=d" ((unsigned long)(productLow)), |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
250 |
"=d" ((unsigned long)(productHi)) |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
251 |
: "%0" ((unsigned long)(myValue)), |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
252 |
"dmi" ((unsigned long)(otherValue))); |
68 | 253 |
# else |
254 |
# if defined (__GNUC__) && defined(i386) |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
255 |
asm ("mull %3" |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
256 |
: "=a" ((unsigned long)(productLow)), |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
257 |
"=d" ((unsigned long)(productHi)) |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
258 |
: "%0" ((unsigned long)(myValue)), |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
259 |
"rm" ((unsigned long)(otherValue))); |
68 | 260 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
261 |
{ |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
262 |
unsigned INT pHH, pHL, pLH, pLL; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
263 |
unsigned INT low1, low2, hi1, hi2; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
264 |
unsigned INT t; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
265 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
266 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
267 |
* |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
268 |
* this is too slow: |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
269 |
* since most machines can do 32*32 to 64 bit multiply, |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
270 |
* (or at least 32*32 with Overflow check) |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
271 |
* - need more assembler (inline) functions here |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
272 |
*/ |
2788 | 273 |
# ifdef alpha64 |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
274 |
low1 = low32Bits(myValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
275 |
hi1 = hi32Bits(myValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
276 |
low2 = low32Bits(otherValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
277 |
hi2 = hi32Bits(otherValue); |
2785 | 278 |
# define LLMASK 0xC000000000000000L |
279 |
# else |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
280 |
low1 = low16Bits(myValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
281 |
hi1 = hi16Bits(myValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
282 |
low2 = low16Bits(otherValue); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
283 |
hi2 = hi16Bits(otherValue); |
2785 | 284 |
# define LLMASK 0xC0000000 |
285 |
# endif |
|
68 | 286 |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
287 |
pLH = low1 * hi2; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
288 |
pHL = hi1 * low2; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
289 |
pLL = low1 * low2; |
3909
272567862afe
oops - multiply of 64 bit values wrong if both low-parts were zero
Claus Gittinger <cg@exept.de>
parents:
3892
diff
changeset
|
290 |
pHH = hi1 * hi2; |
68 | 291 |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
292 |
/* |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
293 |
* the common case ... |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
294 |
*/ |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
295 |
if ((pHL == 0) |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
296 |
&& (pLH == 0) |
3909
272567862afe
oops - multiply of 64 bit values wrong if both low-parts were zero
Claus Gittinger <cg@exept.de>
parents:
3892
diff
changeset
|
297 |
&& (pHH == 0) |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
298 |
&& ((pLL & LLMASK) == 0)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
299 |
if (negative < 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
300 |
RETURN ( __MKSMALLINT(- ((INT)pLL)) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
301 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
302 |
RETURN ( __MKSMALLINT((INT)pLL) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
303 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
304 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
305 |
/* |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
306 |
* pHH |--------|--------| |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
307 |
* pLH |--------|--------| |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
308 |
* pHL |--------|--------| |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
309 |
* pLL |--------|--------| |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
310 |
*/ |
68 | 311 |
|
2788 | 312 |
# ifdef alpha64 |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
313 |
t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
314 |
productLow = (t << 32) + low32Bits(pLL); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
315 |
productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
316 |
if (t >= 0x100000000L) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
317 |
productHi += t >> 32; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
318 |
} |
2785 | 319 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
320 |
t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
321 |
productLow = (t << 16) + low16Bits(pLL); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
322 |
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
323 |
if (t >= 0x10000L) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
324 |
productHi += t >> 16; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
325 |
} |
2785 | 326 |
# endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
327 |
} |
68 | 328 |
# endif |
329 |
# endif |
|
2785 | 330 |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
331 |
if (productHi == 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
332 |
if (negative < 0) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
333 |
if (productLow <= -(_MIN_INT)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
334 |
RETURN ( __MKSMALLINT(-((INT)productLow)) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
335 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
336 |
} else { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
337 |
if (productLow <= _MAX_INT) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
338 |
RETURN ( __MKSMALLINT(productLow) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
339 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
340 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
341 |
} |
95 | 342 |
#endif |
343 |
||
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
344 |
{ |
2788 | 345 |
# ifdef alpha64 |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
346 |
RETURN (__MKLARGEINT128(negative, productLow, productHi)); |
2785 | 347 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
348 |
RETURN (__MKLARGEINT64(negative, productLow, productHi)); |
2785 | 349 |
# endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
350 |
} |
283 | 351 |
} else if (__isFloatLike(aNumber)) { |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
352 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
353 |
double val = (double)__intVal(self) * __floatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
354 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
355 |
__qMKFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
356 |
RETURN ( newFloat ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
357 |
} else if (__isShortFloat(aNumber)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
358 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
359 |
float val = (float)__intVal(self) * __shortFloatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
360 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
361 |
__qMKSFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
362 |
RETURN ( newFloat ); |
1 | 363 |
} |
2641 | 364 |
%}. |
1 | 365 |
^ aNumber productFromInteger:self |
366 |
! |
|
367 |
||
701 | 368 |
+ aNumber |
369 |
"return the sum of the receivers value and the arguments value" |
|
370 |
||
371 |
%{ /* NOCONTEXT */ |
|
372 |
||
373 |
if (__isSmallInteger(aNumber)) { |
|
374 |
#ifdef _ADD_IO_IO |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
375 |
RETURN ( _ADD_IO_IO(self, aNumber) ); |
701 | 376 |
#else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
377 |
REGISTER INT sum; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
378 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
379 |
sum = __intVal(self) + __intVal(aNumber); |
4065 | 380 |
if (__ISVALIDINTEGER(sum)) { |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
381 |
RETURN ( __MKSMALLINT(sum) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
382 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
383 |
RETURN ( __MKLARGEINT(sum) ); |
701 | 384 |
#endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
385 |
} else if (__isFloatLike(aNumber)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
386 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
387 |
double val = (double)__intVal(self) + __floatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
388 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
389 |
__qMKFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
390 |
RETURN ( newFloat ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
391 |
} else if (__isShortFloat(aNumber)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
392 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
393 |
float val = (float)__intVal(self) + __shortFloatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
394 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
395 |
__qMKSFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
396 |
RETURN ( newFloat ); |
701 | 397 |
} |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
398 |
%}. |
701 | 399 |
^ aNumber sumFromInteger:self |
400 |
! |
|
401 |
||
402 |
- aNumber |
|
403 |
"return the difference of the receivers value and the arguments value" |
|
404 |
||
405 |
%{ /* NOCONTEXT */ |
|
406 |
||
407 |
if (__isSmallInteger(aNumber)) { |
|
408 |
#ifdef _SUB_IO_IO |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
409 |
RETURN ( _SUB_IO_IO(self, aNumber) ); |
701 | 410 |
#else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
411 |
REGISTER INT diff; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
412 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
413 |
diff = __intVal(self) - __intVal(aNumber); |
4065 | 414 |
if (__ISVALIDINTEGER(diff)) { |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
415 |
RETURN ( __MKSMALLINT(diff) ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
416 |
} |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
417 |
RETURN ( __MKLARGEINT(diff) ); |
701 | 418 |
#endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
419 |
} else if (__isFloatLike(aNumber)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
420 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
421 |
double val = (double)__intVal(self) - __floatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
422 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
423 |
__qMKFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
424 |
RETURN ( newFloat ); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
425 |
} else if (__isShortFloat(aNumber)) { |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
426 |
OBJ newFloat; |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
427 |
float val = (float)__intVal(self) - __shortFloatVal(aNumber); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
428 |
|
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
429 |
__qMKSFLOAT(newFloat, val); |
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
430 |
RETURN ( newFloat ); |
701 | 431 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
432 |
%}. |
701 | 433 |
^ aNumber differenceFromInteger:self |
434 |
! |
|
435 |
||
1 | 436 |
/ aNumber |
437 |
"return the quotient of the receivers value and the arguments value" |
|
438 |
||
439 |
%{ /* NOCONTEXT */ |
|
440 |
||
441 |
INT me, t, val; |
|
442 |
double dval; |
|
443 |
||
252 | 444 |
if (__isSmallInteger(aNumber)) { |
3135 | 445 |
val = __intVal(aNumber); |
446 |
if (val != 0) { |
|
447 |
me = __intVal(self); |
|
448 |
t = me / val; |
|
1 | 449 |
#ifdef GOOD_OPTIMIZER |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
450 |
if (me % val == 0) { |
1 | 451 |
#else |
3135 | 452 |
/* this is stupid - all I want is to look for a remainder ... |
453 |
but most compilers are too stupid and generate an extra modulus |
|
454 |
instruction for "if (me % val)". |
|
455 |
Even if most divide instructions already leave the remainder in |
|
456 |
some register. |
|
457 |
Therefore I use a multiplication which is faster than a modulo |
|
458 |
on most machines. Hint to GNU people :-) |
|
459 |
*/ |
|
460 |
if ((t * val) == me) { |
|
1 | 461 |
#endif |
3135 | 462 |
RETURN ( __MKSMALLINT(t) ); |
463 |
} |
|
464 |
} |
|
1 | 465 |
} else { |
3135 | 466 |
if (__isFloatLike(aNumber)) { |
467 |
dval = __floatVal(aNumber); |
|
468 |
if (dval != 0.0) { |
|
469 |
OBJ newFloat; |
|
470 |
double val = (double)__intVal(self) / dval; |
|
471 |
||
472 |
__qMKFLOAT(newFloat, val); |
|
473 |
RETURN ( newFloat ); |
|
474 |
} |
|
475 |
} |
|
1 | 476 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
477 |
%}. |
1 | 478 |
aNumber isInteger ifTrue:[ |
3135 | 479 |
aNumber == 0 ifTrue:[ |
480 |
^ DivisionByZeroSignal raise. |
|
481 |
]. |
|
482 |
^ Fraction numerator:self denominator:aNumber |
|
1 | 483 |
]. |
484 |
^ aNumber quotientFromInteger:self |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
485 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
486 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
487 |
8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
488 |
9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
489 |
9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
490 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
491 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
492 |
-8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
493 |
-9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
494 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
495 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
496 |
" |
1 | 497 |
! |
498 |
||
2 | 499 |
// aNumber |
1 | 500 |
"return the integer part of the quotient of the receivers value |
1884 | 501 |
and the arguments value. The result is truncated toward negative infinity |
502 |
and negative, if the operands signs differ. |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
503 |
Be careful with negative results: 9 // 4 = 2, |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
504 |
while -9 // 4 = -3. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
505 |
See #quo: which returns -2 in the latter." |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
506 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
507 |
%{ /* NOCONTEXT */ |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
508 |
INT dividend, divisor, rslt; |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
509 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
510 |
if (__isSmallInteger(aNumber)) { |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
511 |
divisor = __intVal(aNumber); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
512 |
if (divisor != 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
513 |
dividend = __intVal(self); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
514 |
rslt = dividend / divisor; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
515 |
/* |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
516 |
* Optimized to speed up positive result |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
517 |
*/ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
518 |
if (rslt <= 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
519 |
if (rslt == 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
520 |
if (dividend * divisor < 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
521 |
/* |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
522 |
* result (negative) has been truncated toward 0. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
523 |
* Return -1, because we truncate toward negative inf. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
524 |
*/ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
525 |
rslt = -1; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
526 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
527 |
} else { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
528 |
/* |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
529 |
* If result (negative) has been truncated toward 0, |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
530 |
* subtract 1, beacuse we truncate toward negative inf. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
531 |
*/ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
532 |
if (divisor > 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
533 |
if (rslt * divisor > dividend) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
534 |
rslt--; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
535 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
536 |
} else { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
537 |
if (rslt * divisor < dividend) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
538 |
rslt--; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
539 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
540 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
541 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
542 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
543 |
RETURN ( __MKSMALLINT(rslt) ); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
544 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
545 |
} else { |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
546 |
if (__isFraction(aNumber)) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
547 |
OBJ t; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
548 |
INT num, den; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
549 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
550 |
t = __FractionInstPtr(aNumber)->f_numerator; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
551 |
if (__isSmallInteger(t)) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
552 |
num = __intVal(t); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
553 |
t = __FractionInstPtr(aNumber)->f_denominator; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
554 |
if (__isSmallInteger(t)) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
555 |
den = __intVal(t); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
556 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
557 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
558 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
559 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
560 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
561 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
562 |
(aNumber = 0) ifTrue:[ |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
563 |
^ DivisionByZeroSignal raise. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
564 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
565 |
^ self retry:#// coercing:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
566 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
567 |
" |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
568 |
9 // 4 ~~ 2 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
569 |
-9 // 4 ~~ -3 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
570 |
9 // -4 ~~ -3 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
571 |
-9 // -4 ~~ 2 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
572 |
1 // 2 ~~ 0 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
573 |
-1 // 2 ~~ -1 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
574 |
1 // -2 ~~ -1 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
575 |
-1 // -2 ~~ 0 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
576 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
577 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
578 |
9 quo:4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
579 |
-9 quo:4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
580 |
9 quo:-4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
581 |
-9 quo:-4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
582 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
583 |
! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
584 |
|
2 | 585 |
\\ aNumber |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
586 |
"Answer the integer remainder m defined by division with truncation toward |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
587 |
negative infinity. The remainder has the same sign as aNumber. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
588 |
m < |aNumber| AND there is an integer k with (k * aNumber + m) = self |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
589 |
Compare with #rem: |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
590 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
591 |
Redefined for speed." |
1 | 592 |
|
593 |
%{ /* NOCONTEXT */ |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
594 |
INT dividend, divisor, rem; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
595 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
596 |
if (__isSmallInteger(aNumber) |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
597 |
&& (divisor = __intVal(aNumber)) != 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
598 |
/* |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
599 |
* Note that the sign of something modulo a negative number is undefined |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
600 |
* in C! |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
601 |
*/ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
602 |
dividend = __intVal(self); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
603 |
rem = dividend % divisor; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
604 |
if (rem) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
605 |
if ((rem < 0) != (divisor < 0)) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
606 |
/* sign of remainder is different from sign of divisor */ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
607 |
rem = -rem; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
608 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
609 |
if ((dividend < 0) != (divisor < 0)) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
610 |
/* different signs, so division would have returned a |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
611 |
* negative number. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
612 |
* C rounds toward zero, this code will simulate |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
613 |
* rounding towards negative infinity. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
614 |
*/ |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
615 |
rem = divisor - rem; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
616 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
617 |
} |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
618 |
RETURN ( __MKSMALLINT(rem) ); |
1 | 619 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
620 |
%}. |
2 | 621 |
(aNumber = 0) ifTrue:[ |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
622 |
^ DivisionByZeroSignal raise. |
1 | 623 |
]. |
2 | 624 |
^ self retry:#\\ coercing:aNumber |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
625 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
626 |
" |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
627 |
9 \\ 4 == 1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
628 |
-9 \\ 4 == 3 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
629 |
9 \\ -4 == -3 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
630 |
-9 \\ -4 == -1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
631 |
(9 rem:4) == 1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
632 |
(-9 rem:4) == -1 ifFalse:[self halt]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
633 |
" |
1 | 634 |
! |
635 |
||
636 |
abs |
|
637 |
"return the absolute value of the receiver |
|
638 |
reimplemented here for speed" |
|
639 |
||
640 |
%{ /* NOCONTEXT */ |
|
641 |
||
1133 | 642 |
INT val = __intVal(self); |
1 | 643 |
|
62 | 644 |
if (val >= 0) { |
214 | 645 |
RETURN (self); |
62 | 646 |
} |
1 | 647 |
if (val != _MIN_INT) { |
1133 | 648 |
RETURN ( __MKSMALLINT(-val) ); |
1 | 649 |
} |
3430 | 650 |
/* only reached for minVal */ |
651 |
RETURN( __MKLARGEINT(-_MIN_INT)); |
|
324 | 652 |
%}. |
3430 | 653 |
"/ "only reached for minVal" |
654 |
"/ ^ self negated |
|
1 | 655 |
! |
656 |
||
657 |
negated |
|
658 |
"return the negative value of the receiver |
|
659 |
reimplemented here for speed" |
|
660 |
||
661 |
%{ /* NOCONTEXT */ |
|
662 |
||
1133 | 663 |
INT val = __intVal(self); |
1 | 664 |
|
665 |
if (val != _MIN_INT) { |
|
1133 | 666 |
RETURN ( __MKSMALLINT(- val) ); |
1 | 667 |
} |
3430 | 668 |
/* only reached for minVal */ |
669 |
RETURN (__MKLARGEINT( -_MIN_INT)); |
|
324 | 670 |
%}. |
3430 | 671 |
"/ "only reached for minVal" |
672 |
"/ ^ (LargeInteger value:(SmallInteger maxVal)) + 1 |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
673 |
! |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
674 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
675 |
quo:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
676 |
"return the integer part of the quotient of the receivers value |
1884 | 677 |
and the arguments value. The result is truncated towards zero |
678 |
and negative, if the operands signs differ.. |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
679 |
For positive results, this is the same as #//, |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
680 |
for negative results, the remainder is ignored. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
681 |
I.e.: '9 // 4 = 2' and '-9 // 4 = -3' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
682 |
in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
683 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
684 |
%{ /* NOCONTEXT */ |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
685 |
INT val; |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
686 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
687 |
if (__isSmallInteger(aNumber)) { |
2216 | 688 |
val = __intVal(aNumber); |
689 |
if (val != 0) { |
|
690 |
RETURN ( __MKSMALLINT(__intVal(self) / val) ); |
|
691 |
} |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
692 |
} else { |
2216 | 693 |
if (__isFraction(aNumber)) { |
694 |
OBJ t; |
|
695 |
INT num, den; |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
696 |
|
2216 | 697 |
t = __FractionInstPtr(aNumber)->f_numerator; |
698 |
if (__isSmallInteger(t)) { |
|
699 |
num = __intVal(t); |
|
700 |
t = __FractionInstPtr(aNumber)->f_denominator; |
|
701 |
if (__isSmallInteger(t)) { |
|
702 |
den = __intVal(t); |
|
703 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
|
704 |
} |
|
705 |
} |
|
706 |
} |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
707 |
} |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
708 |
%}. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
709 |
(aNumber = 0) ifTrue:[ |
2216 | 710 |
^ DivisionByZeroSignal raise. |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
711 |
]. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
712 |
^ self retry:#quo: coercing:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
713 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
714 |
" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
715 |
9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
716 |
-9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
717 |
9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
718 |
-9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
719 |
" |
1 | 720 |
! ! |
721 |
||
722 |
!SmallInteger methodsFor:'bit operators'! |
|
723 |
||
724 |
allMask:anInteger |
|
62 | 725 |
"return true if all 1-bits in anInteger are also 1 in the receiver" |
726 |
||
727 |
^ (self bitAnd:anInteger) == anInteger |
|
1 | 728 |
|
62 | 729 |
"2r00001111 allMask:2r00000001" |
730 |
"2r00001111 allMask:2r00011110" |
|
731 |
"2r00001111 allMask:2r00000000" |
|
1 | 732 |
! |
733 |
||
734 |
anyMask:anInteger |
|
62 | 735 |
"return true if any 1-bits in anInteger is also 1 in the receiver. |
736 |
(somewhat incorrect, if the mask is zero)" |
|
1 | 737 |
|
62 | 738 |
^ (self bitAnd:anInteger) ~~ 0 |
739 |
||
740 |
"2r00001111 anyMask:2r00000001" |
|
741 |
"2r00001111 anyMask:2r11110000" |
|
1 | 742 |
! |
743 |
||
701 | 744 |
bitAnd:anInteger |
745 |
"return the bitwise-and of the receiver and the argument, anInteger" |
|
1 | 746 |
|
747 |
%{ /* NOCONTEXT */ |
|
748 |
||
701 | 749 |
/* anding the tags doesn't change it */ |
750 |
if (__isSmallInteger(anInteger)) { |
|
751 |
RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) ); |
|
1 | 752 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
753 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
754 |
^ self retry:#bitAnd: coercing:anInteger |
701 | 755 |
|
756 |
"(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
|
1 | 757 |
! |
758 |
||
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
759 |
bitAt:index |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
760 |
"return the value of the index's bit (index starts at 1). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
761 |
Notice: the result of bitAt: on negative receivers is not |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
762 |
defined in the language standard (since the implementation |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
763 |
is free to choose any internal representation for integers)" |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
764 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
765 |
|mask| |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
766 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
767 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
768 |
^ self error:'index out of bounds' |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
769 |
]. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
770 |
mask := 1 bitShift:(index - 1). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
771 |
((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
772 |
^ 1 |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
773 |
! |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
774 |
|
3156 | 775 |
bitClear:anInteger |
776 |
"return the bitwise-and of the receiver and the complement of the argument, anInteger, |
|
777 |
returning the receiver with bits of the argument cleared." |
|
778 |
||
779 |
%{ /* NOCONTEXT */ |
|
780 |
||
781 |
/* anding the tags doesn't change it */ |
|
782 |
if (__isSmallInteger(anInteger)) { |
|
783 |
RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) ); |
|
784 |
} |
|
785 |
%}. |
|
786 |
^ self retry:#bitClear: coercing:anInteger |
|
787 |
||
788 |
" |
|
789 |
(2r001010100 bitClear:2r00001111) radixPrintStringRadix:2 |
|
790 |
" |
|
791 |
! |
|
792 |
||
701 | 793 |
bitInvert |
794 |
"return the value of the receiver with all bits inverted" |
|
62 | 795 |
|
1 | 796 |
%{ /* NOCONTEXT */ |
797 |
||
701 | 798 |
/* invert anything except tag bits */ |
799 |
RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) ); |
|
800 |
%} |
|
801 |
! |
|
1 | 802 |
|
701 | 803 |
bitOr:anInteger |
804 |
"return the bitwise-or of the receiver and the argument, anInteger" |
|
805 |
||
806 |
%{ /* NOCONTEXT */ |
|
807 |
||
808 |
/* oring the tags doesn't change it */ |
|
809 |
if (__isSmallInteger(anInteger)) { |
|
810 |
RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) ); |
|
1 | 811 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
812 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
813 |
^ self retry:#bitOr: coercing:anInteger |
701 | 814 |
|
815 |
"(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2" |
|
1 | 816 |
! |
817 |
||
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
818 |
bitShift32:shiftCount |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
819 |
"return the value of the receiver shifted by shiftCount bits, |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
820 |
but only within 32 bits, shifting into/out-of the sign bit. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
821 |
May be useful for communication interfaces, to create ST-numbers |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
822 |
from a signed 32bit int value given as individual bytes." |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
823 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
824 |
%{ /* NOCONTEXT */ |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
825 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
826 |
INT bits, count; |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
827 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
828 |
if (__isSmallInteger(shiftCount)) { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
829 |
count = __intVal(shiftCount); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
830 |
if (count >= 32) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
831 |
RETURN (__MKSMALLINT(0)); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
832 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
833 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
834 |
bits = __intVal(self); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
835 |
if (count > 0) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
836 |
bits = bits << count; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
837 |
} else { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
838 |
bits = bits >> (-count); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
839 |
} |
2785 | 840 |
#ifdef alpha64 |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
841 |
bits &= 0xFFFFFFFFL; |
2785 | 842 |
#endif |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
843 |
RETURN (__MKINT(bits)); |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
844 |
} |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
845 |
%}. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
846 |
^ self primitiveFailed |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
847 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
848 |
" |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
849 |
128 bitShift:24 |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
850 |
128 bitShift32:24 |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
851 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
852 |
1 bitShift:31 |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
853 |
1 bitShift32:31 |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
854 |
" |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
855 |
! |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
856 |
|
1 | 857 |
bitShift:shiftCount |
858 |
"return the value of the receiver shifted by shiftCount bits; |
|
62 | 859 |
leftShift if shiftCount > 0; rightShift otherwise. |
95 | 860 |
Notice: the result of bitShift: on negative receivers is not |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
861 |
defined in the language standard (since the implementation |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
862 |
is free to choose any internal representation for integers)" |
1 | 863 |
|
864 |
%{ /* NOCONTEXT */ |
|
865 |
||
866 |
INT bits, count; |
|
867 |
||
252 | 868 |
if (__isSmallInteger(shiftCount)) { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
869 |
bits = __intVal(self); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
870 |
if (bits == 0) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
871 |
RETURN (self); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
872 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
873 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
874 |
count = __intVal(shiftCount); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
875 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
876 |
if (count > 0) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
877 |
/* |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
878 |
* a left shift |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
879 |
*/ |
2785 | 880 |
#if defined(USE_LONGLONG) |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
881 |
unsigned LONGLONG result; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
882 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
883 |
result = bits; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
884 |
if (count <= N_INT_BITS) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
885 |
result <<= count; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
886 |
if (result <= _MAX_INT) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
887 |
RETURN ( __MKSMALLINT(result) ); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
888 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
889 |
{ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
890 |
RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
891 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
892 |
} |
95 | 893 |
#else |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
894 |
/* |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
895 |
* check for overflow |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
896 |
*/ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
897 |
if (count < (N_INT_BITS-1)) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
898 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
899 |
RETURN ( __MKSMALLINT(bits << count) ); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
900 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
901 |
/* |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
902 |
* so, there is an overflow ... |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
903 |
* handle it as largeInteger |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
904 |
*/ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
905 |
/* FALL THROUGH */ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
906 |
} |
95 | 907 |
#endif |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
908 |
} else { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
909 |
if (count == 0) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
910 |
RETURN (self); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
911 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
912 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
913 |
/* |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
914 |
* right shifts cannot overflow |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
915 |
* |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
916 |
* some machines ignore shifts bigger than |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
917 |
* the number of bits in an int ... |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
918 |
*/ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
919 |
count = -count; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
920 |
if (count > (N_INT_BITS-1)) { |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
921 |
RETURN (__MKSMALLINT(0)); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
922 |
} |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
923 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
924 |
RETURN ( __MKSMALLINT(bits >> count) ); |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
925 |
} |
1 | 926 |
} |
85 | 927 |
%}. |
928 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
929 |
^ (LargeInteger value:self) bitShift:shiftCount |
85 | 930 |
]. |
1 | 931 |
^ self bitShift:(shiftCount coerce:1) |
932 |
! |
|
933 |
||
701 | 934 |
bitTest:aMask |
935 |
"return true, if any bit from aMask is set in the receiver" |
|
1 | 936 |
|
937 |
%{ /* NOCONTEXT */ |
|
938 |
||
701 | 939 |
/* and all bits except tag */ |
940 |
if (__isSmallInteger(aMask)) { |
|
941 |
RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); |
|
1 | 942 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
943 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
944 |
^ self retry:#bitTest: coercing:aMask |
1 | 945 |
! |
946 |
||
947 |
bitXor:anInteger |
|
13 | 948 |
"return the bitwise-exclusive-or of the receiver and the argument, anInteger" |
1 | 949 |
|
950 |
%{ /* NOCONTEXT */ |
|
951 |
||
952 |
/* xoring the tags turns it off - or it in again */ |
|
252 | 953 |
if (__isSmallInteger(anInteger)) { |
214 | 954 |
RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) ); |
1 | 955 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
956 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
957 |
^ self retry:#bitXor: coercing:anInteger |
1 | 958 |
! |
959 |
||
3683 | 960 |
clearBit:anInteger |
961 |
"return a new number where the specified bit is off. |
|
962 |
Bits are counted from 1 starting with the least significant." |
|
963 |
||
964 |
%{ /* NOCONTEXT */ |
|
965 |
||
966 |
if (__isSmallInteger(anInteger)) { |
|
967 |
int index = __intVal(anInteger); |
|
968 |
||
969 |
#ifdef alpha64 |
|
970 |
if (index <= 63) |
|
971 |
#else |
|
972 |
if (index <= 30) |
|
973 |
#endif |
|
974 |
{ |
|
975 |
INT mask = __MASKSMALLINT(1 << (index-1)); |
|
976 |
||
977 |
RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) ); |
|
978 |
} |
|
979 |
RETURN (self); |
|
980 |
} |
|
981 |
%}. |
|
982 |
^ self retry:#clearBit: coercing:anInteger |
|
983 |
||
984 |
" |
|
985 |
(16r401 clearBit:1 ) hexPrintString |
|
986 |
(16r3fffffff clearBit:1) hexPrintString |
|
987 |
(16r3fffffff clearBit:29) hexPrintString |
|
988 |
(16r3fffffff clearBit:30) hexPrintString |
|
989 |
(16r3fffffff clearBit:31) hexPrintString |
|
990 |
(16r3fffffff bitAt:30) hexPrintString |
|
991 |
(16r3fffffff bitAt:29) hexPrintString |
|
992 |
(16r40000001 clearBit:1) hexPrintString |
|
993 |
(16rF0000001 clearBit:29) hexPrintString |
|
994 |
(16rF0000001 clearBit:30) hexPrintString |
|
995 |
(16rF0000001 clearBit:31) hexPrintString |
|
996 |
(16rF0000001 clearBit:32) hexPrintString |
|
997 |
" |
|
998 |
||
999 |
||
1000 |
! |
|
1001 |
||
701 | 1002 |
highBit |
1003 |
"return the bitIndex of the highest bit set. The returned bitIndex |
|
1004 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1 | 1005 |
|
1006 |
%{ /* NOCONTEXT */ |
|
1007 |
||
701 | 1008 |
INT mask, index, bits; |
1009 |
||
1133 | 1010 |
bits = __intVal(self); |
701 | 1011 |
if (bits == 0) { |
1133 | 1012 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 1013 |
} |
2785 | 1014 |
|
2653 | 1015 |
#ifdef alpha64 |
2781 | 1016 |
mask = 0x2000000000000000L; |
701 | 1017 |
index = 62; |
1018 |
#else |
|
1019 |
mask = 0x20000000; |
|
1020 |
index = 30; |
|
1021 |
#endif |
|
2785 | 1022 |
|
701 | 1023 |
while (index) { |
1024 |
if (bits & mask) break; |
|
1025 |
mask = mask >> 1; |
|
1026 |
index--; |
|
1 | 1027 |
} |
1133 | 1028 |
RETURN ( __MKSMALLINT(index) ); |
1 | 1029 |
%} |
701 | 1030 |
"2r000100 highBit" |
1031 |
"2r010100 highBit" |
|
1032 |
"2r000001 highBit" |
|
1033 |
"0 highBit" |
|
1034 |
"SmallInteger maxVal highBit" |
|
1035 |
! |
|
1036 |
||
1037 |
lowBit |
|
1038 |
"return the bitIndex of the lowest bit set. The returned bitIndex |
|
1039 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1040 |
||
1041 |
%{ /* NOCONTEXT */ |
|
1042 |
||
1043 |
INT mask, index, bits; |
|
1044 |
||
1133 | 1045 |
bits = __intVal(self); |
701 | 1046 |
if (bits == 0) { |
2431 | 1047 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 1048 |
} |
2431 | 1049 |
|
1050 |
if ((bits & 0xFFFFFF) == 0) { |
|
1051 |
mask = 0x1000000; |
|
1052 |
index = 25; |
|
1053 |
} else { |
|
1054 |
if ((bits & 0xFFFF) == 0) { |
|
1055 |
mask = 0x10000; |
|
1056 |
index = 17; |
|
1057 |
} else { |
|
1058 |
if ((bits & 0xFF) == 0) { |
|
1059 |
mask = 0x100; |
|
1060 |
index = 9; |
|
1061 |
} else { |
|
1062 |
mask = 1; |
|
1063 |
index = 1; |
|
1064 |
} |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
2653 | 1068 |
#ifdef alpha64 |
701 | 1069 |
while (index != 63) { |
1070 |
#else |
|
1071 |
while (index != 31) { |
|
1072 |
#endif |
|
2431 | 1073 |
if (bits & mask) { |
1074 |
RETURN ( __MKSMALLINT(index) ); |
|
1075 |
} |
|
1076 |
mask = mask << 1; |
|
1077 |
index++; |
|
701 | 1078 |
} |
1133 | 1079 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 1080 |
%} |
2431 | 1081 |
" |
1082 |
2r000100 lowBit |
|
1083 |
2r010010 lowBit |
|
1084 |
2r100001 lowBit |
|
1085 |
16r1000 lowBit |
|
1086 |
16r1000000 lowBit |
|
1087 |
0 lowBit |
|
1088 |
" |
|
701 | 1089 |
! |
1090 |
||
1091 |
noMask:anInteger |
|
1092 |
"return true if no 1-bit in anInteger is 1 in the receiver" |
|
1093 |
||
1094 |
^ (self bitAnd:anInteger) == 0 |
|
1095 |
||
1096 |
"2r00001111 noMask:2r00000001" |
|
1097 |
"2r00001111 noMask:2r11110000" |
|
1 | 1098 |
! ! |
1099 |
||
1100 |
!SmallInteger methodsFor:'byte access'! |
|
1101 |
||
1102 |
digitAt:index |
|
1103 |
"return 8 bits of value, starting at byte index" |
|
1104 |
||
1105 |
%{ /* NOCONTEXT */ |
|
1106 |
||
357 | 1107 |
REGISTER INT val; |
1108 |
INT idx; |
|
1 | 1109 |
|
252 | 1110 |
if (__isSmallInteger(index)) { |
3892 | 1111 |
val = __intVal(self); |
1112 |
if (val < 0) |
|
1113 |
val = -val; |
|
1114 |
switch (idx = __intVal(index)) { |
|
1115 |
case 1: |
|
1116 |
break; |
|
1117 |
case 2: |
|
1118 |
val = (val >> 8); |
|
1119 |
break; |
|
1120 |
case 3: |
|
1121 |
val = (val >> 16); |
|
1122 |
break; |
|
1123 |
case 4: |
|
1124 |
val = (val >> 24); |
|
1125 |
break; |
|
2653 | 1126 |
#ifdef alpha64 |
3892 | 1127 |
case 5: |
1128 |
val = (val >> 32); |
|
1129 |
break; |
|
1130 |
case 6: |
|
1131 |
val = (val >> 40); |
|
1132 |
break; |
|
1133 |
case 7: |
|
1134 |
val = (val >> 48); |
|
1135 |
break; |
|
1136 |
case 8: |
|
1137 |
val = (val >> 56); |
|
1138 |
break; |
|
1 | 1139 |
#endif |
3892 | 1140 |
default: |
1141 |
if (idx < 1) |
|
1142 |
goto bad; /* sorry */ |
|
1143 |
RETURN (__MKSMALLINT(0)); |
|
1144 |
} |
|
1145 |
RETURN ( __MKSMALLINT( val & 0xFF) ); |
|
1 | 1146 |
} |
357 | 1147 |
bad: ; |
77 | 1148 |
%}. |
1149 |
index > 0 ifFalse:[ |
|
3892 | 1150 |
" |
1151 |
index less than 1 - not allowed |
|
1152 |
" |
|
1153 |
^ self primitiveFailed |
|
77 | 1154 |
]. |
1155 |
^ 0 |
|
62 | 1156 |
|
357 | 1157 |
" |
1158 |
(16r12345678 digitAt:1) printStringRadix:16 |
|
1159 |
(16r12345678 digitAt:3) printStringRadix:16 |
|
1160 |
(16r12345678 digitAt:15) printStringRadix:16 |
|
1161 |
(16r12345678 digitAt:0) printStringRadix:16 |
|
1162 |
(16r12345678 digitAt:-10) printStringRadix:16 |
|
1163 |
" |
|
701 | 1164 |
! |
1165 |
||
3892 | 1166 |
digitByteAt:index |
1167 |
"return 8 bits of my signed value, starting at byte index. |
|
1168 |
For positive receivers, this is the same as #digitAt:; |
|
1169 |
for negative ones, the actual bit representation is returned." |
|
1170 |
||
1171 |
%{ /* NOCONTEXT */ |
|
1172 |
||
1173 |
REGISTER INT val; |
|
1174 |
INT idx; |
|
1175 |
||
1176 |
if (__isSmallInteger(index)) { |
|
1177 |
val = __intVal(self); |
|
1178 |
switch (idx = __intVal(index)) { |
|
1179 |
case 1: |
|
1180 |
break; |
|
1181 |
case 2: |
|
1182 |
val = (val >> 8); |
|
1183 |
break; |
|
1184 |
case 3: |
|
1185 |
val = (val >> 16); |
|
1186 |
break; |
|
1187 |
case 4: |
|
1188 |
val = (val >> 24); |
|
1189 |
break; |
|
1190 |
#ifdef alpha64 |
|
1191 |
case 5: |
|
1192 |
val = (val >> 32); |
|
1193 |
break; |
|
1194 |
case 6: |
|
1195 |
val = (val >> 40); |
|
1196 |
break; |
|
1197 |
case 7: |
|
1198 |
val = (val >> 48); |
|
1199 |
break; |
|
1200 |
case 8: |
|
1201 |
val = (val >> 56); |
|
1202 |
break; |
|
1203 |
#endif |
|
1204 |
default: |
|
1205 |
if (idx < 1) |
|
1206 |
goto bad; /* sorry */ |
|
1207 |
if (val < 0) { |
|
1208 |
RETURN (__MKSMALLINT(0xFF)); |
|
1209 |
} |
|
1210 |
RETURN (__MKSMALLINT(0)); |
|
1211 |
} |
|
1212 |
RETURN ( __MKSMALLINT( val & 0xFF) ); |
|
1213 |
} |
|
1214 |
bad: ; |
|
1215 |
%}. |
|
1216 |
index > 0 ifFalse:[ |
|
1217 |
" |
|
1218 |
index less than 1 - not allowed |
|
1219 |
" |
|
1220 |
^ self primitiveFailed |
|
1221 |
]. |
|
1222 |
^ 0 |
|
1223 |
||
1224 |
" |
|
1225 |
(10 digitByteAt:1) printStringRadix:16 |
|
1226 |
(10 digitByteAt:3) printStringRadix:16 |
|
1227 |
(-10 digitByteAt:1) printStringRadix:16 |
|
1228 |
(-10 digitByteAt:3) printStringRadix:16 |
|
1229 |
" |
|
1230 |
! |
|
1231 |
||
701 | 1232 |
digitLength |
2815 | 1233 |
"return the number bytes required to represent this Integer. |
1234 |
For negative receivers, the digitLength of its absolute value |
|
1235 |
is returned." |
|
1236 |
||
1237 |
%{ /* NOCONTEXT */ |
|
1238 |
||
1239 |
INT val = __intVal(self); |
|
1240 |
||
1241 |
if (val < 0) { |
|
1242 |
val = -val; |
|
1243 |
} |
|
1244 |
#ifdef alpha64 |
|
1245 |
if (val & 0xFFFFFFFF00000000L) { |
|
1246 |
if (val & 0xFFFF000000000000L) { |
|
1247 |
if (val & 0xFF00000000000000L) { |
|
1248 |
RETURN ( __MKSMALLINT(8)); |
|
1249 |
} else { |
|
1250 |
RETURN ( __MKSMALLINT(7)); |
|
1251 |
} |
|
1252 |
} else { |
|
1253 |
if (val & 0x0000FF0000000000L) { |
|
1254 |
RETURN ( __MKSMALLINT(6)); |
|
1255 |
} else { |
|
1256 |
RETURN ( __MKSMALLINT(5)); |
|
1257 |
} |
|
1258 |
} |
|
1259 |
} |
|
1260 |
#endif |
|
1261 |
||
1262 |
if (val & 0xFFFF0000) { |
|
1263 |
if (val & 0xFF000000) { |
|
1264 |
RETURN ( __MKSMALLINT(4)); |
|
1265 |
} else { |
|
1266 |
RETURN ( __MKSMALLINT(3)); |
|
1267 |
} |
|
1268 |
} else { |
|
1269 |
if (val & 0x0000FF00) { |
|
1270 |
RETURN ( __MKSMALLINT(2)); |
|
1271 |
} else { |
|
1272 |
RETURN ( __MKSMALLINT(1)); |
|
1273 |
} |
|
1274 |
} |
|
1275 |
||
1276 |
%}. |
|
701 | 1277 |
^ self abs highBit - 1 // 8 + 1 |
2815 | 1278 |
|
1279 |
" |
|
1280 |
16rFF00000000000000 digitLength |
|
1281 |
-16rFF00000000000000 digitLength |
|
1282 |
||
1283 |
16rFF000000 digitLength |
|
1284 |
16rFF0000 digitLength |
|
1285 |
16rFF00 digitLength |
|
1286 |
16rFF digitLength |
|
1287 |
-16rFF000000 digitLength |
|
1288 |
-16rFF0000 digitLength |
|
1289 |
-16rFF00 digitLength |
|
1290 |
-16rFF digitLength |
|
1291 |
" |
|
1 | 1292 |
! ! |
1293 |
||
701 | 1294 |
!SmallInteger methodsFor:'catching messages'! |
1 | 1295 |
|
701 | 1296 |
basicAt:index |
1297 |
"catch indexed access - report an error |
|
1298 |
defined here since basicAt: in Object ommits the SmallInteger check." |
|
1299 |
||
1300 |
self notIndexed |
|
1 | 1301 |
! |
1302 |
||
701 | 1303 |
basicAt:index put:anObject |
1304 |
"catch indexed access - report an error |
|
1305 |
defined here since basicAt:put: in Object ommits the SmallInteger check." |
|
1306 |
||
1307 |
self notIndexed |
|
1308 |
! |
|
1 | 1309 |
|
701 | 1310 |
basicSize |
1311 |
"return the number of indexed instvars - SmallIntegers have none. |
|
1312 |
Defined here since basicSize in Object ommits the SmallInteger check." |
|
1313 |
||
1314 |
^ 0 |
|
1315 |
! |
|
1316 |
||
1317 |
size |
|
1318 |
"return the number of indexed instvars - SmallIntegers have none." |
|
1319 |
||
1320 |
^ 0 |
|
1 | 1321 |
! ! |
1322 |
||
1323 |
!SmallInteger methodsFor:'coercing and converting'! |
|
1324 |
||
701 | 1325 |
asCharacter |
1326 |
"Return a character with the receiver as ascii value" |
|
41 | 1327 |
|
701 | 1328 |
^ Character value:self |
1 | 1329 |
! |
1330 |
||
1331 |
asFloat |
|
1332 |
"return a Float with same value as receiver" |
|
1333 |
||
1334 |
%{ /* NOCONTEXT */ |
|
1335 |
||
1336 |
OBJ newFloat; |
|
1133 | 1337 |
double dVal = (double)__intVal(self); |
1 | 1338 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1339 |
__qMKFLOAT(newFloat, dVal); |
1 | 1340 |
RETURN ( newFloat ); |
1341 |
%} |
|
1342 |
! |
|
1343 |
||
1344 |
asLargeInteger |
|
1345 |
"return a LargeInteger with same value as receiver" |
|
1346 |
||
1347 |
^ LargeInteger value:self |
|
1348 |
! |
|
1349 |
||
1199 | 1350 |
asShortFloat |
1351 |
"return a ShortFloat with same value as receiver" |
|
1352 |
||
1353 |
%{ /* NOCONTEXT */ |
|
1354 |
||
1355 |
OBJ dummy = @global(ShortFloat); |
|
1356 |
OBJ newFloat; |
|
1357 |
float fVal = (float)__intVal(self); |
|
1358 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1359 |
__qMKSFLOAT(newFloat, fVal); |
1199 | 1360 |
RETURN ( newFloat ); |
1361 |
%} |
|
1362 |
! |
|
1363 |
||
701 | 1364 |
coerce:aNumber |
1365 |
"return aNumber converted into receivers type" |
|
1366 |
||
1367 |
^ aNumber asInteger |
|
1368 |
! |
|
1369 |
||
1370 |
generality |
|
1371 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1372 |
||
1373 |
^ 20 |
|
1336 | 1374 |
! |
1375 |
||
1376 |
signExtendedByteValue |
|
1377 |
"return a smallInteger from sign-extending the 8'th bit. |
|
1378 |
May be useful for communication interfaces" |
|
1379 |
||
1380 |
%{ /* NOCONTEXT */ |
|
2781 | 1381 |
INT i = __intVal(self); |
1336 | 1382 |
|
1383 |
if (i & 0x80) { |
|
3892 | 1384 |
i = i | ~0xFFL; |
1336 | 1385 |
} else { |
3457
ca75a27af2f6
signExtendedByteValue for alpha64
Claus Gittinger <cg@exept.de>
parents:
3434
diff
changeset
|
1386 |
i = i & 0x7F; |
1336 | 1387 |
} |
1388 |
||
1389 |
RETURN (__MKSMALLINT(i)); |
|
1390 |
%} |
|
1391 |
||
1392 |
" |
|
1393 |
16rFF signExtendedByteValue |
|
1394 |
16r7F signExtendedByteValue |
|
1395 |
" |
|
1396 |
! |
|
1397 |
||
1398 |
signExtendedShortValue |
|
1399 |
"return a smallInteger from sign-extending the 16'th bit. |
|
1400 |
May be useful for communication interfaces" |
|
1401 |
||
1402 |
%{ /* NOCONTEXT */ |
|
2781 | 1403 |
INT i = __intVal(self); |
1336 | 1404 |
|
1405 |
if (i & 0x8000) { |
|
3892 | 1406 |
i = i | ~0xFFFFL; |
1336 | 1407 |
} else { |
3458
084d1511cd2a
same for signExtendedShortValue (alpha)
Claus Gittinger <cg@exept.de>
parents:
3457
diff
changeset
|
1408 |
i = i & 0x7FFF; |
1336 | 1409 |
} |
1410 |
||
1411 |
RETURN (__MKSMALLINT(i)); |
|
1412 |
%} |
|
1413 |
||
1414 |
" |
|
3892 | 1415 |
16rFFFF signExtendedShortValue |
1336 | 1416 |
16r7FFF signExtendedShortValue |
1417 |
" |
|
701 | 1418 |
! ! |
1419 |
||
1420 |
!SmallInteger methodsFor:'comparing'! |
|
1421 |
||
1422 |
< aNumber |
|
1423 |
"return true, if the argument is greater than the receiver" |
|
1424 |
||
1425 |
%{ /* NOCONTEXT */ |
|
1426 |
||
1427 |
if (__isSmallInteger(aNumber)) { |
|
1428 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1429 |
RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false ); |
701 | 1430 |
#else |
1431 |
/* tag bit does not change ordering */ |
|
1432 |
RETURN ( ((INT)self < (INT)aNumber) ? true : false ); |
|
1433 |
#endif |
|
1434 |
} |
|
1435 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1436 |
RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false ); |
701 | 1437 |
} |
1438 |
%} |
|
1439 |
. |
|
1440 |
^ aNumber lessFromInteger:self |
|
1441 |
"^ self retry:#< coercing:aNumber" |
|
1442 |
! |
|
1443 |
||
1444 |
<= aNumber |
|
1445 |
"return true, if the argument is greater or equal" |
|
1446 |
||
1447 |
%{ /* NOCONTEXT */ |
|
1448 |
||
1449 |
if (__isSmallInteger(aNumber)) { |
|
1450 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1451 |
RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false ); |
701 | 1452 |
#else |
1453 |
/* tag bit does not change ordering */ |
|
1454 |
RETURN ( ((INT)self <= (INT)aNumber) ? true : false ); |
|
1455 |
#endif |
|
1456 |
} |
|
1457 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1458 |
RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false ); |
701 | 1459 |
} |
1460 |
%} |
|
1461 |
. |
|
1462 |
^ self retry:#<= coercing:aNumber |
|
1463 |
! |
|
1464 |
||
1465 |
= aNumber |
|
1466 |
"return true, if the arguments value is equal to mine" |
|
1467 |
||
1468 |
%{ /* NOCONTEXT */ |
|
1469 |
||
1470 |
if (aNumber == self) { |
|
1471 |
RETURN ( true ); |
|
1472 |
} |
|
1473 |
if (! __isNonNilObject(aNumber)) { |
|
1474 |
/* a smallint or nil */ |
|
1475 |
RETURN ( false ); |
|
1476 |
} |
|
1477 |
||
1478 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1479 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false ); |
701 | 1480 |
} |
1481 |
%} |
|
1482 |
. |
|
1483 |
aNumber respondsToArithmetic ifFalse:[^ false]. |
|
1484 |
^ self retry:#= coercing:aNumber |
|
1485 |
! |
|
1486 |
||
1487 |
> aNumber |
|
1488 |
"return true, if the argument is less than the receiver" |
|
1489 |
||
1490 |
%{ /* NOCONTEXT */ |
|
1491 |
||
1492 |
if (__isSmallInteger(aNumber)) { |
|
1493 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1494 |
RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false ); |
701 | 1495 |
#else |
1496 |
/* tag bit does not change ordering */ |
|
1497 |
RETURN ( ((INT)self > (INT)aNumber) ? true : false ); |
|
1498 |
#endif |
|
1499 |
} |
|
1500 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1501 |
RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false ); |
701 | 1502 |
} |
1503 |
%} |
|
1504 |
. |
|
1505 |
^ self retry:#> coercing:aNumber |
|
1506 |
! |
|
1507 |
||
1508 |
>= aNumber |
|
1509 |
"return true, if the argument is less or equal" |
|
1510 |
||
1511 |
%{ /* NOCONTEXT */ |
|
1512 |
||
1513 |
if (__isSmallInteger(aNumber)) { |
|
1514 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1515 |
RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false ); |
701 | 1516 |
#else |
1517 |
/* tag bit does not change ordering */ |
|
1518 |
RETURN ( ((INT)self >= (INT)aNumber) ? true : false ); |
|
1519 |
#endif |
|
1520 |
} |
|
1521 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1522 |
RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false ); |
701 | 1523 |
} |
1524 |
%} |
|
1525 |
. |
|
1526 |
^ self retry:#>= coercing:aNumber |
|
1527 |
! |
|
1 | 1528 |
|
701 | 1529 |
hash |
1530 |
"return an integer useful for hashing on value" |
|
1531 |
||
1532 |
self >= 0 ifTrue:[^ self]. |
|
1533 |
^ self negated |
|
1534 |
! |
|
1535 |
||
1536 |
identityHash |
|
1537 |
"return an integer useful for hashing on identity" |
|
1538 |
||
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1539 |
self >= 0 ifTrue:[^ self]. |
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1540 |
^ self negated |
1963
ea26c7b9ca1d
experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
1541 |
|
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1542 |
"Modified: 11.11.1996 / 18:42:14 / cg" |
701 | 1543 |
! |
1544 |
||
1545 |
max:aNumber |
|
1546 |
"return the receiver or the argument, whichever is greater" |
|
1547 |
||
1548 |
%{ /* NOCONTEXT */ |
|
1549 |
||
1550 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 1551 |
#if TAG_INT == 1 |
1552 |
/* tag bit does not change ordering */ |
|
1553 |
if ((INT)(self) > (INT)(aNumber)) |
|
701 | 1554 |
#else |
2216 | 1555 |
if (__intVal(self) > __intVal(aNumber)) |
701 | 1556 |
#endif |
2216 | 1557 |
{ |
701 | 1558 |
RETURN ( self ); |
1559 |
} |
|
1560 |
RETURN ( aNumber ); |
|
1561 |
} |
|
1562 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1563 |
if ( (double)__intVal(self) > __floatVal(aNumber) ) { |
701 | 1564 |
RETURN ( self ); |
1565 |
} |
|
1566 |
RETURN ( aNumber ); |
|
1567 |
} |
|
2216 | 1568 |
%}. |
1569 |
"/ fallback for non-smallInteger argument |
|
1570 |
||
701 | 1571 |
(self > aNumber) ifTrue:[^ self]. |
1572 |
^ aNumber |
|
1573 |
! |
|
1574 |
||
1575 |
min:aNumber |
|
1576 |
"return the receiver or the argument, whichever is smaller" |
|
1577 |
||
1578 |
%{ /* NOCONTEXT */ |
|
1579 |
||
1580 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 1581 |
#if TAG_INT == 1 |
1582 |
/* tag bit does not change ordering */ |
|
1583 |
if ((INT)(self) < (INT)(aNumber)) |
|
701 | 1584 |
#else |
2216 | 1585 |
if (__intVal(self) < __intVal(aNumber)) |
701 | 1586 |
#endif |
2216 | 1587 |
{ |
701 | 1588 |
RETURN ( self ); |
1589 |
} |
|
1590 |
RETURN ( aNumber ); |
|
1591 |
} |
|
1592 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1593 |
if ( (double)__intVal(self) < __floatVal(aNumber) ) { |
701 | 1594 |
RETURN ( self ); |
1595 |
} |
|
1596 |
RETURN ( aNumber ); |
|
1597 |
} |
|
2216 | 1598 |
%}. |
1599 |
"/ fallback for non-smallInteger argument |
|
1600 |
||
701 | 1601 |
(self < aNumber) ifTrue:[^ self]. |
1602 |
^ aNumber |
|
1603 |
! |
|
1604 |
||
1605 |
~= aNumber |
|
1606 |
"return true, if the arguments value is not equal to mine" |
|
1607 |
||
1608 |
%{ /* NOCONTEXT */ |
|
1609 |
||
1610 |
if (aNumber == self) { |
|
1611 |
RETURN ( false ); |
|
1612 |
} |
|
1613 |
if (! __isNonNilObject(aNumber)) { |
|
1614 |
/* a smallint or nil */ |
|
1615 |
RETURN ( true ); |
|
1616 |
} |
|
1617 |
||
1618 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1619 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? false : true ); |
701 | 1620 |
} |
2216 | 1621 |
%}. |
701 | 1622 |
aNumber respondsToArithmetic ifFalse:[^ true]. |
1623 |
^ self retry:#~= coercing:aNumber |
|
1624 |
! ! |
|
1625 |
||
1626 |
!SmallInteger methodsFor:'copying'! |
|
1627 |
||
1628 |
deepCopy |
|
1629 |
"return a deep copy of myself |
|
1630 |
- reimplemented here since smallintegers are unique" |
|
1631 |
||
1632 |
^ self |
|
1633 |
! |
|
1634 |
||
1635 |
deepCopyUsing:aDictionary |
|
1636 |
"return a deep copy of myself |
|
1637 |
- reimplemented here since smallintegers are unique" |
|
1638 |
||
1639 |
^ self |
|
1640 |
! |
|
1641 |
||
1642 |
shallowCopy |
|
1643 |
"return a shallow copy of myself |
|
1644 |
- reimplemented here since smallintegers are unique" |
|
1645 |
||
1646 |
^ self |
|
1647 |
! |
|
1648 |
||
1649 |
simpleDeepCopy |
|
1650 |
"return a deep copy of myself |
|
1651 |
- reimplemented here since smallintegers are unique" |
|
1652 |
||
1653 |
^ self |
|
1 | 1654 |
! ! |
1655 |
||
214 | 1656 |
!SmallInteger methodsFor:'iteration'! |
1 | 1657 |
|
1658 |
timesRepeat:aBlock |
|
357 | 1659 |
"evaluate the argument, aBlock self times. |
1660 |
Reimplemented as primitive for speed" |
|
1 | 1661 |
|
357 | 1662 |
%{ |
1663 |
REGISTER INT tmp; |
|
1664 |
static struct inlineCache blockVal = __ILC0(0); |
|
1 | 1665 |
|
357 | 1666 |
tmp = __intVal(self); |
1667 |
if (tmp > 0) { |
|
1668 |
if (__isBlockLike(aBlock) |
|
1133 | 1669 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(0))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1670 |
{ |
2254 | 1671 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1672 |
|
2216 | 1673 |
/* |
2678 | 1674 |
* specially tuned version for compiled blocks, |
1675 |
* (the most common case) |
|
2216 | 1676 |
*/ |
2254 | 1677 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1678 |
#ifdef PARANOIA |
1679 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
|
1680 |
#endif |
|
1681 |
) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1682 |
|
357 | 1683 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1684 |
|
2254 | 1685 |
# define BLOCK_ARG aBlock |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1686 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1687 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1688 |
|
2254 | 1689 |
# define BLOCK_ARG rHome |
1690 |
REGISTER OBJ rHome; |
|
2678 | 1691 |
|
1692 |
/* |
|
1693 |
* home on stack - no need to refetch |
|
1694 |
*/ |
|
2254 | 1695 |
rHome = __BlockInstPtr(aBlock)->b_home; |
1696 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1697 |
#endif |
2254 | 1698 |
{ |
2604
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1699 |
#ifdef WIN32 |
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1700 |
# undef UNROLL_LOOPS |
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1701 |
#endif |
2693 | 1702 |
|
2216 | 1703 |
#ifdef UNROLL_LOOPS |
1704 |
||
2254 | 1705 |
/* |
1706 |
* you are not supposed to program like this - I know what I do |
|
1707 |
*/ |
|
1708 |
while (tmp > 8) { |
|
1709 |
if (InterruptPending != nil) goto interrupted0; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1710 |
continue0: |
2254 | 1711 |
(*codeVal)(BLOCK_ARG); |
1712 |
if (InterruptPending != nil) goto interrupted1; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1713 |
continue1: |
2254 | 1714 |
(*codeVal)(BLOCK_ARG); |
1715 |
if (InterruptPending != nil) goto interrupted2; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1716 |
continue2: |
2254 | 1717 |
(*codeVal)(BLOCK_ARG); |
1718 |
if (InterruptPending != nil) goto interrupted3; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1719 |
continue3: |
2254 | 1720 |
(*codeVal)(BLOCK_ARG); |
1721 |
if (InterruptPending != nil) goto interrupted4; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1722 |
continue4: |
2254 | 1723 |
(*codeVal)(BLOCK_ARG); |
1724 |
if (InterruptPending != nil) goto interrupted5; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1725 |
continue5: |
2254 | 1726 |
(*codeVal)(BLOCK_ARG); |
1727 |
if (InterruptPending != nil) goto interrupted6; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1728 |
continue6: |
2254 | 1729 |
(*codeVal)(BLOCK_ARG); |
1730 |
if (InterruptPending != nil) goto interrupted7; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1731 |
continue7: |
2254 | 1732 |
(*codeVal)(BLOCK_ARG); |
1733 |
tmp -= 8; |
|
1734 |
} |
|
2216 | 1735 |
#endif /* UNROLL_LOOPS */ |
2254 | 1736 |
do { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1737 |
if (InterruptPending != nil) goto interruptedX; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1738 |
continueX: |
2254 | 1739 |
(*codeVal)(BLOCK_ARG); |
1740 |
} while(--tmp); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1741 |
|
2254 | 1742 |
RETURN (self); |
2693 | 1743 |
if (0) { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1744 |
#ifdef UNROLL_LOOPS |
2693 | 1745 |
interrupted0: |
1746 |
__interruptL(@line); goto continue0; |
|
1747 |
interrupted1: |
|
1748 |
__interruptL(@line); goto continue1; |
|
1749 |
interrupted2: |
|
1750 |
__interruptL(@line); goto continue2; |
|
1751 |
interrupted3: |
|
1752 |
__interruptL(@line); goto continue3; |
|
1753 |
interrupted4: |
|
1754 |
__interruptL(@line); goto continue4; |
|
1755 |
interrupted5: |
|
1756 |
__interruptL(@line); goto continue5; |
|
1757 |
interrupted6: |
|
1758 |
__interruptL(@line); goto continue6; |
|
1759 |
interrupted7: |
|
1760 |
__interruptL(@line); goto continue7; |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1761 |
#endif /* UNROLL_LOOPS */ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1762 |
interruptedX: |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1763 |
__interruptL(@line); goto continueX; |
2693 | 1764 |
} |
394 | 1765 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1766 |
} |
394 | 1767 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1768 |
|
2216 | 1769 |
# undef BLOCK_ARG |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1770 |
|
400 | 1771 |
#ifdef NEW_BLOCK_CALL |
2216 | 1772 |
# define BLOCK_ARG aBlock |
1773 |
# define IBLOCK_ARG nil |
|
400 | 1774 |
#else |
2216 | 1775 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
1776 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
400 | 1777 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1778 |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1779 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1780 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1781 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1782 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1783 |
do { |
2254 | 1784 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1785 |
|
2254 | 1786 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1787 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1788 |
* arg is a compiled block with code - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1789 |
* directly call it without going through Block>>value |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1790 |
* however, if there is an interrupt, refetch the code pointer. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1791 |
*/ |
2649 | 1792 |
/* stay here, while no interrupts are pending ... */ |
1793 |
do { |
|
1794 |
(*codeVal)(BLOCK_ARG); |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1795 |
if (InterruptPending != nil) goto outerLoop; |
2649 | 1796 |
} while (--tmp); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1797 |
RETURN (self); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1798 |
} else { |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1799 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1800 |
|
2216 | 1801 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1802 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1803 |
* arg is a compiled block with bytecode - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1804 |
* directly call interpreter without going through Block>>value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1805 |
*/ |
2216 | 1806 |
__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1807 |
} else { |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1808 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1809 |
* arg is something else - call it with #value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1810 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1811 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1812 |
} |
400 | 1813 |
} |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1814 |
outerLoop: ; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1815 |
} while (--tmp); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1816 |
|
2216 | 1817 |
# undef BLOCK_ARG |
1818 |
# undef IBLOCK_ARG |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1819 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1820 |
RETURN (self); |
357 | 1821 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1822 |
|
394 | 1823 |
/* |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1824 |
* not a block-like thingy - call it with #value |
394 | 1825 |
*/ |
1826 |
do { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1827 |
if (InterruptPending != nil) __interruptL(@line); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1828 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
394 | 1829 |
} while(--tmp); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1830 |
RETURN (self); |
357 | 1831 |
} |
1832 |
%} |
|
1833 |
||
1834 |
"/ |count "{ Class: SmallInteger }" | |
|
1835 |
"/ |
|
1836 |
"/ count := self. |
|
1837 |
"/ [count > 0] whileTrue:[ |
|
1838 |
"/ aBlock value. |
|
1839 |
"/ count := count - 1 |
|
1840 |
"/ ] |
|
1 | 1841 |
! |
1842 |
||
701 | 1843 |
to:stop by:incr do:aBlock |
1844 |
"reimplemented as primitive for speed" |
|
1845 |
||
1846 |
%{ |
|
1847 |
REGISTER INT tmp, step; |
|
1848 |
REGISTER INT final; |
|
1849 |
static struct inlineCache blockVal = __ILC1(0); |
|
1850 |
||
1851 |
if (__bothSmallInteger(incr, stop)) { |
|
1133 | 1852 |
tmp = __intVal(self); |
1853 |
final = __intVal(stop); |
|
1854 |
step = __intVal(incr); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1855 |
|
701 | 1856 |
if (__isBlockLike(aBlock) |
1133 | 1857 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1858 |
{ |
2254 | 1859 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1860 |
|
2216 | 1861 |
/* |
1862 |
* specially tuned version for static compiled blocks, called with |
|
1863 |
* home on the stack (the most common case) |
|
1864 |
*/ |
|
2254 | 1865 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1866 |
#ifdef PARANOIA |
1867 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
|
1868 |
#endif |
|
1869 |
) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1870 |
|
701 | 1871 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1872 |
|
2254 | 1873 |
# define BLOCK_ARG aBlock |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1874 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1875 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1876 |
|
2254 | 1877 |
# define BLOCK_ARG rHome |
1878 |
REGISTER OBJ rHome; |
|
1879 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
1880 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1881 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1882 |
#endif |
2254 | 1883 |
{ |
1884 |
if (step < 0) { |
|
1885 |
if (step == -1) { |
|
1886 |
while (tmp >= final) { |
|
1887 |
if (InterruptPending != nil) __interruptL(@line); |
|
1888 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1889 |
tmp--; |
|
2216 | 1890 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1891 |
} else { |
2254 | 1892 |
while (tmp >= final) { |
2216 | 1893 |
if (InterruptPending != nil) __interruptL(@line); |
2254 | 1894 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2216 | 1895 |
tmp += step; |
1896 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1897 |
} |
2254 | 1898 |
} else { |
1899 |
if (step == 1) { |
|
1900 |
while (tmp <= final) { |
|
1901 |
if (InterruptPending != nil) __interruptL(@line); |
|
1902 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1903 |
tmp++; |
|
1904 |
} |
|
1905 |
} else { |
|
1906 |
while (tmp <= final) { |
|
1907 |
if (InterruptPending != nil) __interruptL(@line); |
|
1908 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1909 |
tmp += step; |
|
1910 |
} |
|
1911 |
} |
|
2216 | 1912 |
} |
2254 | 1913 |
RETURN (self); |
2216 | 1914 |
} |
1915 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1916 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1917 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1918 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1919 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1920 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1921 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1922 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1923 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1924 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1925 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1926 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1927 |
# define IBLOCK_ARG nil |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1928 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1929 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1930 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1931 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1932 |
|
701 | 1933 |
if (step < 0) { |
1934 |
while (tmp >= final) { |
|
2254 | 1935 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1936 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1937 |
if (InterruptPending != nil) __interruptL(@line); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1938 |
|
2254 | 1939 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 1940 |
/* |
1941 |
* arg is a compiled block with code - |
|
1942 |
* directly call it without going through Block>>value |
|
1943 |
*/ |
|
2254 | 1944 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1945 |
} else { |
2216 | 1946 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1947 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1948 |
* arg is a compiled block with bytecode - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1949 |
* directly call interpreter without going through Block>>value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1950 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1951 |
#ifdef PASS_ARG_POINTER |
2216 | 1952 |
{ |
1953 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1954 |
|
2216 | 1955 |
idx = __MKSMALLINT(tmp); |
1956 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
1957 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1958 |
#else |
2216 | 1959 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1960 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1961 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1962 |
} else { |
2216 | 1963 |
/* |
1964 |
* arg is something else - call it with #value |
|
1965 |
*/ |
|
1966 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1967 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1968 |
} |
701 | 1969 |
tmp += step; |
1970 |
} |
|
1971 |
} else { |
|
1972 |
while (tmp <= final) { |
|
2254 | 1973 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1974 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1975 |
if (InterruptPending != nil) __interruptL(@line); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1976 |
|
2254 | 1977 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 1978 |
/* |
1979 |
* arg is a compiled block with code - |
|
1980 |
* directly call it without going through Block>>value |
|
1981 |
*/ |
|
2254 | 1982 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2216 | 1983 |
} else { |
1984 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
1985 |
/* |
|
1986 |
* arg is a compiled block with bytecode - |
|
1987 |
* directly call interpreter without going through Block>>value |
|
1988 |
*/ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1989 |
#ifdef PASS_ARG_POINTER |
2216 | 1990 |
{ |
1991 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1992 |
|
2216 | 1993 |
idx = __MKSMALLINT(tmp); |
1994 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
1995 |
} |
|
701 | 1996 |
#else |
2216 | 1997 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1998 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1999 |
|
2216 | 2000 |
} else { |
2001 |
/* |
|
2002 |
* arg is something else - call it with #value: |
|
2003 |
*/ |
|
2004 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
2005 |
} |
|
2006 |
} |
|
2007 |
tmp += step; |
|
2008 |
} |
|
701 | 2009 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2010 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2011 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2012 |
# undef IBLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2013 |
|
701 | 2014 |
} else { |
2015 |
/* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2016 |
* arg is something else - call it with #value: |
701 | 2017 |
*/ |
2018 |
if (step < 0) { |
|
2019 |
while (tmp >= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2020 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 2021 |
|
2022 |
(*blockVal.ilc_func)(aBlock, |
|
2023 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2024 |
nil, &blockVal, |
1133 | 2025 |
__MKSMALLINT(tmp)); |
701 | 2026 |
tmp += step; |
2027 |
} |
|
2028 |
} else { |
|
2029 |
while (tmp <= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2030 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 2031 |
|
2032 |
(*blockVal.ilc_func)(aBlock, |
|
2033 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2034 |
nil, &blockVal, |
1133 | 2035 |
__MKSMALLINT(tmp)); |
701 | 2036 |
tmp += step; |
2037 |
} |
|
2038 |
} |
|
2039 |
} |
|
2040 |
RETURN ( self ); |
|
2041 |
} |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
2042 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2043 |
"/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2044 |
"/ arrive here if stop is not a smallInteger |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2045 |
"/ pass on to super ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2046 |
|
701 | 2047 |
^ super to:stop by:incr do:aBlock |
2048 |
||
2049 |
" |
|
2050 |
1 to:10 by:3 do:[:i | i printNewline] |
|
2051 |
" |
|
2052 |
! |
|
2053 |
||
1 | 2054 |
to:stop do:aBlock |
62 | 2055 |
"evaluate aBlock for every integer between (and including) the receiver |
2056 |
and the argument, stop. |
|
357 | 2057 |
Reimplemented as primitive for speed" |
1 | 2058 |
|
2059 |
%{ |
|
2060 |
REGISTER INT tmp; |
|
2061 |
INT final; |
|
216 | 2062 |
static struct inlineCache blockVal = __ILC1(0); |
1 | 2063 |
|
252 | 2064 |
if (__isSmallInteger(stop)) { |
1133 | 2065 |
tmp = __intVal(self); |
2066 |
final = __intVal(stop); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2067 |
|
214 | 2068 |
if (__isBlockLike(aBlock) |
1133 | 2069 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2070 |
{ |
2216 | 2071 |
/* |
2072 |
* specially tuned version for the most common case, |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2073 |
* where called with home on the stack |
2216 | 2074 |
*/ |
2254 | 2075 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2076 |
|
2254 | 2077 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2078 |
||
13 | 2079 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2080 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2081 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2082 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2083 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2084 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2085 |
# define BLOCK_ARG rHome |
2216 | 2086 |
REGISTER OBJ rHome; |
2087 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
2088 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2089 |
#endif |
400 | 2090 |
{ |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2091 |
|
2678 | 2092 |
#ifdef PARANOIA |
2093 |
if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
|
2094 |
#endif |
|
2095 |
{ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2096 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2097 |
* static compiled blocks ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2098 |
*/ |
2216 | 2099 |
#ifdef UNROLL_LOOPS |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2100 |
/* |
2693 | 2101 |
* The following code is designed to run as fast as possible; |
2102 |
* - taken branches only if interrupts are pending |
|
2103 |
* - only forward branches (which are usually predicted as not taken) |
|
2104 |
* - unrolled the loop |
|
2105 |
* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2106 |
* you are not supposed to program like this - I know what I do |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2107 |
*/ |
2693 | 2108 |
# if TAG_INT==1 |
2770 | 2109 |
INT t8 = (INT)(__MKSMALLINT(tmp+8)); |
2110 |
tmp = (INT)(__MKSMALLINT(tmp)); |
|
2111 |
final = (INT)(__MKSMALLINT(final)); |
|
2693 | 2112 |
# else |
2770 | 2113 |
INT t8 = tmp+8; |
2693 | 2114 |
# endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2115 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2116 |
for (;;) { |
2693 | 2117 |
|
2118 |
while (t8 <= final) { |
|
2119 |
# if TAG_INT==1 |
|
2770 | 2120 |
t8 += (INT)(__MASKSMALLINT(8)); |
2693 | 2121 |
# else |
2122 |
t8 += 8; |
|
2123 |
# endif |
|
2124 |
if (InterruptPending != nil) goto interrupted0; |
|
2125 |
continue0: |
|
2126 |
# if TAG_INT==1 |
|
2127 |
(*codeVal)(BLOCK_ARG, tmp); |
|
2128 |
# else |
|
2129 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2130 |
# endif |
|
2131 |
if (InterruptPending != nil) goto interrupted1; |
|
2132 |
continue1: |
|
2133 |
# if TAG_INT==1 |
|
2770 | 2134 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) ); |
2693 | 2135 |
# else |
2136 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1)); |
|
2137 |
# endif |
|
2138 |
if (InterruptPending != nil) goto interrupted2; |
|
2139 |
continue2: |
|
2140 |
# if TAG_INT==1 |
|
2770 | 2141 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) ); |
2693 | 2142 |
# else |
2143 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2)); |
|
2144 |
# endif |
|
2145 |
if (InterruptPending != nil) goto interrupted3; |
|
2146 |
continue3: |
|
2147 |
# if TAG_INT==1 |
|
2770 | 2148 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) ); |
2693 | 2149 |
# else |
2150 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3)); |
|
2151 |
# endif |
|
2152 |
if (InterruptPending != nil) goto interrupted4; |
|
2153 |
continue4: |
|
2154 |
# if TAG_INT==1 |
|
2770 | 2155 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) ); |
2693 | 2156 |
# else |
2157 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4)); |
|
2158 |
# endif |
|
2159 |
if (InterruptPending != nil) goto interrupted5; |
|
2160 |
continue5: |
|
2161 |
# if TAG_INT==1 |
|
2770 | 2162 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) ); |
2693 | 2163 |
# else |
2164 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5)); |
|
2165 |
# endif |
|
2166 |
if (InterruptPending != nil) goto interrupted6; |
|
2167 |
continue6: |
|
2168 |
# if TAG_INT==1 |
|
2770 | 2169 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) ); |
2693 | 2170 |
# else |
2171 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6)); |
|
2172 |
# endif |
|
2173 |
if (InterruptPending != nil) goto interrupted7; |
|
2174 |
continue7: |
|
2175 |
# if TAG_INT==1 |
|
2770 | 2176 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) ); |
2693 | 2177 |
# else |
2178 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7)); |
|
2179 |
# endif |
|
2180 |
||
2181 |
# if TAG_INT==1 |
|
2770 | 2182 |
tmp += (INT)(__MASKSMALLINT(8)); |
2693 | 2183 |
# else |
2184 |
tmp += 8; |
|
2185 |
# endif |
|
2186 |
} |
|
2187 |
while (tmp <= final) { |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2188 |
if (InterruptPending != nil) goto interruptedX; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2189 |
continueX: |
2693 | 2190 |
# if TAG_INT==1 |
2191 |
(*codeVal)(BLOCK_ARG, tmp); |
|
2770 | 2192 |
tmp += (INT)(__MASKSMALLINT(1)); |
2693 | 2193 |
# else |
2194 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2195 |
tmp++; |
|
2196 |
# endif |
|
2197 |
} |
|
2198 |
RETURN (self); |
|
2199 |
||
2216 | 2200 |
if (0) { |
2201 |
/* |
|
2202 |
* no discussion about those gotos ... |
|
2203 |
* ... its better for your CPU's pipelines |
|
2204 |
* (if you dont understand why, just dont argue). |
|
2205 |
*/ |
|
2206 |
interrupted7: |
|
2207 |
__interruptL(@line); goto continue7; |
|
2208 |
interrupted6: |
|
2209 |
__interruptL(@line); goto continue6; |
|
2210 |
interrupted5: |
|
2211 |
__interruptL(@line); goto continue5; |
|
2212 |
interrupted4: |
|
2213 |
__interruptL(@line); goto continue4; |
|
2214 |
interrupted3: |
|
2215 |
__interruptL(@line); goto continue3; |
|
2216 |
interrupted2: |
|
2217 |
__interruptL(@line); goto continue2; |
|
2218 |
interrupted1: |
|
2219 |
__interruptL(@line); goto continue1; |
|
2220 |
interrupted0: |
|
2221 |
__interruptL(@line); goto continue0; |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2222 |
interruptedX: |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2223 |
__interruptL(@line); goto continueX; |
2216 | 2224 |
} |
2640 | 2225 |
} |
2641 | 2226 |
#else |
2640 | 2227 |
while (tmp <= final) { |
2228 |
if (InterruptPending != nil) __interruptL(@line); |
|
2229 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2230 |
tmp ++; |
|
2216 | 2231 |
} |
2640 | 2232 |
RETURN (self); |
2641 | 2233 |
#endif /* UNROLL_LOOPS */ |
2216 | 2234 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2235 |
|
2216 | 2236 |
/* |
2237 |
* mhmh - seems to be a block with dynamic code |
|
2238 |
* must refetch, to allow dynamic recompilation or code flush. |
|
2239 |
*/ |
|
2240 |
while (tmp <= final) { |
|
2241 |
if (InterruptPending != nil) __interruptL(@line); |
|
2254 | 2242 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break; |
2243 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2216 | 2244 |
tmp ++; |
2245 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2246 |
|
2216 | 2247 |
if (tmp > final) { |
2248 |
RETURN (self); |
|
2249 |
} |
|
2250 |
} |
|
2251 |
} |
|
2252 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2253 |
|
2216 | 2254 |
# undef BLOCK_ARG |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2255 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2256 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2257 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2258 |
# define IBLOCK_ARG nil |
400 | 2259 |
#else |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2260 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2261 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
400 | 2262 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
2263 |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2264 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2265 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2266 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2267 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2268 |
while (tmp <= final) { |
2254 | 2269 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2270 |
|
2254 | 2271 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 2272 |
/* |
2273 |
* arg is a compiled block with code - |
|
2274 |
* directly call it without going through Block>>value |
|
2275 |
*/ |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2276 |
|
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2277 |
/* stay here, while no interrupts are pending ... */ |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2278 |
do { |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2279 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2280 |
if (InterruptPending != nil) goto outerLoop; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2281 |
tmp++; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2282 |
} while (tmp <= final); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2283 |
RETURN (self); |
2216 | 2284 |
} else { |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2285 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2286 |
|
2216 | 2287 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2288 |
/* |
|
2289 |
* arg is a compiled block with bytecode - |
|
2290 |
* directly call interpreter without going through Block>>value |
|
2291 |
*/ |
|
400 | 2292 |
#ifdef PASS_ARG_POINTER |
2216 | 2293 |
{ |
2294 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2295 |
|
2216 | 2296 |
idx = __MKSMALLINT(tmp); |
2297 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
2298 |
} |
|
400 | 2299 |
#else |
2216 | 2300 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
400 | 2301 |
#endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2302 |
|
2216 | 2303 |
} else { |
2304 |
/* |
|
2305 |
* arg is something else - call it with #value: |
|
2306 |
*/ |
|
2307 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
2308 |
} |
|
2309 |
} |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2310 |
outerLoop: ; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2311 |
tmp++; |
214 | 2312 |
} |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2313 |
|
2216 | 2314 |
# undef BLOCK_ARG |
2315 |
# undef IBLOCK_ARG |
|
1 | 2316 |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2317 |
RETURN (self); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2318 |
} |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2319 |
/* |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2320 |
* arg is something else - call it with #value: |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2321 |
*/ |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2322 |
while (tmp <= final) { |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2323 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2324 |
|
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2325 |
(*blockVal.ilc_func)(aBlock, |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2326 |
@symbol(value:), |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2327 |
nil, &blockVal, |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2328 |
__MKSMALLINT(tmp)); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2329 |
tmp++; |
214 | 2330 |
} |
2331 |
RETURN ( self ); |
|
1 | 2332 |
} |
400 | 2333 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2334 |
|
400 | 2335 |
"/ |
2336 |
"/ arrive here if stop is not a smallInteger |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2337 |
"/ pass on to super ... |
400 | 2338 |
"/ |
62 | 2339 |
^ super to:stop do:aBlock |
2340 |
||
216 | 2341 |
" |
2342 |
1 to:10 do:[:i | i printNewline] |
|
2343 |
" |
|
701 | 2344 |
! ! |
1 | 2345 |
|
701 | 2346 |
!SmallInteger methodsFor:'misc math'! |
1 | 2347 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2348 |
divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2349 |
"return an array filled with self // aNumber and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2350 |
self \\ aNumber. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2351 |
The result is only defined for positive receiver and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2352 |
argument." |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2353 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2354 |
%{ /* NOCONTEXT */ |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2355 |
INT val, div, mod, mySelf; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2356 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2357 |
if (__isSmallInteger(aNumber) && |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2358 |
(val = __intVal(aNumber)) > 0) { |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2359 |
mySelf = __intVal(self); |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2360 |
div = mySelf / val; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2361 |
mod = mySelf % val; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2362 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2363 |
RETURN (__ARRAY_WITH2( __MKSMALLINT(div), |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2364 |
__MKSMALLINT(mod))); |
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2365 |
} |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2366 |
%}. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2367 |
^ super divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2368 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2369 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2370 |
10 // 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2371 |
10 \\ 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2372 |
10 divMod:3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2373 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2374 |
! |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2375 |
|
701 | 2376 |
gcd:anInteger |
2377 |
"return the greatest common divisor (Euclid's algorithm). |
|
2378 |
This has been redefined here for more speed since due to the |
|
2379 |
use of gcd in Fraction code, it has become time-critical for |
|
2380 |
some code. (thanx to MessageTally)" |
|
2381 |
||
2382 |
%{ /* NOCONTEXT */ |
|
1 | 2383 |
|
701 | 2384 |
if (__isSmallInteger(anInteger)) { |
2791
646ce29939a5
oops - alpha has funny modulu results ...
Claus Gittinger <cg@exept.de>
parents:
2788
diff
changeset
|
2385 |
INT orgArg, ttt, selfInt, orgSelfInt, temp; |
701 | 2386 |
|
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2387 |
ttt = orgArg = __intVal(anInteger); |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2388 |
if (ttt) { |
2791
646ce29939a5
oops - alpha has funny modulu results ...
Claus Gittinger <cg@exept.de>
parents:
2788
diff
changeset
|
2389 |
selfInt = orgSelfInt = __intVal(self); |
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2390 |
while (ttt != 0) { |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2391 |
temp = selfInt % ttt; |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2392 |
selfInt = ttt; |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2393 |
ttt = temp; |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2394 |
} |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2395 |
/* |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2396 |
* since its not defined in C, what the sign of |
3135 | 2397 |
* a modulus result is when the arg is negative, |
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2398 |
* change it explicitely here ... |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2399 |
*/ |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2400 |
if (orgArg < 0) { |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2401 |
/* result should be negative */ |
2791
646ce29939a5
oops - alpha has funny modulu results ...
Claus Gittinger <cg@exept.de>
parents:
2788
diff
changeset
|
2402 |
if (orgSelfInt > 0) selfInt = -selfInt; |
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2403 |
} else { |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2404 |
/* result should be positive */ |
2791
646ce29939a5
oops - alpha has funny modulu results ...
Claus Gittinger <cg@exept.de>
parents:
2788
diff
changeset
|
2405 |
if (orgSelfInt < 0) selfInt = -selfInt; |
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2406 |
} |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2407 |
RETURN ( __MKSMALLINT(selfInt) ); |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2408 |
} |
1 | 2409 |
} |
2410 |
%} |
|
2411 |
. |
|
701 | 2412 |
^ super gcd:anInteger |
2413 |
! |
|
62 | 2414 |
|
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2415 |
gcd_helper:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2416 |
"same as gcd - see knuth & Integer>>gcd:" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2417 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2418 |
^ self gcd:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2419 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2420 |
"Created: 1.3.1997 / 16:58:01 / cg" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2421 |
! |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2422 |
|
701 | 2423 |
intlog10 |
2424 |
"return the truncation of log10 of the receiver - |
|
2425 |
stupid implementation; used to find out the number of digits needed |
|
2426 |
to print a number/and for conversion to a LargeInteger. |
|
2427 |
Implemented that way, to allow for tiny systems without a Float class |
|
2428 |
(i.e. without log)." |
|
2 | 2429 |
|
701 | 2430 |
self <= 0 ifTrue:[ |
2431 |
self error:'logarithm of negative integer' |
|
2 | 2432 |
]. |
701 | 2433 |
self < 10 ifTrue:[^ 1]. |
2434 |
self < 100 ifTrue:[^ 2]. |
|
2435 |
self < 1000 ifTrue:[^ 3]. |
|
2436 |
self < 10000 ifTrue:[^ 4]. |
|
2437 |
self < 100000 ifTrue:[^ 5]. |
|
2438 |
self < 1000000 ifTrue:[^ 6]. |
|
2439 |
self < 10000000 ifTrue:[^ 7]. |
|
2440 |
self < 100000000 ifTrue:[^ 8]. |
|
2441 |
self < 1000000000 ifTrue:[^ 9]. |
|
2442 |
^ 10 |
|
2 | 2443 |
! ! |
2444 |
||
3135 | 2445 |
!SmallInteger methodsFor:'modulo arithmetic'! |
2 | 2446 |
|
701 | 2447 |
plus:aNumber |
2448 |
"return the sum of the receiver and the argument, as SmallInteger. |
|
2449 |
The argument must be another SmallInteger. |
|
3135 | 2450 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2451 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 2452 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2453 |
and can therefore speed things up by not going through LargeIntegers." |
41 | 2454 |
|
701 | 2455 |
%{ /* NOCONTEXT */ |
2456 |
||
2457 |
if (__isSmallInteger(aNumber)) { |
|
3135 | 2458 |
INT sum; |
2459 |
||
2460 |
sum = __intVal(self) + __intVal(aNumber); |
|
2785 | 2461 |
#ifdef alpha64 |
3135 | 2462 |
sum &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2463 |
#else |
3135 | 2464 |
sum &= 0x7FFFFFFF; |
2785 | 2465 |
#endif |
3135 | 2466 |
RETURN ( __MKSMALLINT(sum)); |
701 | 2467 |
} |
2785 | 2468 |
%}. |
701 | 2469 |
self primitiveFailed |
2 | 2470 |
! |
2471 |
||
701 | 2472 |
subtract:aNumber |
2473 |
"return the difference of the receiver and the argument, as SmallInteger. |
|
2474 |
The argument must be another SmallInteger. |
|
3135 | 2475 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2476 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 2477 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2478 |
and can therefore speed things up by not going through LargeIntegers." |
2479 |
||
2480 |
%{ /* NOCONTEXT */ |
|
2 | 2481 |
|
701 | 2482 |
if (__isSmallInteger(aNumber)) { |
3135 | 2483 |
INT diff; |
2484 |
||
2485 |
diff = __intVal(self) - __intVal(aNumber); |
|
2785 | 2486 |
#ifdef alpha64 |
3135 | 2487 |
diff &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2488 |
#else |
3135 | 2489 |
diff &= 0x7FFFFFFF; |
2785 | 2490 |
#endif |
3135 | 2491 |
RETURN ( __MKSMALLINT(diff)); |
701 | 2492 |
} |
2216 | 2493 |
%}. |
701 | 2494 |
self primitiveFailed |
2495 |
! |
|
2496 |
||
2497 |
times:aNumber |
|
2498 |
"return the product of the receiver and the argument, as SmallInteger. |
|
2499 |
The argument must be another SmallInteger. |
|
3135 | 2500 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2501 |
smallInteger range is returned (i.e. the low bits of the product). |
3135 | 2502 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2503 |
and can therefore speed things up by not going through LargeIntegers." |
2504 |
||
2505 |
%{ /* NOCONTEXT */ |
|
2506 |
||
2507 |
if (__isSmallInteger(aNumber)) { |
|
3135 | 2508 |
INT prod; |
2509 |
||
2510 |
prod = __intVal(self) * __intVal(aNumber); |
|
2785 | 2511 |
#ifdef alpha64 |
3135 | 2512 |
prod &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2513 |
#else |
3135 | 2514 |
prod &= 0x7FFFFFFF; |
2785 | 2515 |
#endif |
3135 | 2516 |
RETURN ( __MKSMALLINT(prod)); |
701 | 2517 |
} |
2216 | 2518 |
%}. |
701 | 2519 |
self primitiveFailed |
1 | 2520 |
! ! |
2521 |
||
2522 |
!SmallInteger methodsFor:'printing & storing'! |
|
2523 |
||
62 | 2524 |
printOn:aStream |
68 | 2525 |
"append my printstring (base 10) to aStream." |
62 | 2526 |
|
2527 |
aStream nextPutAll:(self printString) |
|
2528 |
! |
|
2529 |
||
701 | 2530 |
printOn:aStream base:radix |
2531 |
"append my printstring in any number base to aStream. |
|
2532 |
The radix argument should be between 2 and 36." |
|
2533 |
||
2534 |
aStream nextPutAll:(self printStringRadix:radix) |
|
2535 |
! |
|
2536 |
||
1 | 2537 |
printString |
2538 |
"return my printstring (base 10)" |
|
2539 |
||
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2540 |
"since this was heavily used in some applications, |
68 | 2541 |
here is an exception to the rule of basing printString |
2542 |
upon the printOn: method." |
|
2543 |
||
1 | 2544 |
%{ /* NOCONTEXT */ |
2545 |
||
2546 |
char buffer[30]; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2547 |
char *cp; |
1 | 2548 |
OBJ newString; |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2549 |
INT myValue; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2550 |
int negative = 0; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2551 |
|
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2552 |
#ifdef SLOW_CODE |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2553 |
/* |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2554 |
* this takes twice as long as the code below ... |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2555 |
* (printf is soooo slow) |
369 | 2556 |
*/ |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2557 |
# ifdef alpha64 |
2781 | 2558 |
sprintf(buffer, "%ld", __intVal(self)); |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2559 |
# else |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2560 |
sprintf(buffer, "%d", __intVal(self)); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2561 |
# endif |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2562 |
newString = __MKSTRING(buffer COMMA_SND); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2563 |
|
2781 | 2564 |
#else |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2565 |
myValue = __intVal(self); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2566 |
if (myValue == 0) { |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2567 |
RETURN (__MKSTRING_L("0", 1)); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2568 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2569 |
if (myValue < 0) { |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2570 |
negative = 1; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2571 |
myValue = -myValue; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2572 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2573 |
cp = buffer + sizeof(buffer) - 1; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2574 |
*cp-- = '\0'; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2575 |
while (myValue != 0) { |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2576 |
*cp = '0' + (myValue % 10); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2577 |
myValue = myValue / 10; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2578 |
cp--; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2579 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2580 |
if (negative) { |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2581 |
*cp-- = '-'; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2582 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2583 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
2781 | 2584 |
#endif |
282 | 2585 |
if (newString != nil) { |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2586 |
RETURN (newString); |
282 | 2587 |
} |
2588 |
%}. |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2589 |
"/ only arrive here, |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2590 |
"/ when having memory problems (i.e. no space for string) ... |
282 | 2591 |
^ super printString |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2592 |
|
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2593 |
" |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2594 |
1234 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2595 |
0 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2596 |
-100 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2597 |
" |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2598 |
|
1 | 2599 |
! |
2600 |
||
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2601 |
printStringRadix:base |
62 | 2602 |
"return my printstring (optimized for bases 16, 10 and 8)" |
1 | 2603 |
|
3705 | 2604 |
|s| |
2605 |
||
2606 |
%{ |
|
2607 |
char buffer[64+3]; /* for alpha, base 2 plus sign */ |
|
2608 |
char *cp; |
|
1 | 2609 |
OBJ newString; |
3705 | 2610 |
INT myValue; |
2611 |
int negative = 0; |
|
3706 | 2612 |
INT __base; |
1 | 2613 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2614 |
if (__isSmallInteger(base)) { |
3707 | 2615 |
__base = __intVal(base); |
3706 | 2616 |
|
3705 | 2617 |
#ifdef SLOW_CODE |
3706 | 2618 |
switch (__base) { |
2619 |
case 10: |
|
2788 | 2620 |
#ifdef alpha64 |
3706 | 2621 |
format = "%ld"; |
2781 | 2622 |
#else |
3706 | 2623 |
format = "%d"; |
2781 | 2624 |
#endif |
3706 | 2625 |
break; |
2626 |
case 16: |
|
2788 | 2627 |
#ifdef alpha64 |
3706 | 2628 |
format = "%lx"; |
2781 | 2629 |
#else |
3706 | 2630 |
format = "%x"; |
3705 | 2631 |
#endif |
3706 | 2632 |
break; |
2633 |
case 8: |
|
3705 | 2634 |
#ifdef alpha64 |
3706 | 2635 |
format = "%lo"; |
3705 | 2636 |
#else |
3706 | 2637 |
format = "%o"; |
2781 | 2638 |
#endif |
3706 | 2639 |
break; |
3705 | 2640 |
} |
2641 |
||
2642 |
if (format) { |
|
2643 |
/* |
|
2644 |
* actually only needed on sparc: since thisContext is |
|
2645 |
* in a global register, which gets destroyed by printf, |
|
2646 |
* manually save it here - very stupid ... |
|
2647 |
*/ |
|
2648 |
__BEGIN_PROTECT_REGISTERS__ |
|
2649 |
||
2650 |
sprintf(buffer, format, __intVal(self)); |
|
2651 |
||
2652 |
__END_PROTECT_REGISTERS__ |
|
2653 |
||
2654 |
newString = __MKSTRING(buffer COMMA_SND); |
|
2655 |
if (newString != nil) { |
|
2656 |
RETURN (newString); |
|
2657 |
} |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2658 |
} |
3705 | 2659 |
#else |
3706 | 2660 |
if ((__base <= 36) && (__base > 1)) { |
3705 | 2661 |
myValue = __intVal(self); |
2662 |
if (myValue == 0) { |
|
2663 |
RETURN (__MKSTRING_L("0", 1)); |
|
2664 |
} |
|
2665 |
if (myValue < 0) { |
|
2666 |
negative = 1; |
|
2667 |
myValue = -myValue; |
|
2668 |
} |
|
2669 |
cp = buffer + sizeof(buffer) - 1; |
|
2670 |
*cp-- = '\0'; |
|
2671 |
while (myValue != 0) { |
|
2672 |
int digit; |
|
2673 |
||
3706 | 2674 |
digit = myValue % __base; |
3705 | 2675 |
if (digit <= 9) { |
2676 |
*cp = '0' + digit; |
|
2677 |
} else { |
|
2678 |
*cp = 'A' + digit - 10; |
|
2679 |
} |
|
3706 | 2680 |
myValue = myValue / __base; |
3705 | 2681 |
cp--; |
2682 |
} |
|
2683 |
if (negative) { |
|
2684 |
*cp-- = '-'; |
|
2685 |
} |
|
2686 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
|
2687 |
if (newString != nil) { |
|
2688 |
RETURN (newString); |
|
2689 |
} |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2690 |
} |
3705 | 2691 |
#endif |
1 | 2692 |
} |
314 | 2693 |
%}. |
3705 | 2694 |
"/ arrive here, for bad base, |
2695 |
"/ or when having memory problems (i.e. no space for string) ... |
|
2696 |
||
2697 |
"/ |
|
2698 |
"/ fall back for seldom used bases |
|
2699 |
"/ Notice: cannt use super>>printStringRadix: here, |
|
2700 |
"/ since that would lead to endless recursion ... |
|
2701 |
"/ (a consequence of reversing printOn / printString functionality) |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2702 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2703 |
s := WriteStream on:(String new:10). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2704 |
super printOn:s base:base. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2705 |
^ s contents. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2706 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2707 |
" |
3705 | 2708 |
127 printStringRadix:16 |
2709 |
123 printStringRadix:16 |
|
2710 |
123 printStringRadix:10 |
|
2711 |
123 printStringRadix:8 |
|
2712 |
123 printStringRadix:3 |
|
2713 |
123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2714 |
123 printStringRadix:1 |
3705 | 2715 |
|
2716 |
-127 printStringRadix:16 |
|
2717 |
-123 printStringRadix:16 |
|
2718 |
-123 printStringRadix:10 |
|
2719 |
-123 printStringRadix:8 |
|
2720 |
-123 printStringRadix:3 |
|
2721 |
-123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2722 |
" |
1 | 2723 |
! |
2724 |
||
2725 |
printfPrintString:formatString |
|
2726 |
"non-portable, but sometimes useful. |
|
2727 |
return a printed representation of the receiver |
|
62 | 2728 |
as specified by formatString, which is defined by the C- |
2729 |
function 'printf'. |
|
2730 |
No checking for string overrun - the resulting string |
|
2731 |
must be shorter than 256 chars or else ... |
|
2781 | 2732 |
This method is NONSTANDARD and may be removed without notice; |
2733 |
it is provided to allow special conversions in very special |
|
2734 |
situaltions. |
|
2735 |
Notice that a conversion may not be portable; for example, |
|
2736 |
to correctly convert an int on a 64-bit alpha, a %ld is required, |
|
2737 |
while other systems may be happy with a %d ... |
|
2738 |
Use at your own risk (if at all)" |
|
1 | 2739 |
|
13 | 2740 |
%{ /* STACK: 400 */ |
1 | 2741 |
|
2742 |
char buffer[256]; |
|
314 | 2743 |
OBJ s; |
1 | 2744 |
|
62 | 2745 |
if (__isString(formatString)) { |
379 | 2746 |
/* |
2747 |
* actually only needed on sparc: since thisContext is |
|
2748 |
* in a global register, which gets destroyed by printf, |
|
2749 |
* manually save it here - very stupid ... |
|
2750 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2751 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2752 |
|
1133 | 2753 |
sprintf(buffer, __stringVal(formatString), __intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2754 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2755 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2756 |
|
1133 | 2757 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 2758 |
if (s != nil) { |
2759 |
RETURN (s); |
|
2760 |
} |
|
1 | 2761 |
} |
314 | 2762 |
%}. |
1 | 2763 |
self primitiveFailed |
2764 |
||
2765 |
"123 printfPrintString:'%%d -> %d'" |
|
2766 |
"123 printfPrintString:'%%6d -> %6d'" |
|
2767 |
"123 printfPrintString:'%%x -> %x'" |
|
2768 |
"123 printfPrintString:'%%4x -> %4x'" |
|
2769 |
"123 printfPrintString:'%%04x -> %04x'" |
|
2770 |
! ! |
|
701 | 2771 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2772 |
!SmallInteger methodsFor:'private'! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2773 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2774 |
sign:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2775 |
"private: for protocol completeness with LargeIntegers" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2776 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2777 |
|absVal| |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2778 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2779 |
absVal := self abs. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2780 |
aNumber < 0 ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2781 |
^ absVal negated |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2782 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2783 |
aNumber == 0 ifTrue:[^ 0]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2784 |
^ absVal |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2785 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2786 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2787 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2788 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2789 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2790 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2791 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2792 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2793 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2794 |
! ! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2795 |
|
701 | 2796 |
!SmallInteger methodsFor:'testing'! |
2797 |
||
2798 |
between:min and:max |
|
2799 |
"return true if the receiver is less than or equal to the argument max |
|
2800 |
and greater than or equal to the argument min. |
|
2801 |
- reimplemented here for speed" |
|
2802 |
||
2803 |
%{ /* NOCONTEXT */ |
|
2804 |
||
2805 |
if (__bothSmallInteger(min, max)) { |
|
2806 |
REGISTER INT selfVal; |
|
2807 |
||
1133 | 2808 |
selfVal = __intVal(self); |
2809 |
if (selfVal < __intVal(min)) { |
|
701 | 2810 |
RETURN ( false ); |
2811 |
} |
|
1133 | 2812 |
if (selfVal > __intVal(max)) { |
701 | 2813 |
RETURN ( false ); |
2814 |
} |
|
2815 |
RETURN ( true ); |
|
2816 |
} |
|
2216 | 2817 |
%}. |
701 | 2818 |
(self < min) ifTrue:[^ false]. |
2819 |
(self > max) ifTrue:[^ false]. |
|
2820 |
^ true |
|
2821 |
! |
|
2822 |
||
2823 |
even |
|
2824 |
"return true, if the receiver is even" |
|
2825 |
||
2826 |
%{ /* NOCONTEXT */ |
|
2827 |
||
2216 | 2828 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true ); |
701 | 2829 |
%} |
2830 |
! |
|
2831 |
||
2832 |
negative |
|
2833 |
"return true, if the receiver is less than zero |
|
2834 |
reimplemented here for speed" |
|
2835 |
||
2836 |
%{ /* NOCONTEXT */ |
|
2837 |
||
2216 | 2838 |
#if TAG_INT == 1 |
701 | 2839 |
/* tag bit does not change sign */ |
2840 |
RETURN ( ((INT)(self) < 0) ? true : false ); |
|
2216 | 2841 |
#else |
2842 |
RETURN ( (__intVal(self) < 0) ? true : false ); |
|
701 | 2843 |
#endif |
2844 |
%} |
|
2845 |
! |
|
2846 |
||
2847 |
odd |
|
2848 |
"return true, if the receiver is odd" |
|
2849 |
||
2850 |
%{ /* NOCONTEXT */ |
|
2851 |
||
2216 | 2852 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false ); |
701 | 2853 |
%} |
2854 |
! |
|
2855 |
||
2856 |
positive |
|
2857 |
"return true, if the receiver is not negative |
|
2858 |
reimplemented here for speed" |
|
2859 |
||
2860 |
%{ /* NOCONTEXT */ |
|
2861 |
||
2216 | 2862 |
#if TAG_INT == 1 |
701 | 2863 |
/* tag bit does not change sign */ |
2864 |
RETURN ( ((INT)(self) >= 0) ? true : false ); |
|
2216 | 2865 |
#else |
2866 |
RETURN ( (__intVal(self) >= 0) ? true : false ); |
|
701 | 2867 |
#endif |
2868 |
%} |
|
2869 |
! |
|
2870 |
||
2871 |
sign |
|
2872 |
"return the sign of the receiver |
|
2873 |
reimplemented here for speed" |
|
2874 |
||
2875 |
%{ /* NOCONTEXT */ |
|
2876 |
||
1133 | 2877 |
INT val = __intVal(self); |
701 | 2878 |
|
2879 |
if (val < 0) { |
|
1133 | 2880 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 2881 |
} |
2882 |
if (val > 0) { |
|
1133 | 2883 |
RETURN ( __MKSMALLINT(1) ); |
701 | 2884 |
} |
1133 | 2885 |
RETURN ( __MKSMALLINT(0) ); |
701 | 2886 |
%} |
2887 |
! |
|
2888 |
||
2889 |
strictlyPositive |
|
2890 |
"return true, if the receiver is greater than zero |
|
2891 |
reimplemented here for speed" |
|
2892 |
||
2893 |
%{ /* NOCONTEXT */ |
|
2894 |
||
2216 | 2895 |
#if TAG_INT == 1 |
701 | 2896 |
/* tag bit does not change sign */ |
2897 |
RETURN ( ((INT)(self) > 0) ? true : false ); |
|
2216 | 2898 |
#else |
2899 |
RETURN ( (__intVal(self) > 0) ? true : false ); |
|
701 | 2900 |
#endif |
2901 |
%} |
|
2902 |
! ! |
|
2903 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2904 |
!SmallInteger class methodsFor:'documentation'! |
701 | 2905 |
|
2906 |
version |
|
4065 | 2907 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.109 1999-03-19 21:39:37 cg Exp $' |
701 | 2908 |
! ! |