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