author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 10 Jun 2013 17:32:35 +0100 | |
branch | jv |
changeset 18066 | 89d51443ba6f |
parent 18062 | 014678b4657a |
parent 15325 | 48feb23cd013 |
child 18070 | d262e3aecaca |
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 |
" |
|
5410 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
1 | 14 |
Integer subclass:#SmallInteger |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
15 |
instanceVariableNames:'' |
15259 | 16 |
classVariableNames:'ZeroString' |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
17 |
poolDictionaries:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
18 |
category:'Magnitude-Numbers' |
1 | 19 |
! |
20 |
||
14755 | 21 |
!SmallInteger primitiveDefinitions! |
22 |
%{ |
|
23 |
#include <stdio.h> |
|
24 |
%} |
|
25 |
! ! |
|
26 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
27 |
!SmallInteger class methodsFor:'documentation'! |
1 | 28 |
|
88 | 29 |
copyright |
30 |
" |
|
31 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
214 | 32 |
All Rights Reserved |
88 | 33 |
|
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
68 | 43 |
documentation |
44 |
" |
|
8908 | 45 |
SmallIntegers are Integers in the range of at least +/- 2^30 |
2785 | 46 |
(i.e. 31 bits, which is not a guaranteed: on an alpha, 63 bits are used, |
47 |
if the system was configured for 64bit mode). |
|
88 | 48 |
|
68 | 49 |
These are no real objects - they have no instances (not even storage !!) |
50 |
and cannot be subclassed. |
|
51 |
The reason is to save both storage and runtime by not collecting |
|
8908 | 52 |
SmallIntegers in the system. SmallInts are marked by having the TAG_INT |
53 |
bit set, in contrast to all other objects which do not. |
|
54 |
Since this knowledge is hardwired into the system (and there is no |
|
55 |
class-field stored with SmallIntegers) there can be no subclass of |
|
88 | 56 |
SmallInteger (sorry). |
57 |
||
58 |
If you really need this kind of thing, create a subclass of Integer, |
|
59 |
with an instance variable holding the value. |
|
1295 | 60 |
|
61 |
[author:] |
|
2216 | 62 |
Claus Gittinger |
1556 | 63 |
|
64 |
[see also:] |
|
2216 | 65 |
Number |
66 |
Float Fraction FixedPoint |
|
67 |
LargeInteger |
|
68 | 68 |
" |
69 |
! ! |
|
1 | 70 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
71 |
!SmallInteger class methodsFor:'instance creation'! |
1 | 72 |
|
73 |
basicNew |
|
74 |
"catch instance creation |
|
75 |
- SmallIntegers cannot be created with new" |
|
76 |
||
77 |
self error:'instances of SmallInteger cannot be created with new' |
|
78 |
! |
|
79 |
||
80 |
basicNew:size |
|
81 |
"catch instance creation |
|
82 |
- SmallIntegers cannot be created with new" |
|
83 |
||
84 |
self error:'instances of SmallInteger cannot be created with new' |
|
85 |
! ! |
|
86 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
87 |
!SmallInteger class methodsFor:'bit mask constants'! |
701 | 88 |
|
89 |
bitMaskFor:index |
|
90 |
"return a bitmask for the index's bit (index starts at 1)" |
|
91 |
||
92 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
8908 | 93 |
^ SubscriptOutOfBoundsSignal |
94 |
raiseRequestWith:index |
|
95 |
errorString:'index out of bounds' |
|
701 | 96 |
]. |
97 |
^ 1 bitShift:(index - 1) |
|
98 |
! ! |
|
99 |
||
15259 | 100 |
!SmallInteger class methodsFor:'class initialization'! |
101 |
||
102 |
initialize |
|
103 |
ZeroString := '0' |
|
104 |
! ! |
|
105 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
106 |
!SmallInteger class methodsFor:'constants'! |
1 | 107 |
|
108 |
maxBits |
|
68 | 109 |
"return the number of bits in instances of me. |
110 |
For very special uses only - not constant across implementations" |
|
1 | 111 |
|
112 |
%{ /* NOCONTEXT */ |
|
8913 | 113 |
RETURN ( __mkSmallInteger(N_INT_BITS) ); |
1 | 114 |
%} |
2 | 115 |
|
116 |
"SmallInteger maxBits" |
|
1 | 117 |
! |
118 |
||
119 |
maxBytes |
|
68 | 120 |
"return the number of bytes in instances of me. |
121 |
For very special uses only - not constant across implementations" |
|
1 | 122 |
|
123 |
%{ /* NOCONTEXT */ |
|
8913 | 124 |
RETURN ( __mkSmallInteger(N_INT_BITS / 8 + 1) ); |
1 | 125 |
%} |
2 | 126 |
|
3684 | 127 |
" |
128 |
SmallInteger maxBytes |
|
129 |
" |
|
1 | 130 |
! |
131 |
||
132 |
maxVal |
|
68 | 133 |
"return the largest Integer representable as SmallInteger. |
134 |
For very special uses only - not constant across implementations" |
|
1 | 135 |
|
136 |
%{ /* NOCONTEXT */ |
|
8913 | 137 |
RETURN ( __mkSmallInteger(_MAX_INT) ); |
1 | 138 |
%} |
2 | 139 |
|
140 |
"SmallInteger maxVal" |
|
701 | 141 |
! |
142 |
||
143 |
minVal |
|
144 |
"return the smallest Integer representable as SmallInteger. |
|
145 |
For very special uses only - not constant across implementations" |
|
146 |
||
147 |
%{ /* NOCONTEXT */ |
|
8913 | 148 |
RETURN ( __mkSmallInteger(_MIN_INT) ); |
701 | 149 |
%} |
150 |
||
151 |
"SmallInteger minVal" |
|
1 | 152 |
! ! |
153 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
154 |
!SmallInteger class methodsFor:'queries'! |
3 | 155 |
|
50 | 156 |
canBeSubclassed |
157 |
"return true, if its allowed to create subclasses of the receiver. |
|
3914 | 158 |
Return false here - since it is NOT possible for SmallInteger |
159 |
(due to the tagged representation of SmallIntegers)" |
|
50 | 160 |
|
161 |
^ false |
|
3914 | 162 |
|
163 |
"Modified: / 5.11.1998 / 16:11:27 / cg" |
|
1 | 164 |
! |
165 |
||
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
166 |
hasImmediateInstances |
4661 | 167 |
"return true if this class has immediate instances |
168 |
i.e. if the instances are represented in the pointer itself and |
|
169 |
no real object header/storage is used for the object. |
|
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
170 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
171 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
172 |
^ true |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
173 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
174 |
"Created: 3.6.1997 / 12:01:26 / cg" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
175 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
176 |
|
701 | 177 |
isBuiltInClass |
1264 | 178 |
"return true if this class is known by the run-time-system. |
179 |
Here, true is returned." |
|
1 | 180 |
|
181 |
^ true |
|
1264 | 182 |
|
183 |
"Modified: 23.4.1996 / 16:00:33 / cg" |
|
1 | 184 |
! ! |
185 |
||
186 |
!SmallInteger methodsFor:'arithmetic'! |
|
187 |
||
188 |
* aNumber |
|
11728 | 189 |
"return the product of the receiver and the argument" |
1 | 190 |
|
191 |
%{ /* NOCONTEXT */ |
|
192 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
193 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
194 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
195 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
196 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
197 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
198 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
199 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
200 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
201 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
202 |
|
68 | 203 |
INT myValue, otherValue; |
204 |
unsigned INT productLow, productHi; |
|
205 |
int negative; |
|
206 |
||
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
207 |
# define low16Bits(foo) ((foo) & 0xFFFF) |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
208 |
# define hi16Bits(foo) ((foo) >> 16) |
2785 | 209 |
# define low32Bits(foo) ((foo) & 0xFFFFFFFFL) |
210 |
# define hi32Bits(foo) ((foo) >> 32) |
|
95 | 211 |
|
212 |
/* |
|
213 |
* can we use long long arithmetic ? |
|
4176 | 214 |
* |
215 |
* long-long arithmetic seems to be buggy with some systems |
|
216 |
* (took me a while to find this out :-( |
|
217 |
* (try 10000 * 10000) |
|
95 | 218 |
*/ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
219 |
#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2) |
4184 | 220 |
# define USE_LONGLONG_FOR_MUL |
4176 | 221 |
#endif |
222 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
223 |
#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2) |
4184 | 224 |
# define USE_LONGLONG_FOR_MUL |
95 | 225 |
#endif |
1 | 226 |
|
252 | 227 |
if (__isSmallInteger(aNumber)) { |
14632 | 228 |
myValue = __intVal(self); |
229 |
otherValue = __intVal(aNumber); |
|
2785 | 230 |
|
4184 | 231 |
#if defined(USE_LONGLONG_FOR_MUL) |
14632 | 232 |
{ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
233 |
# if defined(__alpha__) && !defined(__alpha64__) |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
234 |
# define LONGLONG INT64 |
2785 | 235 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
236 |
# define LONGLONG long long |
2785 | 237 |
# endif |
14632 | 238 |
LONGLONG product; |
239 |
||
240 |
product = (LONGLONG)myValue * (LONGLONG)otherValue; |
|
241 |
if ((product >= (LONGLONG)_MIN_INT) |
|
242 |
&& (product <= (LONGLONG)_MAX_INT)) { |
|
243 |
RETURN ( __mkSmallInteger((INT)product) ); |
|
244 |
} |
|
245 |
if (product < 0) { |
|
246 |
negative = -1; |
|
247 |
product = -product; |
|
248 |
} else { |
|
249 |
negative = 1; |
|
250 |
} |
|
251 |
productHi = product >> 32; |
|
252 |
productLow = product & 0xFFFFFFFFL; |
|
253 |
} |
|
4176 | 254 |
#else /* no long-long */ |
14632 | 255 |
negative = 1; |
256 |
if (myValue < 0) { |
|
257 |
negative = -1; |
|
258 |
myValue = -myValue; |
|
259 |
} |
|
260 |
if (otherValue < 0) { |
|
261 |
negative = -negative; |
|
262 |
otherValue = -otherValue; |
|
263 |
} |
|
68 | 264 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
265 |
# if defined(__GNUC__) && defined(__mc68k__) |
14632 | 266 |
asm ("mulu%.l %3,%1:%0" |
267 |
: "=d" ((unsigned long)(productLow)), |
|
268 |
"=d" ((unsigned long)(productHi)) |
|
269 |
: "%0" ((unsigned long)(myValue)), |
|
270 |
"dmi" ((unsigned long)(otherValue))); |
|
68 | 271 |
# else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
272 |
# if defined (__GNUC__) && defined(__i386__) |
14632 | 273 |
asm ("mull %3" |
274 |
: "=a" ((unsigned long)(productLow)), |
|
275 |
"=d" ((unsigned long)(productHi)) |
|
276 |
: "%0" ((unsigned long)(myValue)), |
|
277 |
"rm" ((unsigned long)(otherValue))); |
|
68 | 278 |
# else |
10342 | 279 |
# if defined(WIN32) && defined(__BORLANDC__) |
14632 | 280 |
asm { |
281 |
mov eax, myValue |
|
282 |
mov edx, otherValue |
|
283 |
mul edx |
|
284 |
mov productLow, eax |
|
285 |
mov productHi, edx |
|
286 |
} |
|
4167 | 287 |
# else /* generic */ |
14632 | 288 |
{ |
289 |
unsigned INT pHH, pHL, pLH, pLL; |
|
290 |
unsigned INT low1, low2, hi1, hi2; |
|
291 |
unsigned INT t; |
|
292 |
||
293 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
|
294 |
* |
|
295 |
* this is too slow: |
|
296 |
* since most machines can do 32*32 to 64 bit multiply, |
|
297 |
* (or at least 32*32 with Overflow check) |
|
298 |
* - need more assembler (inline) functions here |
|
299 |
*/ |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
300 |
# if __POINTER_SIZE__ == 8 |
14632 | 301 |
low1 = low32Bits((unsigned INT)myValue); |
302 |
hi1 = hi32Bits((unsigned INT)myValue); |
|
303 |
low2 = low32Bits((unsigned INT)otherValue); |
|
304 |
hi2 = hi32Bits((unsigned INT)otherValue); |
|
4167 | 305 |
# define LLMASK 0xC000000000000000L |
306 |
# else |
|
14632 | 307 |
low1 = low16Bits((unsigned INT)myValue); |
308 |
hi1 = hi16Bits((unsigned INT)myValue); |
|
309 |
low2 = low16Bits((unsigned INT)otherValue); |
|
310 |
hi2 = hi16Bits((unsigned INT)otherValue); |
|
4167 | 311 |
# define LLMASK 0xC0000000 |
312 |
# endif |
|
313 |
||
14632 | 314 |
pLH = low1 * hi2; |
315 |
pHL = hi1 * low2; |
|
316 |
pLL = low1 * low2; |
|
317 |
pHH = hi1 * hi2; |
|
318 |
||
319 |
/* |
|
320 |
* the common case ... |
|
321 |
*/ |
|
322 |
if ((pHL == 0) |
|
323 |
&& (pLH == 0) |
|
324 |
&& (pHH == 0) |
|
325 |
&& ((pLL & LLMASK) == 0)) { |
|
326 |
if (negative < 0) { |
|
327 |
RETURN ( __mkSmallInteger(- ((INT)pLL)) ); |
|
328 |
} |
|
329 |
RETURN ( __mkSmallInteger((INT)pLL) ); |
|
330 |
} |
|
331 |
||
332 |
/* |
|
333 |
* pHH |--------|--------| |
|
334 |
* pLH |--------|--------| |
|
335 |
* pHL |--------|--------| |
|
336 |
* pLL |--------|--------| |
|
337 |
*/ |
|
4167 | 338 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
339 |
# if __POINTER_SIZE__ == 8 |
14632 | 340 |
t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); |
341 |
productLow = (t << 32) + low32Bits(pLL); |
|
342 |
productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); |
|
4167 | 343 |
# else |
14632 | 344 |
t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); |
345 |
productLow = (t << 16) + low16Bits(pLL); |
|
346 |
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); |
|
4167 | 347 |
# endif |
14632 | 348 |
} |
4167 | 349 |
# endif /* ! WIN32 */ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
350 |
# endif /* ! (__GNUC__ && __i386__) */ |
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
351 |
# endif /* ! (__GNUC__ && __mc68k__) */ |
4167 | 352 |
|
14632 | 353 |
if (productHi == 0) { |
354 |
if (negative < 0) { |
|
355 |
if (productLow <= -(_MIN_INT)) { |
|
356 |
RETURN ( __mkSmallInteger(-((INT)productLow)) ); |
|
357 |
} |
|
358 |
} else { |
|
359 |
if (productLow <= _MAX_INT) { |
|
360 |
RETURN ( __mkSmallInteger(productLow) ); |
|
361 |
} |
|
362 |
} |
|
363 |
} |
|
4167 | 364 |
#endif /* ! USE_LONGLONG */ |
365 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
366 |
#if __POINTER_SIZE__ == 8 |
14632 | 367 |
RETURN (__MKLARGEINT128(negative, productLow, productHi)); |
4167 | 368 |
#else |
14632 | 369 |
RETURN (__MKLARGEINT64(negative, productLow, productHi)); |
95 | 370 |
#endif |
283 | 371 |
} else if (__isFloatLike(aNumber)) { |
14632 | 372 |
OBJ newFloat; |
373 |
double val = (double)__intVal(self) * __floatVal(aNumber); |
|
374 |
||
375 |
__qMKFLOAT(newFloat, val); |
|
376 |
RETURN ( newFloat ); |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
377 |
} else if (__isShortFloat(aNumber)) { |
14632 | 378 |
OBJ newFloat; |
379 |
float val = (float)__intVal(self) * __shortFloatVal(aNumber); |
|
380 |
||
381 |
__qMKSFLOAT(newFloat, val); |
|
382 |
RETURN ( newFloat ); |
|
1 | 383 |
} |
2641 | 384 |
%}. |
1 | 385 |
^ aNumber productFromInteger:self |
386 |
! |
|
387 |
||
701 | 388 |
+ aNumber |
389 |
"return the sum of the receivers value and the arguments value" |
|
390 |
||
391 |
%{ /* NOCONTEXT */ |
|
392 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
393 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
394 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
395 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
396 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
397 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
398 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
399 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
400 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
401 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
402 |
|
701 | 403 |
if (__isSmallInteger(aNumber)) { |
404 |
#ifdef _ADD_IO_IO |
|
8908 | 405 |
RETURN ( _ADD_IO_IO(self, aNumber) ); |
701 | 406 |
#else |
8908 | 407 |
REGISTER INT sum; |
408 |
||
409 |
sum = __intVal(self) + __intVal(aNumber); |
|
410 |
if (__ISVALIDINTEGER(sum)) { |
|
8913 | 411 |
RETURN ( __mkSmallInteger(sum) ); |
8908 | 412 |
} |
413 |
RETURN ( __MKLARGEINT(sum) ); |
|
701 | 414 |
#endif |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
415 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
416 |
if (__isFloatLike(aNumber)) { |
8908 | 417 |
OBJ newFloat; |
418 |
double val = (double)__intVal(self) + __floatVal(aNumber); |
|
419 |
||
420 |
__qMKFLOAT(newFloat, val); |
|
421 |
RETURN ( newFloat ); |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
422 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
423 |
if (__isShortFloat(aNumber)) { |
8908 | 424 |
OBJ newFloat; |
425 |
float val = (float)__intVal(self) + __shortFloatVal(aNumber); |
|
426 |
||
427 |
__qMKSFLOAT(newFloat, val); |
|
428 |
RETURN ( newFloat ); |
|
701 | 429 |
} |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
430 |
%}. |
701 | 431 |
^ aNumber sumFromInteger:self |
432 |
! |
|
433 |
||
434 |
- aNumber |
|
435 |
"return the difference of the receivers value and the arguments value" |
|
436 |
||
437 |
%{ /* NOCONTEXT */ |
|
438 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
439 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
440 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
441 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
442 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
443 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
444 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
445 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
446 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
447 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
448 |
|
701 | 449 |
if (__isSmallInteger(aNumber)) { |
450 |
#ifdef _SUB_IO_IO |
|
8908 | 451 |
RETURN ( _SUB_IO_IO(self, aNumber) ); |
701 | 452 |
#else |
8908 | 453 |
REGISTER INT diff; |
454 |
||
455 |
diff = __intVal(self) - __intVal(aNumber); |
|
456 |
if (__ISVALIDINTEGER(diff)) { |
|
8913 | 457 |
RETURN ( __mkSmallInteger(diff) ); |
8908 | 458 |
} |
459 |
RETURN ( __MKLARGEINT(diff) ); |
|
701 | 460 |
#endif |
8908 | 461 |
} |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
462 |
if (__isFloatLike(aNumber)) { |
8908 | 463 |
OBJ newFloat; |
464 |
double val = (double)__intVal(self) - __floatVal(aNumber); |
|
465 |
||
466 |
__qMKFLOAT(newFloat, val); |
|
467 |
RETURN ( newFloat ); |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
468 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
469 |
if (__isShortFloat(aNumber)) { |
8908 | 470 |
OBJ newFloat; |
471 |
float val = (float)__intVal(self) - __shortFloatVal(aNumber); |
|
472 |
||
473 |
__qMKSFLOAT(newFloat, val); |
|
474 |
RETURN ( newFloat ); |
|
701 | 475 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
476 |
%}. |
701 | 477 |
^ aNumber differenceFromInteger:self |
478 |
! |
|
479 |
||
1 | 480 |
/ aNumber |
481 |
"return the quotient of the receivers value and the arguments value" |
|
482 |
||
483 |
%{ /* NOCONTEXT */ |
|
484 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
485 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
486 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
487 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
488 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
489 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
490 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
491 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
492 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
493 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
494 |
|
1 | 495 |
INT me, t, val; |
496 |
double dval; |
|
497 |
||
252 | 498 |
if (__isSmallInteger(aNumber)) { |
8908 | 499 |
val = __intVal(aNumber); |
500 |
if (val != 0) { |
|
501 |
me = __intVal(self); |
|
502 |
t = me / val; |
|
1 | 503 |
#ifdef GOOD_OPTIMIZER |
8908 | 504 |
if (me % val == 0) { |
1 | 505 |
#else |
8908 | 506 |
/* this is stupid - all I want is to look for a remainder ... |
507 |
but most compilers are too stupid and generate an extra modulus |
|
508 |
instruction for "if (me % val)". |
|
509 |
Even if most divide instructions already leave the remainder in |
|
510 |
some register. |
|
511 |
Therefore I use a multiplication which is faster than a modulo |
|
512 |
on most machines. Hint to GNU people :-) |
|
513 |
*/ |
|
514 |
if ((t * val) == me) { |
|
1 | 515 |
#endif |
8913 | 516 |
RETURN ( __mkSmallInteger(t) ); |
8908 | 517 |
} |
518 |
} |
|
1 | 519 |
} else { |
8908 | 520 |
if (__isFloatLike(aNumber)) { |
521 |
dval = __floatVal(aNumber); |
|
522 |
if (dval != 0.0) { |
|
523 |
OBJ newFloat; |
|
524 |
double val = (double)__intVal(self) / dval; |
|
525 |
||
526 |
__qMKFLOAT(newFloat, val); |
|
527 |
RETURN ( newFloat ); |
|
528 |
} |
|
529 |
} |
|
1 | 530 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
531 |
%}. |
1 | 532 |
aNumber isInteger ifTrue:[ |
8908 | 533 |
aNumber == 0 ifTrue:[ |
534 |
^ ZeroDivide raiseRequestWith:thisContext. |
|
535 |
]. |
|
536 |
^ Fraction numerator:self denominator:aNumber |
|
1 | 537 |
]. |
538 |
^ aNumber quotientFromInteger:self |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
539 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
540 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
541 |
8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
542 |
9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
543 |
9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
544 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
545 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
546 |
-8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
547 |
-9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
548 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
549 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
550 |
" |
1 | 551 |
! |
552 |
||
2 | 553 |
// aNumber |
1 | 554 |
"return the integer part of the quotient of the receivers value |
1884 | 555 |
and the arguments value. The result is truncated toward negative infinity |
556 |
and negative, if the operands signs differ. |
|
14795 | 557 |
Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3. |
558 |
Especially surprising: |
|
559 |
-1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1. |
|
6067 | 560 |
The following is always true: |
14795 | 561 |
(receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
562 |
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
|
563 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
564 |
%{ /* NOCONTEXT */ |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
565 |
|
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
566 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
567 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
568 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
569 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
570 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
571 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
572 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
573 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
574 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
575 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
576 |
INT dividend, divisor, rslt; |
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 |
if (__isSmallInteger(aNumber)) { |
14795 | 579 |
divisor = __intVal(aNumber); |
580 |
if (divisor != 0) { |
|
581 |
dividend = __intVal(self); |
|
582 |
rslt = dividend / divisor; |
|
583 |
/* |
|
584 |
* Optimized to speed up positive result |
|
585 |
*/ |
|
586 |
if (rslt <= 0) { |
|
587 |
if (rslt == 0) { |
|
588 |
if ((dividend ^ divisor) < 0) { |
|
589 |
/* |
|
590 |
* result (negative) has been truncated toward 0. |
|
591 |
* Return -1, because we truncate toward negative inf. |
|
592 |
*/ |
|
593 |
rslt = -1; |
|
594 |
} |
|
595 |
} else { |
|
596 |
/* |
|
597 |
* If result (negative) has been truncated toward 0, |
|
598 |
* subtract 1, because we truncate toward negative inf. |
|
599 |
*/ |
|
600 |
if (divisor > 0) { |
|
601 |
if (rslt * divisor > dividend) { |
|
602 |
rslt--; |
|
603 |
} |
|
604 |
} else { |
|
605 |
if (rslt * divisor < dividend) { |
|
606 |
rslt--; |
|
607 |
} |
|
608 |
} |
|
609 |
} |
|
610 |
} |
|
611 |
RETURN ( __mkSmallInteger(rslt) ); |
|
612 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
613 |
} else { |
14795 | 614 |
if (__isFraction(aNumber)) { |
615 |
OBJ t; |
|
616 |
INT num, den; |
|
617 |
||
618 |
t = __FractionInstPtr(aNumber)->f_numerator; |
|
619 |
if (__isSmallInteger(t)) { |
|
620 |
num = __intVal(t); |
|
621 |
t = __FractionInstPtr(aNumber)->f_denominator; |
|
622 |
if (__isSmallInteger(t)) { |
|
623 |
den = __intVal(t); |
|
624 |
RETURN ( __mkSmallInteger(__intVal(self) * den / num )); |
|
625 |
} |
|
626 |
} |
|
627 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
628 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
629 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
630 |
(aNumber = 0) ifTrue:[ |
14795 | 631 |
^ ZeroDivide raiseRequestWith:thisContext. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
632 |
]. |
13006 | 633 |
^ aNumber integerQuotientFromInteger:self |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
634 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
635 |
" |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
636 |
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
|
637 |
-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
|
638 |
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
|
639 |
-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
|
640 |
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
|
641 |
-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
|
642 |
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
|
643 |
-1 // -2 ~~ 0 ifTrue:[self halt]. |
8908 | 644 |
10000 // 3600000 ~~ 0 ifTrue:[self halt]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
645 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
646 |
9 quo:4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
647 |
-9 quo:4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
648 |
9 quo:-4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
649 |
-9 quo:-4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
650 |
" |
13006 | 651 |
|
652 |
"Modified: / 09-08-2010 / 19:50:23 / cg" |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
653 |
! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
654 |
|
2 | 655 |
\\ aNumber |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
656 |
"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
|
657 |
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
|
658 |
m < |aNumber| AND there is an integer k with (k * aNumber + m) = self |
6067 | 659 |
The following is always true: |
14632 | 660 |
(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
661 |
Compare with #rem: |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
662 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
663 |
Redefined for speed." |
1 | 664 |
|
665 |
%{ /* NOCONTEXT */ |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
666 |
|
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
667 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
668 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
669 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
670 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
671 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
672 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
673 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
674 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
675 |
*/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
5988
diff
changeset
|
676 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
677 |
INT dividend, divisor, rem; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
678 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
679 |
if (__isSmallInteger(aNumber) |
14632 | 680 |
&& (divisor = __intVal(aNumber)) != 0) { |
681 |
/* |
|
682 |
* Note that the sign of something modulo a negative number is undefined |
|
683 |
* in C! |
|
684 |
*/ |
|
685 |
dividend = __intVal(self); |
|
686 |
rem = dividend % divisor; |
|
687 |
if (rem) { |
|
688 |
if ((rem ^ divisor) < 0) { |
|
689 |
/* sign of remainder is different from sign of divisor */ |
|
690 |
rem = -rem; |
|
691 |
} |
|
692 |
if ((dividend ^ divisor) < 0) { |
|
693 |
/* different signs, so division would have returned a |
|
694 |
* negative number. |
|
695 |
* C rounds toward zero, this code will simulate |
|
696 |
* rounding towards negative infinity. |
|
697 |
*/ |
|
698 |
rem = divisor - rem; |
|
699 |
} |
|
700 |
} |
|
701 |
RETURN ( __mkSmallInteger(rem) ); |
|
1 | 702 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
703 |
%}. |
2 | 704 |
(aNumber = 0) ifTrue:[ |
14632 | 705 |
^ ZeroDivide raiseRequestWith:thisContext. |
1 | 706 |
]. |
14003 | 707 |
^ aNumber moduloFromInteger:self |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
708 |
|
8908 | 709 |
" |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
710 |
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
|
711 |
-9 \\ 4 == 3 ifFalse:[self halt]. |
8908 | 712 |
9 \\ -4 == -3 ifFalse:[self halt]. |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
713 |
-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
|
714 |
(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
|
715 |
(-9 rem:4) == -1 ifFalse:[self halt]. |
4967
ce7e7852115f
Fix bad result -1 when doing 1000 // 3600000
Stefan Vogel <sv@exept.de>
parents:
4955
diff
changeset
|
716 |
1000 \\ 3600000 == 1000 ifFalse:[self halt] |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
717 |
" |
13006 | 718 |
|
14003 | 719 |
"Modified: / 12-02-2012 / 20:43:40 / cg" |
1 | 720 |
! |
721 |
||
722 |
abs |
|
723 |
"return the absolute value of the receiver |
|
724 |
reimplemented here for speed" |
|
725 |
||
726 |
%{ /* NOCONTEXT */ |
|
727 |
||
1133 | 728 |
INT val = __intVal(self); |
1 | 729 |
|
62 | 730 |
if (val >= 0) { |
8908 | 731 |
RETURN (self); |
62 | 732 |
} |
1 | 733 |
if (val != _MIN_INT) { |
8913 | 734 |
RETURN ( __mkSmallInteger(-val) ); |
1 | 735 |
} |
3430 | 736 |
/* only reached for minVal */ |
737 |
RETURN( __MKLARGEINT(-_MIN_INT)); |
|
324 | 738 |
%}. |
5410 | 739 |
^ super abs |
1 | 740 |
! |
741 |
||
742 |
negated |
|
743 |
"return the negative value of the receiver |
|
744 |
reimplemented here for speed" |
|
745 |
||
746 |
%{ /* NOCONTEXT */ |
|
747 |
||
1133 | 748 |
INT val = __intVal(self); |
1 | 749 |
|
750 |
if (val != _MIN_INT) { |
|
8913 | 751 |
RETURN ( __mkSmallInteger(- val) ); |
1 | 752 |
} |
3430 | 753 |
/* only reached for minVal */ |
754 |
RETURN (__MKLARGEINT( -_MIN_INT)); |
|
324 | 755 |
%}. |
5410 | 756 |
^ 0 - self |
3430 | 757 |
"/ "only reached for minVal" |
758 |
"/ ^ (LargeInteger value:(SmallInteger maxVal)) + 1 |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
759 |
! |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
760 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
761 |
quo:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
762 |
"return the integer part of the quotient of the receivers value |
1884 | 763 |
and the arguments value. The result is truncated towards zero |
8908 | 764 |
and negative, if the operands signs differ.. |
6067 | 765 |
The following is always true: |
8908 | 766 |
(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
767 |
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
|
768 |
for negative results, the remainder is ignored. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
769 |
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
|
770 |
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
|
771 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
772 |
%{ /* NOCONTEXT */ |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
773 |
INT val; |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
774 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
775 |
if (__isSmallInteger(aNumber)) { |
8908 | 776 |
val = __intVal(aNumber); |
777 |
if (val != 0) { |
|
8913 | 778 |
RETURN ( __mkSmallInteger(__intVal(self) / val) ); |
8908 | 779 |
} |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
780 |
} else { |
8908 | 781 |
if (__isFraction(aNumber)) { |
782 |
OBJ t; |
|
783 |
INT num, den; |
|
784 |
||
785 |
t = __FractionInstPtr(aNumber)->f_numerator; |
|
786 |
if (__isSmallInteger(t)) { |
|
787 |
num = __intVal(t); |
|
788 |
t = __FractionInstPtr(aNumber)->f_denominator; |
|
789 |
if (__isSmallInteger(t)) { |
|
790 |
den = __intVal(t); |
|
8913 | 791 |
RETURN ( __mkSmallInteger(__intVal(self) * den / num )); |
8908 | 792 |
} |
793 |
} |
|
794 |
} |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
795 |
} |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
796 |
%}. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
797 |
(aNumber = 0) ifTrue:[ |
8908 | 798 |
^ ZeroDivide raiseRequestWith:thisContext. |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
799 |
]. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
800 |
^ self retry:#quo: coercing:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
801 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
802 |
" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
803 |
9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
804 |
-9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
805 |
9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
806 |
-9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
807 |
" |
1 | 808 |
! ! |
809 |
||
13908 | 810 |
|
15322 | 811 |
|
1 | 812 |
!SmallInteger methodsFor:'bit operators'! |
813 |
||
701 | 814 |
bitAnd:anInteger |
815 |
"return the bitwise-and of the receiver and the argument, anInteger" |
|
1 | 816 |
|
817 |
%{ /* NOCONTEXT */ |
|
818 |
||
701 | 819 |
/* anding the tags doesn't change it */ |
820 |
if (__isSmallInteger(anInteger)) { |
|
8908 | 821 |
RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) ); |
1 | 822 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
823 |
%}. |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
824 |
anInteger class == LargeInteger ifTrue:[ |
8908 | 825 |
^ anInteger bitAnd:self |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
826 |
]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
827 |
^ self retry:#bitAnd: coercing:anInteger |
701 | 828 |
|
829 |
"(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
|
1 | 830 |
! |
831 |
||
8334 | 832 |
bitAt:anIntegerIndex |
11500 | 833 |
"return the value of the index's bit (index starts at 1) as 0 or 1. |
8908 | 834 |
Notice: the result of bitAt: on negative receivers is not |
14632 | 835 |
defined in the language standard (since the implementation |
836 |
is free to choose any internal representation for integers)" |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
837 |
|
8334 | 838 |
%{ /* NOCONTEXT */ |
839 |
||
840 |
if (__isSmallInteger(anIntegerIndex)) { |
|
14632 | 841 |
INT idx = __smallIntegerVal(anIntegerIndex); |
842 |
if (idx > 0) { |
|
843 |
if (idx > N_INT_BITS) { |
|
844 |
RETURN(__mkSmallInteger(0)); |
|
845 |
} |
|
846 |
RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0)); |
|
847 |
} |
|
8334 | 848 |
} |
849 |
%}. |
|
850 |
||
8908 | 851 |
^ SubscriptOutOfBoundsSignal |
14632 | 852 |
raiseRequestWith:anIntegerIndex |
853 |
errorString:'index out of bounds' |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
854 |
|
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
855 |
" |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
856 |
16r00000001 bitAt:0 |
8908 | 857 |
16r00000001 bitAt:1 |
858 |
16r00000001 bitAt:2 |
|
859 |
16r00008000 bitAt:16 |
|
860 |
16r00800000 bitAt:24 |
|
861 |
16r08000000 bitAt:28 |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
862 |
16r10000000 bitAt:29 |
8908 | 863 |
16r20000000 bitAt:30 |
864 |
16r40000000 bitAt:31 |
|
865 |
16r80000000 bitAt:32 |
|
866 |
16r100000000 bitAt:33 |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
867 |
" |
8334 | 868 |
|
869 |
" Smalltalk implementation: |
|
870 |
|mask| |
|
871 |
||
872 |
anIntegerIndex <= 0 ifTrue:[ |
|
14632 | 873 |
^ SubscriptOutOfBoundsSignal |
874 |
raiseRequestWith:anIntegerIndex |
|
875 |
errorString:'index out of bounds' |
|
8334 | 876 |
]. |
877 |
(anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0]. |
|
878 |
mask := 1 bitShift:(anIntegerIndex - 1). |
|
879 |
((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
|
880 |
^ 1 |
|
881 |
" |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
882 |
! |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
883 |
|
3156 | 884 |
bitClear:anInteger |
885 |
"return the bitwise-and of the receiver and the complement of the argument, anInteger, |
|
886 |
returning the receiver with bits of the argument cleared." |
|
887 |
||
888 |
%{ /* NOCONTEXT */ |
|
889 |
||
890 |
/* anding the tags doesn't change it */ |
|
891 |
if (__isSmallInteger(anInteger)) { |
|
8908 | 892 |
RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) ); |
3156 | 893 |
} |
894 |
%}. |
|
895 |
^ self retry:#bitClear: coercing:anInteger |
|
896 |
||
897 |
" |
|
898 |
(2r001010100 bitClear:2r00001111) radixPrintStringRadix:2 |
|
5458 | 899 |
(2r111111111 bitClear:2r00001000) radixPrintStringRadix:2 |
3156 | 900 |
" |
901 |
! |
|
902 |
||
11493 | 903 |
bitCount |
904 |
"return the number of 1-bits in the receiver" |
|
905 |
||
906 |
%{ /* NOCONTEXT */ |
|
13908 | 907 |
unsigned int _cnt; |
13912 | 908 |
unsigned INT _self = __intVal(self); |
909 |
||
15322 | 910 |
# define ALGORIHTM_3 |
911 |
||
912 |
# ifdef ALGORITHM_1 |
|
13908 | 913 |
// old k&r code; might be better if only one or two bits are set |
914 |
||
915 |
_cnt = 0; |
|
11666 | 916 |
while (_self) { |
15322 | 917 |
_cnt++; |
918 |
_self = _self & (_self - 1); |
|
11493 | 919 |
} |
15322 | 920 |
# else |
921 |
# ifdef ALGORITHM_2 |
|
13908 | 922 |
// seems to be faster on the average (and has better worst case) |
923 |
||
924 |
static unsigned char table[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; |
|
925 |
||
926 |
_cnt = 0; |
|
927 |
while (_self) { |
|
15322 | 928 |
_cnt += table[ _self & 0x0F ]; |
929 |
_self >>= 4; |
|
13908 | 930 |
} |
15322 | 931 |
# else |
932 |
# ifdef ALGORIHTM_3 |
|
13912 | 933 |
// the fastest, but hard (impossible) to understand (google for fastest bit count) |
15322 | 934 |
# if __POINTER_SIZE__ == 8 |
13912 | 935 |
unsigned int _v1, _v2; |
936 |
||
937 |
_v1 = _self & 0xFFFFFFFF; |
|
938 |
_v1 = _v1 - ((_v1 >> 1) & 0x55555555); |
|
939 |
_v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333); |
|
940 |
_v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F); |
|
941 |
||
942 |
_v2 = (unsigned int)(_self >> 32); |
|
943 |
_v2 = _v2 - ((_v2 >> 1) & 0x55555555); |
|
944 |
_v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333); |
|
945 |
_v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F); |
|
946 |
||
947 |
_cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24); |
|
15322 | 948 |
# else |
13908 | 949 |
_cnt = _self - ((_self >> 1) & 0x55555555); |
950 |
_cnt = (_cnt & 0x33333333) + ((_cnt >> 2) & 0x33333333); |
|
951 |
_cnt = ((_cnt + (_cnt >> 4)) & 0x0F0F0F0F); |
|
13912 | 952 |
_cnt = (_cnt * 0x01010101) >> 24; |
15322 | 953 |
# endif |
954 |
# else |
|
955 |
error error error |
|
15309 | 956 |
# endif |
13908 | 957 |
# endif |
958 |
# endif |
|
11493 | 959 |
|
960 |
RETURN ( __MKSMALLINT(_cnt)); |
|
961 |
%} |
|
962 |
||
963 |
" |
|
15322 | 964 |
|
13908 | 965 |
1 to:1000000 do:[:n | |
15322 | 966 |
self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) |
13909 | 967 |
]. |
968 |
||
14632 | 969 |
#( |
15322 | 970 |
16r00010000 16r00100000 16r01000000 16r10000000 |
971 |
16r00020000 16r00200000 16r02000000 16r20000000 |
|
972 |
16r00040000 16r00400000 16r04000000 16r40000000 |
|
973 |
16r00080000 16r00800000 16r08000000 16r80000000 |
|
974 |
||
975 |
16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF |
|
976 |
16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE |
|
977 |
16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD |
|
978 |
16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC |
|
13909 | 979 |
) do:[:n | |
15322 | 980 |
self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) |
11493 | 981 |
] |
13908 | 982 |
|
983 |
1 to:10000000 do:[:n | |
|
15322 | 984 |
(n bitCount) |
13908 | 985 |
] |
11493 | 986 |
" |
13908 | 987 |
|
13912 | 988 |
"Modified: / 09-01-2012 / 19:12:41 / cg" |
11493 | 989 |
! |
990 |
||
701 | 991 |
bitInvert |
992 |
"return the value of the receiver with all bits inverted" |
|
62 | 993 |
|
1 | 994 |
%{ /* NOCONTEXT */ |
995 |
||
701 | 996 |
/* invert anything except tag bits */ |
997 |
RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) ); |
|
5412 | 998 |
%}. |
999 |
^ self primitiveFailed |
|
701 | 1000 |
! |
1 | 1001 |
|
701 | 1002 |
bitOr:anInteger |
1003 |
"return the bitwise-or of the receiver and the argument, anInteger" |
|
1004 |
||
1005 |
%{ /* NOCONTEXT */ |
|
1006 |
||
1007 |
/* oring the tags doesn't change it */ |
|
1008 |
if (__isSmallInteger(anInteger)) { |
|
8908 | 1009 |
RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) ); |
1 | 1010 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1011 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1012 |
^ self retry:#bitOr: coercing:anInteger |
701 | 1013 |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1014 |
" |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1015 |
(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2 |
8908 | 1016 |
(0 bitOr:16r20000000) hexPrintString |
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1017 |
(0 bitOr:16r40000000) hexPrintString |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1018 |
(0 bitOr:16r80000000) hexPrintString |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1019 |
" |
1 | 1020 |
! |
1021 |
||
1022 |
bitShift:shiftCount |
|
1023 |
"return the value of the receiver shifted by shiftCount bits; |
|
62 | 1024 |
leftShift if shiftCount > 0; rightShift otherwise. |
8908 | 1025 |
Notice: the result of bitShift: on negative receivers is not |
1026 |
defined in the language standard (since the implementation |
|
1027 |
is free to choose any internal representation for integers). |
|
1028 |
However, ST/X preserves the sign." |
|
1 | 1029 |
|
1030 |
%{ /* NOCONTEXT */ |
|
1031 |
||
1032 |
INT bits, count; |
|
1033 |
||
252 | 1034 |
if (__isSmallInteger(shiftCount)) { |
8908 | 1035 |
bits = __intVal(self); |
1036 |
if (bits == 0) { |
|
1037 |
RETURN (self); |
|
1038 |
} |
|
1039 |
||
1040 |
count = __intVal(shiftCount); |
|
1041 |
||
1042 |
if (count > 0) { |
|
1043 |
/* |
|
1044 |
* a left shift |
|
1045 |
*/ |
|
4183
4a745f6f47b6
oops - longlong shift fails with i386,GCC
Claus Gittinger <cg@exept.de>
parents:
4177
diff
changeset
|
1046 |
#if defined(USE_LONGLONG_FOR_SHIFT) |
8908 | 1047 |
if (count <= N_INT_BITS) { |
1048 |
unsigned LONGLONG result; |
|
1049 |
||
1050 |
result = (unsigned LONGLONG)bits; |
|
1051 |
result <<= count; |
|
1052 |
if (result <= _MAX_INT) { |
|
8913 | 1053 |
RETURN ( __mkSmallInteger(result) ); |
8908 | 1054 |
} |
1055 |
{ |
|
1056 |
RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); |
|
1057 |
} |
|
1058 |
} |
|
95 | 1059 |
#else |
8908 | 1060 |
/* |
1061 |
* check for overflow |
|
1062 |
*/ |
|
1063 |
if (count < (N_INT_BITS-1)) { |
|
1064 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
|
8913 | 1065 |
RETURN ( __mkSmallInteger(bits << count) ); |
8908 | 1066 |
} |
1067 |
/* |
|
1068 |
* so, there is an overflow ... |
|
1069 |
* handle it as largeInteger |
|
1070 |
*/ |
|
1071 |
/* FALL THROUGH */ |
|
1072 |
} |
|
95 | 1073 |
#endif |
8908 | 1074 |
} else { |
1075 |
if (count == 0) { |
|
1076 |
RETURN (self); |
|
1077 |
} |
|
1078 |
||
1079 |
/* |
|
1080 |
* right shifts cannot overflow |
|
1081 |
* |
|
1082 |
* some machines ignore shifts bigger than |
|
1083 |
* the number of bits in an int ... |
|
1084 |
*/ |
|
1085 |
count = -count; |
|
1086 |
if (count > (N_INT_BITS-1)) { |
|
8913 | 1087 |
RETURN (__mkSmallInteger(0)); |
8908 | 1088 |
} |
1089 |
||
8913 | 1090 |
RETURN ( __mkSmallInteger(bits >> count) ); |
8908 | 1091 |
} |
1 | 1092 |
} |
85 | 1093 |
%}. |
1094 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
8908 | 1095 |
^ (LargeInteger value:self) bitShift:shiftCount |
85 | 1096 |
]. |
6400
3746d31f044a
bitShift:float trouble fixed.
Claus Gittinger <cg@exept.de>
parents:
6344
diff
changeset
|
1097 |
^ self bitShift:(1 coerce:shiftCount) "/ is this a good idea ? |
1 | 1098 |
! |
1099 |
||
701 | 1100 |
bitTest:aMask |
5782 | 1101 |
"return true, if any bit from aMask is set in the receiver. |
1102 |
I.e. true, if the bitwise-AND of the receiver and the argument, anInteger |
|
1103 |
is non-0, false otherwise." |
|
1 | 1104 |
|
1105 |
%{ /* NOCONTEXT */ |
|
1106 |
||
701 | 1107 |
/* and all bits except tag */ |
1108 |
if (__isSmallInteger(aMask)) { |
|
14632 | 1109 |
RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); |
1 | 1110 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1111 |
%}. |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
1112 |
aMask class == LargeInteger ifTrue:[ |
14632 | 1113 |
^ (aMask bitAnd:self) ~~ 0 |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
1114 |
]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1115 |
^ self retry:#bitTest: coercing:aMask |
11519 | 1116 |
|
1117 |
" |
|
14632 | 1118 |
2r10001 bitTest:2r00001 |
1119 |
2r10001 bitTest:2r00010 |
|
1120 |
2r10001 bitTest:2r00100 |
|
1121 |
2r10001 bitTest:2r01000 |
|
1122 |
2r10001 bitTest:2r10000 |
|
1123 |
2r10001 bitTest:2r10001 |
|
1124 |
2r10001 bitTest:2r10010 |
|
11519 | 1125 |
" |
1 | 1126 |
! |
1127 |
||
1128 |
bitXor:anInteger |
|
13 | 1129 |
"return the bitwise-exclusive-or of the receiver and the argument, anInteger" |
1 | 1130 |
|
1131 |
%{ /* NOCONTEXT */ |
|
1132 |
||
1133 |
/* xoring the tags turns it off - or it in again */ |
|
252 | 1134 |
if (__isSmallInteger(anInteger)) { |
214 | 1135 |
RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) ); |
1 | 1136 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1137 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1138 |
^ self retry:#bitXor: coercing:anInteger |
1 | 1139 |
! |
1140 |
||
3683 | 1141 |
clearBit:anInteger |
8937 | 1142 |
"return a new integer where the specified bit is off. |
5209 | 1143 |
Bits are counted from 1 starting with the least significant. |
15131 | 1144 |
The methods name may be misleading: the receiver is not changed, |
5209 | 1145 |
but a new number is returned. Should be named #withBitCleared:" |
3683 | 1146 |
|
1147 |
%{ /* NOCONTEXT */ |
|
1148 |
||
1149 |
if (__isSmallInteger(anInteger)) { |
|
15131 | 1150 |
int index = __intVal(anInteger); |
1151 |
||
1152 |
if (index > 0) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1153 |
#if __POINTER_SIZE__ == 8 |
15131 | 1154 |
if (index <= 62) |
3683 | 1155 |
#else |
15131 | 1156 |
if (index <= 30) |
3683 | 1157 |
#endif |
15131 | 1158 |
{ |
1159 |
INT mask = __MASKSMALLINT(1 << (index-1)); |
|
1160 |
||
1161 |
RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) ); |
|
1162 |
} |
|
1163 |
RETURN (self); /* nothing to do ... */ |
|
1164 |
} |
|
3683 | 1165 |
} |
1166 |
%}. |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1167 |
^ super clearBit:anInteger |
3683 | 1168 |
|
1169 |
" |
|
1170 |
(16r401 clearBit:1 ) hexPrintString |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1171 |
(16r401 clearBit:0 ) hexPrintString |
3683 | 1172 |
(16r3fffffff clearBit:1) hexPrintString |
8908 | 1173 |
(16r3fffffff clearBit:29) hexPrintString |
1174 |
(16r3fffffff clearBit:30) hexPrintString |
|
1175 |
(16r3fffffff clearBit:31) hexPrintString |
|
1176 |
(16r3fffffff bitAt:29) hexPrintString |
|
1177 |
(16r3fffffff bitAt:30) hexPrintString |
|
1178 |
(16r3fffffff bitAt:31) hexPrintString |
|
1179 |
(16r40000001 clearBit:1) hexPrintString |
|
1180 |
(16rF0000001 clearBit:29) hexPrintString |
|
3683 | 1181 |
(16rF0000001 clearBit:30) hexPrintString |
8908 | 1182 |
(16rF0000001 clearBit:31) hexPrintString |
1183 |
(16rF0000001 clearBit:32) hexPrintString |
|
3683 | 1184 |
" |
1185 |
! |
|
1186 |
||
701 | 1187 |
highBit |
1188 |
"return the bitIndex of the highest bit set. The returned bitIndex |
|
8908 | 1189 |
starts at 1 for the least significant bit. |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1190 |
Returns 0 if no bit is set." |
1 | 1191 |
|
1192 |
%{ /* NOCONTEXT */ |
|
1193 |
||
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1194 |
unsigned INT bits; |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1195 |
int index; |
701 | 1196 |
|
1133 | 1197 |
bits = __intVal(self); |
701 | 1198 |
if (bits == 0) { |
14632 | 1199 |
RETURN ( __mkSmallInteger(0) ); |
701 | 1200 |
} |
2785 | 1201 |
|
14632 | 1202 |
#ifdef __BSR |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1203 |
/* |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1204 |
* so much for CISC CPUS: |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1205 |
* the following code is not faster on a PIII-400 |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1206 |
* (but saves a few code-bytes, though) |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1207 |
*/ |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1208 |
index = __BSR(bits); |
4955
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1209 |
#else |
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1210 |
|
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1211 |
index = 0; |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1212 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1213 |
# if __POINTER_SIZE__ == 8 |
4951 | 1214 |
if (bits & 0xFFFFFFFF00000000L) { |
14632 | 1215 |
index += 32; bits = bits >> 32; |
4951 | 1216 |
} |
4955
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1217 |
# endif |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1218 |
if (bits & 0xFFFF0000L) { |
14632 | 1219 |
index += 16; bits = bits >> 16; |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1220 |
} |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1221 |
if (bits & 0xFF00) { |
14632 | 1222 |
index += 8; bits = bits >> 8; |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1223 |
} |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1224 |
if (bits & 0xF0) { |
14632 | 1225 |
index += 4; bits = bits >> 4; |
1 | 1226 |
} |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1227 |
if (bits & 0xC) { |
14632 | 1228 |
index += 2; bits = bits >> 2; |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1229 |
} |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1230 |
if (bits & 0x2) { |
14632 | 1231 |
index += 1; bits = bits >> 1; |
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1232 |
} |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1233 |
#endif /* no BSR instruction */ |
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1234 |
|
8913 | 1235 |
RETURN ( __mkSmallInteger(index+1) ); |
1 | 1236 |
%} |
4951 | 1237 |
" |
8908 | 1238 |
2r0 highBit |
1239 |
2r1 highBit |
|
1240 |
2r10 highBit |
|
1241 |
2r100 highBit |
|
1242 |
2r1000 highBit |
|
1243 |
2r100000000000 highBit |
|
6481
d5c94e93067c
highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6480
diff
changeset
|
1244 |
|
4951 | 1245 |
((0 to:64) collect:[:s | 1 bitShift:s]) |
14632 | 1246 |
collect:[:n | n highBit] |
4951 | 1247 |
|
1248 |
(((0 to:64) collect:[:s | 1 bitShift:s]) |
|
14632 | 1249 |
collect:[:n | n highBit]) = (1 to:65) |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1250 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1251 |
|
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1252 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1253 |
Time millisecondsToRun:[ |
14632 | 1254 |
1000000 timesRepeat:[ |
1255 |
2r1 highBit |
|
1256 |
] |
|
8908 | 1257 |
] |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1258 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1259 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1260 |
Time millisecondsToRun:[ |
14632 | 1261 |
1000000 timesRepeat:[ |
1262 |
2r1111 highBit |
|
1263 |
] |
|
8908 | 1264 |
] |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1265 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1266 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1267 |
Time millisecondsToRun:[ |
14632 | 1268 |
1000000 timesRepeat:[ |
1269 |
2r11111111111111 highBit |
|
1270 |
] |
|
8908 | 1271 |
] |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1272 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1273 |
" |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1274 |
Time millisecondsToRun:[ |
14632 | 1275 |
1000000 timesRepeat:[ |
1276 |
2r11111111111111111111111111 highBit |
|
1277 |
] |
|
8908 | 1278 |
] |
4951 | 1279 |
" |
1280 |
||
1281 |
" |
|
8908 | 1282 |
2r000100 highBit |
1283 |
2r010100 highBit |
|
1284 |
2r000001 highBit |
|
1285 |
0 highBit |
|
1286 |
SmallInteger maxVal highBit |
|
4951 | 1287 |
" |
701 | 1288 |
! |
1289 |
||
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1290 |
invertBit:anInteger |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1291 |
"return a new number where the specified bit is inverted. |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1292 |
Bits are counted from 1 starting with the least significant. |
15131 | 1293 |
The methods name may be misleading: the receiver is not changed, |
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1294 |
but a new number is returned. Should be named #withBitInverted:" |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1295 |
|
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1296 |
%{ /* NOCONTEXT */ |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1297 |
|
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1298 |
if (__isSmallInteger(anInteger)) { |
15131 | 1299 |
int index = __intVal(anInteger); |
1300 |
||
1301 |
if (index > 0) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1302 |
#if __POINTER_SIZE__ == 8 |
15131 | 1303 |
if (index <= 62) |
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1304 |
#else |
15131 | 1305 |
if (index <= 30) |
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1306 |
#endif |
15131 | 1307 |
{ |
1308 |
INT mask = __MASKSMALLINT(1 << (index-1)); |
|
1309 |
||
1310 |
RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) ); |
|
1311 |
} |
|
1312 |
} |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1313 |
} |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1314 |
%}. |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1315 |
^ super invertBit:anInteger |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1316 |
|
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1317 |
" |
8908 | 1318 |
(16r401 invertBit:2 ) hexPrintString |
1319 |
(16r401 invertBit:1 ) hexPrintString |
|
1320 |
(16r30000000 invertBit:1) hexPrintString |
|
1321 |
(16r40000000 invertBit:0) hexPrintString |
|
1322 |
(16r0 invertBit:29) hexPrintString |
|
1323 |
(16r0 invertBit:30) hexPrintString |
|
1324 |
(16r0 invertBit:31) hexPrintString |
|
1325 |
(16r0 invertBit:32) hexPrintString |
|
1326 |
(16r0 invertBit:33) hexPrintString |
|
1327 |
(16r0 invertBit:100) hexPrintString |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1328 |
" |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1329 |
! |
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1330 |
|
701 | 1331 |
lowBit |
1332 |
"return the bitIndex of the lowest bit set. The returned bitIndex |
|
8908 | 1333 |
starts at 1 for the least significant bit. |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1334 |
Returns 0 if no bit is set." |
701 | 1335 |
|
1336 |
%{ /* NOCONTEXT */ |
|
1337 |
||
6482 | 1338 |
unsigned INT bits; |
1339 |
int index; |
|
701 | 1340 |
|
1133 | 1341 |
bits = __intVal(self); |
701 | 1342 |
if (bits == 0) { |
8913 | 1343 |
RETURN ( __mkSmallInteger(0) ); |
701 | 1344 |
} |
2431 | 1345 |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1346 |
#ifdef __BSF |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1347 |
/* |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1348 |
* so much for CISC CPUS: |
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1349 |
* the following code is only marginally faster on a PIII-400 |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1350 |
* (and not at all faster on an Athlon...) |
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1351 |
* but saves a few code-bytes, though. |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1352 |
*/ |
6482 | 1353 |
index = __BSF(bits); |
8913 | 1354 |
RETURN ( __mkSmallInteger(index + 1) ); |
4955
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1355 |
#else |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1356 |
|
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1357 |
index = 1; |
2431 | 1358 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1359 |
# if __POINTER_SIZE__ == 8 |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1360 |
if ((bits<<32) == 0) { |
8908 | 1361 |
index += 32; bits >>= 32; |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1362 |
} |
4955
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1363 |
# endif |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1364 |
|
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1365 |
if ((bits & 0xFFFF)==0) { |
8908 | 1366 |
index += 16; bits >>= 16; |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1367 |
} |
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1368 |
if ((bits & 0xFF)==0) { |
8908 | 1369 |
index += 8; bits >>= 8; |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1370 |
} |
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1371 |
if ((bits & 0xF)==0) { |
8908 | 1372 |
index += 4; bits >>= 4; |
701 | 1373 |
} |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1374 |
if ((bits & 0x3)==0) { |
8908 | 1375 |
index += 2; bits >>= 2; |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1376 |
} |
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1377 |
if ((bits & 0x1)==0) { |
8908 | 1378 |
index += 1; |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1379 |
} |
4955
a294a8a19434
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4954
diff
changeset
|
1380 |
#endif |
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1381 |
|
8913 | 1382 |
RETURN ( __mkSmallInteger(index) ); |
701 | 1383 |
%} |
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1384 |
|
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1385 |
" |
8908 | 1386 |
0 lowBit |
1387 |
2r0001 lowBit |
|
1388 |
2r0010 lowBit |
|
1389 |
2r0100 lowBit |
|
1390 |
2r1000 lowBit |
|
1391 |
||
1392 |
2r000100 lowBit |
|
1393 |
2r010010 lowBit |
|
1394 |
2r100001 lowBit |
|
1395 |
16r1000 lowBit |
|
1396 |
16r1000000 lowBit |
|
1397 |
16r1000000000000000 lowBit |
|
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1398 |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1399 |
Time millisecondsToRun:[ |
8908 | 1400 |
1000000 timesRepeat:[ |
1401 |
2r1000 lowBit |
|
1402 |
] |
|
1403 |
] |
|
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1404 |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1405 |
Time millisecondsToRun:[ |
8908 | 1406 |
1000000 timesRepeat:[ |
1407 |
2r11110000000 lowBit |
|
1408 |
] |
|
1409 |
] |
|
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1410 |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1411 |
Time millisecondsToRun:[ |
8908 | 1412 |
1000000 timesRepeat:[ |
1413 |
2r1000000000000 lowBit |
|
1414 |
] |
|
1415 |
] |
|
6480
4ff7f2af25fc
lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents:
6417
diff
changeset
|
1416 |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1417 |
Time millisecondsToRun:[ |
8908 | 1418 |
1000000 timesRepeat:[ |
1419 |
2r1000000000000000000000000000 lowBit |
|
1420 |
] |
|
1421 |
] |
|
4954
af47cd256ddf
slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents:
4953
diff
changeset
|
1422 |
" |
5209 | 1423 |
! |
1424 |
||
10972 | 1425 |
rightShift:shiftCount |
1426 |
"return the value of the receiver shifted by shiftCount bits; |
|
1427 |
right shift if shiftCount > 0; left shift otherwise. |
|
1428 |
Notice: the result of bitShift: on negative receivers is not |
|
14632 | 1429 |
defined in the language standard (since the implementation |
1430 |
is free to choose any internal representation for integers). |
|
1431 |
However, ST/X preserves the sign." |
|
10972 | 1432 |
|
1433 |
%{ /* NOCONTEXT */ |
|
1434 |
||
1435 |
INT bits, count; |
|
1436 |
||
1437 |
if (__isSmallInteger(shiftCount)) { |
|
14632 | 1438 |
bits = __intVal(self); |
1439 |
if (bits == 0) { |
|
1440 |
RETURN (self); |
|
1441 |
} |
|
1442 |
||
1443 |
count = __intVal(shiftCount); |
|
1444 |
||
1445 |
if (count < 0) { |
|
1446 |
/* |
|
1447 |
* a left shift |
|
1448 |
*/ |
|
1449 |
count = -count; |
|
10972 | 1450 |
#if defined(USE_LONGLONG_FOR_SHIFT) |
14632 | 1451 |
if (count <= N_INT_BITS) { |
1452 |
unsigned LONGLONG result; |
|
1453 |
||
1454 |
result = (unsigned LONGLONG)bits; |
|
1455 |
result <<= count; |
|
1456 |
if (result <= _MAX_INT) { |
|
1457 |
RETURN ( __mkSmallInteger(result) ); |
|
1458 |
} |
|
1459 |
{ |
|
1460 |
RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); |
|
1461 |
} |
|
1462 |
} |
|
10972 | 1463 |
#else |
14632 | 1464 |
/* |
1465 |
* check for overflow |
|
1466 |
*/ |
|
1467 |
if (count < (N_INT_BITS-1)) { |
|
1468 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
|
1469 |
RETURN ( __mkSmallInteger(bits << count) ); |
|
1470 |
} |
|
1471 |
/* |
|
1472 |
* so, there is an overflow ... |
|
1473 |
* handle it as largeInteger |
|
1474 |
*/ |
|
1475 |
/* FALL THROUGH */ |
|
1476 |
} |
|
10972 | 1477 |
#endif |
14632 | 1478 |
} else { |
1479 |
if (count == 0) { |
|
1480 |
RETURN (self); |
|
1481 |
} |
|
1482 |
||
1483 |
/* |
|
1484 |
* right shifts cannot overflow |
|
1485 |
* |
|
1486 |
* some machines ignore shifts bigger than |
|
1487 |
* the number of bits in an int ... |
|
1488 |
*/ |
|
1489 |
if (count > (N_INT_BITS-1)) { |
|
1490 |
RETURN (__mkSmallInteger(0)); |
|
1491 |
} |
|
1492 |
||
1493 |
RETURN ( __mkSmallInteger(bits >> count) ); |
|
1494 |
} |
|
10972 | 1495 |
} |
1496 |
%}. |
|
1497 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
14632 | 1498 |
^ (LargeInteger value:self) rightShift:shiftCount |
10972 | 1499 |
]. |
1500 |
^ self rightShift:(1 coerce:shiftCount) "/ is this a good idea ? |
|
1501 |
||
1502 |
||
1503 |
" |
|
14632 | 1504 |
16 rightShift:2 |
1505 |
4 rightShift:-2 |
|
10972 | 1506 |
" |
1507 |
! |
|
1508 |
||
5209 | 1509 |
setBit:anInteger |
8937 | 1510 |
"return a new integer where the specified bit is on. |
5209 | 1511 |
Bits are counted from 1 starting with the least significant. |
15131 | 1512 |
The methods name may be misleading: the receiver is not changed, |
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1513 |
but a new number is returned. Should be named #withBitSet:" |
5209 | 1514 |
|
1515 |
%{ /* NOCONTEXT */ |
|
1516 |
||
1517 |
if (__isSmallInteger(anInteger)) { |
|
15131 | 1518 |
int index = __intVal(anInteger); |
1519 |
||
1520 |
if (index > 0) { |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1521 |
#if __POINTER_SIZE__ == 8 |
15131 | 1522 |
if (index <= 62) |
5209 | 1523 |
#else |
15131 | 1524 |
if (index <= 30) |
5209 | 1525 |
#endif |
15131 | 1526 |
{ |
1527 |
INT mask = __MASKSMALLINT(1 << (index-1)); |
|
1528 |
||
1529 |
RETURN ( ((OBJ) ((INT)self | (INT)mask)) ); |
|
1530 |
} |
|
1531 |
} |
|
5209 | 1532 |
} |
1533 |
%}. |
|
5496
338c81a04468
index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents:
5458
diff
changeset
|
1534 |
^ super setBit:anInteger |
5209 | 1535 |
|
1536 |
" |
|
8908 | 1537 |
(16r401 setBit:2 ) hexPrintString |
1538 |
(16r30000000 setBit:1) hexPrintString |
|
1539 |
(16r40000000 setBit:0) hexPrintString |
|
1540 |
(16r0 setBit:29) hexPrintString |
|
1541 |
(16r0 setBit:30) hexPrintString |
|
1542 |
(16r0 setBit:31) hexPrintString |
|
1543 |
(16r0 setBit:32) hexPrintString |
|
1544 |
(16r0 setBit:33) hexPrintString |
|
1545 |
(16r0 setBit:100) hexPrintString |
|
5209 | 1546 |
" |
6417 | 1547 |
! ! |
1548 |
||
7267 | 1549 |
!SmallInteger methodsFor:'bit operators-32bit'! |
6417 | 1550 |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1551 |
asSigned32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1552 |
"return a 32-bit integer with my bit-pattern. For protocol completeness." |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1553 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1554 |
^ self |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1555 |
! |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1556 |
|
6417 | 1557 |
asUnsigned32 |
1558 |
"return a 32-bit integer with my bit-pattern, but positive. |
|
1559 |
May be required for bit operations on the sign-bit and/or to |
|
1560 |
convert C/Java numbers." |
|
1561 |
||
1562 |
self < 0 ifTrue:[ |
|
8908 | 1563 |
^ 16r100000000 + self |
6417 | 1564 |
]. |
1565 |
^ self |
|
1566 |
||
1567 |
" |
|
8908 | 1568 |
(-1 asUnsigned32) hexPrintString |
1569 |
1 asUnsigned32 |
|
1570 |
(SmallInteger minVal asUnsigned32) hexPrintString |
|
1571 |
(SmallInteger maxVal asUnsigned32) hexPrintString |
|
6417 | 1572 |
" |
1573 |
! |
|
1574 |
||
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1575 |
bitInvert32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1576 |
"return the value of the receiver with all bits inverted in 32bit signed int space |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1577 |
(changes the sign)" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1578 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1579 |
%{ /* NOCONTEXT */ |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1580 |
unsigned INT v; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1581 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1582 |
v = __intVal(self); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1583 |
v = ~v; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1584 |
#if __POINTER_SIZE__ == 8 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1585 |
v &= 0xFFFFFFFFL; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1586 |
#endif |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1587 |
RETURN ( __MKUINT(v) ); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1588 |
%}. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1589 |
^ self primitiveFailed |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1590 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1591 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1592 |
1 bitInvert32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1593 |
16r40000000 bitInvert32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1594 |
16r80000000 bitInvert32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1595 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1596 |
! |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1597 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1598 |
bitRotate32:shiftCount |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1599 |
"return the value of the receiver rotated by shiftCount bits, |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1600 |
but only within 32 bits, rotating left for positive, right for negative counts. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1601 |
Rotates through the sign bit. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1602 |
Useful for crypt algorithms, or to emulate C/Java semantics." |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1603 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1604 |
%{ /* NOCONTEXT */ |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1605 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1606 |
unsigned INT bits; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1607 |
int count; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1608 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1609 |
if (__isSmallInteger(shiftCount)) { |
14632 | 1610 |
count = __intVal(shiftCount); |
1611 |
count = count % 32; |
|
1612 |
||
1613 |
bits = __intVal(self); |
|
1614 |
if (count > 0) { |
|
1615 |
bits = (bits << count) | (bits >> (32-count)); |
|
1616 |
} else { |
|
1617 |
bits = (bits >> (-count)) | (bits << (32-(-count))); |
|
1618 |
} |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1619 |
#if __POINTER_SIZE__ == 8 |
14632 | 1620 |
bits &= 0xFFFFFFFFL; |
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1621 |
#endif |
14632 | 1622 |
RETURN (__MKUINT(bits)); |
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1623 |
} |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1624 |
%}. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1625 |
^ self primitiveFailed |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1626 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1627 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1628 |
128 rotate32:1 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1629 |
|
14632 | 1630 |
1 rotate32:1 |
1631 |
1 rotate32:2 |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1632 |
1 rotate32:31 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1633 |
1 rotate32:32 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1634 |
|
14632 | 1635 |
1 rotate32:-1 |
1636 |
1 rotate32:-2 |
|
1637 |
1 rotate32:-3 |
|
1638 |
1 rotate32:-32 |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1639 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1640 |
! |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1641 |
|
6417 | 1642 |
bitShift32:shiftCount |
1643 |
"return the value of the receiver shifted by shiftCount bits, |
|
1644 |
but only within 32 bits, shifting into/out-of the sign bit. |
|
1645 |
May be useful for communication interfaces, to create ST-numbers |
|
1646 |
from a signed 32bit int value given as individual bytes, |
|
1647 |
or to emulate C/Java semantics." |
|
1648 |
||
1649 |
%{ /* NOCONTEXT */ |
|
1650 |
||
1651 |
INT bits, count; |
|
1652 |
||
1653 |
if (__isSmallInteger(shiftCount)) { |
|
8908 | 1654 |
count = __intVal(shiftCount); |
1655 |
if (count >= 32) { |
|
8913 | 1656 |
RETURN (__mkSmallInteger(0)); |
8908 | 1657 |
} |
1658 |
||
1659 |
bits = __intVal(self); |
|
1660 |
if (count > 0) { |
|
1661 |
bits = bits << count; |
|
1662 |
} else { |
|
1663 |
bits = bits >> (-count); |
|
1664 |
} |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1665 |
#if __POINTER_SIZE__ == 8 |
8908 | 1666 |
bits &= 0xFFFFFFFFL; |
6417 | 1667 |
#endif |
8908 | 1668 |
RETURN (__MKINT(bits)); |
6417 | 1669 |
} |
1670 |
%}. |
|
1671 |
^ self primitiveFailed |
|
1672 |
||
1673 |
" |
|
8908 | 1674 |
128 bitShift:24 |
1675 |
128 bitShift32:24 |
|
1676 |
||
1677 |
1 bitShift:31 |
|
1678 |
1 bitShift32:31 |
|
6417 | 1679 |
" |
6415
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1680 |
! |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1681 |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1682 |
bitXor32:aNumber |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1683 |
"return the xor of the receiver and the argument. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1684 |
The argument must be another SmallInteger or a 4-byte LargeInteger. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1685 |
If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1686 |
This is of course not always correct, but allows for C/Java behavior to be emulated." |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1687 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1688 |
%{ /* NOCONTEXT */ |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1689 |
INT rslt; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1690 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1691 |
rslt = __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1692 |
#if __POINTER_SIZE__ == 8 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1693 |
rslt &= 0xFFFFFFFFL; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1694 |
#endif |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1695 |
RETURN ( __MKUINT(rslt)); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1696 |
%}. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1697 |
self primitiveFailed |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1698 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1699 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1700 |
16r7FFFFFFF bitXor: 16r80000000 4294967295 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1701 |
16r7FFFFFFF bitXor32: 16r80000000 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1702 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1703 |
! |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
1704 |
|
6415
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1705 |
unsignedBitShift32:shiftCount |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1706 |
"return the value of the receiver shifted by shiftCount bits, |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1707 |
but only within 32 unsigned bits. |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1708 |
May be useful for communication interfaces, to create ST-numbers |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1709 |
from an unsigned 32bit int value given as individual byte, |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1710 |
or to emulate C/Java semantics." |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1711 |
|
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1712 |
%{ /* NOCONTEXT */ |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1713 |
|
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1714 |
unsigned INT bits; |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1715 |
INT count; |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1716 |
|
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1717 |
if (__isSmallInteger(shiftCount)) { |
8908 | 1718 |
count = __intVal(shiftCount); |
1719 |
if (count >= 32) { |
|
8913 | 1720 |
RETURN (__mkSmallInteger(0)); |
8908 | 1721 |
} |
1722 |
||
1723 |
bits = __intVal(self); |
|
1724 |
if (count > 0) { |
|
1725 |
bits = bits << count; |
|
1726 |
} else { |
|
1727 |
bits = bits >> (-count); |
|
1728 |
} |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1729 |
#if __POINTER_SIZE__ == 8 |
8908 | 1730 |
bits &= 0xFFFFFFFFL; |
6415
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1731 |
#endif |
8908 | 1732 |
RETURN (__MKUINT(bits)); |
6415
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1733 |
} |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1734 |
%}. |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1735 |
^ self primitiveFailed |
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1736 |
|
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1737 |
" |
8908 | 1738 |
128 unsignedBitShift:24 |
1739 |
128 unsignedBitShift32:24 |
|
1740 |
||
1741 |
1 unsignedBitShift:31 |
|
1742 |
1 unsignedBitShift32:31 |
|
1743 |
||
1744 |
-1 unsignedBitShift32:-1 |
|
1745 |
-1 unsignedBitShift32:1 |
|
6415
f163a6319b5f
unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents:
6400
diff
changeset
|
1746 |
" |
1 | 1747 |
! ! |
1748 |
||
1749 |
!SmallInteger methodsFor:'byte access'! |
|
1750 |
||
13991 | 1751 |
byteSwapped |
1752 |
"lsb -> msb; |
|
1753 |
i.e. a.b.c.d -> d.c.b.a" |
|
1754 |
||
1755 |
%{ /* NOCONTEXT */ |
|
1756 |
||
1757 |
#if __POINTER_SIZE__ == 4 |
|
14632 | 1758 |
unsigned int v = __intVal(self); |
1759 |
unsigned int swapped; |
|
13991 | 1760 |
|
1761 |
# ifdef __BORLANDC__ |
|
1762 |
# ifdef USE_BSWAP |
|
1763 |
_asm { |
|
14632 | 1764 |
mov eax, v |
1765 |
bswap eax |
|
1766 |
mov swapped, eax |
|
13991 | 1767 |
}; |
1768 |
# else |
|
1769 |
_asm { |
|
14632 | 1770 |
mov eax, v |
1771 |
xchg al, ah |
|
1772 |
rol eax, 16 |
|
1773 |
xchg al, ah |
|
1774 |
mov swapped, eax |
|
13991 | 1775 |
}; |
1776 |
# endif |
|
1777 |
# else |
|
1778 |
swapped = ((v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24)); |
|
1779 |
# endif |
|
1780 |
RETURN (__MKUINT(swapped)); |
|
1781 |
#endif /* __POINTER_SIZE__ */ |
|
1782 |
%}. |
|
1783 |
^ super byteSwapped |
|
1784 |
||
1785 |
" |
|
14632 | 1786 |
16r11223344 byteSwapped hexPrintString |
1787 |
16r44332211 byteSwapped hexPrintString |
|
13991 | 1788 |
" |
1789 |
||
1790 |
"Created: / 09-01-2012 / 23:01:33 / cg" |
|
1791 |
! |
|
1792 |
||
1 | 1793 |
digitAt:index |
1794 |
"return 8 bits of value, starting at byte index" |
|
1795 |
||
1796 |
%{ /* NOCONTEXT */ |
|
1797 |
||
357 | 1798 |
REGISTER INT val; |
1799 |
INT idx; |
|
1 | 1800 |
|
252 | 1801 |
if (__isSmallInteger(index)) { |
4167 | 1802 |
val = __intVal(self); |
1803 |
if (val < 0) |
|
1804 |
val = -val; |
|
1805 |
switch (idx = __intVal(index)) { |
|
1806 |
case 1: |
|
1807 |
break; |
|
1808 |
case 2: |
|
1809 |
val = (val >> 8); |
|
1810 |
break; |
|
1811 |
case 3: |
|
1812 |
val = (val >> 16); |
|
1813 |
break; |
|
1814 |
case 4: |
|
1815 |
val = (val >> 24); |
|
1816 |
break; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1817 |
#if __POINTER_SIZE__ == 8 |
4167 | 1818 |
case 5: |
1819 |
val = (val >> 32); |
|
1820 |
break; |
|
1821 |
case 6: |
|
1822 |
val = (val >> 40); |
|
1823 |
break; |
|
1824 |
case 7: |
|
1825 |
val = (val >> 48); |
|
1826 |
break; |
|
1827 |
case 8: |
|
1828 |
val = (val >> 56); |
|
1829 |
break; |
|
1 | 1830 |
#endif |
4167 | 1831 |
default: |
1832 |
if (idx < 1) |
|
1833 |
goto bad; /* sorry */ |
|
8913 | 1834 |
RETURN (__mkSmallInteger(0)); |
4167 | 1835 |
} |
8913 | 1836 |
RETURN ( __mkSmallInteger( val & 0xFF) ); |
1 | 1837 |
} |
357 | 1838 |
bad: ; |
77 | 1839 |
%}. |
1840 |
index > 0 ifFalse:[ |
|
4167 | 1841 |
" |
1842 |
index less than 1 - not allowed |
|
1843 |
" |
|
1844 |
^ self primitiveFailed |
|
77 | 1845 |
]. |
1846 |
^ 0 |
|
62 | 1847 |
|
357 | 1848 |
" |
1849 |
(16r12345678 digitAt:1) printStringRadix:16 |
|
1850 |
(16r12345678 digitAt:3) printStringRadix:16 |
|
1851 |
(16r12345678 digitAt:15) printStringRadix:16 |
|
1852 |
(16r12345678 digitAt:0) printStringRadix:16 |
|
1853 |
(16r12345678 digitAt:-10) printStringRadix:16 |
|
1854 |
" |
|
701 | 1855 |
! |
1856 |
||
3892 | 1857 |
digitByteAt:index |
1858 |
"return 8 bits of my signed value, starting at byte index. |
|
1859 |
For positive receivers, this is the same as #digitAt:; |
|
1860 |
for negative ones, the actual bit representation is returned." |
|
1861 |
||
1862 |
%{ /* NOCONTEXT */ |
|
1863 |
||
1864 |
REGISTER INT val; |
|
1865 |
INT idx; |
|
1866 |
||
1867 |
if (__isSmallInteger(index)) { |
|
4167 | 1868 |
val = __intVal(self); |
1869 |
switch (idx = __intVal(index)) { |
|
1870 |
case 1: |
|
1871 |
break; |
|
1872 |
case 2: |
|
1873 |
val = (val >> 8); |
|
1874 |
break; |
|
1875 |
case 3: |
|
1876 |
val = (val >> 16); |
|
1877 |
break; |
|
1878 |
case 4: |
|
1879 |
val = (val >> 24); |
|
1880 |
break; |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
1881 |
#if __POINTER_SIZE__ == 8 |
4167 | 1882 |
case 5: |
1883 |
val = (val >> 32); |
|
1884 |
break; |
|
1885 |
case 6: |
|
1886 |
val = (val >> 40); |
|
1887 |
break; |
|
1888 |
case 7: |
|
1889 |
val = (val >> 48); |
|
1890 |
break; |
|
1891 |
case 8: |
|
1892 |
val = (val >> 56); |
|
1893 |
break; |
|
3892 | 1894 |
#endif |
4167 | 1895 |
default: |
1896 |
if (idx < 1) |
|
1897 |
goto bad; /* sorry */ |
|
1898 |
if (val < 0) { |
|
8913 | 1899 |
RETURN (__mkSmallInteger(0xFF)); |
4167 | 1900 |
} |
8913 | 1901 |
RETURN (__mkSmallInteger(0)); |
4167 | 1902 |
} |
8913 | 1903 |
RETURN ( __mkSmallInteger( val & 0xFF) ); |
3892 | 1904 |
} |
1905 |
bad: ; |
|
1906 |
%}. |
|
1907 |
index > 0 ifFalse:[ |
|
4167 | 1908 |
" |
1909 |
index less than 1 - not allowed |
|
1910 |
" |
|
1911 |
^ self primitiveFailed |
|
3892 | 1912 |
]. |
1913 |
^ 0 |
|
1914 |
||
1915 |
" |
|
8908 | 1916 |
(10 digitByteAt:1) printStringRadix:16 |
1917 |
(10 digitByteAt:3) printStringRadix:16 |
|
3892 | 1918 |
(-10 digitByteAt:1) printStringRadix:16 |
1919 |
(-10 digitByteAt:3) printStringRadix:16 |
|
1920 |
" |
|
1921 |
! |
|
1922 |
||
4827
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
1923 |
digitBytes |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
1924 |
"return a byteArray filled with the receivers bits |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
1925 |
(8 bits of the absolute value per element), |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
1926 |
least significant byte is first" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
1927 |
|
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1928 |
|absValue |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1929 |
b1 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1930 |
b2 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1931 |
b3 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1932 |
b4 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1933 |
b5 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1934 |
b6 "{ Class: SmallInteger }" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1935 |
b7 "{ Class: SmallInteger }" digitByteArray| |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1936 |
|
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1937 |
" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1938 |
could have simply created a 4-byte largeinteger and normalize it. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1939 |
The code below does the normalize right away, avoiding the |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1940 |
overhead of producing any intermediate byte-arrays (and the scanning) |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1941 |
" |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1942 |
self == 0 ifTrue: [ |
14632 | 1943 |
^ ByteArray with:0. |
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1944 |
]. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1945 |
|
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1946 |
self < 0 ifTrue: [ |
14632 | 1947 |
absValue := self negated |
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1948 |
] ifFalse: [ |
14632 | 1949 |
absValue := self. |
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1950 |
]. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1951 |
|
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1952 |
b1 := absValue bitAnd:16rFF. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1953 |
absValue := absValue bitShift:-8. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1954 |
absValue == 0 ifTrue:[ |
14632 | 1955 |
digitByteArray := ByteArray with:b1 |
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
1956 |
] ifFalse:[ |
14632 | 1957 |
b2 := absValue bitAnd:16rFF. |
1958 |
absValue := absValue bitShift:-8. |
|
1959 |
absValue == 0 ifTrue:[ |
|
1960 |
digitByteArray := ByteArray with:b1 with:b2 |
|
1961 |
] ifFalse:[ |
|
1962 |
b3 := absValue bitAnd:16rFF. |
|
1963 |
absValue := absValue bitShift:-8. |
|
1964 |
absValue == 0 ifTrue:[ |
|
1965 |
digitByteArray := ByteArray with:b1 with:b2 with:b3 |
|
1966 |
] ifFalse:[ |
|
1967 |
b4 := absValue bitAnd:16rFF. |
|
1968 |
absValue := absValue bitShift:-8. |
|
1969 |
absValue == 0 ifTrue:[ |
|
1970 |
digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4 |
|
1971 |
] ifFalse:[ |
|
1972 |
b5 := absValue bitAnd:16rFF. |
|
1973 |
absValue := absValue bitShift:-8. |
|
1974 |
absValue == 0 ifTrue:[ |
|
1975 |
digitByteArray := ByteArray new:5. |
|
1976 |
digitByteArray at:1 put:b1. |
|
1977 |
digitByteArray at:2 put:b2. |
|
1978 |
digitByteArray at:3 put:b3. |
|
1979 |
digitByteArray at:4 put:b4. |
|
1980 |
digitByteArray at:5 put:b5. |
|
1981 |
] ifFalse:[ |
|
1982 |
b6 := absValue bitAnd:16rFF. |
|
1983 |
absValue := absValue bitShift:-8. |
|
1984 |
absValue == 0 ifTrue:[ |
|
1985 |
digitByteArray := ByteArray new:6. |
|
1986 |
digitByteArray at:1 put:b1. |
|
1987 |
digitByteArray at:2 put:b2. |
|
1988 |
digitByteArray at:3 put:b3. |
|
1989 |
digitByteArray at:4 put:b4. |
|
1990 |
digitByteArray at:5 put:b5. |
|
1991 |
digitByteArray at:6 put:b6. |
|
1992 |
] ifFalse:[ |
|
1993 |
b7 := absValue bitAnd:16rFF. |
|
1994 |
absValue := absValue bitShift:-8. |
|
1995 |
absValue == 0 ifTrue:[ |
|
1996 |
digitByteArray := ByteArray new:7. |
|
1997 |
digitByteArray at:1 put:b1. |
|
1998 |
digitByteArray at:2 put:b2. |
|
1999 |
digitByteArray at:3 put:b3. |
|
2000 |
digitByteArray at:4 put:b4. |
|
2001 |
digitByteArray at:5 put:b5. |
|
2002 |
digitByteArray at:6 put:b6. |
|
2003 |
digitByteArray at:7 put:b7. |
|
2004 |
] ifFalse:[ |
|
2005 |
digitByteArray := ByteArray new:8. |
|
2006 |
digitByteArray at:1 put:b1. |
|
2007 |
digitByteArray at:2 put:b2. |
|
2008 |
digitByteArray at:3 put:b3. |
|
2009 |
digitByteArray at:4 put:b4. |
|
2010 |
digitByteArray at:5 put:b5. |
|
2011 |
digitByteArray at:6 put:b6. |
|
2012 |
digitByteArray at:7 put:b7. |
|
2013 |
digitByteArray at:8 put:absValue. |
|
2014 |
] |
|
2015 |
] |
|
2016 |
] |
|
2017 |
] |
|
2018 |
] |
|
2019 |
] |
|
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2020 |
]. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2021 |
|
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2022 |
^ digitByteArray |
4827
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2023 |
|
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2024 |
" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2025 |
16r12 digitBytes |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2026 |
16r1234 digitBytes |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2027 |
16r12345678 digitBytes |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2028 |
" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2029 |
! |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2030 |
|
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2031 |
digitBytesMSB:msbFlag |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2032 |
"return a byteArray filled with the receivers bits |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2033 |
(8 bits of the absolute value per element), |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2034 |
if msbflag = true, most significant byte is first, |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2035 |
otherwise least significant byte is first" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2036 |
|
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2037 |
msbFlag ifTrue:[ |
14632 | 2038 |
^ self digitBytes reversed. "digitBytes has been just created - reverse inplace" |
10487
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2039 |
]. |
f6287f4b83c9
Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents:
10342
diff
changeset
|
2040 |
^ self digitBytes |
4827
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2041 |
|
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2042 |
" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2043 |
16r12 digitBytesMSB:true |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2044 |
16r1234 digitBytesMSB:true |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2045 |
16r1234 digitBytesMSB:false |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2046 |
16r12345678 digitBytesMSB:true |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2047 |
16r12345678 digitBytesMSB:false |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2048 |
" |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2049 |
! |
905b98a07798
New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents:
4661
diff
changeset
|
2050 |
|
701 | 2051 |
digitLength |
2815 | 2052 |
"return the number bytes required to represent this Integer. |
2053 |
For negative receivers, the digitLength of its absolute value |
|
2054 |
is returned." |
|
2055 |
||
2056 |
%{ /* NOCONTEXT */ |
|
2057 |
||
2058 |
INT val = __intVal(self); |
|
2059 |
||
2060 |
if (val < 0) { |
|
4167 | 2061 |
val = -val; |
2815 | 2062 |
} |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
2063 |
#if __POINTER_SIZE__ == 8 |
2815 | 2064 |
if (val & 0xFFFFFFFF00000000L) { |
4167 | 2065 |
if (val & 0xFFFF000000000000L) { |
2066 |
if (val & 0xFF00000000000000L) { |
|
8913 | 2067 |
RETURN ( __mkSmallInteger(8)); |
4167 | 2068 |
} else { |
8913 | 2069 |
RETURN ( __mkSmallInteger(7)); |
4167 | 2070 |
} |
2071 |
} else { |
|
2072 |
if (val & 0x0000FF0000000000L) { |
|
8913 | 2073 |
RETURN ( __mkSmallInteger(6)); |
4167 | 2074 |
} else { |
8913 | 2075 |
RETURN ( __mkSmallInteger(5)); |
4167 | 2076 |
} |
2077 |
} |
|
2815 | 2078 |
} |
2079 |
#endif |
|
2080 |
||
2081 |
if (val & 0xFFFF0000) { |
|
4167 | 2082 |
if (val & 0xFF000000) { |
8913 | 2083 |
RETURN ( __mkSmallInteger(4)); |
4167 | 2084 |
} else { |
8913 | 2085 |
RETURN ( __mkSmallInteger(3)); |
4167 | 2086 |
} |
2815 | 2087 |
} else { |
4167 | 2088 |
if (val & 0x0000FF00) { |
8913 | 2089 |
RETURN ( __mkSmallInteger(2)); |
4167 | 2090 |
} else { |
8913 | 2091 |
RETURN ( __mkSmallInteger(1)); |
4167 | 2092 |
} |
2815 | 2093 |
} |
2094 |
||
2095 |
%}. |
|
701 | 2096 |
^ self abs highBit - 1 // 8 + 1 |
2815 | 2097 |
|
2098 |
" |
|
2099 |
16rFF00000000000000 digitLength |
|
2100 |
-16rFF00000000000000 digitLength |
|
2101 |
||
2102 |
16rFF000000 digitLength |
|
8908 | 2103 |
16rFF0000 digitLength |
2104 |
16rFF00 digitLength |
|
2105 |
16rFF digitLength |
|
2106 |
-16rFF000000 digitLength |
|
2107 |
-16rFF0000 digitLength |
|
2108 |
-16rFF00 digitLength |
|
2109 |
-16rFF digitLength |
|
2815 | 2110 |
" |
14167 | 2111 |
! |
2112 |
||
2113 |
swapBytes |
|
2114 |
"swap byte pair-wise in an integer |
|
2115 |
i.e. a.b.c.d -> b.a.d.c" |
|
2116 |
||
2117 |
%{ /* NOCONTEXT */ |
|
2118 |
||
15322 | 2119 |
unsigned INT v = __intVal(self); |
2120 |
unsigned INT swapped; |
|
2121 |
||
2122 |
#if __POINTER_SIZE__ == 8 |
|
15325 | 2123 |
swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8); |
15322 | 2124 |
#else |
15325 | 2125 |
swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8); |
15322 | 2126 |
#endif /* __POINTER_SIZE__ */ |
2127 |
if (__ISVALIDINTEGER(swapped)) { |
|
2128 |
RETURN ( __mkSmallInteger(swapped) ); |
|
2129 |
} |
|
15309 | 2130 |
RETURN (__MKUINT(swapped)); |
14167 | 2131 |
%}. |
2132 |
^ super swapBytes |
|
2133 |
||
2134 |
" |
|
15325 | 2135 |
16r11223344 swapBytes hexPrintString |
2136 |
16r44332211 swapBytes hexPrintString |
|
2137 |
16r1122334455667788 swapBytes hexPrintString |
|
2138 |
16r11223344556677889900 swapBytes hexPrintString |
|
14167 | 2139 |
" |
2140 |
||
2141 |
"Created: / 09-01-2012 / 23:01:33 / cg" |
|
1 | 2142 |
! ! |
2143 |
||
701 | 2144 |
!SmallInteger methodsFor:'catching messages'! |
1 | 2145 |
|
701 | 2146 |
basicAt:index |
2147 |
"catch indexed access - report an error |
|
2148 |
defined here since basicAt: in Object ommits the SmallInteger check." |
|
2149 |
||
14540 | 2150 |
^ self notIndexed |
1 | 2151 |
! |
2152 |
||
701 | 2153 |
basicAt:index put:anObject |
2154 |
"catch indexed access - report an error |
|
2155 |
defined here since basicAt:put: in Object ommits the SmallInteger check." |
|
2156 |
||
2157 |
self notIndexed |
|
2158 |
! |
|
1 | 2159 |
|
701 | 2160 |
basicSize |
2161 |
"return the number of indexed instvars - SmallIntegers have none. |
|
2162 |
Defined here since basicSize in Object ommits the SmallInteger check." |
|
2163 |
||
2164 |
^ 0 |
|
2165 |
! |
|
2166 |
||
2167 |
size |
|
2168 |
"return the number of indexed instvars - SmallIntegers have none." |
|
2169 |
||
2170 |
^ 0 |
|
1 | 2171 |
! ! |
2172 |
||
5240 | 2173 |
!SmallInteger methodsFor:'coercing & converting'! |
1 | 2174 |
|
701 | 2175 |
asCharacter |
2176 |
"Return a character with the receiver as ascii value" |
|
41 | 2177 |
|
701 | 2178 |
^ Character value:self |
1 | 2179 |
! |
2180 |
||
2181 |
asFloat |
|
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
2182 |
"return a Float with same value as receiver. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
2183 |
Redefined for performance (machine can do it faster)" |
1 | 2184 |
|
2185 |
%{ /* NOCONTEXT */ |
|
2186 |
||
2187 |
OBJ newFloat; |
|
1133 | 2188 |
double dVal = (double)__intVal(self); |
1 | 2189 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2190 |
__qMKFLOAT(newFloat, dVal); |
1 | 2191 |
RETURN ( newFloat ); |
5412 | 2192 |
%}. |
2193 |
^ self primitiveFailed |
|
1 | 2194 |
! |
2195 |
||
2196 |
asLargeInteger |
|
2197 |
"return a LargeInteger with same value as receiver" |
|
2198 |
||
2199 |
^ LargeInteger value:self |
|
2200 |
! |
|
2201 |
||
1199 | 2202 |
asShortFloat |
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
2203 |
"return a ShortFloat with same value as receiver. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
2204 |
Redefined for performance (machine can do it faster)" |
1199 | 2205 |
|
2206 |
%{ /* NOCONTEXT */ |
|
2207 |
||
2208 |
OBJ dummy = @global(ShortFloat); |
|
2209 |
OBJ newFloat; |
|
2210 |
float fVal = (float)__intVal(self); |
|
2211 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
2212 |
__qMKSFLOAT(newFloat, fVal); |
1199 | 2213 |
RETURN ( newFloat ); |
5412 | 2214 |
%}. |
2215 |
^ self primitiveFailed |
|
1199 | 2216 |
! |
2217 |
||
8408
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2218 |
codePoint |
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2219 |
"for compatibility with Characters. |
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2220 |
(Allows for integers to be stored into U16/U32 strings)" |
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2221 |
|
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2222 |
^ self |
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2223 |
! |
61f12d6c1ab0
juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents:
8365
diff
changeset
|
2224 |
|
701 | 2225 |
coerce:aNumber |
11718 | 2226 |
"convert the argument aNumber into an instance of the receivers class and return it." |
701 | 2227 |
|
2228 |
^ aNumber asInteger |
|
2229 |
! |
|
2230 |
||
2231 |
generality |
|
2232 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
2233 |
||
2234 |
^ 20 |
|
1336 | 2235 |
! |
2236 |
||
12866
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2237 |
signExtended24BitValue |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2238 |
"return a smallInteger from sign-extending the 24'th bit. |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2239 |
May be useful for communication interfaces" |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2240 |
|
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2241 |
%{ /* NOCONTEXT */ |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2242 |
INT i = __intVal(self); |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2243 |
|
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2244 |
if (i & 0x800000) { |
14632 | 2245 |
i = i | ~0xFFFFFFL; |
12866
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2246 |
} else { |
14632 | 2247 |
i = i & 0x7FFFFF; |
12866
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2248 |
} |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2249 |
|
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2250 |
RETURN (__mkSmallInteger(i)); |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2251 |
%}. |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2252 |
^ self primitiveFailed |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2253 |
|
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2254 |
" |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2255 |
16rFFFFFF signExtended24BitValue |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2256 |
16r800000 signExtended24BitValue |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2257 |
16r7FFFFF signExtended24BitValue |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2258 |
" |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2259 |
! |
42e5e690c197
added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents:
12787
diff
changeset
|
2260 |
|
1336 | 2261 |
signExtendedByteValue |
2262 |
"return a smallInteger from sign-extending the 8'th bit. |
|
2263 |
May be useful for communication interfaces" |
|
2264 |
||
2265 |
%{ /* NOCONTEXT */ |
|
2781 | 2266 |
INT i = __intVal(self); |
1336 | 2267 |
|
2268 |
if (i & 0x80) { |
|
14632 | 2269 |
i = i | ~0xFFL; |
1336 | 2270 |
} else { |
14632 | 2271 |
i = i & 0x7F; |
1336 | 2272 |
} |
2273 |
||
8913 | 2274 |
RETURN (__mkSmallInteger(i)); |
5412 | 2275 |
%}. |
2276 |
^ self primitiveFailed |
|
1336 | 2277 |
|
2278 |
" |
|
14632 | 2279 |
16rFF signExtendedByteValue |
2280 |
16r80 signExtendedByteValue |
|
2281 |
16r7F signExtendedByteValue |
|
1336 | 2282 |
" |
2283 |
! |
|
2284 |
||
15083 | 2285 |
signExtendedLongValue |
2286 |
"return a smallInteger from sign-extending the 32'th bit. |
|
2287 |
May be useful for communication interfaces" |
|
2288 |
||
2289 |
%{ /* NOCONTEXT */ |
|
2290 |
INT i = __intVal(self); |
|
2291 |
||
2292 |
if (i & 0x80000000) { |
|
2293 |
i = i | ~0xFFFFFFFFL; |
|
2294 |
} else { |
|
2295 |
i = i & 0x7FFFFFFF; |
|
2296 |
} |
|
2297 |
||
2298 |
RETURN (__mkSmallInteger(i)); |
|
2299 |
%}. |
|
2300 |
^ self primitiveFailed |
|
2301 |
||
2302 |
" |
|
2303 |
16rFFFFFFFF signExtendedLongValue |
|
2304 |
16r80000000 signExtendedLongValue |
|
2305 |
16r7FFFFFFF signExtendedLongValue |
|
2306 |
" |
|
2307 |
! |
|
2308 |
||
1336 | 2309 |
signExtendedShortValue |
2310 |
"return a smallInteger from sign-extending the 16'th bit. |
|
2311 |
May be useful for communication interfaces" |
|
2312 |
||
2313 |
%{ /* NOCONTEXT */ |
|
2781 | 2314 |
INT i = __intVal(self); |
1336 | 2315 |
|
2316 |
if (i & 0x8000) { |
|
14632 | 2317 |
i = i | ~0xFFFFL; |
1336 | 2318 |
} else { |
14632 | 2319 |
i = i & 0x7FFF; |
1336 | 2320 |
} |
2321 |
||
8913 | 2322 |
RETURN (__mkSmallInteger(i)); |
5412 | 2323 |
%}. |
2324 |
^ self primitiveFailed |
|
1336 | 2325 |
|
2326 |
" |
|
14632 | 2327 |
16rFFFF signExtendedShortValue |
2328 |
16r8000 signExtendedShortValue |
|
2329 |
16r7FFF signExtendedShortValue |
|
1336 | 2330 |
" |
701 | 2331 |
! ! |
2332 |
||
2333 |
!SmallInteger methodsFor:'comparing'! |
|
2334 |
||
2335 |
< aNumber |
|
2336 |
"return true, if the argument is greater than the receiver" |
|
2337 |
||
2338 |
%{ /* NOCONTEXT */ |
|
2339 |
||
2340 |
if (__isSmallInteger(aNumber)) { |
|
2341 |
#ifdef POSITIVE_ADDRESSES |
|
8908 | 2342 |
RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false ); |
701 | 2343 |
#else |
8908 | 2344 |
/* tag bit does not change ordering */ |
2345 |
RETURN ( ((INT)self < (INT)aNumber) ? true : false ); |
|
701 | 2346 |
#endif |
2347 |
} |
|
2348 |
if (__isFloatLike(aNumber)) { |
|
8908 | 2349 |
RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false ); |
701 | 2350 |
} |
6676
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2351 |
%}. |
701 | 2352 |
^ aNumber lessFromInteger:self |
2353 |
"^ self retry:#< coercing:aNumber" |
|
2354 |
! |
|
2355 |
||
2356 |
<= aNumber |
|
2357 |
"return true, if the argument is greater or equal" |
|
2358 |
||
2359 |
%{ /* NOCONTEXT */ |
|
2360 |
||
2361 |
if (__isSmallInteger(aNumber)) { |
|
2362 |
#ifdef POSITIVE_ADDRESSES |
|
8908 | 2363 |
RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false ); |
701 | 2364 |
#else |
8908 | 2365 |
/* tag bit does not change ordering */ |
2366 |
RETURN ( ((INT)self <= (INT)aNumber) ? true : false ); |
|
701 | 2367 |
#endif |
2368 |
} |
|
2369 |
if (__isFloatLike(aNumber)) { |
|
8908 | 2370 |
RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false ); |
701 | 2371 |
} |
5930
d7728046c2e1
compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents:
5782
diff
changeset
|
2372 |
%}. |
d7728046c2e1
compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents:
5782
diff
changeset
|
2373 |
^ (self > aNumber) not |
6676
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2374 |
|
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2375 |
"Modified: / 31.7.2002 / 10:07:17 / cg" |
701 | 2376 |
! |
2377 |
||
2378 |
= aNumber |
|
7356 | 2379 |
"return true, if the argument represents the same numeric value |
2380 |
as the receiver, false otherwise" |
|
701 | 2381 |
|
2382 |
%{ /* NOCONTEXT */ |
|
2383 |
||
2384 |
if (aNumber == self) { |
|
8908 | 2385 |
RETURN ( true ); |
701 | 2386 |
} |
2387 |
if (! __isNonNilObject(aNumber)) { |
|
8908 | 2388 |
/* a smallint or nil */ |
2389 |
RETURN ( false ); |
|
701 | 2390 |
} |
2391 |
||
7356 | 2392 |
if (__qIsFloatLike(aNumber)) { |
8908 | 2393 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false ); |
701 | 2394 |
} |
7356 | 2395 |
if (__qIsShortFloat(aNumber)) { |
8908 | 2396 |
RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false ); |
7356 | 2397 |
} |
2398 |
%}. |
|
2399 |
^ aNumber equalFromInteger:self |
|
701 | 2400 |
! |
2401 |
||
2402 |
> aNumber |
|
2403 |
"return true, if the argument is less than the receiver" |
|
2404 |
||
2405 |
%{ /* NOCONTEXT */ |
|
2406 |
||
2407 |
if (__isSmallInteger(aNumber)) { |
|
2408 |
#ifdef POSITIVE_ADDRESSES |
|
8908 | 2409 |
RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false ); |
701 | 2410 |
#else |
8908 | 2411 |
/* tag bit does not change ordering */ |
2412 |
RETURN ( ((INT)self > (INT)aNumber) ? true : false ); |
|
701 | 2413 |
#endif |
2414 |
} |
|
2415 |
if (__isFloatLike(aNumber)) { |
|
8908 | 2416 |
RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false ); |
701 | 2417 |
} |
5930
d7728046c2e1
compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents:
5782
diff
changeset
|
2418 |
%}. |
6676
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2419 |
^ (aNumber < self) |
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2420 |
|
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2421 |
"Modified: / 31.7.2002 / 10:07:05 / cg" |
701 | 2422 |
! |
2423 |
||
2424 |
>= aNumber |
|
2425 |
"return true, if the argument is less or equal" |
|
2426 |
||
2427 |
%{ /* NOCONTEXT */ |
|
2428 |
||
2429 |
if (__isSmallInteger(aNumber)) { |
|
2430 |
#ifdef POSITIVE_ADDRESSES |
|
8908 | 2431 |
RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false ); |
701 | 2432 |
#else |
8908 | 2433 |
/* tag bit does not change ordering */ |
2434 |
RETURN ( ((INT)self >= (INT)aNumber) ? true : false ); |
|
701 | 2435 |
#endif |
2436 |
} |
|
2437 |
if (__isFloatLike(aNumber)) { |
|
8908 | 2438 |
RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false ); |
701 | 2439 |
} |
5930
d7728046c2e1
compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents:
5782
diff
changeset
|
2440 |
%}. |
d7728046c2e1
compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents:
5782
diff
changeset
|
2441 |
^ (self < aNumber) not |
6676
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2442 |
|
15f2e3080e13
double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents:
6482
diff
changeset
|
2443 |
"Modified: / 31.7.2002 / 10:07:11 / cg" |
701 | 2444 |
! |
1 | 2445 |
|
701 | 2446 |
hash |
2447 |
"return an integer useful for hashing on value" |
|
2448 |
||
2449 |
self >= 0 ifTrue:[^ self]. |
|
2450 |
^ self negated |
|
2451 |
! |
|
2452 |
||
2453 |
identityHash |
|
2454 |
"return an integer useful for hashing on identity" |
|
2455 |
||
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
2456 |
self >= 0 ifTrue:[^ self]. |
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
2457 |
^ self negated |
1963
ea26c7b9ca1d
experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
2458 |
|
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
2459 |
"Modified: 11.11.1996 / 18:42:14 / cg" |
701 | 2460 |
! |
2461 |
||
2462 |
max:aNumber |
|
2463 |
"return the receiver or the argument, whichever is greater" |
|
2464 |
||
2465 |
%{ /* NOCONTEXT */ |
|
2466 |
||
2467 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 2468 |
#if TAG_INT == 1 |
2469 |
/* tag bit does not change ordering */ |
|
2470 |
if ((INT)(self) > (INT)(aNumber)) |
|
701 | 2471 |
#else |
2216 | 2472 |
if (__intVal(self) > __intVal(aNumber)) |
701 | 2473 |
#endif |
2216 | 2474 |
{ |
701 | 2475 |
RETURN ( self ); |
2476 |
} |
|
2477 |
RETURN ( aNumber ); |
|
2478 |
} |
|
2479 |
if (__isFloatLike(aNumber)) { |
|
1133 | 2480 |
if ( (double)__intVal(self) > __floatVal(aNumber) ) { |
701 | 2481 |
RETURN ( self ); |
2482 |
} |
|
2483 |
RETURN ( aNumber ); |
|
2484 |
} |
|
2216 | 2485 |
%}. |
2486 |
"/ fallback for non-smallInteger argument |
|
2487 |
||
701 | 2488 |
(self > aNumber) ifTrue:[^ self]. |
2489 |
^ aNumber |
|
2490 |
! |
|
2491 |
||
2492 |
min:aNumber |
|
2493 |
"return the receiver or the argument, whichever is smaller" |
|
2494 |
||
2495 |
%{ /* NOCONTEXT */ |
|
2496 |
||
2497 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 2498 |
#if TAG_INT == 1 |
2499 |
/* tag bit does not change ordering */ |
|
2500 |
if ((INT)(self) < (INT)(aNumber)) |
|
701 | 2501 |
#else |
2216 | 2502 |
if (__intVal(self) < __intVal(aNumber)) |
701 | 2503 |
#endif |
2216 | 2504 |
{ |
701 | 2505 |
RETURN ( self ); |
2506 |
} |
|
2507 |
RETURN ( aNumber ); |
|
2508 |
} |
|
2509 |
if (__isFloatLike(aNumber)) { |
|
1133 | 2510 |
if ( (double)__intVal(self) < __floatVal(aNumber) ) { |
701 | 2511 |
RETURN ( self ); |
2512 |
} |
|
2513 |
RETURN ( aNumber ); |
|
2514 |
} |
|
2216 | 2515 |
%}. |
2516 |
"/ fallback for non-smallInteger argument |
|
2517 |
||
701 | 2518 |
(self < aNumber) ifTrue:[^ self]. |
2519 |
^ aNumber |
|
2520 |
! |
|
2521 |
||
2522 |
~= aNumber |
|
2523 |
"return true, if the arguments value is not equal to mine" |
|
2524 |
||
2525 |
%{ /* NOCONTEXT */ |
|
2526 |
||
2527 |
if (aNumber == self) { |
|
8908 | 2528 |
RETURN ( false ); |
701 | 2529 |
} |
2530 |
if (! __isNonNilObject(aNumber)) { |
|
8908 | 2531 |
/* a smallint or nil */ |
2532 |
RETURN ( true ); |
|
701 | 2533 |
} |
2534 |
||
7356 | 2535 |
if (__qIsFloatLike(aNumber)) { |
8908 | 2536 |
RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false ); |
7356 | 2537 |
} |
2538 |
if (__qIsShortFloat(aNumber)) { |
|
8908 | 2539 |
RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false ); |
701 | 2540 |
} |
2216 | 2541 |
%}. |
7356 | 2542 |
^ (self = aNumber) not |
701 | 2543 |
! ! |
2544 |
||
2545 |
!SmallInteger methodsFor:'copying'! |
|
2546 |
||
2547 |
deepCopy |
|
2548 |
"return a deep copy of myself |
|
2549 |
- reimplemented here since smallintegers are unique" |
|
2550 |
||
2551 |
^ self |
|
2552 |
! |
|
2553 |
||
10947 | 2554 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
701 | 2555 |
"return a deep copy of myself |
2556 |
- reimplemented here since smallintegers are unique" |
|
2557 |
||
2558 |
^ self |
|
2559 |
! |
|
2560 |
||
2561 |
shallowCopy |
|
2562 |
"return a shallow copy of myself |
|
2563 |
- reimplemented here since smallintegers are unique" |
|
2564 |
||
2565 |
^ self |
|
2566 |
! |
|
2567 |
||
2568 |
simpleDeepCopy |
|
2569 |
"return a deep copy of myself |
|
2570 |
- reimplemented here since smallintegers are unique" |
|
2571 |
||
2572 |
^ self |
|
1 | 2573 |
! ! |
2574 |
||
214 | 2575 |
!SmallInteger methodsFor:'iteration'! |
1 | 2576 |
|
2577 |
timesRepeat:aBlock |
|
357 | 2578 |
"evaluate the argument, aBlock self times. |
2579 |
Reimplemented as primitive for speed" |
|
1 | 2580 |
|
357 | 2581 |
%{ |
2582 |
REGISTER INT tmp; |
|
2583 |
static struct inlineCache blockVal = __ILC0(0); |
|
1 | 2584 |
|
357 | 2585 |
tmp = __intVal(self); |
2586 |
if (tmp > 0) { |
|
8908 | 2587 |
if (__isBlockLike(aBlock) |
8913 | 2588 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) { |
8908 | 2589 |
{ |
2590 |
REGISTER OBJFUNC codeVal; |
|
2591 |
||
2592 |
/* |
|
2593 |
* specially tuned version for compiled blocks, |
|
2594 |
* (the most common case) |
|
2595 |
*/ |
|
2596 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
2678 | 2597 |
#ifdef PARANOIA |
8908 | 2598 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 2599 |
#endif |
8908 | 2600 |
) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2601 |
|
357 | 2602 |
#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
|
2603 |
|
2254 | 2604 |
# 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
|
2605 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2606 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2607 |
|
2254 | 2608 |
# define BLOCK_ARG rHome |
8908 | 2609 |
REGISTER OBJ rHome; |
2610 |
||
2611 |
/* |
|
2612 |
* home on stack - no need to refetch |
|
2613 |
*/ |
|
2614 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
2615 |
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
|
2616 |
#endif |
8908 | 2617 |
{ |
8919 | 2618 |
#ifdef __UNROLL_LOOPS__ |
2216 | 2619 |
|
8908 | 2620 |
/* |
2621 |
* you are not supposed to program like this - I know what I do |
|
2622 |
*/ |
|
2623 |
while (tmp > 8) { |
|
2624 |
if (InterruptPending != nil) goto interrupted0; |
|
2625 |
continue0: |
|
2626 |
(*codeVal)(BLOCK_ARG); |
|
2627 |
if (InterruptPending != nil) goto interrupted1; |
|
2628 |
continue1: |
|
2629 |
(*codeVal)(BLOCK_ARG); |
|
2630 |
if (InterruptPending != nil) goto interrupted2; |
|
2631 |
continue2: |
|
2632 |
(*codeVal)(BLOCK_ARG); |
|
2633 |
if (InterruptPending != nil) goto interrupted3; |
|
2634 |
continue3: |
|
2635 |
(*codeVal)(BLOCK_ARG); |
|
2636 |
if (InterruptPending != nil) goto interrupted4; |
|
2637 |
continue4: |
|
2638 |
(*codeVal)(BLOCK_ARG); |
|
2639 |
if (InterruptPending != nil) goto interrupted5; |
|
2640 |
continue5: |
|
2641 |
(*codeVal)(BLOCK_ARG); |
|
2642 |
if (InterruptPending != nil) goto interrupted6; |
|
2643 |
continue6: |
|
2644 |
(*codeVal)(BLOCK_ARG); |
|
2645 |
if (InterruptPending != nil) goto interrupted7; |
|
2646 |
continue7: |
|
2647 |
(*codeVal)(BLOCK_ARG); |
|
2648 |
tmp -= 8; |
|
2649 |
} |
|
8919 | 2650 |
#endif /* __UNROLL_LOOPS__ */ |
8908 | 2651 |
do { |
2652 |
if (InterruptPending != nil) goto interruptedX; |
|
2653 |
continueX: |
|
2654 |
(*codeVal)(BLOCK_ARG); |
|
2655 |
} while(--tmp); |
|
2656 |
||
2657 |
RETURN (self); |
|
2658 |
if (0) { |
|
8919 | 2659 |
#ifdef __UNROLL_LOOPS__ |
8908 | 2660 |
interrupted0: |
2661 |
__interruptL(@line); goto continue0; |
|
2662 |
interrupted1: |
|
2663 |
__interruptL(@line); goto continue1; |
|
2664 |
interrupted2: |
|
2665 |
__interruptL(@line); goto continue2; |
|
2666 |
interrupted3: |
|
2667 |
__interruptL(@line); goto continue3; |
|
2668 |
interrupted4: |
|
2669 |
__interruptL(@line); goto continue4; |
|
2670 |
interrupted5: |
|
2671 |
__interruptL(@line); goto continue5; |
|
2672 |
interrupted6: |
|
2673 |
__interruptL(@line); goto continue6; |
|
2674 |
interrupted7: |
|
2675 |
__interruptL(@line); goto continue7; |
|
8919 | 2676 |
#endif /* __UNROLL_LOOPS__ */ |
8908 | 2677 |
interruptedX: |
2678 |
__interruptL(@line); goto continueX; |
|
2679 |
} |
|
2680 |
} |
|
2681 |
} |
|
2682 |
} |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
2683 |
|
2216 | 2684 |
# undef BLOCK_ARG |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
2685 |
|
400 | 2686 |
#ifdef NEW_BLOCK_CALL |
2216 | 2687 |
# define BLOCK_ARG aBlock |
2688 |
# define IBLOCK_ARG nil |
|
400 | 2689 |
#else |
2216 | 2690 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
2691 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
400 | 2692 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
2693 |
|
8908 | 2694 |
/* |
2695 |
* sorry - must check for the blocks code within the loops; |
|
2696 |
* it could be recompiled or flushed (in the interrupt) |
|
2697 |
*/ |
|
2698 |
do { |
|
2699 |
REGISTER OBJFUNC codeVal; |
|
2700 |
||
2701 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
2702 |
/* |
|
2703 |
* arg is a compiled block with code - |
|
2704 |
* directly call it without going through Block>>value |
|
2705 |
* however, if there is an interrupt, refetch the code pointer. |
|
2706 |
*/ |
|
2707 |
/* stay here, while no interrupts are pending ... */ |
|
2708 |
do { |
|
2709 |
(*codeVal)(BLOCK_ARG); |
|
2710 |
if (InterruptPending != nil) goto outerLoop; |
|
2711 |
} while (--tmp); |
|
2712 |
RETURN (self); |
|
2713 |
} else { |
|
2714 |
if (InterruptPending != nil) __interruptL(@line); |
|
2715 |
||
2716 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
2717 |
/* |
|
2718 |
* arg is a compiled block with bytecode - |
|
2719 |
* directly call interpreter without going through Block>>value |
|
2720 |
*/ |
|
2721 |
__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil); |
|
2722 |
} else { |
|
2723 |
/* |
|
2724 |
* arg is something else - call it with #value |
|
2725 |
*/ |
|
2726 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
|
2727 |
} |
|
2728 |
} |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2729 |
outerLoop: ; |
8908 | 2730 |
} while (--tmp); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2731 |
|
2216 | 2732 |
# undef BLOCK_ARG |
2733 |
# undef IBLOCK_ARG |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2734 |
|
8908 | 2735 |
RETURN (self); |
2736 |
} |
|
2737 |
||
2738 |
/* |
|
2739 |
* not a block-like thingy - call it with #value |
|
2740 |
*/ |
|
2741 |
do { |
|
2742 |
if (InterruptPending != nil) __interruptL(@line); |
|
2743 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
|
2744 |
} while(--tmp); |
|
2745 |
RETURN (self); |
|
357 | 2746 |
} |
5412 | 2747 |
%}. |
2748 |
^ super timesRepeat:aBlock |
|
357 | 2749 |
|
2750 |
"/ |count "{ Class: SmallInteger }" | |
|
2751 |
"/ |
|
2752 |
"/ count := self. |
|
2753 |
"/ [count > 0] whileTrue:[ |
|
2754 |
"/ aBlock value. |
|
2755 |
"/ count := count - 1 |
|
2756 |
"/ ] |
|
1 | 2757 |
! |
2758 |
||
701 | 2759 |
to:stop by:incr do:aBlock |
2760 |
"reimplemented as primitive for speed" |
|
2761 |
||
2762 |
%{ |
|
2763 |
REGISTER INT tmp, step; |
|
2764 |
REGISTER INT final; |
|
2765 |
static struct inlineCache blockVal = __ILC1(0); |
|
2766 |
||
2767 |
if (__bothSmallInteger(incr, stop)) { |
|
1133 | 2768 |
tmp = __intVal(self); |
2769 |
final = __intVal(stop); |
|
2770 |
step = __intVal(incr); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2771 |
|
701 | 2772 |
if (__isBlockLike(aBlock) |
8913 | 2773 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2774 |
{ |
2254 | 2775 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2776 |
|
2216 | 2777 |
/* |
2778 |
* specially tuned version for static compiled blocks, called with |
|
2779 |
* home on the stack (the most common case) |
|
2780 |
*/ |
|
4167 | 2781 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 2782 |
#ifdef PARANOIA |
4167 | 2783 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 2784 |
#endif |
2785 |
) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2786 |
|
701 | 2787 |
#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
|
2788 |
|
2254 | 2789 |
# 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
|
2790 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2791 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2792 |
|
2254 | 2793 |
# define BLOCK_ARG rHome |
2794 |
REGISTER OBJ rHome; |
|
2795 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
8908 | 2796 |
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
|
2797 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2798 |
#endif |
2254 | 2799 |
{ |
2800 |
if (step < 0) { |
|
2801 |
if (step == -1) { |
|
2802 |
while (tmp >= final) { |
|
2803 |
if (InterruptPending != nil) __interruptL(@line); |
|
8913 | 2804 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2254 | 2805 |
tmp--; |
2216 | 2806 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2807 |
} else { |
2254 | 2808 |
while (tmp >= final) { |
2216 | 2809 |
if (InterruptPending != nil) __interruptL(@line); |
8913 | 2810 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2216 | 2811 |
tmp += step; |
2812 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2813 |
} |
2254 | 2814 |
} else { |
2815 |
if (step == 1) { |
|
2816 |
while (tmp <= final) { |
|
2817 |
if (InterruptPending != nil) __interruptL(@line); |
|
8913 | 2818 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2254 | 2819 |
tmp++; |
2820 |
} |
|
2821 |
} else { |
|
4167 | 2822 |
while (tmp <= final) { |
2254 | 2823 |
if (InterruptPending != nil) __interruptL(@line); |
8913 | 2824 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2254 | 2825 |
tmp += step; |
2826 |
} |
|
2827 |
} |
|
2216 | 2828 |
} |
2254 | 2829 |
RETURN (self); |
2216 | 2830 |
} |
2831 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2832 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2833 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2834 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2835 |
* 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
|
2836 |
* 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
|
2837 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2838 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2839 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2840 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2841 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2842 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2843 |
# define IBLOCK_ARG nil |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2844 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2845 |
# 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
|
2846 |
# 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
|
2847 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2848 |
|
701 | 2849 |
if (step < 0) { |
2850 |
while (tmp >= final) { |
|
2254 | 2851 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2852 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2853 |
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
|
2854 |
|
2254 | 2855 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 2856 |
/* |
2857 |
* arg is a compiled block with code - |
|
2858 |
* directly call it without going through Block>>value |
|
2859 |
*/ |
|
8913 | 2860 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2861 |
} else { |
2216 | 2862 |
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
|
2863 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2864 |
* 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
|
2865 |
* 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
|
2866 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2867 |
#ifdef PASS_ARG_POINTER |
2216 | 2868 |
{ |
2869 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2870 |
|
8913 | 2871 |
idx = __mkSmallInteger(tmp); |
2216 | 2872 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
2873 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2874 |
#else |
8913 | 2875 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2876 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2877 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2878 |
} else { |
2216 | 2879 |
/* |
2880 |
* arg is something else - call it with #value |
|
2881 |
*/ |
|
8913 | 2882 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2883 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2884 |
} |
701 | 2885 |
tmp += step; |
2886 |
} |
|
2887 |
} else { |
|
2888 |
while (tmp <= final) { |
|
2254 | 2889 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2890 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2891 |
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
|
2892 |
|
2254 | 2893 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 2894 |
/* |
2895 |
* arg is a compiled block with code - |
|
2896 |
* directly call it without going through Block>>value |
|
2897 |
*/ |
|
8913 | 2898 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2216 | 2899 |
} else { |
2900 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
2901 |
/* |
|
2902 |
* arg is a compiled block with bytecode - |
|
2903 |
* directly call interpreter without going through Block>>value |
|
2904 |
*/ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2905 |
#ifdef PASS_ARG_POINTER |
2216 | 2906 |
{ |
2907 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2908 |
|
8913 | 2909 |
idx = __mkSmallInteger(tmp); |
2216 | 2910 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
2911 |
} |
|
701 | 2912 |
#else |
8913 | 2913 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2914 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2915 |
|
2216 | 2916 |
} else { |
2917 |
/* |
|
2918 |
* arg is something else - call it with #value: |
|
2919 |
*/ |
|
8913 | 2920 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp)); |
2216 | 2921 |
} |
2922 |
} |
|
2923 |
tmp += step; |
|
2924 |
} |
|
701 | 2925 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2926 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2927 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2928 |
# undef IBLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2929 |
|
701 | 2930 |
} else { |
2931 |
/* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2932 |
* arg is something else - call it with #value: |
701 | 2933 |
*/ |
2934 |
if (step < 0) { |
|
2935 |
while (tmp >= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2936 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 2937 |
|
8908 | 2938 |
(*blockVal.ilc_func)(aBlock, |
2939 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2940 |
nil, &blockVal, |
8913 | 2941 |
__mkSmallInteger(tmp)); |
701 | 2942 |
tmp += step; |
2943 |
} |
|
2944 |
} else { |
|
2945 |
while (tmp <= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2946 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 2947 |
|
8908 | 2948 |
(*blockVal.ilc_func)(aBlock, |
2949 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2950 |
nil, &blockVal, |
8913 | 2951 |
__mkSmallInteger(tmp)); |
701 | 2952 |
tmp += step; |
2953 |
} |
|
2954 |
} |
|
2955 |
} |
|
2956 |
RETURN ( self ); |
|
2957 |
} |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
2958 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2959 |
"/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2960 |
"/ 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
|
2961 |
"/ pass on to super ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2962 |
|
701 | 2963 |
^ super to:stop by:incr do:aBlock |
2964 |
||
2965 |
" |
|
2966 |
1 to:10 by:3 do:[:i | i printNewline] |
|
2967 |
" |
|
2968 |
! |
|
2969 |
||
1 | 2970 |
to:stop do:aBlock |
62 | 2971 |
"evaluate aBlock for every integer between (and including) the receiver |
2972 |
and the argument, stop. |
|
357 | 2973 |
Reimplemented as primitive for speed" |
1 | 2974 |
|
2975 |
%{ |
|
2976 |
REGISTER INT tmp; |
|
2977 |
INT final; |
|
216 | 2978 |
static struct inlineCache blockVal = __ILC1(0); |
1 | 2979 |
|
252 | 2980 |
if (__isSmallInteger(stop)) { |
1133 | 2981 |
tmp = __intVal(self); |
2982 |
final = __intVal(stop); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2983 |
|
214 | 2984 |
if (__isBlockLike(aBlock) |
8913 | 2985 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2986 |
{ |
2216 | 2987 |
/* |
2988 |
* 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
|
2989 |
* where called with home on the stack |
2216 | 2990 |
*/ |
2254 | 2991 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2992 |
|
4167 | 2993 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2254 | 2994 |
|
13 | 2995 |
#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
|
2996 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2997 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2998 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2999 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3000 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3001 |
# define BLOCK_ARG rHome |
2216 | 3002 |
REGISTER OBJ rHome; |
3003 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
8908 | 3004 |
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
|
3005 |
#endif |
400 | 3006 |
{ |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3007 |
|
2678 | 3008 |
#ifdef PARANOIA |
8908 | 3009 |
if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 3010 |
#endif |
3011 |
{ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3012 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3013 |
* static compiled blocks ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3014 |
*/ |
8919 | 3015 |
#ifdef __UNROLL_LOOPS__ |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3016 |
/* |
2693 | 3017 |
* The following code is designed to run as fast as possible; |
3018 |
* - taken branches only if interrupts are pending |
|
3019 |
* - only forward branches (which are usually predicted as not taken) |
|
3020 |
* - unrolled the loop |
|
3021 |
* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3022 |
* 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
|
3023 |
*/ |
2693 | 3024 |
# if TAG_INT==1 |
8913 | 3025 |
INT t8 = (INT)(__mkSmallInteger(tmp+8)); |
3026 |
tmp = (INT)(__mkSmallInteger(tmp)); |
|
3027 |
final = (INT)(__mkSmallInteger(final)); |
|
2693 | 3028 |
# else |
2770 | 3029 |
INT t8 = tmp+8; |
2693 | 3030 |
# endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3031 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3032 |
for (;;) { |
2693 | 3033 |
|
3034 |
while (t8 <= final) { |
|
3035 |
# if TAG_INT==1 |
|
2770 | 3036 |
t8 += (INT)(__MASKSMALLINT(8)); |
2693 | 3037 |
# else |
3038 |
t8 += 8; |
|
3039 |
# endif |
|
3040 |
if (InterruptPending != nil) goto interrupted0; |
|
3041 |
continue0: |
|
3042 |
# if TAG_INT==1 |
|
3043 |
(*codeVal)(BLOCK_ARG, tmp); |
|
3044 |
# else |
|
8913 | 3045 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2693 | 3046 |
# endif |
3047 |
if (InterruptPending != nil) goto interrupted1; |
|
3048 |
continue1: |
|
3049 |
# if TAG_INT==1 |
|
2770 | 3050 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) ); |
2693 | 3051 |
# else |
8913 | 3052 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1)); |
2693 | 3053 |
# endif |
3054 |
if (InterruptPending != nil) goto interrupted2; |
|
3055 |
continue2: |
|
3056 |
# if TAG_INT==1 |
|
2770 | 3057 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) ); |
2693 | 3058 |
# else |
8913 | 3059 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2)); |
2693 | 3060 |
# endif |
3061 |
if (InterruptPending != nil) goto interrupted3; |
|
3062 |
continue3: |
|
3063 |
# if TAG_INT==1 |
|
2770 | 3064 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) ); |
2693 | 3065 |
# else |
8913 | 3066 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3)); |
2693 | 3067 |
# endif |
3068 |
if (InterruptPending != nil) goto interrupted4; |
|
3069 |
continue4: |
|
3070 |
# if TAG_INT==1 |
|
2770 | 3071 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) ); |
2693 | 3072 |
# else |
8913 | 3073 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4)); |
2693 | 3074 |
# endif |
3075 |
if (InterruptPending != nil) goto interrupted5; |
|
3076 |
continue5: |
|
3077 |
# if TAG_INT==1 |
|
2770 | 3078 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) ); |
2693 | 3079 |
# else |
8913 | 3080 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5)); |
2693 | 3081 |
# endif |
3082 |
if (InterruptPending != nil) goto interrupted6; |
|
3083 |
continue6: |
|
3084 |
# if TAG_INT==1 |
|
2770 | 3085 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) ); |
2693 | 3086 |
# else |
8913 | 3087 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6)); |
2693 | 3088 |
# endif |
3089 |
if (InterruptPending != nil) goto interrupted7; |
|
3090 |
continue7: |
|
3091 |
# if TAG_INT==1 |
|
2770 | 3092 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) ); |
2693 | 3093 |
# else |
8913 | 3094 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7)); |
2693 | 3095 |
# endif |
3096 |
||
3097 |
# if TAG_INT==1 |
|
2770 | 3098 |
tmp += (INT)(__MASKSMALLINT(8)); |
2693 | 3099 |
# else |
3100 |
tmp += 8; |
|
3101 |
# endif |
|
3102 |
} |
|
4167 | 3103 |
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
|
3104 |
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
|
3105 |
continueX: |
2693 | 3106 |
# if TAG_INT==1 |
3107 |
(*codeVal)(BLOCK_ARG, tmp); |
|
2770 | 3108 |
tmp += (INT)(__MASKSMALLINT(1)); |
2693 | 3109 |
# else |
8913 | 3110 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2693 | 3111 |
tmp++; |
3112 |
# endif |
|
4167 | 3113 |
} |
3114 |
RETURN (self); |
|
2693 | 3115 |
|
2216 | 3116 |
if (0) { |
3117 |
/* |
|
3118 |
* no discussion about those gotos ... |
|
3119 |
* ... its better for your CPU's pipelines |
|
3120 |
* (if you dont understand why, just dont argue). |
|
3121 |
*/ |
|
3122 |
interrupted7: |
|
3123 |
__interruptL(@line); goto continue7; |
|
3124 |
interrupted6: |
|
3125 |
__interruptL(@line); goto continue6; |
|
3126 |
interrupted5: |
|
3127 |
__interruptL(@line); goto continue5; |
|
3128 |
interrupted4: |
|
3129 |
__interruptL(@line); goto continue4; |
|
3130 |
interrupted3: |
|
3131 |
__interruptL(@line); goto continue3; |
|
3132 |
interrupted2: |
|
3133 |
__interruptL(@line); goto continue2; |
|
3134 |
interrupted1: |
|
3135 |
__interruptL(@line); goto continue1; |
|
3136 |
interrupted0: |
|
3137 |
__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
|
3138 |
interruptedX: |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
3139 |
__interruptL(@line); goto continueX; |
2216 | 3140 |
} |
2640 | 3141 |
} |
2641 | 3142 |
#else |
2640 | 3143 |
while (tmp <= final) { |
3144 |
if (InterruptPending != nil) __interruptL(@line); |
|
8913 | 3145 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2640 | 3146 |
tmp ++; |
2216 | 3147 |
} |
2640 | 3148 |
RETURN (self); |
8919 | 3149 |
#endif /* __UNROLL_LOOPS__ */ |
2216 | 3150 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3151 |
|
2216 | 3152 |
/* |
3153 |
* mhmh - seems to be a block with dynamic code |
|
3154 |
* must refetch, to allow dynamic recompilation or code flush. |
|
3155 |
*/ |
|
3156 |
while (tmp <= final) { |
|
3157 |
if (InterruptPending != nil) __interruptL(@line); |
|
2254 | 3158 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break; |
8913 | 3159 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
2216 | 3160 |
tmp ++; |
3161 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3162 |
|
2216 | 3163 |
if (tmp > final) { |
3164 |
RETURN (self); |
|
3165 |
} |
|
3166 |
} |
|
3167 |
} |
|
3168 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3169 |
|
2216 | 3170 |
# undef BLOCK_ARG |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3171 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3172 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3173 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3174 |
# define IBLOCK_ARG nil |
400 | 3175 |
#else |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3176 |
# 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
|
3177 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
400 | 3178 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
3179 |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3180 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3181 |
* 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
|
3182 |
* 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
|
3183 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3184 |
while (tmp <= final) { |
2254 | 3185 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3186 |
|
2254 | 3187 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 3188 |
/* |
3189 |
* arg is a compiled block with code - |
|
3190 |
* directly call it without going through Block>>value |
|
3191 |
*/ |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3192 |
|
4167 | 3193 |
/* stay here, while no interrupts are pending ... */ |
3194 |
do { |
|
8913 | 3195 |
(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp)); |
4167 | 3196 |
if (InterruptPending != nil) goto outerLoop; |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3197 |
tmp++; |
4167 | 3198 |
} while (tmp <= final); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3199 |
RETURN (self); |
2216 | 3200 |
} else { |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3201 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3202 |
|
2216 | 3203 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
3204 |
/* |
|
3205 |
* arg is a compiled block with bytecode - |
|
3206 |
* directly call interpreter without going through Block>>value |
|
3207 |
*/ |
|
400 | 3208 |
#ifdef PASS_ARG_POINTER |
2216 | 3209 |
{ |
3210 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3211 |
|
8913 | 3212 |
idx = __mkSmallInteger(tmp); |
2216 | 3213 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
3214 |
} |
|
400 | 3215 |
#else |
8913 | 3216 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp)); |
400 | 3217 |
#endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3218 |
|
2216 | 3219 |
} else { |
3220 |
/* |
|
3221 |
* arg is something else - call it with #value: |
|
3222 |
*/ |
|
8913 | 3223 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp)); |
2216 | 3224 |
} |
3225 |
} |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3226 |
outerLoop: ; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3227 |
tmp++; |
214 | 3228 |
} |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3229 |
|
2216 | 3230 |
# undef BLOCK_ARG |
3231 |
# undef IBLOCK_ARG |
|
1 | 3232 |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3233 |
RETURN (self); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3234 |
} |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3235 |
/* |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3236 |
* arg is something else - call it with #value: |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3237 |
*/ |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3238 |
while (tmp <= final) { |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3239 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3240 |
|
8908 | 3241 |
(*blockVal.ilc_func)(aBlock, |
3242 |
@symbol(value:), |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3243 |
nil, &blockVal, |
8913 | 3244 |
__mkSmallInteger(tmp)); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
3245 |
tmp++; |
214 | 3246 |
} |
3247 |
RETURN ( self ); |
|
1 | 3248 |
} |
400 | 3249 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
3250 |
|
400 | 3251 |
"/ |
3252 |
"/ 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
|
3253 |
"/ pass on to super ... |
400 | 3254 |
"/ |
62 | 3255 |
^ super to:stop do:aBlock |
3256 |
||
216 | 3257 |
" |
3258 |
1 to:10 do:[:i | i printNewline] |
|
3259 |
" |
|
701 | 3260 |
! ! |
1 | 3261 |
|
701 | 3262 |
!SmallInteger methodsFor:'misc math'! |
1 | 3263 |
|
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3264 |
bernoulli |
8908 | 3265 |
"returns the nth Bernoulli number. |
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3266 |
The series runs this: |
8908 | 3267 |
1/6, 1/30, 1/42, 1/30, 5/66, 691/2730, etc |
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3268 |
Uses a table of the first 20 bernoulli numbers. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3269 |
So bernoulli(42) will fail for now. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3270 |
Used with taylor series for tan" |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3271 |
|
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3272 |
|table p| |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3273 |
|
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3274 |
table := #( |
8908 | 3275 |
(1 6) |
3276 |
(-1 30) |
|
3277 |
(1 42) |
|
3278 |
(-1 30) |
|
3279 |
(5 66) |
|
3280 |
(-691 2730) |
|
3281 |
(7 6) |
|
3282 |
(-3617 510) |
|
3283 |
(43867 798) |
|
3284 |
(-174611 330) |
|
3285 |
(854513 138) |
|
3286 |
(-236364091 2730) |
|
3287 |
(8553103 6) |
|
3288 |
(-23749461029 870) |
|
3289 |
(8615841276005 14322) |
|
3290 |
(-7709321041217 510) |
|
3291 |
(2577687858367 6) |
|
3292 |
(-26315271553053477373 1919190) |
|
3293 |
(2929993913841559 6) |
|
3294 |
(-261082718496449122051 13530) |
|
3295 |
). |
|
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3296 |
|
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3297 |
self even ifTrue:[ |
8908 | 3298 |
self == 0 ifTrue:[^1]. |
3299 |
p := table at:(self / 2). |
|
3300 |
^ Fraction numerator:(p first) denominator:(p second). |
|
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3301 |
]. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3302 |
self == 1 ifTrue:[ ^ (1 / 2) ]. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3303 |
^ 0. |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3304 |
|
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3305 |
" |
8908 | 3306 |
0 bernoulli |
3307 |
1 bernoulli |
|
3308 |
2 bernoulli |
|
3309 |
3 bernoulli |
|
3310 |
4 bernoulli |
|
3311 |
5 bernoulli |
|
3312 |
6 bernoulli |
|
3313 |
8 bernoulli |
|
7438
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3314 |
38 bernoulli |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3315 |
40 bernoulli |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3316 |
41 bernoulli |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3317 |
42 bernoulli |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3318 |
" |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3319 |
! |
f5f6fd13b1df
code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents:
7356
diff
changeset
|
3320 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3321 |
divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3322 |
"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
|
3323 |
self \\ aNumber. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3324 |
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
|
3325 |
argument." |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3326 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3327 |
%{ /* NOCONTEXT */ |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3328 |
INT val, div, mod, mySelf; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3329 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
3330 |
if (__isSmallInteger(aNumber) && |
4167 | 3331 |
(val = __intVal(aNumber)) > 0) { |
3332 |
mySelf = __intVal(self); |
|
3333 |
div = mySelf / val; |
|
3334 |
mod = mySelf % val; |
|
3335 |
||
8913 | 3336 |
RETURN (__ARRAY_WITH2( __mkSmallInteger(div), |
3337 |
__mkSmallInteger(mod))); |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3338 |
} |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3339 |
%}. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3340 |
^ super divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3341 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3342 |
" |
8908 | 3343 |
10 // 3 |
3344 |
10 \\ 3 |
|
3345 |
10 divMod:3 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3346 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3347 |
! |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
3348 |
|
701 | 3349 |
gcd:anInteger |
3350 |
"return the greatest common divisor (Euclid's algorithm). |
|
3351 |
This has been redefined here for more speed since due to the |
|
3352 |
use of gcd in Fraction code, it has become time-critical for |
|
3353 |
some code. (thanx to MessageTally)" |
|
3354 |
||
3355 |
%{ /* NOCONTEXT */ |
|
1 | 3356 |
|
701 | 3357 |
if (__isSmallInteger(anInteger)) { |
4167 | 3358 |
INT orgArg, ttt, selfInt, orgSelfInt, temp; |
3359 |
||
3360 |
ttt = orgArg = __intVal(anInteger); |
|
3361 |
if (ttt) { |
|
3362 |
selfInt = orgSelfInt = __intVal(self); |
|
3363 |
while (ttt != 0) { |
|
3364 |
temp = selfInt % ttt; |
|
3365 |
selfInt = ttt; |
|
3366 |
ttt = temp; |
|
3367 |
} |
|
3368 |
/* |
|
3369 |
* since its not defined in C, what the sign of |
|
3370 |
* a modulus result is when the arg is negative, |
|
3371 |
* change it explicitely here ... |
|
3372 |
*/ |
|
3373 |
if (orgArg < 0) { |
|
3374 |
/* result should be negative */ |
|
3375 |
if (orgSelfInt > 0) selfInt = -selfInt; |
|
3376 |
} else { |
|
3377 |
/* result should be positive */ |
|
3378 |
if (orgSelfInt < 0) selfInt = -selfInt; |
|
3379 |
} |
|
8913 | 3380 |
RETURN ( __mkSmallInteger(selfInt) ); |
4167 | 3381 |
} |
1 | 3382 |
} |
3383 |
%} |
|
3384 |
. |
|
701 | 3385 |
^ super gcd:anInteger |
3386 |
! |
|
62 | 3387 |
|
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3388 |
gcd_helper:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3389 |
"same as gcd - see knuth & Integer>>gcd:" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3390 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3391 |
^ self gcd:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3392 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3393 |
"Created: 1.3.1997 / 16:58:01 / cg" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3394 |
! |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
3395 |
|
701 | 3396 |
intlog10 |
14492 | 3397 |
"return the truncation of log10 of the receiver. |
3398 |
The same as (self log:10) floor. |
|
3399 |
Stupid implementation, which is used to find out the number of digits needed |
|
701 | 3400 |
to print a number/and for conversion to a LargeInteger. |
7356 | 3401 |
Implemented that way, to allow for tiny systems (PDAs) without a Float class |
701 | 3402 |
(i.e. without log)." |
2 | 3403 |
|
701 | 3404 |
self <= 0 ifTrue:[ |
15322 | 3405 |
^ self class |
3406 |
raise:#domainErrorSignal |
|
3407 |
receiver:self |
|
3408 |
selector:#intlog10 |
|
3409 |
arguments:#() |
|
3410 |
errorString:'logarithm of negative integer' |
|
2 | 3411 |
]. |
14492 | 3412 |
self < 10000 ifTrue:[ |
15322 | 3413 |
self < 10 ifTrue:[^ 0]. |
3414 |
self < 100 ifTrue:[^ 1]. |
|
3415 |
self < 1000 ifTrue:[^ 2]. |
|
3416 |
^ 3 |
|
14492 | 3417 |
]. |
3418 |
self < 100000000 ifTrue:[ |
|
15322 | 3419 |
self < 100000 ifTrue:[^ 4]. |
3420 |
self < 1000000 ifTrue:[^ 5]. |
|
3421 |
self < 10000000 ifTrue:[^ 6]. |
|
3422 |
^ 7 |
|
14492 | 3423 |
]. |
7356 | 3424 |
self < 1000000000 ifTrue:[^ 8]. |
15322 | 3425 |
|
3426 |
SmallInteger maxBytes == 4 ifTrue:[ |
|
3427 |
^ 9 |
|
3428 |
] ifFalse:[ |
|
3429 |
self < 10000000000 ifTrue:[^ 9]. |
|
3430 |
self < 100000000000 ifTrue:[^ 10]. |
|
3431 |
self < 1000000000000 ifTrue:[^ 11]. |
|
3432 |
self < 10000000000000 ifTrue:[^ 12]. |
|
3433 |
self < 100000000000000 ifTrue:[^ 13]. |
|
3434 |
self < 1000000000000000 ifTrue:[^ 14]. |
|
3435 |
self < 10000000000000000 ifTrue:[^ 15]. |
|
3436 |
self < 100000000000000000 ifTrue:[^ 16]. |
|
3437 |
self < 1000000000000000000 ifTrue:[^ 17]. |
|
3438 |
^ 18. |
|
3439 |
]. |
|
3440 |
"/ not reached |
|
8908 | 3441 |
" |
3442 |
99 intlog10 |
|
14632 | 3443 |
100 intlog10 |
3444 |
101 intlog10 |
|
3445 |
(101 log:10) floor |
|
8908 | 3446 |
120 intlog10 |
6344 | 3447 |
-1 intlog10 |
3448 |
" |
|
2 | 3449 |
! ! |
3450 |
||
3135 | 3451 |
!SmallInteger methodsFor:'modulo arithmetic'! |
2 | 3452 |
|
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3453 |
plus32:aNumber |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3454 |
"return the sum of the receiver and the argument, as SmallInteger. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3455 |
The argument must be another SmallInteger. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3456 |
If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3457 |
This is of course not always correct, but allows for C/Java behavior to be emulated." |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3458 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3459 |
%{ /* NOCONTEXT */ |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3460 |
INT sum; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3461 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3462 |
sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3463 |
#if __POINTER_SIZE__ == 8 |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3464 |
sum &= 0xFFFFFFFFL; |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3465 |
#endif |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3466 |
RETURN ( __MKUINT(sum)); |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3467 |
%}. |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3468 |
self primitiveFailed |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3469 |
|
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3470 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3471 |
16r7FFFFFFF + 1 2147483648 |
14632 | 3472 |
16r7FFFFFFF plus32: 1 |
12876
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3473 |
" |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3474 |
! |
813dd84a5901
more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents:
12866
diff
changeset
|
3475 |
|
701 | 3476 |
plus:aNumber |
3477 |
"return the sum of the receiver and the argument, as SmallInteger. |
|
3478 |
The argument must be another SmallInteger. |
|
8908 | 3479 |
If the result overflows the smallInteger range, the value modulo the |
701 | 3480 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 3481 |
This is of course not always correct, but some code does a modulo anyway |
701 | 3482 |
and can therefore speed things up by not going through LargeIntegers." |
41 | 3483 |
|
701 | 3484 |
%{ /* NOCONTEXT */ |
3485 |
||
3486 |
if (__isSmallInteger(aNumber)) { |
|
8908 | 3487 |
INT sum; |
3488 |
||
3489 |
sum = __intVal(self) + __intVal(aNumber); |
|
3490 |
if (!__ISVALIDINTEGER(sum)) { |
|
3491 |
/* keep the sign */ |
|
3492 |
sum %= _MAX_INT; |
|
3493 |
} |
|
8913 | 3494 |
RETURN ( __mkSmallInteger(sum)); |
701 | 3495 |
} |
2785 | 3496 |
%}. |
701 | 3497 |
self primitiveFailed |
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3498 |
|
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3499 |
" |
8908 | 3500 |
5 plus:-1 |
3501 |
5 plus:1 |
|
3502 |
1 plus:-5 |
|
3503 |
self maxVal plus:1 |
|
3504 |
self maxVal + 1 |
|
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3505 |
" |
2 | 3506 |
! |
3507 |
||
701 | 3508 |
subtract:aNumber |
3509 |
"return the difference of the receiver and the argument, as SmallInteger. |
|
3510 |
The argument must be another SmallInteger. |
|
8908 | 3511 |
If the result overflows the smallInteger range, the value modulo the |
701 | 3512 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 3513 |
This is of course not always correct, but some code does a modulo anyway |
701 | 3514 |
and can therefore speed things up by not going through LargeIntegers." |
3515 |
||
3516 |
%{ /* NOCONTEXT */ |
|
2 | 3517 |
|
701 | 3518 |
if (__isSmallInteger(aNumber)) { |
8908 | 3519 |
INT diff; |
3520 |
||
3521 |
diff = __intVal(self) - __intVal(aNumber); |
|
3522 |
if (!__ISVALIDINTEGER(diff)) { |
|
3523 |
/* keep the sign */ |
|
3524 |
diff %= _MAX_INT; |
|
3525 |
} |
|
8913 | 3526 |
RETURN ( __mkSmallInteger(diff)); |
701 | 3527 |
} |
2216 | 3528 |
%}. |
701 | 3529 |
self primitiveFailed |
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3530 |
|
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3531 |
" |
8908 | 3532 |
-1 subtract:5 |
3533 |
5 subtract:1 |
|
3534 |
1 subtract:-5 |
|
3535 |
self minVal subtract:1 |
|
3536 |
self minVal - 1 |
|
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3537 |
" |
701 | 3538 |
! |
3539 |
||
3540 |
times:aNumber |
|
3541 |
"return the product of the receiver and the argument, as SmallInteger. |
|
3542 |
The argument must be another SmallInteger. |
|
8908 | 3543 |
If the result overflows the smallInteger range, the value modulo the |
701 | 3544 |
smallInteger range is returned (i.e. the low bits of the product). |
3135 | 3545 |
This is of course not always correct, but some code does a modulo anyway |
701 | 3546 |
and can therefore speed things up by not going through LargeIntegers." |
3547 |
||
3548 |
%{ /* NOCONTEXT */ |
|
3549 |
||
8506 | 3550 |
INT myValue, otherValue; |
3551 |
unsigned INT productLow, productHi; |
|
3552 |
int negative; |
|
3553 |
||
3554 |
# define low16Bits(foo) ((foo) & 0xFFFF) |
|
3555 |
# define hi16Bits(foo) ((foo) >> 16) |
|
3556 |
# define low32Bits(foo) ((foo) & 0xFFFFFFFFL) |
|
3557 |
# define hi32Bits(foo) ((foo) >> 32) |
|
3558 |
||
3559 |
/* |
|
3560 |
* can we use long long arithmetic ? |
|
3561 |
* |
|
3562 |
* long-long arithmetic seems to be buggy with some systems |
|
3563 |
* (took me a while to find this out :-( |
|
3564 |
* (try 10000 * 10000) |
|
3565 |
*/ |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3566 |
#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2) |
8506 | 3567 |
# define USE_LONGLONG_FOR_MUL |
3568 |
#endif |
|
3569 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3570 |
#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2) |
8506 | 3571 |
# define USE_LONGLONG_FOR_MUL |
3572 |
#endif |
|
3573 |
||
701 | 3574 |
if (__isSmallInteger(aNumber)) { |
14632 | 3575 |
myValue = __intVal(self); |
3576 |
otherValue = __intVal(aNumber); |
|
8506 | 3577 |
|
3578 |
#if defined(USE_LONGLONG_FOR_MUL) |
|
14632 | 3579 |
{ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3580 |
# if defined(__alpha__) && !defined(__alpha64__) |
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3581 |
# define LONGLONG INT64 |
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3582 |
# else |
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3583 |
# define LONGLONG long long |
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3584 |
# endif |
14632 | 3585 |
LONGLONG product; |
3586 |
||
3587 |
product = (LONGLONG)myValue * (LONGLONG)otherValue; |
|
3588 |
if (product < 0) { |
|
3589 |
RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT))); |
|
3590 |
} |
|
3591 |
RETURN ( __mkSmallInteger((INT)(product & _MAX_INT))); |
|
3592 |
} |
|
8506 | 3593 |
#else /* no long-long */ |
14632 | 3594 |
negative = 1; |
3595 |
if (myValue < 0) { |
|
3596 |
negative = -1; |
|
3597 |
myValue = -myValue; |
|
3598 |
} |
|
3599 |
if (otherValue < 0) { |
|
3600 |
negative = -negative; |
|
3601 |
otherValue = -otherValue; |
|
3602 |
} |
|
8506 | 3603 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3604 |
# if defined(__GNUC__) && defined(__mc68k__) |
14632 | 3605 |
asm ("mulu%.l %3,%1:%0" |
3606 |
: "=d" ((unsigned long)(productLow)), |
|
3607 |
"=d" ((unsigned long)(productHi)) |
|
3608 |
: "%0" ((unsigned long)(myValue)), |
|
3609 |
"dmi" ((unsigned long)(otherValue))); |
|
8506 | 3610 |
# else |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3611 |
# if defined (__GNUC__) && defined(__i386__) |
14632 | 3612 |
asm ("mull %3" |
3613 |
: "=a" ((unsigned long)(productLow)), |
|
3614 |
"=d" ((unsigned long)(productHi)) |
|
3615 |
: "%0" ((unsigned long)(myValue)), |
|
3616 |
"rm" ((unsigned long)(otherValue))); |
|
8506 | 3617 |
# else |
10342 | 3618 |
# if defined(WIN32) && defined(__BORLANDC__) |
14632 | 3619 |
asm { |
3620 |
mov eax, myValue |
|
3621 |
mov edx, otherValue |
|
3622 |
mul edx |
|
3623 |
mov productLow, eax |
|
3624 |
mov productHi, edx |
|
3625 |
} |
|
8506 | 3626 |
# else /* generic */ |
14632 | 3627 |
{ |
3628 |
unsigned INT pHH, pHL, pLH, pLL; |
|
3629 |
unsigned INT low1, low2, hi1, hi2; |
|
3630 |
unsigned INT t; |
|
3631 |
||
3632 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
|
3633 |
* |
|
3634 |
* this is too slow: |
|
3635 |
* since most machines can do 32*32 to 64 bit multiply, |
|
3636 |
* (or at least 32*32 with Overflow check) |
|
3637 |
* - need more assembler (inline) functions here |
|
3638 |
*/ |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3639 |
# if __POINTER_SIZE__ == 8 |
14632 | 3640 |
low1 = low32Bits((unsigned INT)myValue); |
3641 |
hi1 = hi32Bits((unsigned INT)myValue); |
|
3642 |
low2 = low32Bits((unsigned INT)otherValue); |
|
3643 |
hi2 = hi32Bits((unsigned INT)otherValue); |
|
8506 | 3644 |
# define LLMASK 0xC000000000000000L |
3645 |
# else |
|
14632 | 3646 |
low1 = low16Bits((unsigned INT)myValue); |
3647 |
hi1 = hi16Bits((unsigned INT)myValue); |
|
3648 |
low2 = low16Bits((unsigned INT)otherValue); |
|
3649 |
hi2 = hi16Bits((unsigned INT)otherValue); |
|
8506 | 3650 |
# define LLMASK 0xC0000000 |
3651 |
# endif |
|
3652 |
||
14632 | 3653 |
pLH = low1 * hi2; |
3654 |
pHL = hi1 * low2; |
|
3655 |
pLL = low1 * low2; |
|
3656 |
pHH = hi1 * hi2; |
|
3657 |
||
3658 |
/* |
|
3659 |
* the common case ... |
|
3660 |
*/ |
|
3661 |
if ((pHL == 0) |
|
3662 |
&& (pLH == 0) |
|
3663 |
&& (pHH == 0) |
|
3664 |
&& ((pLL & LLMASK) == 0)) { |
|
3665 |
if (negative < 0) { |
|
3666 |
RETURN ( __mkSmallInteger(- ((INT)pLL)) ); |
|
3667 |
} |
|
3668 |
RETURN ( __mkSmallInteger((INT)pLL) ); |
|
3669 |
} |
|
3670 |
||
3671 |
/* |
|
3672 |
* pHH |--------|--------| |
|
3673 |
* pLH |--------|--------| |
|
3674 |
* pHL |--------|--------| |
|
3675 |
* pLL |--------|--------| |
|
3676 |
*/ |
|
8506 | 3677 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3678 |
# if __POINTER_SIZE__ == 8 |
14632 | 3679 |
t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); |
3680 |
productLow = (t << 32) + low32Bits(pLL); |
|
3681 |
productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); |
|
8506 | 3682 |
# else |
14632 | 3683 |
t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); |
3684 |
productLow = (t << 16) + low16Bits(pLL); |
|
3685 |
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); |
|
8506 | 3686 |
# endif |
14632 | 3687 |
} |
8506 | 3688 |
# endif /* ! WIN32 */ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3689 |
# endif /* ! (__GNUC__ && __i386__) */ |
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8506
diff
changeset
|
3690 |
# endif /* ! (__GNUC__ && __mc68k__) */ |
8506 | 3691 |
|
14632 | 3692 |
if (negative < 0) { |
3693 |
RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT))); |
|
3694 |
} |
|
3695 |
RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT))); |
|
8506 | 3696 |
#endif /* ! USE_LONGLONG */ |
701 | 3697 |
} |
2216 | 3698 |
%}. |
8506 | 3699 |
|
701 | 3700 |
self primitiveFailed |
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3701 |
|
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3702 |
" |
14632 | 3703 |
5 times:-1 |
3704 |
5 times:1 |
|
3705 |
self maxVal-1 times:2 |
|
3706 |
self maxVal-1 times:-2 |
|
3707 |
self maxVal-1 * 2 bitAnd:16r3fffffff |
|
8498
854b2c98379e
keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
3708 |
" |
1 | 3709 |
! ! |
3710 |
||
3711 |
!SmallInteger methodsFor:'printing & storing'! |
|
3712 |
||
62 | 3713 |
printOn:aStream |
68 | 3714 |
"append my printstring (base 10) to aStream." |
62 | 3715 |
|
3716 |
aStream nextPutAll:(self printString) |
|
3717 |
! |
|
3718 |
||
11792
6782c723834a
changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents:
11728
diff
changeset
|
3719 |
printOn:aStream base:base showRadix:showRadix |
5988 | 3720 |
"append a string representation of the receiver in the specified numberBase to aStream |
3721 |
(if showRadix is true, with initial XXr) |
|
11792
6782c723834a
changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents:
11728
diff
changeset
|
3722 |
The base argument should be between 2 and 36." |
6144 | 3723 |
|
5988 | 3724 |
showRadix ifTrue:[ |
14632 | 3725 |
base printOn:aStream. |
3726 |
aStream nextPut:$r. |
|
5988 | 3727 |
]. |
11792
6782c723834a
changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents:
11728
diff
changeset
|
3728 |
|
14632 | 3729 |
(base isInteger and:[ base between:2 and:36 ]) ifTrue:[ |
3730 |
aStream nextPutAll:(self printStringRadix:base) |
|
11792
6782c723834a
changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents:
11728
diff
changeset
|
3731 |
] ifFalse:[ |
14632 | 3732 |
super printOn:aStream base:base showRadix:false. |
11792
6782c723834a
changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents:
11728
diff
changeset
|
3733 |
]. |
5988 | 3734 |
|
12977
fbf5437b15fb
changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents:
12876
diff
changeset
|
3735 |
"Created: / 07-09-2001 / 13:54:40 / cg" |
fbf5437b15fb
changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents:
12876
diff
changeset
|
3736 |
"Modified: / 02-08-2010 / 12:25:20 / cg" |
701 | 3737 |
! |
3738 |
||
1 | 3739 |
printString |
3740 |
"return my printstring (base 10)" |
|
3741 |
||
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3742 |
"since this was heavily used in some applications, |
68 | 3743 |
here is an exception to the rule of basing printString |
3744 |
upon the printOn: method." |
|
3745 |
||
1 | 3746 |
%{ /* NOCONTEXT */ |
15259 | 3747 |
char buffer[30]; /* enough for 64 bit machines */ |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3748 |
char *cp; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3749 |
OBJ newString = nil; |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3750 |
INT myValue; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3751 |
int negative = 0; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3752 |
int len; |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3753 |
|
15259 | 3754 |
if (self == __MKSMALLINT(0)) { |
3755 |
RETURN (@global(ZeroString)); |
|
3756 |
// RETURN (__MKSTRING_L("0", 1)); |
|
3757 |
} |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3758 |
myValue = __intVal(self); |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3759 |
#ifdef SLOW_CODE |
8908 | 3760 |
/* |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3761 |
* 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
|
3762 |
* (printf is soooo slow) |
369 | 3763 |
*/ |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3764 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3765 |
/* |
15259 | 3766 |
* PROTECT_REGISTERS: |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3767 |
* actually only needed on sparc: since thisContext is |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3768 |
* in a global register, which gets destroyed by printf, |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3769 |
* manually save it here - very stupid ... |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3770 |
*/ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3771 |
__BEGIN_PROTECT_REGISTERS__ |
15259 | 3772 |
len = snprintf(buffer, sizeof(buffer), "%"_ld_"", myValue); |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3773 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3774 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3775 |
if (len >= 0 && len <= sizeof(buffer)) { |
15259 | 3776 |
newString = __MKSTRING_L(buffer, len); |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3777 |
} |
2781 | 3778 |
#else |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3779 |
if (myValue < 0) { |
15259 | 3780 |
negative = 1; |
3781 |
myValue = -myValue; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3782 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3783 |
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
|
3784 |
*cp-- = '\0'; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3785 |
while (myValue != 0) { |
15259 | 3786 |
*cp = '0' + (myValue % 10); |
3787 |
myValue = myValue / 10; |
|
3788 |
cp--; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3789 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3790 |
if (negative) { |
15259 | 3791 |
*cp-- = '-'; |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3792 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3793 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
2781 | 3794 |
#endif |
282 | 3795 |
if (newString != nil) { |
15259 | 3796 |
RETURN (newString); |
282 | 3797 |
} |
3798 |
%}. |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3799 |
"/ only arrive here, |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3800 |
"/ when having memory problems (i.e. no space for string) ... |
282 | 3801 |
^ super printString |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3802 |
|
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3803 |
" |
8908 | 3804 |
1234 printString |
3805 |
0 printString |
|
3806 |
-100 printString |
|
15259 | 3807 |
|
3808 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 123456789012 printString ]] 180 180 180 170 180 |
|
3809 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 12345678 printString ]] 140 150 140 150 140 |
|
3810 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 1234 printString ]] 130 140 130 130 130 |
|
3811 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 12 printString ]] 130 120 120 120 110 |
|
3812 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 5 printString ]] 110 110 100 110 90 |
|
3813 |
Time millisecondsToRun:[ 1000000 timesRepeat:[ 0 printString ]] 60 |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
3814 |
" |
1 | 3815 |
! |
3816 |
||
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3817 |
printStringRadix:base |
62 | 3818 |
"return my printstring (optimized for bases 16, 10 and 8)" |
1 | 3819 |
|
3705 | 3820 |
|s| |
3821 |
||
3822 |
%{ |
|
15259 | 3823 |
char buffer[64+3]; /* for 64bit machines, base 2, plus sign, plus 0-byte */ |
3705 | 3824 |
char *cp; |
1 | 3825 |
OBJ newString; |
3705 | 3826 |
INT myValue; |
3827 |
int negative = 0; |
|
3706 | 3828 |
INT __base; |
1 | 3829 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3830 |
if (__isSmallInteger(base)) { |
15259 | 3831 |
if (self == __MKSMALLINT(0)) { |
3832 |
RETURN (__MKSTRING_L("0", 1)); |
|
3833 |
} |
|
3834 |
myValue = __intVal(self); |
|
3835 |
__base = __intVal(base); |
|
3706 | 3836 |
|
3705 | 3837 |
#ifdef SLOW_CODE |
15259 | 3838 |
/* disabled, because printf is slower than the code below */ |
3839 |
||
3840 |
switch (__base) { |
|
3841 |
case 10: |
|
3842 |
format = "%"_ld_""; |
|
3843 |
break; |
|
3844 |
case 16: |
|
3845 |
format = "%"_lx_""; |
|
3846 |
break; |
|
3847 |
case 8: |
|
3848 |
format = "%"_lo_""; |
|
3849 |
break; |
|
3850 |
} |
|
3851 |
||
3852 |
if (format) { |
|
3853 |
/* |
|
3854 |
* actually only needed on sparc: since thisContext is |
|
3855 |
* in a global register, which gets destroyed by printf, |
|
3856 |
* manually save it here - very stupid ... |
|
3857 |
*/ |
|
3858 |
__BEGIN_PROTECT_REGISTERS__ |
|
3859 |
||
3860 |
len = snprintf(buffer, sizeof(buffer), format, (long)myValue); |
|
3861 |
||
3862 |
__END_PROTECT_REGISTERS__ |
|
3863 |
||
3864 |
if (len > 0 && len <= sizeof(buffer)) { |
|
3865 |
newString = __MKSTRING_L(buffer, len); |
|
3866 |
if (newString != nil) { |
|
3867 |
RETURN (newString); |
|
3868 |
} |
|
3869 |
} |
|
3870 |
} |
|
3705 | 3871 |
#else |
15259 | 3872 |
if ((__base <= 36) && (__base > 1)) { |
3873 |
if (myValue < 0) { |
|
3874 |
negative = 1; |
|
3875 |
myValue = -myValue; |
|
3876 |
} |
|
3877 |
cp = buffer + sizeof(buffer) - 1; |
|
3878 |
*cp-- = '\0'; |
|
3879 |
while (myValue != 0) { |
|
3880 |
int digit; |
|
3881 |
||
3882 |
digit = myValue % __base; |
|
3883 |
if (digit <= 9) { |
|
3884 |
*cp = '0' + digit; |
|
3885 |
} else { |
|
3886 |
*cp = 'A' + digit - 10; |
|
3887 |
} |
|
3888 |
myValue = myValue / __base; |
|
3889 |
cp--; |
|
3890 |
} |
|
3891 |
if (negative) { |
|
3892 |
*cp-- = '-'; |
|
3893 |
} |
|
3894 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
|
3895 |
if (newString != nil) { |
|
3896 |
RETURN (newString); |
|
3897 |
} |
|
3898 |
} |
|
3705 | 3899 |
#endif |
1 | 3900 |
} |
314 | 3901 |
%}. |
3705 | 3902 |
"/ arrive here, for bad base, |
3903 |
"/ or when having memory problems (i.e. no space for string) ... |
|
3904 |
||
3905 |
"/ |
|
3906 |
"/ fall back for seldom used bases |
|
3907 |
"/ Notice: cannt use super>>printStringRadix: here, |
|
3908 |
"/ since that would lead to endless recursion ... |
|
3909 |
"/ (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
|
3910 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3911 |
s := WriteStream on:(String new:10). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3912 |
super printOn:s base:base. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3913 |
^ s contents. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3914 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3915 |
" |
8908 | 3916 |
127 printStringRadix:16 |
3917 |
123 printStringRadix:12 |
|
3918 |
123 printStringRadix:10 |
|
3919 |
123 printStringRadix:8 |
|
3920 |
123 printStringRadix:3 |
|
3921 |
123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3922 |
123 printStringRadix:1 |
3705 | 3923 |
|
8908 | 3924 |
-127 printStringRadix:16 |
3925 |
-123 printStringRadix:12 |
|
3926 |
-123 printStringRadix:10 |
|
3927 |
-123 printStringRadix:8 |
|
3928 |
-123 printStringRadix:3 |
|
3929 |
-123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
3930 |
" |
1 | 3931 |
! |
3932 |
||
3933 |
printfPrintString:formatString |
|
7746 | 3934 |
"non-standard, but sometimes useful. |
1 | 3935 |
return a printed representation of the receiver |
15259 | 3936 |
as specified by formatString, which is defined by the C-function 'printf'. |
8908 | 3937 |
No checking for string overrun - the resulting string |
62 | 3938 |
must be shorter than 256 chars or else ... |
2781 | 3939 |
This method is NONSTANDARD and may be removed without notice; |
15259 | 3940 |
it is provided to allow special conversions in very special situations. |
2781 | 3941 |
Notice that a conversion may not be portable; for example, |
3942 |
to correctly convert an int on a 64-bit alpha, a %ld is required, |
|
14632 | 3943 |
on 64bit mingw or visualc, %lld is required, |
3944 |
while other systems may be happy with a %d. |
|
15259 | 3945 |
You cannot use lld unconditionally, because some (old) c printfs do not support it!!) |
11923
bf02cbdab69f
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11792
diff
changeset
|
3946 |
Use at your own risk (if at all). |
15259 | 3947 |
WARNNG: this goes directly to the C-printf function and may therefore be inherently unsafe. |
11923
bf02cbdab69f
changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents:
11792
diff
changeset
|
3948 |
Please use the printf: method, which is safe as it is completely implemented in Smalltalk." |
1 | 3949 |
|
13 | 3950 |
%{ /* STACK: 400 */ |
1 | 3951 |
char buffer[256]; |
314 | 3952 |
OBJ s; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3953 |
int len; |
1 | 3954 |
|
12482
41f0acde1b79
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11923
diff
changeset
|
3955 |
if (__isStringLike(formatString)) { |
15259 | 3956 |
/* |
3957 |
* actually only needed on sparc: since thisContext is |
|
3958 |
* in a global register, which gets destroyed by printf, |
|
3959 |
* manually save it here - very stupid ... |
|
3960 |
*/ |
|
3961 |
__BEGIN_PROTECT_REGISTERS__ |
|
3962 |
||
3963 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self)); |
|
3964 |
||
3965 |
__END_PROTECT_REGISTERS__ |
|
3966 |
||
3967 |
if (len < 0) goto fail; |
|
3968 |
||
3969 |
s = __MKSTRING_L(buffer, len); |
|
3970 |
if (s != nil) { |
|
3971 |
RETURN (s); |
|
3972 |
} |
|
1 | 3973 |
} |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3974 |
fail: ; |
314 | 3975 |
%}. |
1 | 3976 |
self primitiveFailed |
3977 |
||
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3978 |
" |
15259 | 3979 |
123 printfPrintString:'%%d -> %d' |
3980 |
123 printfPrintString:'%%6d -> %6d' |
|
3981 |
123 printfPrintString:'%%x -> %x' |
|
3982 |
123 printfPrintString:'%%4x -> %4x' |
|
3983 |
123 printfPrintString:'%%04x -> %04x' |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8408
diff
changeset
|
3984 |
" |
1 | 3985 |
! ! |
701 | 3986 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3987 |
!SmallInteger methodsFor:'private'! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3988 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3989 |
sign:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3990 |
"private: for protocol completeness with LargeIntegers" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3991 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3992 |
|absVal| |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3993 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3994 |
absVal := self abs. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3995 |
aNumber < 0 ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3996 |
^ absVal negated |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3997 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3998 |
aNumber == 0 ifTrue:[^ 0]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
3999 |
^ absVal |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
4000 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
4001 |
" |
8908 | 4002 |
-4 sign:-1 |
4003 |
-4 sign:0 |
|
4004 |
-4 sign:1 |
|
4005 |
-4 sign:-1 |
|
4006 |
-4 sign:0 |
|
4007 |
-4 sign:1 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
4008 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
4009 |
! ! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
4010 |
|
701 | 4011 |
!SmallInteger methodsFor:'testing'! |
4012 |
||
4013 |
between:min and:max |
|
4014 |
"return true if the receiver is less than or equal to the argument max |
|
4015 |
and greater than or equal to the argument min. |
|
4016 |
- reimplemented here for speed" |
|
4017 |
||
4018 |
%{ /* NOCONTEXT */ |
|
4019 |
||
4020 |
if (__bothSmallInteger(min, max)) { |
|
4021 |
REGISTER INT selfVal; |
|
4022 |
||
1133 | 4023 |
selfVal = __intVal(self); |
4024 |
if (selfVal < __intVal(min)) { |
|
701 | 4025 |
RETURN ( false ); |
4026 |
} |
|
1133 | 4027 |
if (selfVal > __intVal(max)) { |
701 | 4028 |
RETURN ( false ); |
4029 |
} |
|
4030 |
RETURN ( true ); |
|
4031 |
} |
|
2216 | 4032 |
%}. |
701 | 4033 |
(self < min) ifTrue:[^ false]. |
4034 |
(self > max) ifTrue:[^ false]. |
|
4035 |
^ true |
|
4036 |
! |
|
4037 |
||
4038 |
even |
|
4039 |
"return true, if the receiver is even" |
|
4040 |
||
4041 |
%{ /* NOCONTEXT */ |
|
4042 |
||
2216 | 4043 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true ); |
5412 | 4044 |
%}. |
4045 |
^ super even |
|
701 | 4046 |
! |
4047 |
||
13386 | 4048 |
isPowerOfTwo |
4049 |
"return true, if the receiver is a power of 2" |
|
4050 |
||
4051 |
"/ mhmh: how about the following |
|
4052 |
"/ self == 0 ifTrue:[^ false]. |
|
4053 |
||
4054 |
^ (self bitAnd:(self - 1)) == 0 |
|
4055 |
||
4056 |
" |
|
4057 |
0 isPowerOfTwo |
|
4058 |
1 isPowerOfTwo |
|
4059 |
2 isPowerOfTwo |
|
14632 | 4060 |
3 isPowerOfTwo |
4061 |
4 isPowerOfTwo |
|
4062 |
16r8000000000000000 isPowerOfTwo |
|
4063 |
16r8000000000000001 isPowerOfTwo |
|
13386 | 4064 |
|
4065 |
10000 factorial isPowerOfTwo |
|
14632 | 4066 |
|n| n := 10000 factorial. Time millisecondsToRun:[1000 timesRepeat:[ n isPowerOfTwo]] |
13386 | 4067 |
" |
4068 |
||
4069 |
"Modified: / 20-06-2011 / 12:41:18 / cg" |
|
4070 |
! |
|
4071 |
||
701 | 4072 |
negative |
4073 |
"return true, if the receiver is less than zero |
|
4074 |
reimplemented here for speed" |
|
4075 |
||
4076 |
%{ /* NOCONTEXT */ |
|
4077 |
||
2216 | 4078 |
#if TAG_INT == 1 |
701 | 4079 |
/* tag bit does not change sign */ |
4080 |
RETURN ( ((INT)(self) < 0) ? true : false ); |
|
2216 | 4081 |
#else |
4082 |
RETURN ( (__intVal(self) < 0) ? true : false ); |
|
701 | 4083 |
#endif |
5412 | 4084 |
%}. |
4085 |
^ self < 0 |
|
701 | 4086 |
! |
4087 |
||
14693 | 4088 |
nextPowerOf2 |
4089 |
"return the power of 2 at or above the receiver. |
|
4090 |
Useful for padding." |
|
4091 |
||
4092 |
%{ /* NOCONTEXT */ |
|
4093 |
INT x; |
|
4094 |
||
4095 |
x = __intVal(self) - 1; |
|
4096 |
x |= (x >> 1); |
|
4097 |
x |= (x >> 2); |
|
4098 |
x |= (x >> 4); |
|
4099 |
x |= (x >> 8); |
|
4100 |
x |= (x >> 16); |
|
4101 |
#if __POINTER_SIZE__ == 8 |
|
4102 |
x |= (x >> 32); |
|
4103 |
#endif |
|
4104 |
RETURN (__MKINT(x + 1)); |
|
4105 |
%} |
|
4106 |
" |
|
4107 |
1 nextPowerOf2 |
|
4108 |
2 nextPowerOf2 |
|
4109 |
3 nextPowerOf2 |
|
4110 |
4 nextPowerOf2 |
|
4111 |
5 nextPowerOf2 |
|
4112 |
6 nextPowerOf2 |
|
4113 |
7 nextPowerOf2 |
|
4114 |
8 nextPowerOf2 |
|
4115 |
||
4116 |
22 nextPowerOf2 |
|
4117 |
10 factorial nextPowerOf2 |
|
4118 |
20 factorial nextPowerOf2 |
|
4119 |
" |
|
4120 |
! |
|
4121 |
||
701 | 4122 |
odd |
4123 |
"return true, if the receiver is odd" |
|
4124 |
||
4125 |
%{ /* NOCONTEXT */ |
|
4126 |
||
2216 | 4127 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false ); |
5412 | 4128 |
%}. |
4129 |
^ super odd |
|
4130 |
||
701 | 4131 |
! |
4132 |
||
13913 | 4133 |
parityOdd |
4134 |
"return true, if an odd number of bits are set in the receiver, false otherwise. |
|
4135 |
(i.e. true for odd parity) |
|
4136 |
Undefined for negative values (smalltalk does not require the machine to use 2's complement)" |
|
4137 |
||
4138 |
%{ /* NOCONTEXT */ |
|
4139 |
||
4140 |
// tricky, but very fast (google for it, to understand) |
|
4141 |
#if __POINTER_SIZE__ == 4 |
|
14632 | 4142 |
unsigned int v = __intVal(self); |
13913 | 4143 |
|
4144 |
v ^= v >> 16; |
|
4145 |
v ^= v >> 8; |
|
4146 |
v ^= v >> 4; |
|
4147 |
v &= 0xf; |
|
4148 |
RETURN ( ( (0x6996 >> v) & 1 ) ? true : false ); |
|
4149 |
#endif |
|
4150 |
%}. |
|
4151 |
^ super parityOdd |
|
4152 |
||
4153 |
" |
|
14632 | 4154 |
self assert: |
4155 |
(((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0]) |
|
4156 |
asByteArray collect:[:c | c + $0 asciiValue]) asString |
|
4157 |
= |
|
4158 |
'0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110' |
|
4159 |
||
4160 |
self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd). |
|
4161 |
self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd). |
|
4162 |
self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd). |
|
4163 |
self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd). |
|
4164 |
self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd). |
|
13913 | 4165 |
" |
4166 |
||
4167 |
"Modified (comment): / 09-01-2012 / 19:55:37 / cg" |
|
4168 |
! |
|
4169 |
||
701 | 4170 |
positive |
4171 |
"return true, if the receiver is not negative |
|
4172 |
reimplemented here for speed" |
|
4173 |
||
4174 |
%{ /* NOCONTEXT */ |
|
4175 |
||
2216 | 4176 |
#if TAG_INT == 1 |
701 | 4177 |
/* tag bit does not change sign */ |
4178 |
RETURN ( ((INT)(self) >= 0) ? true : false ); |
|
2216 | 4179 |
#else |
4180 |
RETURN ( (__intVal(self) >= 0) ? true : false ); |
|
701 | 4181 |
#endif |
5412 | 4182 |
%}. |
4183 |
^ super positive |
|
4184 |
||
701 | 4185 |
! |
4186 |
||
4187 |
sign |
|
7471 | 4188 |
"return the sign of the receiver (-1, 0 or 1). |
701 | 4189 |
reimplemented here for speed" |
4190 |
||
4191 |
%{ /* NOCONTEXT */ |
|
4192 |
||
1133 | 4193 |
INT val = __intVal(self); |
701 | 4194 |
|
4195 |
if (val < 0) { |
|
8913 | 4196 |
RETURN ( __mkSmallInteger(-1) ); |
701 | 4197 |
} |
4198 |
if (val > 0) { |
|
8913 | 4199 |
RETURN ( __mkSmallInteger(1) ); |
701 | 4200 |
} |
8913 | 4201 |
RETURN ( __mkSmallInteger(0) ); |
5412 | 4202 |
%}. |
4203 |
^ super sign |
|
701 | 4204 |
! |
4205 |
||
4206 |
strictlyPositive |
|
4207 |
"return true, if the receiver is greater than zero |
|
4208 |
reimplemented here for speed" |
|
4209 |
||
4210 |
%{ /* NOCONTEXT */ |
|
4211 |
||
2216 | 4212 |
#if TAG_INT == 1 |
701 | 4213 |
/* tag bit does not change sign */ |
4214 |
RETURN ( ((INT)(self) > 0) ? true : false ); |
|
2216 | 4215 |
#else |
4216 |
RETURN ( (__intVal(self) > 0) ? true : false ); |
|
701 | 4217 |
#endif |
5412 | 4218 |
%}. |
4219 |
^ super strictlyPositive |
|
701 | 4220 |
! ! |
4221 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
4222 |
!SmallInteger class methodsFor:'documentation'! |
701 | 4223 |
|
4224 |
version |
|
15325 | 4225 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.207 2013-05-27 08:12:49 cg Exp $' |
12482
41f0acde1b79
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11923
diff
changeset
|
4226 |
! |
41f0acde1b79
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11923
diff
changeset
|
4227 |
|
41f0acde1b79
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11923
diff
changeset
|
4228 |
version_CVS |
15325 | 4229 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.207 2013-05-27 08:12:49 cg Exp $' |
701 | 4230 |
! ! |
14755 | 4231 |
|
15259 | 4232 |
|
4233 |
SmallInteger initialize! |