SmallInteger.st
author Claus Gittinger <cg@exept.de>
Mon, 19 Aug 2019 17:10:26 +0200
changeset 24554 1841effd762b
parent 24406 588966201b30
child 24694 65f3557c7a36
permissions -rw-r--r--
#REFACTORING by exept class: SmallInteger changed: #bitCount #bitDeinterleave:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    12
"{ Package: 'stx:libbasic' }"
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    13
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
    14
"{ NameSpace: Smalltalk }"
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
    15
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    16
Integer subclass:#SmallInteger
20819
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    17
	instanceVariableNames:''
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    18
	classVariableNames:'ZeroString'
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    19
	poolDictionaries:''
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    20
	category:'Magnitude-Numbers'
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
    21
!
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    22
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    23
!SmallInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 COPYRIGHT (c) 1988 by Claus Gittinger
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    28
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    39
documentation
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    40
"
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    41
    SmallIntegers are Integers in the range of at least +/- 2^30
19318
Claus Gittinger <cg@exept.de>
parents: 19317
diff changeset
    42
    i.e. 31 bits, but this is not a guaranteed:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    43
	on an alpha or x86_64, 63 bits are used, if the system was configured for 64bit mode.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    44
	under the Schteam-VM, 64 bits are used (i.e. a full long integer)
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    45
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    46
    These are no real objects - they have no instances (not even storage !!)
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    47
    and cannot be subclassed.
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    48
    The reason is to save both storage and runtime by not boxing and
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    49
    garbage collecting SmallIntegers in the system.
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    50
    SmallInts are marked by having the TAG_INT
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    51
    bit set, in contrast to all other objects which do not.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    52
    Since this knowledge is hardwired into the system (and there is no
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    53
    class-field stored with SmallIntegers) there can be no subclass of
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    54
    SmallInteger (sorry).
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    55
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    56
    If you really need this kind of thing, create a subclass of Integer,
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    57
    with an instance variable holding the value.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    58
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    59
    Because the range and sharing of SmallIntegers is different among implementations
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    60
    (both in different dialects, and in different architectures within the Smalltalk/X family),
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    61
    you should not depend on the identity of two integers with the same value.
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    62
    For portable code, when comparing integers, use #'=' and #'~=' (instead of #'==' / #'~~'),
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    63
    unless you are comparing very small integers in the -1024 .. 0 .. 1024 range.
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    64
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    65
    [author:]
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    66
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    67
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    68
    [see also:]
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    69
	Number
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    70
	Float Fraction FixedPoint
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    71
	LargeInteger
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    72
"
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    73
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    75
!SmallInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
basicNew:size
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
    self error:'instances of SmallInteger cannot be created with new'
23476
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    89
!
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    90
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    91
fastFromString:aString at:startIndex
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    92
    "return the next SmallInteger from the string starting at startIndex.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    93
     No spaces are skipped.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    94
     Raises an error, if the index is out of bounds,
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    95
     Returns garbage if the argument string is not a valid integer.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    96
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    97
     This is a specially tuned entry (using a low-level C-call to atol).
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    98
     It has been added to allow high speed string decomposition into 
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    99
     numbers, especially for mass-data (reading millions of numbers)."
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   100
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   101
%{   /* NOCONTEXT */
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   102
     if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   103
        char *cp = (char *)(__stringVal(aString));
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   104
        int idx = __intVal(startIndex) - 1;
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   105
        long atol(const char *);
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   106
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   107
        if ((unsigned)idx < __stringSize(aString)) {
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   108
            long val = atol(cp + idx);
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   109
            RETURN (__MKINT(val));
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   110
        }
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   111
     }
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   112
%}.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   113
     self primitiveFailed.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   114
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   115
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   116
     SmallInteger fastFromString:'hello12345' at:6
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   117
     SmallInteger fastFromString:'12345' at:1
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   118
     SmallInteger fastFromString:'12345' at:2
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   119
     SmallInteger fastFromString:'12345' at:3
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   120
     SmallInteger fastFromString:'12345' at:4
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   121
     SmallInteger fastFromString:'12345' at:5
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   122
     SmallInteger fastFromString:'12345' at:6
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   123
     SmallInteger fastFromString:'12345' at:0
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   124
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   125
     Time millisecondsToRun:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   126
        1000000 timesRepeat:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   127
            SmallInteger readFrom:'12345'
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   128
        ]
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   129
     ]
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   130
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   131
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   132
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   133
     Time millisecondsToRun:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   134
        1000000 timesRepeat:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   135
            SmallInteger fastFromString:'12345' at:1
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   136
        ]
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   137
     ]
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   138
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   139
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   140
    "Created: / 27-10-2018 / 08:52:32 / Claus Gittinger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   143
!SmallInteger class methodsFor:'bit mask constants'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   144
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   145
bitMaskFor:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   146
    "return a bitmask for the index's bit (index starts at 1)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   147
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   148
    (index between:1 and:SmallInteger maxBits) ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   149
	^ SubscriptOutOfBoundsSignal
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   150
		raiseRequestWith:index
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   151
		errorString:'index out of bounds'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   152
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   153
    ^ 1 bitShift:(index - 1)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   154
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   155
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   156
!SmallInteger class methodsFor:'class initialization'!
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   157
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   158
initialize
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   159
    ZeroString := '0'
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   160
! !
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   161
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   162
!SmallInteger class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
maxBits
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   165
    "return the number of bits in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   166
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   169
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   170
    // longs are always 64bits
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   171
    return context._RETURN ( STInteger._new(64) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   172
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   173
    RETURN ( __mkSmallInteger(N_INT_BITS) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   174
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   176
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   177
     SmallInteger maxBits
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   178
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
maxBytes
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   182
    "return the number of bytes in instances of me.
19486
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   183
     For very special uses only - not constant across implementations.
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   184
     Notice: this is inlined by the compiler(s) as a constant,
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   185
     therefore, a query like 'SmallInteger maxBytes == 8'
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   186
     costs nothing; it is compiled in as a constant."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   189
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   190
    // longs are always 8 bytes
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   191
    return context._RETURN ( STInteger._new(8) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   192
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   193
    RETURN ( __mkSmallInteger(N_INT_BITS / 8 + 1) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   194
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   195
%}
3684
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   196
    "
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   197
     SmallInteger maxBytes
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   198
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   199
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   200
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
maxVal
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   202
    "return the largest Integer representable as SmallInteger.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   203
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   204
a27a279701f8 Initial revision
claus
parents:
diff changeset
   205
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   206
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   207
    return context._RETURN ( STInteger._MAX_INTVAL );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   208
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   209
    RETURN ( __mkSmallInteger(_MAX_INT) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   210
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   211
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   212
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   213
     SmallInteger maxVal
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   214
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   215
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   216
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   217
minVal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   218
    "return the smallest Integer representable as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   219
     For very special uses only - not constant across implementations"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   220
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   221
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   222
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   223
    return context._RETURN ( STInteger._MIN_INTVAL );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   224
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   225
    RETURN ( __mkSmallInteger(_MIN_INT) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   226
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   227
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   228
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   229
     SmallInteger minVal
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   230
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   232
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   233
!SmallInteger class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   234
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   235
canBeSubclassed
21444
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   236
    "return true, if it's allowed to create subclasses of the receiver.
3914
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   237
     Return false here - since it is NOT possible for SmallInteger
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   238
     (due to the tagged representation of SmallIntegers)"
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   239
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   240
    ^ false
3914
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   241
21444
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   242
    "Modified: / 05-11-1998 / 16:11:27 / cg"
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   243
    "Modified (comment): / 13-02-2017 / 20:30:46 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   244
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   245
2672
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   246
hasImmediateInstances
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   247
    "return true if this class has immediate instances
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   248
     i.e. if the instances are represented in the pointer itself and
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   249
     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
   250
     Redefined from Behavior"
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   251
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   252
    ^ true
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   253
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   254
    "Created: 3.6.1997 / 12:01:26 / cg"
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   255
!
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   256
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   257
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   258
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   259
     Here, true is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   262
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   263
    "Modified: 23.4.1996 / 16:00:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
!SmallInteger methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
* aNumber
11728
0c197f1c3cd0 comment
Claus Gittinger <cg@exept.de>
parents: 11718
diff changeset
   269
    "return the product of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   272
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   273
    return context._RETURN( self.times( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   274
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   275
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   276
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   277
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   278
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   279
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   280
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   281
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   282
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   283
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   284
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   285
    INT myValue, otherValue;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   286
    unsigned INT productLow, productHi;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   287
    int negative;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   288
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   289
    myValue = __intVal(self);
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   290
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   291
#   define low16Bits(foo)  ((foo) & 0xFFFF)
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   292
#   define hi16Bits(foo)   ((foo) >> 16)
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   293
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   294
#   define hi32Bits(foo)   ((foo) >> 32)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   295
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   296
    /*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   297
     * can we use long long arithmetic ?
4176
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   298
     *
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   299
     * long-long arithmetic seems to be buggy with some systems
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   300
     * (took me a while to find this out :-(
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   301
     * (try 10000 * 10000)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   302
     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   303
# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   304
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   305
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   306
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   307
# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   308
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   309
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   310
252
   311
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   312
	otherValue = __intVal(aNumber);
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   313
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   314
# if defined(USE_LONGLONG_FOR_MUL)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   315
	{
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   316
#  if defined(__alpha__) && !defined(__alpha64__)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   317
#   define LONGLONG      INT64
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   318
#  else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   319
#   define LONGLONG      long long
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   320
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   321
	    LONGLONG product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   322
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   323
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   324
	    if ((product >= (LONGLONG)_MIN_INT)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   325
	     && (product <= (LONGLONG)_MAX_INT)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   326
		RETURN ( __mkSmallInteger((INT)product) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   327
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   328
	    if (product < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   329
		negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   330
		product = -product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   331
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   332
		negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   333
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   334
	    productHi = product >> 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   335
	    productLow = product & 0xFFFFFFFFLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   336
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   337
# else /* no long-long */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   338
	negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   339
	if (myValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   340
	    negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   341
	    myValue = -myValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   342
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   343
	if (otherValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   344
	    negative = -negative;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   345
	    otherValue = -otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   346
	}
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   347
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   348
#  if defined(__GNUC__) && defined(__mc68k__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   349
	asm ("mulu%.l %3,%1:%0"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   350
		: "=d"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   351
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   352
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   353
		  "dmi" ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   354
#  else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   355
#   if defined (__GNUC__) && defined(__x86__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   356
	asm ("mull %3"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   357
		: "=a"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   358
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   359
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   360
		  "rm"  ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   361
#   else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   362
#    if defined(__win32__) && defined(__BORLANDC__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   363
	asm {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   364
	    mov   eax, myValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   365
	    mov   edx, otherValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   366
	    mul   edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   367
	    mov   productLow, eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   368
	    mov   productHi, edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   369
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   370
#    else /* generic */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   371
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   372
	    unsigned INT pHH, pHL, pLH, pLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   373
	    unsigned INT low1, low2, hi1, hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   374
	    unsigned INT t;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   375
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   376
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   377
	     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   378
	     * this is too slow:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   379
	     * since most machines can do 32*32 to 64 bit multiply,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   380
	     * (or at least 32*32 with Overflow check)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   381
	     * - need more assembler (inline) functions here
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   382
	     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   383
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   384
	    low1 = low32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   385
	    hi1 = hi32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   386
	    low2 = low32Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   387
	    hi2 = hi32Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
   388
#      define LLMASK 0xC000000000000000LL
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   389
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   390
	    low1 = low16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   391
	    hi1 = hi16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   392
	    low2 = low16Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   393
	    hi2 = hi16Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
   394
#      define LLMASK 0xC0000000L
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   395
#     endif
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   396
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   397
	    pLH = low1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   398
	    pHL = hi1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   399
	    pLL = low1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   400
	    pHH = hi1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   401
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   402
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   403
	     * the common case ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   404
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   405
	    if ((pHL == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   406
	     && (pLH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   407
	     && (pHH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   408
	     && ((pLL & LLMASK) == 0)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   409
		if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   410
		    RETURN ( __mkSmallInteger(- ((INT)pLL)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   411
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   412
		RETURN ( __mkSmallInteger((INT)pLL) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   413
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   414
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   415
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   416
	     *   pHH |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   417
	     *   pLH          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   418
	     *   pHL          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   419
	     *   pLL                   |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   420
	     */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   421
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   422
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   423
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   424
	    productLow = (t << 32) + low32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   425
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   426
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   427
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   428
	    productLow = (t << 16) + low16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   429
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   430
#     endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   431
	}
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   432
#    endif /* ! __win32__ */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   433
#   endif /* ! (__GNUC__ && __x86__) */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   434
#  endif /* ! (__GNUC__ && __mc68k__) */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   435
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   436
	if (productHi == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   437
	    if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   438
		if (productLow <= -(_MIN_INT)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   439
		    RETURN ( __mkSmallInteger(-((INT)productLow)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   440
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   441
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   442
		if (productLow <= _MAX_INT) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   443
		    RETURN ( __mkSmallInteger(productLow) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   444
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   445
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   446
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   447
# endif /* ! USE_LONGLONG */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   448
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   449
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   450
	RETURN (__MKLARGEINT128(negative, productLow, productHi));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   451
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   452
	RETURN (__MKLARGEINT64(negative, productLow, productHi));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   453
# endif
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   454
    } else if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   455
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   456
	double val = (double)myValue * __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   457
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   458
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   459
	RETURN ( newFloat );
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   460
    } else if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   461
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   462
	float val = (float)myValue * __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   463
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   464
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   465
	RETURN ( newFloat );
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   466
    } else if (__isFractionLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   467
	OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   468
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   469
	if (myValue == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   470
	    RETURN(__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   471
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   472
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   473
	if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   474
	    INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   475
	    t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   476
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   477
		INT prod = myValue * num;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   478
		if (prod / myValue == num) { // check for overflow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   479
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   480
		    INT quo = prod / den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   481
		    if (quo * den == prod) {        // check for integer result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   482
			RETURN ( __mkSmallInteger(quo) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   483
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   484
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   485
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   486
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   487
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   488
#endif /* not __SCHTEAM__ */
2641
Claus Gittinger <cg@exept.de>
parents: 2640
diff changeset
   489
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
    ^ aNumber productFromInteger:self
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   491
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   492
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   493
	3 * (1/2)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   494
	6 * (1/2)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   495
	6 * (-1/2)
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   496
   "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   497
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   498
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   499
+ aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   500
    "return the sum of the receiver's value and the argument's value"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   501
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   502
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   503
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   504
    return context._RETURN( self.plus( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   505
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   506
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   507
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   508
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   509
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   510
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   511
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   512
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   513
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   514
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   515
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   516
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   517
# ifdef _ADD_IO_IO
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   518
	RETURN ( _ADD_IO_IO(self, aNumber) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   519
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   520
	REGISTER INT sum;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   521
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   522
	sum =  __intVal(self) + __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   523
	if (__ISVALIDINTEGER(sum)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   524
	    RETURN ( __mkSmallInteger(sum) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   525
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   526
	RETURN ( __MKLARGEINT(sum) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   527
# endif
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   528
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   529
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   530
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   531
	double val = (double)__intVal(self) + __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   532
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   533
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   534
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   535
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   536
    if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   537
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   538
	float val = (float)__intVal(self) + __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   539
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   540
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   541
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   542
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   543
#endif /* not __SCHTEAM__ */
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   544
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   545
    ^ aNumber sumFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   546
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   547
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   548
- aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   549
    "return the difference of the receiver's value and the argument's value"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   550
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   551
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   552
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   553
    return context._RETURN( self.minus( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   554
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   555
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   556
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   557
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   558
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   559
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   560
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   561
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   562
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   563
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   564
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   565
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   566
# ifdef _SUB_IO_IO
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   567
	RETURN ( _SUB_IO_IO(self, aNumber) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   568
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   569
	REGISTER INT diff =  __intVal(self) - __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   570
	if (__ISVALIDINTEGER(diff)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   571
	    RETURN ( __mkSmallInteger(diff) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   572
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   573
	RETURN ( __MKLARGEINT(diff) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   574
# endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   575
    }
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   576
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   577
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   578
	double val = (double)__intVal(self) - __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   579
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   580
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   581
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   582
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   583
    if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   584
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   585
	float val = (float)__intVal(self) - __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   586
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   587
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   588
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   589
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   590
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   591
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   592
    ^ aNumber differenceFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   593
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   594
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   595
/ aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   596
    "return the quotient of the receiver's value and the argument's value"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   597
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   599
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   600
    return context._RETURN( self.quotient( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   601
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   602
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   603
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   604
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   605
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   606
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   607
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   608
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   609
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   610
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   611
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   612
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   613
    INT t, val;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   614
    double dval;
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   615
    INT myValue = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   616
252
   617
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   618
	val = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   619
	if (val != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   620
	    t = myValue / val;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   621
# ifdef GOOD_OPTIMIZER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   622
	    if (myValue % val == 0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   623
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   624
	    /* this is stupid - all I want is to look for a remainder ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   625
	       but most compilers are too stupid and generate an extra modulus
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   626
	       instruction for "if (me % val)".
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   627
	       Even if most divide instructions already leave the remainder in
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   628
	       some register.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   629
	       Therefore I use a multiplication which is faster than a modulo
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   630
	       on most machines. Hint to GNU people :-)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   631
	    */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   632
	    if ((t * val) == myValue) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   633
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   634
		RETURN ( __mkSmallInteger(t) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   635
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   636
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   638
	if (__isFloatLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   639
	    dval = __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   640
	    if (dval != 0.0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   641
		OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   642
		double val = (double)myValue / dval;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   643
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   644
		__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   645
		RETURN ( newFloat );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   646
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   647
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   648
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   649
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   650
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   651
    aNumber isInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   652
	aNumber == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   653
	    ^ ZeroDivide raiseRequestWith:thisContext.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   654
	].
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   655
	^ Fraction numerator:self denominator:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   656
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   657
    ^ aNumber quotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   658
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   659
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   660
     8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   661
     9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   662
     9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   663
     9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   664
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   665
     -8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   666
     -9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   667
     -9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   668
     -9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   669
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   670
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   671
2
claus
parents: 1
diff changeset
   672
// aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   673
    "return the integer part of the quotient of the receiver's value
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   674
     and the argument's value.
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   675
     The result is truncated toward negative infinity
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   676
     and will be negative, if the operands signs differ.
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   677
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   678
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   679
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   680
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
20339
5d56805b999a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20333
diff changeset
   681
     Especially surprising (because of truncation toward negative infinity):
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   682
	-1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   683
	-10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   684
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   685
     See #quo: which truncates toward zero and returns -2 in the above case
20339
5d56805b999a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20333
diff changeset
   686
     and #rem: which is the corresponding remainder."
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   687
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   688
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   689
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   690
    return context._RETURN( self.quotientTruncated( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   691
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   692
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   693
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   694
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   695
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   696
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   697
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   698
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   699
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   700
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   701
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   702
    INT divisor, rslt;
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   703
    INT dividend = __intVal(self);
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   704
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   705
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   706
	divisor = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   707
	if (divisor != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   708
	    rslt = dividend / divisor;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   709
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   710
	     * Optimized to speed up positive result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   711
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   712
	    if (rslt <= 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   713
		if (rslt == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   714
		    if ((dividend ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   715
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   716
			 * result (negative) has been truncated toward 0.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   717
			 * Return -1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   718
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   719
			 rslt = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   720
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   721
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   722
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   723
		     * If result (negative) has been truncated toward 0,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   724
		     * subtract 1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   725
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   726
		    if (divisor > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   727
			if (rslt * divisor > dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   728
			    rslt--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   729
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   730
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   731
			if (rslt * divisor < dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   732
			    rslt--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   733
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   734
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   735
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   736
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   737
	    RETURN ( __mkSmallInteger(rslt) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   738
	}
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   739
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   740
	if (__isFractionLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   741
	    OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   742
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   743
		INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   744
		t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   745
		if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   746
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   747
		    INT prod;
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   748
#if 0 && defined(__GNUC__) // supported from GCC 5
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   749
		    if (!__builtin_mul_overflow(myself, den, &prod)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   750
			goto out;   // overflow, try harder...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   751
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   752
#else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   753
		    prod = dividend * den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   754
		    // make sure, that no overflow occurred
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   755
		    if (prod / den != dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   756
			goto out;   // overflow, try harder...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   757
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   758
#endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   759
		    rslt = prod / num;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   760
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   761
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   762
		     * Optimized to speed up positive result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   763
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   764
		    if (rslt <= 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   765
			if (rslt == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   766
			    if ((dividend ^ num) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   767
				/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   768
				 * result (negative) has been truncated toward 0.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   769
				 * Return -1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   770
				 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   771
				 rslt = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   772
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   773
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   774
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   775
			     * If result (negative) has been truncated toward 0,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   776
			     * subtract 1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   777
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   778
			    if (num > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   779
				if (rslt * num > prod) rslt--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   780
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   781
				if (rslt * num < prod) rslt--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   782
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   783
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   784
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   785
		    RETURN ( __mkSmallInteger(rslt) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   786
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   787
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   788
	}
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   789
    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   790
out:;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   791
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   792
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   793
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   794
	^ ZeroDivide raiseRequestWith:thisContext.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   795
    ].
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   796
    ^ aNumber integerQuotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   797
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   798
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   799
     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
   800
     -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
   801
     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
   802
     -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
   803
     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
   804
     -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
   805
     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
   806
     -1 // -2   ~~ 0 ifTrue:[self halt].
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   807
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   808
     -7 // (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   809
     -7 quo: (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   810
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   811
     7 // (-4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   812
     7 quo: (-4/3)
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   813
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   814
     10000 // 3600000 ~~ 0 ifTrue:[self halt].
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   815
     12 // (1 / 1000000000000000000)
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   816
     12 // (1 / 100000000000000)
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   817
     12 // 0.00000000000001s
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   818
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   819
     9 quo:4   => 2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   820
     -9 quo:4  => -2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   821
     9 quo:-4  => -2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   822
     -9 quo:-4 => 2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   823
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   824
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   825
    "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
   826
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   827
2
claus
parents: 1
diff changeset
   828
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   829
    "Answer the integer remainder m defined by division with truncation toward
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   830
     negative infinity.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   831
     m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   832
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   833
     The returned remainder has the same sign as aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   834
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   835
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   836
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   837
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   838
     Especially surprising:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   839
	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   840
			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   841
	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   842
			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   843
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   844
     See #rem: which is the corresponding remainder for division via #quo:.
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   845
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   846
     Redefined here for speed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   847
a27a279701f8 Initial revision
claus
parents:
diff changeset
   848
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   849
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   850
    return context._RETURN( self.remainder( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   851
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   852
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   853
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   854
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   855
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   856
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   857
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   858
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   859
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   860
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   861
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   862
    INT dividend, divisor, rem;
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   863
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   864
    if (__isSmallInteger(aNumber)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   865
	&& (divisor = __intVal(aNumber)) != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   866
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   867
	 * Note that the sign of something modulo a negative number is undefined
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   868
	 * in C!
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   869
	 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   870
	dividend = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   871
	rem = dividend % divisor;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   872
	if (rem) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   873
	    if ((rem ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   874
		/* sign of remainder is different from sign of divisor */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   875
		rem = -rem;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   876
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   877
	    if ((dividend ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   878
		/* different signs, so division would have returned a
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   879
		 * negative number.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   880
		 * C rounds toward zero, this code will simulate
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   881
		 * rounding towards negative infinity.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   882
		 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   883
		rem = divisor - rem;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   884
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   885
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   886
	RETURN ( __mkSmallInteger(rem) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   887
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   888
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   889
%}.
2
claus
parents: 1
diff changeset
   890
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   891
	^ ZeroDivide raiseRequestWith:thisContext.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   892
    ].
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   893
    ^ aNumber moduloFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   894
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   895
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   896
     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
   897
     -9 \\ 4 == 3 ifFalse:[self halt].
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   898
     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
   899
     -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
   900
     (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
   901
     (-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
   902
     1000 \\ 3600000 == 1000 ifFalse:[self halt]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   903
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   904
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   905
    "Modified: / 12-02-2012 / 20:43:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   906
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   907
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
abs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   909
    "return the absolute value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   910
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   911
a27a279701f8 Initial revision
claus
parents:
diff changeset
   912
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   913
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   914
    return context._RETURN( self.abs());
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   915
#else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   916
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   917
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   918
    if (val >= 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   919
	RETURN (self);
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   920
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   921
    if (val != _MIN_INT) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   922
	RETURN ( __mkSmallInteger(-val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   923
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   924
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   925
    RETURN( __MKLARGEINT(-_MIN_INT));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   926
#endif
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   927
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   928
    ^ super abs
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   929
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   930
a27a279701f8 Initial revision
claus
parents:
diff changeset
   931
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   932
    "return the negative value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   933
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   934
a27a279701f8 Initial revision
claus
parents:
diff changeset
   935
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   936
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   937
    return context._RETURN( self.negated());
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   938
#else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   939
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   940
a27a279701f8 Initial revision
claus
parents:
diff changeset
   941
    if (val != _MIN_INT) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   942
	RETURN ( __mkSmallInteger(- val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   943
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   944
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   945
    RETURN (__MKLARGEINT( -_MIN_INT));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   946
#endif
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   947
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   948
    ^ 0 - self
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   949
!
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   950
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   951
quo:aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   952
    "return the integer part of the quotient of the receiver's value
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   953
     and the argument's value. The result is truncated towards zero
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   954
     and negative, if the operands signs differ..
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   955
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   956
	(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
   957
     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
   958
     for negative results, the remainder is ignored.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   959
     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
   960
     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
   961
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   962
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   963
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   964
    return context._RETURN( self.quotient(aNumber));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   965
#else
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   966
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   967
	INT val = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   968
	if (val != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   969
	    RETURN ( __mkSmallInteger(__intVal(self) / val) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   970
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   971
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   972
	if (__isFractionLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   973
	    OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   974
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   975
		INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   976
		t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   977
		if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   978
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   979
		    INT myself = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   980
		    INT prod;
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   981
#if 0 && defined(__GNUC__) // supported from GCC 5
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   982
		    if (__builtin_mul_overflow(myself, den, &prod)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   983
			RETURN ( __mkSmallInteger(prod / num ));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   984
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   985
#else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   986
		    prod = myself * den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   987
		    // make sure, that no overflow occurred
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   988
		    if (prod / den == myself) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   989
			RETURN ( __mkSmallInteger(prod / num ));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   990
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   991
#endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   992
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   993
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   994
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   995
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   996
#endif /* not __SCHTEAM__ */
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   997
%}.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   998
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   999
	^ ZeroDivide raiseRequestWith:thisContext.
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1000
    ].
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1001
    ^ self retry:#quo: coercing:aNumber
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1002
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1003
    "
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1004
     9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1005
     -9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1006
     9 quo:4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1007
     -9 quo:4
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
  1008
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1009
     -7 // (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1010
     -7 quo: (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1011
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1012
     7 // (-4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1013
     7 quo: (-4/3)
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1014
    "
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1015
!
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1016
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1017
sqrt
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1018
    "return the square root value of the receiver
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1019
     reimplemented here for speed"
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1020
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1021
%{  /* NOCONTEXT */
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1022
#ifdef __SCHTEAM__
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1023
    return context._RETURN( self.sqrt());
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1024
#else
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1025
    double val = __intVal(self);
21744
4ffcc8930e88 #BUGFIX by ca
ca
parents: 21743
diff changeset
  1026
    extern double sqrt();
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1027
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1028
    if (val >= 0.0) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1029
	RETURN (__MKFLOAT(sqrt(val)));
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1030
    }
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1031
#endif
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1032
%}.
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1033
    ^ self class
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1034
	raise:#imaginaryResultSignal
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1035
	receiver:self
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1036
	selector:#sqrt
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1037
	arguments:#()
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1038
	errorString:'bad (negative) receiver in sqrt'
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1039
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1040
    "
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1041
	2 sqrt
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1042
	-2 sqrt
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1043
    "
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1044
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1045
    "Created: / 08-05-2017 / 14:57:07 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1046
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1047
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1048
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1049
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1050
!SmallInteger methodsFor:'bit operators'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1051
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1052
bitAnd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1053
    "return the bitwise-and of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1054
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1055
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1056
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1057
    return context._RETURN( self.bitAnd(anInteger));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1058
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1059
    /* anding the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1060
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1061
	RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1062
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1063
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1064
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1065
    anInteger class == LargeInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1066
	^ anInteger bitAnd:self
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1067
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1068
    ^ self retry:#bitAnd: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1069
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1070
    "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1071
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1072
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1073
bitClear:anInteger
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1074
    "return the bitwise-and of the receiver and the complement of the argument, anInteger,
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1075
     returning the receiver with bits of the argument cleared.
19070
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1076
     (i.e. the same as self bitAnd:aMaskInteger bitInvert).
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1077
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1078
     but a new number is returned. Should be named #withBitCleared:"
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1079
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1080
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1081
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1082
    return context._RETURN( self.bitClear(anInteger));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1083
#else
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1084
    /* anding the tags doesn't change it */
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1085
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1086
	RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1087
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1088
#endif /* not __SCHTEAM__ */
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1089
%}.
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1090
    ^ self retry:#bitClear: coercing:anInteger
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1091
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1092
    "
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1093
     (2r001010100 bitClear:2r00001111) radixPrintStringRadix:2
5458
2aa89d4fad64 example
Claus Gittinger <cg@exept.de>
parents: 5447
diff changeset
  1094
     (2r111111111 bitClear:2r00001000) radixPrintStringRadix:2
19070
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1095
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1096
     (2r001010100 bitAnd:2r00001111 bitInvert) radixPrintStringRadix:2
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1097
    "
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1098
!
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1099
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1100
bitCount
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1101
    "return the number of 1-bits in the receiver"
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1102
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1103
%{  /* NOCONTEXT */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1104
#ifdef __SCHTEAM__
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1105
    long _v1, _v2;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1106
    long _self = self.longValue();
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1107
    long _cnt;
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1108
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1109
    _v1 = _self & 0xFFFFFFFF;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1110
    _v1 = _v1 - ((_v1 >> 1) & 0x55555555);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1111
    _v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1112
    _v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1113
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  1114
    _v2 = (_self >> 32) & 0xFFFFFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1115
    _v2 = _v2 - ((_v2 >> 1) & 0x55555555);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1116
    _v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1117
    _v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1118
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1119
    _cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24);
18948
cab22236fc65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18947
diff changeset
  1120
    return __c__._RETURN( STInteger._qnew( (byte)(_cnt) ) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1121
#else
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1122
    unsigned int _cnt;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1123
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1124
    // popcnt is actually slower on some (older) cpus;
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1125
    // and almost equal to ALG3 on modern intel hardware.
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1126
    // So ALGO3 is good for all
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1127
# if 0 && (defined(__GNUC__) || defined(clang)) && (defined(__x86__) || defined(__x86_64__))
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1128
#  define ALGORITHM_4
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1129
# else
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1130
#  define ALGORITHM_3
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1131
# endif
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  1132
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1133
# if defined( ALGORITHM_1 )
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1134
    // old k&r code; might be better if only one or two bits are set
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1135
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1136
    unsigned INT _self = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1137
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1138
    _cnt = 0;
11666
f30bc3b65e88 tricky bitCount
Claus Gittinger <cg@exept.de>
parents: 11519
diff changeset
  1139
    while (_self) {
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1140
        _cnt++;
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1141
        _self = _self & (_self - 1);
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1142
    }
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1143
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1144
# elif defined( ALGORITHM_2 )
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1145
    // seems to be faster on the average (and has better worst case)
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1146
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1147
    static unsigned char table[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1148
    unsigned INT _self = __intVal(self);
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1149
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1150
    _cnt = 0;
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1151
    while (_self) {
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1152
        _cnt += table[ _self & 0x0F ];
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1153
        _self >>= 4;
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1154
    }
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1155
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1156
# elif defined( ALGORITHM_3 )
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1157
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1158
    // the fastest, but hard (impossible) to understand (google for fastest bit count)
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1159
18898
0dc54d84ac92 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18897
diff changeset
  1160
    unsigned INT _self = __intVal(self);
0dc54d84ac92 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18897
diff changeset
  1161
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1162
#  if __POINTER_SIZE__ == 8
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1163
    unsigned int _v1, _v2;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1164
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1165
    _v1 = _self & 0xFFFFFFFF;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1166
    _v1 = _v1 - ((_v1 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1167
    _v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1168
    _v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1169
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1170
    _v2 = (unsigned int)(_self >> 32);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1171
    _v2 = _v2 - ((_v2 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1172
    _v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1173
    _v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1174
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1175
    _cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24);
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1176
#  else // POINTER_SIZE not 8
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1177
    _cnt = _self - ((_self >> 1) & 0x55555555);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1178
    _cnt = (_cnt & 0x33333333) + ((_cnt >> 2) & 0x33333333);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1179
    _cnt = ((_cnt + (_cnt >> 4)) & 0x0F0F0F0F);
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1180
    _cnt = (_cnt * 0x01010101) >> 24;
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1181
#  endif
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1182
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1183
# elif defined( ALGORITHM_4 )
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1184
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1185
     // using the popcnt instruction (x86 only); 
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1186
     // strange enough, this is slower than ALGO3 on some (older) Pentiums
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1187
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1188
#  if __POINTER_SIZE__ == 8
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1189
    unsigned INT _v;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1190
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1191
    #define _POPCNT(__op)                       \
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1192
    ({                                          \
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1193
        INT __rslt;                             \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1194
        asm("xor    %%rax,%%rax        \n       \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1195
             popcnt %1,%%rax           \n       \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1196
                        "  : "=a" (__rslt)      \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1197
                           : "g" ((INT)(__op))  \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1198
                           : "cc");             \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1199
        (OBJ)__rslt;                            \
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1200
     })
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1201
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1202
    _v = ((INT)self) - TAG_INT;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1203
    _cnt = _POPCNT(_v);
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1204
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1205
#  else // not POINTER_SIZE 8
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1206
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1207
    #define _POPCNT(__op)                       \
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1208
    ({                                          \
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1209
        INT __rslt;                             \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1210
        asm("xor     %%eax,%%eax        \n      \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1211
             popcnt  %1,%%eax           \n      \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1212
                        "  : "=a" (__rslt)      \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1213
                           : "g" ((INT)(__v))   \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1214
                           : "cc");             \
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1215
        (OBJ)__rslt;                            \
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1216
     })
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1217
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1218
    _v = ((INT)self) - TAG_INT;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1219
    _cnt = _POPCNT(_v);
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1220
#  endif
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1221
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1222
# elif defined( ALGORITHM_5 )
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1223
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1224
     // using the builtin_popcnt intrinsic
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1225
    unsigned INT _v;
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1226
    _v = ((INT)self) - TAG_INT;   // remove the tag
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1227
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1228
#  if __POINTER_SIZE__ == 8
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1229
    _cnt = __builtin_popcountll(_v);
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1230
#  else // not POINTER_SIZE 8
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1231
    _cnt = __builtin_popcountl(_v);
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1232
#  endif
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1233
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1234
# else
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1235
      error error error "which ALGORITHM?"
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1236
# endif
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1237
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1238
    RETURN ( __MKSMALLINT(_cnt));
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1239
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1240
#endif /* not __SCHTEAM__ */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1241
%}.
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1242
    ^ super bitCount.
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1243
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1244
    "
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1245
     16rAA bitCount
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1246
     
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1247
     TimeDuration toRun:[
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1248
        1 to:10000000 do:[:n |
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1249
            n bitCount
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1250
        ].
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1251
     ]   
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1252
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1253
     AL1: 967ms 958ms 971ms 930ms
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1254
     AL2: 900ms 872ms 877ms 870ms
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1255
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1256
     AL3: 879ms 849ms 831ms 849ms 
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1257
     AL4: 858ms 852ms 846ms 810ms
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1258
     AL5: 830ms 843ms 835ms 845ms
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  1259
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1260
     Mac PB2012/2.6Ghz I7
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1261
     AL3: 855ms 885ms 859ms 878ms 844ms
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1262
     AL5: 877ms 877ms 846ms 890ms 853ms
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1263
     
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1264
     1 to:1000000 do:[:n |
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1265
        self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
13909
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
  1266
     ].
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
  1267
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1268
     #( 16r00000000
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1269
        16r00010000 16r00100000 16r01000000 16r10000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1270
        16r00020000 16r00200000 16r02000000 16r20000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1271
        16r00040000 16r00400000 16r04000000 16r40000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1272
        16r00080000 16r00800000 16r08000000 16r80000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1273
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1274
        16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1275
        16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1276
        16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1277
        16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1278
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1279
        16r8000000000010000 16r8000000000100000 16r8000000001000000 16r8000000010000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1280
        16r8000000000020000 16r8000000000200000 16r8000000002000000 16r8000000020000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1281
        16r8000000000040000 16r8000000000400000 16r8000000004000000 16r8000000040000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1282
        16r8000000000080000 16r8000000000800000 16r8000000008000000 16r8000000080000000
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1283
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1284
        16r80000000FFFFFFFF 16r800000007FFFFFFF 16r800000003FFFFFFF 16r800000001FFFFFFF
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1285
        16r80000000EEEEEEEE 16r800000007EEEEEEE 16r800000003EEEEEEE 16r800000001EEEEEEE
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1286
        16r80000000DDDDDDDD 16r800000007DDDDDDD 16r800000003DDDDDDD 16r800000001DDDDDDD
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1287
        16r80000000CCCCCCCC 16r800000007CCCCCCC 16r800000003CCCCCCC 16r800000001CCCCCCC
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1288
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1289
        16rFFFFFFFFFFFFFFFF 16r7FFFFFFFFFFFFFFF 16r3FFFFFFFFFFFFFFF 16r1FFFFFFFFFFFFFFF
13909
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
  1290
     ) do:[:n |
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1291
        self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1292
     ]
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1293
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1294
     1 to:10000000 do:[:n |
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1295
        (n bitCount)
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1296
     ]
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1297
    "
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1298
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1299
    "Modified: / 09-01-2012 / 19:12:41 / cg"
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1300
    "Modified: / 20-03-2019 / 12:49:47 / Claus Gittinger"
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1301
!
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1302
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1303
bitDeinterleave:n
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1304
    "extract count integers from an n-way Morton number as a vector;
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1305
     This is the inverse operation from bitInterleave: - see comment there.
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1306
     i.e. if count is 3,
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1307
     and the receiver's bits are
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1308
        cN bN aN ... c2 b2 a2 c1 b1 a1 c0 b0 a0
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1309
     then the result will be a vector containing the numbers a,b,c with bits:
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1310
        aN ... a2 a1 a0
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1311
        bN ... b2 b1 b0
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1312
        cN ... c2 c1 c0.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1313
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1314
     Morton numbers are great to linearize 2D coordinates
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1315
     eg. to sort 2D points by distances"
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1316
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1317
%{
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1318
#if __POINTER_SIZE__ == 8
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1319
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1320
# define M5555555555555555 0x5555555555555555
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1321
# define M3333333333333333 0x3333333333333333
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1322
# define M0f0f0f0f0f0f0f0f 0x0f0f0f0f0f0f0f0f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1323
# define M00ff00ff00ff00ff 0x00ff00ff00ff00ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1324
# define M0000ffff0000ffff 0x0000ffff0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1325
# define M00000000ffffffff 0x00000000ffffffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1326
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1327
# define M9249249249249249 0x9249249249249249
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1328
# define M30c30c30c30c30c3 0x30c30c30c30c30c3
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1329
# define Mf00f00f00f00f00f 0xf00f00f00f00f00f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1330
# define M00ff0000ff0000ff 0x00ff0000ff0000ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1331
# define Mffff00000000ffff 0xffff00000000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1332
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1333
#else
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1334
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1335
# define M5555555555555555 0x55555555
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1336
# define M3333333333333333 0x33333333
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1337
# define M0f0f0f0f0f0f0f0f 0x0f0f0f0f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1338
# define M00ff00ff00ff00ff 0x00ff00ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1339
# define M0000ffff0000ffff 0x0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1340
# define M00000000ffffffff 0
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1341
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1342
# define M9249249249249249 0x49249249
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1343
# define M30c30c30c30c30c3 0xc30c30c3
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1344
# define Mf00f00f00f00f00f 0x0f00f00f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1345
# define M00ff0000ff0000ff 0xff0000ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1346
# define Mffff00000000ffff 0x0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1347
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1348
#endif
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1349
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1350
    unsigned INT bits = __intVal(self);
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1351
    unsigned INT a, b;
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1352
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1353
    if (n == __MKSMALLINT(2)) {
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1354
#       define morton2(x,dst) \
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1355
            { \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1356
                unsigned INT t; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1357
                t = (x) & M5555555555555555; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1358
                t = (t | (t >> 1))  & M3333333333333333; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1359
                t = (t | (t >> 2))  & M0f0f0f0f0f0f0f0f; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1360
                t = (t | (t >> 4))  & M00ff00ff00ff00ff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1361
                t = (t | (t >> 8))  & M0000ffff0000ffff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1362
                t = (t | (t >> 16)) & M00000000ffffffff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1363
                dst = t; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1364
            }
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1365
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1366
        morton2(bits, a);
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1367
        morton2(bits>>1, b);
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1368
        RETURN (__ARRAY_WITH2(__MKSMALLINT(a), __MKSMALLINT(b)));
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1369
    }
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1370
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1371
    if (n == __MKSMALLINT(3)) {
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1372
        unsigned INT c;
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1373
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1374
#       define morton3(x,dst) \
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1375
            { \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1376
                unsigned INT t; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1377
                t = (x) & M9249249249249249; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1378
                t = (t | (t >> 2))  & M30c30c30c30c30c3; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1379
                t = (t | (t >> 4))  & Mf00f00f00f00f00f; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1380
                t = (t | (t >> 8))  & M00ff0000ff0000ff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1381
                t = (t | (t >> 16)) & Mffff00000000ffff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1382
                t = (t | (t >> 32)) & M00000000ffffffff; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1383
                dst = t; \
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1384
            }
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1385
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1386
        morton3(bits, a);
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1387
        morton3(bits>>1, b);
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1388
        morton3(bits>>2, c);
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1389
        RETURN (__ARRAY_WITH3(__MKSMALLINT(a), __MKSMALLINT(b), __MKSMALLINT(c)));
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1390
    }
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1391
done: ;
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1392
%}.
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1393
    ^ super bitDeinterleave:n
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1394
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1395
    "
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1396
     (2r1100 bitInterleaveWith:2r1001) bitDeinterleave:2 -> #(12 9)
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1397
     (197 bitInterleaveWith:144) bitDeinterleave:2 -> #(197 144)
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1398
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1399
     (197 bitInterleaveWith:144 and:62) bitDeinterleave:3 -> #(197 144 62)
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1400
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1401
     |a b|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1402
     (0 to:31) do:[:bitA |
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1403
         a := 1 << bitA.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1404
         (0 to:31) do:[:bitB |
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1405
            b := 1 << bitB.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1406
            self assert:( (a bitInterleaveWith:b) bitDeinterleave:2 ) = {a . b }
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1407
         ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1408
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1409
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1410
     |a b c|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1411
     (0 to:31) do:[:bitA |
24554
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1412
         a := 1 << bitA.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1413
         (0 to:31) do:[:bitB |
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1414
             b := 1 << bitB.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1415
             (0 to:31) do:[:bitC |
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1416
                 c := 1 << bitC.
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1417
                 self assert:( (a bitInterleaveWith:b and:c) bitDeinterleave:3 ) = {a . b . c}
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1418
             ].
1841effd762b #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24406
diff changeset
  1419
         ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1420
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1421
    "
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1422
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1423
    "Created: / 28-08-2017 / 18:32:48 / cg"
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1424
!
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1425
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1426
bitInterleaveWith:anInteger
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1427
    "generate a Morton number (-> https://en.wikipedia.org/wiki/Morton_number_(number_theory))
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1428
     by interleaving bits of the receiver
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1429
     (at even positions if counting from 1) with bits of the argument (at odd bit positions).
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1430
     Thus, if the bits of the receiver are
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1431
	aN ... a2 a1 a0
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1432
     and those of the argument are:
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1433
	bN ... b2 b1 b0
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1434
     the result is
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1435
	bN aN ... b2 a2 b1 a1 b0 a0.
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1436
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1437
     Morton numbers are great to linearize 2D coordinates
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1438
     eg. to sort 2D points by distances"
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1439
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1440
%{
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1441
#if __POINTER_SIZE__ == 8
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1442
# define __SLOW_MULTIPLY__
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1443
# ifndef __SLOW_MULTIPLY__
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1444
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1445
    // the following is only faster, if multiplication is faster than a memory fetch
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1446
    if (__isSmallInteger(anInteger)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1447
	INT _a = __intVal(self);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1448
	INT _b = __intVal(anInteger);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1449
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1450
	if ( (((unsigned)_a)<=0xFFFFFFFF) && (((unsigned)_b)<=0xFFFFFFFF) )  {
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1451
	    int shift = 0;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1452
	    unsigned INT val = 0;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1453
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1454
	    // Interleave bits of (8-bit) a and b, so that all of the
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1455
	    // bits of a are in the even positions and b in the odd;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1456
	    // resulting in a 16-bit Morton Number.
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1457
#           define interleaveBytes(a,b) \
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1458
		((((a * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL >> 49) & 0x5555) \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1459
		| (((b * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL >> 48) & 0xAAAA))
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1460
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1461
	    while (_a | _b) {
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1462
		val |= (interleaveBytes((_a & 0xFF), (_b & 0xFF)) << shift);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1463
		_a = _a >> 8;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1464
		_b = _b >> 8;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1465
		shift += 16;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1466
	    }
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1467
	    RETURN (__MKUINT(val) );
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1468
	}
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1469
    }
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1470
# else
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1471
#  if __POINTER_SIZE__ == 8
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1472
#   define HALF_INT_MAX     0xFFFFFFFFFFFFFFFFLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1473
#   define M55555555        0x5555555555555555LL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1474
#   define M33333333        0x3333333333333333LL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1475
#   define M0F0F0F0F        0x0F0F0F0F0F0F0F0FLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1476
#   define M00FF00FF        0x00FF00FF00FF00FFLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1477
#   define M0000FFFF        0x0000FFFF0000FFFFLL
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1478
#  else
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1479
#   define HALF_INT_MAX     0xFFFFFFFFL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1480
#   define M55555555        0x55555555L
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1481
#   define M33333333        0x33333333L
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1482
#   define M0F0F0F0F        0x0F0F0F0FL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1483
#   define M00FF00FF        0x00FF00FFL
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1484
#   define M0000FFFF        0
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1485
#  endif
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1486
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1487
    if (__isSmallInteger(anInteger)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1488
	INT _a = __intVal(self);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1489
	INT _b = __intVal(anInteger);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1490
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1491
	if ( (((unsigned INT)_a)<=HALF_INT_MAX) && (((unsigned INT)_b)<=HALF_INT_MAX) )  {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1492
	    unsigned INT val;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1493
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1494
	    // spread the bits (...xxx -> ...0x0x0x)
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1495
	    _a = (_a | (_a << 16)) & M0000FFFF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1496
	    _a = (_a | (_a << 8))  & M00FF00FF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1497
	    _a = (_a | (_a << 4))  & M0F0F0F0F;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1498
	    _a = (_a | (_a << 2))  & M33333333;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1499
	    _a = (_a | (_a << 1))  & M55555555;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1500
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1501
	    _b = (_b | (_b << 16)) & M0000FFFF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1502
	    _b = (_b | (_b << 8))  & M00FF00FF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1503
	    _b = (_b | (_b << 4))  & M0F0F0F0F;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1504
	    _b = (_b | (_b << 2))  & M33333333;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1505
	    _b = (_b | (_b << 1))  & M55555555;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1506
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1507
	    // merge the bits (...0a0a0a and ...0b0b0b => ...bababa)
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1508
	    val = _a | (_b << 1);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1509
	    RETURN (__MKUINT(val) );
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1510
	}
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1511
    }
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1512
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1513
# endif
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1514
#endif
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1515
%}.
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1516
    ^ super bitInterleaveWith:anInteger
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1517
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1518
    "
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1519
     (2r1100 bitInterleaveWith:2r1001) printStringRadix:2 -> '11 01 00 10'
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1520
     (2r11000101 bitInterleaveWith:2r10010000) printStringRadix:2'1101001000010001 -> '11 01 00 10 00 01 00 01'
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1521
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1522
     |a b|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1523
     (0 to:31) do:[:bitA |
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1524
	 a := 1 << bitA.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1525
	 (0 to:31) do:[:bitB |
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1526
	    b := 1 << bitB.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1527
	    self assert:( (a bitInterleaveWith:b) bitDeinterleave:2 ) = {a . b }
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1528
	 ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1529
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1530
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1531
    "
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1532
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1533
    "Created: / 28-08-2017 / 14:33:52 / cg"
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1534
    "Modified (comment): / 28-08-2017 / 19:30:14 / cg"
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1535
!
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1536
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1537
bitInvert
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1538
    "return the value of the receiver with all bits inverted.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1539
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1540
     but a new number is returned. Could be named #withBitsInverted"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1541
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1542
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1543
#ifdef __SCHTEAM__
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1544
    long _self = self.longValue();
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1545
    return __c__._RETURN( STInteger._new( ~_self ) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1546
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1547
    /* invert anything except tag bits */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1548
    RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1549
#endif /* not __SCHTEAM__ */
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  1550
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1551
    ^ super bitInvert
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1552
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1553
19069
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1554
bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1555
    "return a new integer, where the low 8 bits are masked and complemented.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1556
     This returns an unsigned version of what bitInvert would return.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1557
     (i.e. same as self bitInvert bitAnd:16rFF)"
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1558
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1559
%{  /* NOCONTEXT */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1560
#ifdef __SCHTEAM__
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1561
    long _self = self.longValue();
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1562
    return __c__._RETURN( STInteger._new( ~_self & 0xFF) );
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1563
#else
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1564
    /* invert anything except tag bits */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1565
    RETURN ( (OBJ) (((INT)self ^ ~TAG_MASK) & (INT)(__mkSmallInteger(0xFF))) );
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1566
#endif /* not __SCHTEAM__ */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1567
%}.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1568
    ^ super bitInvertByte
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  1569
19069
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1570
    "
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1571
     16r7f bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1572
     16r7f bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1573
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1574
     16r80 bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1575
     16r80 bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1576
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1577
     16rff bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1578
     16rff bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1579
    "
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1580
!
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1581
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1582
bitOr:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1583
    "return the bitwise-or of the receiver and the argument, anInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1584
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1585
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1586
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1587
    return context._RETURN( self.bitOr( anInteger ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1588
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1589
    /* oring the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1590
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1591
	RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1592
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1593
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1594
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1595
    ^ self retry:#bitOr: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1596
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1597
    "
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1598
     (2r000000100 bitOr:2r00000011) radixPrintStringRadix:2
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1599
     (0 bitOr:16r20000000) hexPrintString
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1600
     (0 bitOr:16r40000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1601
     (0 bitOr:16r80000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1602
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1603
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1604
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1605
bitReversed
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1606
    "swap (i.e. reverse) bits in an integer
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1607
     i.e. a.b.c.d....x.y.z -> z.y.x...b.a.d.c.
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1608
     Warning: 
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1609
        do not use this without care: it depends on the machine's 
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1610
        word size; i.e. a 64bit machine will return a different result as a 32bit machine.
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1611
        Better use one of the bitReversedXX methods.
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1612
        This my vanish or be replaced by something better"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1613
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1614
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1615
#ifndef __SCHTEAM__
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1616
    unsigned INT v = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1617
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1618
# if __POINTER_SIZE__ == 8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1619
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1620
    v = ((v >> 1) & 0x5555555555555555) | ((v & 0x5555555555555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1621
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1622
    v = ((v >> 2) & 0x3333333333333333) | ((v & 0x3333333333333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1623
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1624
    v = ((v >> 4) & 0x0F0F0F0F0F0F0F0F) | ((v & 0x0F0F0F0F0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1625
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1626
    v = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1627
    // swap 2-byte pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1628
    v = ((v >> 16) & 0x0000FFFF0000FFFF) | (( v & 0x0000FFFF0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1629
    // swap 4-byte long pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1630
    v = ((v >> 32) & 0x00000000FFFFFFFF) | (( v & 0x00000000FFFFFFFF) << 32);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1631
# else
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1632
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1633
    v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1634
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1635
    v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1636
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1637
    v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1638
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1639
    v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1640
    // swap 2-byte long pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1641
    v = ((v >> 16) & 0x0000FFFF) | ((v & 0x0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1642
# endif
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1643
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1644
    if (v <= _MAX_INT) {
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1645
        RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1646
    }
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1647
    RETURN (__MKUINT(v));
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1648
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1649
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1650
    ^ super bitReversed
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1651
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1652
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1653
     2r1001 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1654
     2r100111010011 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1655
     -1 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1656
    "
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1657
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1658
    "Modified (comment): / 27-03-2019 / 18:28:47 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1659
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1660
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1661
bitReversed16
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1662
    "swap (i.e. reverse) the low 16 bits in an integer
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1663
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1664
     i.e. xxx.a.b.c.d....x.y.z -> 000.z.y.x...b.a.d.c."
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1665
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1666
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1667
#ifndef __SCHTEAM__
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1668
    unsigned int v = __intVal(self) & 0xFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1669
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1670
    // swap odd and even bits
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1671
    v = ((v >> 1) & 0x5555) | ((v & 0x5555) << 1);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1672
    // swap consecutive pairs
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1673
    v = ((v >> 2) & 0x3333) | ((v & 0x3333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1674
    // swap nibbles ...
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1675
    v = ((v >> 4) & 0x0F0F) | ((v & 0x0F0F) << 4);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1676
    // swap bytes
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1677
    v = ((v >> 8) & 0x00FF) | ((v & 0x00FF) << 8);
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1678
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1679
    RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1680
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1681
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1682
    ^ super bitReversed16
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1683
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1684
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1685
     2r1001 bitReversed16 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1686
     2r100111010011 bitReversed16 printStringRadix:2
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1687
     16r1ABCD bitReversed16 printStringRadix:2
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1688
     -1 bitReversed16 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1689
    "
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1690
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1691
    "Modified: / 24-03-2019 / 11:55:34 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1692
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1693
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1694
bitReversed32
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1695
    "swap (i.e. reverse) the low 32 bits in an integer
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1696
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1697
     i.e. xxx.a.b.c.d....x.y.z -> 000.z.y.x...b.a.d.c."
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1698
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1699
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1700
#ifndef __SCHTEAM__
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1701
    unsigned int v = __intVal(self) & 0xFFFFFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1702
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1703
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1704
    v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1705
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1706
    v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1707
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1708
    v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1709
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1710
    v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1711
    // swap 16bit words
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1712
    v = ((v >> 16) & 0x0000FFFF) | ((v & 0x0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1713
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1714
# if __POINTER_SIZE__ == 8
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1715
    RETURN ( __mkSmallInteger(v) );
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1716
# else
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1717
    if (v <= _MAX_INT) {
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1718
        RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1719
    }
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1720
    RETURN (__MKUINT(v));
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1721
# endif /* not __SCHTEAM__ */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1722
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1723
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1724
    ^ super bitReversed32
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1725
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1726
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1727
     2r1001 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1728
     2r100111010011 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1729
     -1 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1730
    "
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1731
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1732
    "Modified (format): / 27-03-2019 / 17:54:43 / Claus Gittinger"
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1733
!
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1734
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1735
bitReversed64
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1736
    "swap (i.e. reverse) the low 64 bits in an integer
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1737
     the high bits are ignored and clear in the result
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1738
     i.e. xxx.a.b.c.d....x.y.z -> 000.z.y.x...b.a.d.c."
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1739
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1740
%{  /* NOCONTEXT */
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1741
#ifndef __SCHTEAM__
23996
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1742
    unsigned INT v = __intVal(self);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1743
# if __POINTER_SIZE__ == 8
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1744
    // swap odd and even bits
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1745
    v = ((v >> 1) & 0x5555555555555555ULL) | ((v & 0x5555555555555555ULL) << 1);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1746
    // swap consecutive pairs
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1747
    v = ((v >> 2) & 0x3333333333333333ULL) | ((v & 0x3333333333333333ULL) << 2);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1748
    // swap nibbles ...
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1749
    v = ((v >> 4) & 0x0F0F0F0F0F0F0F0FULL) | ((v & 0x0F0F0F0F0F0F0F0FULL) << 4);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1750
    // swap bytes
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1751
    v = ((v >> 8) & 0x00FF00FF00FF00FFULL) | ((v & 0x00FF00FF00FF00FFULL) << 8);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1752
    // swap 16bit words
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1753
    v = ((v >> 16) & 0x0000FFFF0000FFFFULL) | ((v & 0x0000FFFF0000FFFFULL) << 16);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1754
    // swap 32bit words
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1755
    v = ((v >> 32) & 0x00000000FFFFFFFFULL) | ((v & 0x00000000FFFFFFFFULL) << 32);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1756
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1757
    if (v <= _MAX_INT) {
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1758
        RETURN ( __mkSmallInteger(v) );
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1759
    }
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1760
    RETURN (__MKUINT(v));
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1761
# else
23996
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1762
    // swap odd and even bits
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1763
    v = ((v >> 1) & 0x55555555UL) | ((v & 0x55555555UL) << 1);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1764
    // swap consecutive pairs
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1765
    v = ((v >> 2) & 0x33333333UL) | ((v & 0x33333333UL) << 2);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1766
    // swap nibbles ...
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1767
    v = ((v >> 4) & 0x0F0F0F0FUL) | ((v & 0x0F0F0F0FUL) << 4);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1768
    // swap bytes
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1769
    v = ((v >> 8) & 0x00FF00FFUL) | ((v & 0x00FF00FFUL) << 8);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1770
    // swap 16bit words
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1771
    v = ((v >> 16) & 0x0000FFFFUL) | ((v & 0x0000FFFFUL) << 16);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1772
    // swap 32bit words
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1773
    RETURN (__MKLARGEINT64(1, (INT)0, (INT)v));
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1774
# endif
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1775
#endif /* not __SCHTEAM__ */
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1776
%}.
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1777
    ^ super bitReversed64
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1778
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1779
    "
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1780
     2r1001 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1781
     2r100111010011 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1782
     -1 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1783
    "
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1784
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1785
    "Created: / 27-03-2019 / 18:11:11 / Claus Gittinger"
24004
7a3254568d7f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23996
diff changeset
  1786
    "Modified: / 27-03-2019 / 15:25:26 / stefan"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1787
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1788
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1789
bitReversed8
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1790
    "swap (i.e. reverse) the low 8 bits in an integer
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1791
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1792
     i.e. xxx.a.b.c.d....x.y.z -> 000.z.y.x...b.a.d.c."
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1793
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1794
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1795
#ifndef __SCHTEAM__
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1796
    unsigned int v = __intVal(self) & 0xFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1797
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1798
    // swap odd and even bits
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1799
    v = ((v >> 1) & 0x55) | ((v & 0x55) << 1);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1800
    // swap consecutive pairs
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1801
    v = ((v >> 2) & 0x33) | ((v & 0x33) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1802
    // swap nibbles ...
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1803
    v = ((v >> 4) & 0x0F) | ((v & 0x0F) << 4);
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1804
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1805
    RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1806
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1807
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1808
    ^ super bitReversed8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1809
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1810
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1811
     2r1001 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1812
     2r10011101 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1813
     2r111110011101 bitReversed8 printStringRadix:2
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1814
     16r1234 bitReversed8 printStringRadix:2
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1815
     -1 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1816
    "
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1817
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1818
    "Modified: / 24-03-2019 / 11:57:14 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1819
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1820
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1821
bitShift:shiftCount
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1822
    "return the value of the receiver shifted by shiftCount bits;
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1823
     leftShift if shiftCount > 0; rightShift otherwise.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1824
     Notice: the result of bitShift: on negative receivers is not
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1825
             defined in the language standard (since the implementation
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1826
             is free to choose any internal representation for integers).
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1827
             However, ST/X preserves the sign;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1828
             i.e. it is an arithmetic shift as long as you stay within the 
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1829
             number of bits supported by the platform."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1830
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1831
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1832
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1833
    return context._RETURN( self.bitShift( shiftCount ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1834
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1835
    INT bits, count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1836
252
  1837
    if (__isSmallInteger(shiftCount)) {
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1838
        bits = __intVal(self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1839
        if (bits == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1840
            RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1841
        }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1842
        count = __intVal(shiftCount);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1843
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1844
        if (count > 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1845
            INT sign = 1;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1846
            if (bits < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1847
                bits = -bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1848
                sign = -1;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1849
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1850
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1851
             * a left shift
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1852
             */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1853
# if defined(USE_LONGLONG_FOR_SHIFT)
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1854
            if (count <= N_INT_BITS) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1855
                unsigned LONGLONG result;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1856
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1857
                result = (unsigned LONGLONG)bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1858
                result <<= count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1859
                if (result <= _MAX_INT) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1860
                    if (sign < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1861
                        RETURN ( __MKINT(-result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1862
                    }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1863
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1864
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1865
                {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1866
                    RETURN (__MKLARGEINT64(sign, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1867
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1868
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1869
# else
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1870
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1871
             * check for overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1872
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1873
            if (count < (N_INT_BITS-1)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1874
                if (! (bits >> (N_INT_BITS - 1 - count))) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1875
                    INT result = bits << count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1876
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1877
                    if (sign < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1878
                        RETURN ( __MKINT(-result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1879
                    }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1880
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1881
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1882
                /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1883
                 * so, there is an overflow ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1884
                 * handle it as largeInteger
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1885
                 */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1886
                /* FALL THROUGH */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1887
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1888
# endif
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1889
        } else {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1890
            if (count == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1891
                RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1892
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1893
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1894
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1895
             * right shifts cannot overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1896
             *
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1897
             * some machines ignore shifts bigger than
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1898
             * the number of bits in an int ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1899
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1900
            count = -count;
24406
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1901
            if (count > N_INT_BITS) {
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1902
                RETURN (__mkSmallInteger(bits < 0 ? -1 : 0));
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1903
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1904
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1905
            RETURN ( __mkSmallInteger(bits >> count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1906
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1907
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1908
#endif /* not __SCHTEAM__ */
85
claus
parents: 77
diff changeset
  1909
%}.
claus
parents: 77
diff changeset
  1910
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1911
        ^ (LargeInteger value:self) bitShift:shiftCount
85
claus
parents: 77
diff changeset
  1912
    ].
16448
52a24c07dc59 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16294
diff changeset
  1913
    ^ self bitShift:shiftCount asInteger   "/ is this a good idea ?
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1914
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1915
    "
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1916
       16 bitShift:-1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1917
       16 bitShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1918
       16 bitShift:-63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1919
       
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1920
       -16 bitShift:-1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1921
       -16 bitShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1922
       -16 bitShift:-63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1923
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1924
         4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1925
        -4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1926
        -4 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1927
    "
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1928
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1929
    "Modified (comment): / 03-06-2019 / 17:49:15 / Claus Gittinger"
24406
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1930
    "Modified: / 09-07-2019 / 14:24:07 / Stefan Reise"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1931
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1932
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1933
bitTest:aMask
5782
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1934
    "return true, if any bit from aMask is set in the receiver.
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1935
     I.e. true, if the bitwise-AND of the receiver and the argument, anInteger
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1936
     is non-0, false otherwise."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1937
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1938
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1939
#ifdef __SCHTEAM__
18232
Claus Gittinger <cg@exept.de>
parents: 18227
diff changeset
  1940
    return context._RETURN(
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1941
	    ( self.bitAnd( aMask ) == STInteger._0 )
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1942
	    ? STObject.False : STObject.True );
18232
Claus Gittinger <cg@exept.de>
parents: 18227
diff changeset
  1943
    /* NOTREACHED */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1944
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1945
    /* and all bits except tag */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1946
    if (__isSmallInteger(aMask)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1947
	RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1948
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1949
#endif /* not __SCHTEAM__ */
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1950
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1951
    aMask class == LargeInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1952
	^ (aMask bitAnd:self) ~~ 0
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1953
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1954
    ^ self retry:#bitTest: coercing:aMask
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1955
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1956
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1957
     2r10001 bitTest:2r00001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1958
     2r10001 bitTest:2r00010
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1959
     2r10001 bitTest:2r00100
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1960
     2r10001 bitTest:2r01000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1961
     2r10001 bitTest:2r10000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1962
     2r10001 bitTest:2r10001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1963
     2r10001 bitTest:2r10010
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1964
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1965
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1966
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1967
bitXor:anInteger
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1968
    "return the bitwise-exclusive-or of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1969
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1970
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1971
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1972
    return context._RETURN( self.bitXor( anInteger ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1973
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1974
    /* xoring the tags turns it off - or it in again */
252
  1975
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1976
	RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1977
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1978
#endif /* not __SCHTEAM__ */
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1979
%}.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1980
    ^ self retry:#bitXor: coercing:anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1981
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1982
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1983
highBit
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  1984
    "return the bitIndex of the highest bit set.
19601
bcce77592dae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19486
diff changeset
  1985
     The returned bitIndex starts at 1 for the least significant bit.
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1986
     Returns 0 if no bit is set.
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1987
     Notice for negative numbers, the returned value is undefined (actually: nonsense),
24288
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  1988
     because for 2's complement representation, conceptionally all high bits are 1.
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  1989
     But because we use a sign-magnitude representation for large integers, 
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  1990
     you'll get the high bit of the absolute magnitude for numbers above the SmallInteger
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  1991
     range, in contrast to the highbit of the negative number if within the SmallInt range."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1992
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1993
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1994
#ifdef __SCHTEAM__
18234
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  1995
    {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1996
        long bits = self.longValue();
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1997
        int bitNr = 0;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1998
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1999
        if (bits != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2000
            if ((bits & 0xFFFFFFFF00000000L) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2001
                bitNr += 32; bits >>= 32;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2002
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2003
            if ((bits & 0xFFFF0000L) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2004
                bitNr += 16; bits >>= 16;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2005
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2006
            if ((bits & 0xFF00) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2007
                bitNr += 8; bits >>= 8;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2008
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2009
            if ((bits & 0xF0) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2010
                bitNr += 4; bits >>= 4;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2011
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2012
            if ((bits & 0xC) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2013
                bitNr += 2; bits >>= 2;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2014
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2015
            if ((bits & 0x2) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2016
                bitNr += 1; bits >>= 1;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2017
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2018
            bitNr += 1;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2019
        }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2020
        return context._RETURN( STInteger._new(bitNr) );
18234
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  2021
    }
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  2022
    /* NOTREACHED */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2023
#else
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2024
    unsigned INT bits;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2025
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2026
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2027
# ifdef __BSR
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2028
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2029
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2030
     * 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
  2031
     * (but saves a few code-bytes, though)
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2032
     */
21984
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2033
    index = __BSR((INT)self);
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2034
    RETURN ( __mkSmallInteger(index) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2035
# else
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  2036
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2037
    /*
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2038
     * this uses the FPU, which counts the bits during the normalization
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2039
     * and leaves the high bitnumber in the exponent...
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2040
     * Notice: due to rounding mode details,
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2041
     * this code only works for <=53 bit integers (i.e. only on 32bit machines)
24288
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2042
     * we never use it - it is only here as a hint.
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2043
     */
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2044
#  if (POINTER_SIZE == 4) && defined( USE_IEE_FLOAT_BITS )
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2045
    union {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2046
        double ff;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2047
        int ll[2];
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2048
    } uu;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2049
    int bNr;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2050
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2051
    uu.ff=(double)((INT)(self));
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2052
    bNr = (uu.ll[1]>>20)-1023;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2053
    return __mkSmallInteger(bNr);  // assumes x86 endianness
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2054
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2055
#  else
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2056
    /*
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2057
     * general fallback; not super-fast,
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2058
     * but fast enough on all machines (better than a bit-masking loop, definitely).
24288
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2059
     * Notice, the code runs completely in registers,
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2060
     * so it is probably faster than a table-lookup version (at least if its not in the cache)
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2061
     */
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  2062
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2063
    index = 0;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2064
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2065
    bits = __intVal(self);
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2066
    if (bits == 0) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2067
        RETURN ( __mkSmallInteger(0) );
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2068
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2069
#  if __POINTER_SIZE__ == 8
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2070
    if (bits & 0xFFFFFFFF00000000L) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2071
        index += 32; bits >>= 32;
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2072
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2073
#  endif
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2074
    if (bits & 0xFFFF0000L) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2075
        index += 16; bits >>= 16;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2076
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2077
    if (bits & 0xFF00) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2078
        index += 8; bits >>= 8;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2079
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2080
    if (bits & 0xF0) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2081
        index += 4; bits >>= 4;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2082
    }
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2083
    if (bits & 0xC) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2084
        index += 2; bits >>= 2;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2085
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2086
    if (bits & 0x2) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2087
        index += 1; bits >>= 1;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2088
    }
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2089
#  endif /* not IEE float */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2090
# endif /* no BSR instruction */
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2091
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2092
    RETURN ( __mkSmallInteger(index+1) );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2093
#endif /* not __SCHTEAM__ */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2094
%}.
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2095
    ^ super highBit
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2096
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2097
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2098
     2r0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2099
     2r1 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2100
     2r10 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2101
     2r100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2102
     2r1000 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2103
     2r100000000000 highBit
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2104
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2105
     ((0 to:64) collect:[:s | 1 bitShift:s])
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2106
        collect:[:n | n highBit]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2107
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2108
     (((0 to:64) collect:[:s | 1 bitShift:s])
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2109
        collect:[:n | n highBit]) = (1 to:65)
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2110
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2111
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2112
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2113
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2114
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2115
            2r1 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2116
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2117
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2118
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2119
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2120
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2121
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2122
            2r1111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2123
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2124
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2125
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2126
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2127
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2128
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2129
            2r11111111111111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2130
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2131
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2132
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2133
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2134
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2135
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2136
            2r11111111111111111111111111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2137
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2138
     ]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2139
    "
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2140
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2141
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2142
     2r000100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2143
     2r010100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2144
     2r000001 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2145
     0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2146
     SmallInteger maxVal highBit
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2147
    "
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2148
21984
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2149
    "Modified: / 05-07-2017 / 16:56:08 / cg"
24288
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2150
    "Modified (comment): / 08-06-2019 / 02:07:54 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2151
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2152
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2153
lowBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2154
    "return the bitIndex of the lowest bit set. The returned bitIndex
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2155
     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
  2156
     Returns 0 if no bit is set."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2157
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2158
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2159
#ifdef __SCHTEAM__
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2160
    long bits = self.longValue();
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2161
    int index = 0;
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2162
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2163
    if (bits != 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2164
	if ((bits & 0xFFFFFFFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2165
	    index += 32; bits >>= 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2166
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2167
	if ((bits & 0xFFFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2168
	    index += 16; bits >>= 16;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2169
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2170
	if ((bits & 0xFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2171
	    index += 8; bits >>= 8;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2172
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2173
	if ((bits & 0xFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2174
	    index += 4; bits >>= 4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2175
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2176
	if ((bits & 0x3L)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2177
	    index += 2; bits >>= 2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2178
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2179
	if ((bits & 0x1L)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2180
	    index += 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2181
	}
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2182
    }
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2183
    return __c__._RETURN( STInteger._qnew( index ) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2184
#else
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2185
    unsigned INT bits;
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2186
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2187
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2188
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2189
    if (bits == 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2190
	RETURN ( __mkSmallInteger(0) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2191
    }
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  2192
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2193
# ifdef __BSF
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2194
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2195
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2196
     * 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
  2197
     * (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
  2198
     * but saves a few code-bytes, though.
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2199
     */
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2200
    index = __BSF(bits);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2201
    RETURN ( __mkSmallInteger(index + 1) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2202
# else
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2203
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2204
    index = 1;
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  2205
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2206
#  if __POINTER_SIZE__ == 8
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2207
    if ((bits<<32) == 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2208
	index += 32; bits >>= 32;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2209
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2210
#  endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2211
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2212
    if ((bits & 0xFFFF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2213
	index += 16; bits >>= 16;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2214
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2215
    if ((bits & 0xFF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2216
	index += 8; bits >>= 8;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2217
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2218
    if ((bits & 0xF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2219
	index += 4; bits >>= 4;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2220
    }
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2221
    if ((bits & 0x3)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2222
	index += 2; bits >>= 2;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2223
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2224
    if ((bits & 0x1)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2225
	index += 1;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2226
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2227
# endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2228
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2229
    RETURN ( __mkSmallInteger(index) );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2230
#endif /* not __SCHTEAM__ */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2231
%}.
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2232
    self primitiveFailed "/ must be implemented (or else: recursion)
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2233
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2234
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2235
     0 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2236
     2r0001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2237
     2r0010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2238
     2r0100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2239
     2r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2240
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2241
     2r000100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2242
     2r010010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2243
     2r100001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2244
     16r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2245
     16r1000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2246
     16r1000000000000000 lowBit
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2247
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2248
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2249
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2250
	    2r1000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2251
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2252
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2253
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2254
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2255
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2256
	    2r11110000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2257
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2258
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2259
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2260
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2261
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2262
	    2r1000000000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2263
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2264
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2265
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2266
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2267
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2268
	    2r1000000000000000000000000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2269
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2270
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2271
    "
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2272
!
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2273
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2274
rightShift:shiftCount
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2275
    "return the value of the receiver shifted by shiftCount bits;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2276
     right shift if shiftCount > 0; left shift  otherwise.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2277
     Notice: the result of bitShift: on negative receivers is not
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2278
             defined in the language standard (since the implementation
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2279
             is free to choose any internal representation for integers).
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2280
             However, ST/X preserves the sign,
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2281
             i.e. it is an arithmetic shift as long as you stay within the 
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2282
             number of bits supported by the platform."
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2283
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2284
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2285
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2286
#else
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2287
    INT bits, count;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2288
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2289
    if (__isSmallInteger(shiftCount)) {
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2290
        bits = __intVal(self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2291
        if (bits == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2292
            RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2293
        }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2294
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2295
        count = __intVal(shiftCount);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2296
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2297
        if (count < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2298
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2299
             * a left shift
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2300
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2301
            count = -count;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2302
# if defined(USE_LONGLONG_FOR_SHIFT)
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2303
            if (count <= N_INT_BITS) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2304
                unsigned LONGLONG result;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2305
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2306
                result = (unsigned LONGLONG)bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2307
                result <<= count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2308
                if (result <= _MAX_INT) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2309
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2310
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2311
                {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2312
                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2313
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2314
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2315
# else
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2316
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2317
             * check for overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2318
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2319
            if (count < (N_INT_BITS-1)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2320
                if (! (bits >> (N_INT_BITS - 1 - count))) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2321
                    RETURN ( __mkSmallInteger(bits << count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2322
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2323
                /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2324
                 * so, there is an overflow ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2325
                 * handle it as largeInteger
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2326
                 */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2327
                /* FALL THROUGH */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2328
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2329
# endif
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2330
        } else {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2331
            if (count == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2332
                RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2333
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2334
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2335
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2336
             * right shifts cannot overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2337
             *
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2338
             * some machines ignore shifts bigger than
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2339
             * the number of bits in an int ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2340
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2341
            if (count >= (__POINTER_SIZE__*8)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2342
                RETURN (__mkSmallInteger(0));
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2343
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2344
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2345
            RETURN ( __mkSmallInteger(bits >> count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2346
        }
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2347
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2348
#endif /* not __SCHTEAM__ */
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2349
%}.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2350
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2351
        ^ (LargeInteger value:self) rightShift:shiftCount
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2352
    ].
16448
52a24c07dc59 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16294
diff changeset
  2353
    ^ self rightShift:shiftCount asInteger   "/ is this a good idea ?
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2354
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2355
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2356
    "
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2357
        16 rightShift:1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2358
        16 rightShift:2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2359
        16 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2360
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2361
       -16 rightShift:1
22211
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2362
       -16 rightShift:2
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2363
       -16 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2364
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2365
        1 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2366
       -1 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2367
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2368
         4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2369
        -4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2370
        -4 rightShift:63
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2371
    "
22211
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2372
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2373
    "Modified: / 25-08-2017 / 12:30:42 / cg"
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2374
    "Modified (comment): / 03-06-2019 / 17:50:22 / Claus Gittinger"
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2375
! !
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2376
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2377
!SmallInteger methodsFor:'bit operators - indexed'!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2378
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2379
bitAt:anIntegerIndex
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2380
    "return the value of the index's bit (index starts at 1) as 0 or 1.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2381
     Notice: the result of bitAt: on negative receivers is not
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2382
	     defined in the language standard (since the implementation
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2383
	     is free to choose any internal representation for integers)"
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2384
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2385
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2386
#ifdef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2387
    return context._RETURN( self.bitAt(anIntegerIndex));
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2388
#else
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2389
    if (__isSmallInteger(anIntegerIndex)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2390
	INT idx = __smallIntegerVal(anIntegerIndex);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2391
	if (idx > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2392
	    if (idx > N_INT_BITS) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2393
		RETURN(__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2394
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2395
	    RETURN((__smallIntegerVal(self) & ((INT)1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2396
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2397
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2398
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2399
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2400
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2401
    ^ SubscriptOutOfBoundsError
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2402
	    raiseRequestWith:anIntegerIndex
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2403
	    errorString:'index out of bounds'
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2404
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2405
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2406
     16r000000001 bitAt:0 -> error
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2407
     16r000000001 bitAt:1
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2408
     16r000000001 bitAt:2
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2409
     16r000008000 bitAt:16
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2410
     16r000800000 bitAt:24
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2411
     16r008000000 bitAt:28
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2412
     16r010000000 bitAt:29
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2413
     16r020000000 bitAt:30
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2414
     16r040000000 bitAt:31
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2415
     16r080000000 bitAt:32
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2416
     16r100000000 bitAt:33
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2417
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2418
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2419
" Smalltalk implementation:
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2420
    |mask|
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2421
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2422
    anIntegerIndex <= 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2423
	^ SubscriptOutOfBoundsSignal
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2424
		raiseRequestWith:anIntegerIndex
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2425
		errorString:'index out of bounds'
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2426
    ].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2427
    (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2428
    mask := 1 bitShift:(anIntegerIndex - 1).
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2429
    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2430
    ^ 1
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2431
"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2432
!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2433
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2434
clearBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2435
    "return a new integer where the specified bit is off.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2436
     Bits are counted from 1 starting with the least significant.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2437
     The method's name may be misleading: the receiver is not changed,
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2438
     but a new number is returned. Should be named #withBitCleared:"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2439
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2440
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2441
#ifndef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2442
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2443
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2444
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2445
	if (index > 0) {
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2446
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2447
	    if (index <= 62)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2448
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2449
	    if (index <= 30)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2450
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2451
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2452
		INT mask = __MASKSMALLINT( ((INT)1 << (index-1)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2453
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2454
		RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2455
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2456
	    RETURN (self);  /* nothing to do ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2457
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2458
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2459
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2460
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2461
    ^ super clearBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2462
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2463
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2464
     (16r401 clearBit:1     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2465
     (16r401 clearBit:0     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2466
     (16r3fffffff clearBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2467
     (16r3fffffff clearBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2468
     (16r3fffffff clearBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2469
     (16r3fffffff clearBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2470
     (16r3fffffff bitAt:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2471
     (16r3fffffff bitAt:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2472
     (16r3fffffff bitAt:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2473
     (16r40000001 clearBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2474
     (16rF0000001 clearBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2475
     (16rF0000001 clearBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2476
     (16rF0000001 clearBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2477
     (16rF0000001 clearBit:32) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2478
     (16r1F0000001 clearBit:33) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2479
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2480
!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2481
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2482
invertBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2483
    "return a new number where the specified bit is inverted.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2484
     Bits are counted from 1 starting with the least significant.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2485
     The method's name may be misleading: the receiver is not changed,
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2486
     but a new number is returned. Should be named #withBitInverted:"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2487
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2488
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2489
#ifndef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2490
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2491
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2492
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2493
	if (index > 0) {
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2494
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2495
	    if (index <= 62)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2496
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2497
	    if (index <= 30)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2498
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2499
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2500
		INT mask = __MASKSMALLINT((INT)1 << (index-1));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2501
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2502
		RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2503
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2504
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2505
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2506
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2507
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2508
    ^ super invertBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2509
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2510
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2511
     (16r401 invertBit:2     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2512
     (16r401 invertBit:1     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2513
     (16r30000000 invertBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2514
     (16r40000000 invertBit:0) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2515
     (16r0 invertBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2516
     (16r0 invertBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2517
     (16r0 invertBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2518
     (16r0 invertBit:32) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2519
     (16r0 invertBit:33) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2520
     (16r0 invertBit:100) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2521
    "
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2522
!
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2523
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2524
setBit:anInteger
8937
4f2508548327 comment
Claus Gittinger <cg@exept.de>
parents: 8919
diff changeset
  2525
    "return a new integer where the specified bit is on.
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2526
     Bits are counted from 1 starting with the least significant.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2527
     The method's 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
  2528
     but a new number is returned. Should be named #withBitSet:"
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2529
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2530
%{  /* NOCONTEXT */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2531
#ifndef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2532
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2533
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2534
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2535
	if (index > 0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2536
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2537
	    if (index <= 62)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2538
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2539
	    if (index <= 30)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2540
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2541
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2542
		INT mask = __MASKSMALLINT((INT)1 << (index-1));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2543
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2544
		RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2545
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2546
	}
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2547
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2548
#endif /* not __SCHTEAM__ */
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2549
%}.
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  2550
    ^ super setBit:anInteger
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2551
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2552
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2553
     (16r401 setBit:2     ) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2554
     (16r30000000 setBit:1) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2555
     (16r40000000 setBit:0) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2556
     (16r0 setBit:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2557
     (16r0 setBit:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2558
     (16r0 setBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2559
     (16r0 setBit:32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2560
     (16r0 setBit:33) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2561
     (16r0 setBit:100) hexPrintString
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2562
    "
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  2563
! !
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  2564
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2565
!SmallInteger methodsFor:'byte access'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2566
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2567
byteSwapped
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2568
    "lsb -> msb;
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2569
     i.e. a.b.c.d -> d.c.b.a"
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2570
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2571
    SmallInteger maxBytes == 8 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2572
	^ self byteSwapped64
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2573
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2574
	^ self byteSwapped32
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2575
    ].
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2576
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2577
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2578
     16r11223344 byteSwapped hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2579
     16r44332211 byteSwapped hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2580
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2581
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2582
    "Created: / 09-01-2012 / 23:01:33 / cg"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2583
!
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2584
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2585
byteSwapped16
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2586
    "for 16bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2587
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2588
     i.e. a.b -> b.a"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2589
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2590
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2591
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2592
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2593
    unsigned INT swapped;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2594
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2595
    swapped = ((v>>8)&0xFF) | ((v & 0xFF)<<8);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2596
    RETURN (__mkSmallInteger(swapped));
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2597
#endif /* not __SCHTEAM__ */
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2598
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2599
    ^ super byteSwapped16
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2600
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2601
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2602
     16r1122 byteSwapped16 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2603
     16r2211 byteSwapped16 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2604
     16r332211 byteSwapped16 hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2605
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2606
!
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2607
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2608
byteSwapped32
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2609
    "for 32bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2610
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2611
     i.e. a.b.c.d -> d.c.b.a"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2612
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2613
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2614
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2615
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2616
    unsigned INT swapped;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2617
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2618
# undef HAVE_BSWAP
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2619
# if __POINTER_SIZE__ == 4
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2620
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2621
#  if defined(USE_BSWAP) && defined(__BORLANDC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2622
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2623
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2624
    _asm {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2625
	mov eax, v
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2626
	bswap eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2627
	mov swapped, eax
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2628
    };
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2629
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2630
#  if defined(USE_BSWAP) && defined(__VISUALC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2631
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2632
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2633
    _asm {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2634
	mov eax, v
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2635
	xchg al, ah
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2636
	rol eax, 16
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2637
	xchg al, ah
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2638
	mov swapped, eax
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2639
    };
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2640
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2641
#  if defined(USE_BSWAP) && defined(__GNUC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2642
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2643
16537
d05618865bab class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16521
diff changeset
  2644
    asm("movl %1, %%eax \n\
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2645
	 bswap %%eax    \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2646
	 movl %%eax, %0 \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2647
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2648
	: "=rm"  (swapped)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2649
	: "rm"   (v));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2650
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2651
# endif /* __POINTER_SIZE__ == 4 */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2652
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2653
# if __POINTER_SIZE__ == 8
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2654
    v &= 0xFFFFFFFF;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2655
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  2656
#  if defined(__x86_64__) && defined(__GNUC__) && !defined(__CLANG__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2657
#   define HAVE_BSWAP
19133
Claus Gittinger <cg@exept.de>
parents: 19070
diff changeset
  2658
16537
d05618865bab class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16521
diff changeset
  2659
    asm("movq %1, %%rax \n\
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2660
	 bswap %%eax    \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2661
	 movq %%rax, %0 \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2662
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2663
	: "=rm"  (swapped)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2664
	: "rm"   (v));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2665
#  endif
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2666
# endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2667
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2668
# ifndef HAVE_BSWAP
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2669
    swapped = ((v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2670
# endif
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2671
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2672
    RETURN (__MKUINT(swapped));
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2673
#endif /* not __SCHTEAM__ */
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2674
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2675
    ^ super byteSwapped32
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2676
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2677
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2678
     16r11223344 byteSwapped32 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2679
     16r44332211 byteSwapped32 hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2680
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2681
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2682
    "Created: / 09-01-2012 / 23:01:33 / cg"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2683
!
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2684
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2685
byteSwapped64
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2686
    "for 64bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2687
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2688
     i.e. a.b.c.d.e.f.g.h -> h.g.f.e.d.c.b.a"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2689
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2690
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2691
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2692
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2693
    unsigned INT swapped;
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2694
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2695
# if __POINTER_SIZE__ == 4
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2696
    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2697
    //            xxxxxxxx                                        xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2698
    //                     xxxxxxxx                      xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2699
    //                              xxxxxxxx    xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2700
    swapped = (v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24);
16521
dfd2f93a3045 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16519
diff changeset
  2701
    RETURN(__MKLARGEINT64(1, 0, swapped));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2702
# else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2703
    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2704
    //            xxxxxxxx                                        xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2705
    //                     xxxxxxxx                      xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2706
    //                              xxxxxxxx    xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2707
    swapped =  (v>>56) | ((v>>40)&0xFF00) | ((v>>24) & 0xFF0000) | ((v>>8) & 0xFF000000)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2708
		| ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2709
		| ((v & 0xFF)<<56);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2710
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2711
    RETURN(__MKUINT( swapped ));
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2712
#endif /* not __SCHTEAM__ */
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2713
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2714
    ^ super byteSwapped64
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2715
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2716
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2717
     16r11223344 byteSwapped64 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2718
     16r44332211 byteSwapped64 hexPrintString
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2719
    "
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2720
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2721
    "Created: / 09-01-2012 / 23:01:33 / cg"
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2722
!
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2723
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2724
digitAt:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2725
    "return 8 bits of value, starting at byte index"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2726
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2727
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2728
#ifdef __SCHTEAM__
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2729
    int idx0Based = index.intValue() - 1;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2730
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2731
    if (idx0Based <= 7) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2732
	long myVal = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2733
	if (myVal < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2734
	    myVal = -myVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2735
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2736
	int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2737
	return __c__._RETURN( STInteger._qnew(byteVal) );
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2738
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2739
    if (idx0Based > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2740
	return __c__._RETURN( STInteger._0 );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2741
    }
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2742
#else
357
claus
parents: 329
diff changeset
  2743
    REGISTER INT val;
claus
parents: 329
diff changeset
  2744
    INT idx;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2745
252
  2746
    if (__isSmallInteger(index)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2747
	val = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2748
	if (val < 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2749
	    val = -val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2750
	switch (idx = __intVal(index)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2751
	    case 1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2752
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2753
	    case 2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2754
		val = (val >> 8);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2755
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2756
	    case 3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2757
		val = (val >> 16);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2758
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2759
	    case 4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2760
		val = (val >> 24);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2761
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2762
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2763
	    case 5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2764
		val = (val >> 32);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2765
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2766
	    case 6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2767
		val = (val >> 40);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2768
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2769
	    case 7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2770
		val = (val >> 48);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2771
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2772
	    case 8:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2773
		val = (val >> 56);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2774
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2775
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2776
	    default:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2777
		if (idx < 1)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2778
		    goto bad;   /* sorry */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2779
		RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2780
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2781
	RETURN ( __mkSmallInteger( val & 0xFF) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2782
    }
357
claus
parents: 329
diff changeset
  2783
  bad: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2784
#endif /* not __SCHTEAM__ */
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2785
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2786
    index > 0 ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2787
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2788
	 index less than 1 - not allowed
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2789
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2790
	^ self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2791
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2792
    ^ 0
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  2793
357
claus
parents: 329
diff changeset
  2794
    "
claus
parents: 329
diff changeset
  2795
     (16r12345678 digitAt:1) printStringRadix:16
claus
parents: 329
diff changeset
  2796
     (16r12345678 digitAt:3) printStringRadix:16
claus
parents: 329
diff changeset
  2797
     (16r12345678 digitAt:15) printStringRadix:16
claus
parents: 329
diff changeset
  2798
     (16r12345678 digitAt:0) printStringRadix:16
claus
parents: 329
diff changeset
  2799
     (16r12345678 digitAt:-10) printStringRadix:16
claus
parents: 329
diff changeset
  2800
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2801
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2802
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2803
digitByteAt:index
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2804
    "return 8 bits of my signed value, starting at byte index.
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2805
     For positive receivers, this is the same as #digitAt:;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2806
     for negative ones, the actual bit representation is returned."
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2807
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2808
%{  /* NOCONTEXT */
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2809
#ifdef __SCHTEAM__
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2810
    int idx0Based = index.intValue() - 1;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2811
    long myVal = self.longValue();
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2812
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2813
    if (idx0Based <= 7) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2814
	int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2815
	return __c__._RETURN( STInteger._qnew(byteVal) );
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2816
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2817
    if (idx0Based > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2818
	if (myVal < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2819
	    return __c__._RETURN( STInteger._M1 );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2820
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2821
	    return __c__._RETURN( STInteger._0 );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2822
	}
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2823
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2824
#else
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2825
    REGISTER INT val;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2826
    INT idx;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2827
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2828
    if (__isSmallInteger(index)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2829
	val = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2830
	switch (idx = __intVal(index)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2831
	    case 1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2832
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2833
	    case 2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2834
		val = (val >> 8);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2835
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2836
	    case 3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2837
		val = (val >> 16);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2838
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2839
	    case 4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2840
		val = (val >> 24);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2841
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2842
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2843
	    case 5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2844
		val = (val >> 32);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2845
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2846
	    case 6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2847
		val = (val >> 40);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2848
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2849
	    case 7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2850
		val = (val >> 48);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2851
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2852
	    case 8:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2853
		val = (val >> 56);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2854
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2855
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2856
	    default:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2857
		if (idx < 1)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2858
		    goto bad;   /* sorry */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2859
		if (val < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2860
		    RETURN (__mkSmallInteger(0xFF));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2861
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2862
		RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2863
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2864
	RETURN ( __mkSmallInteger( val & 0xFF) );
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2865
    }
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2866
  bad: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2867
#endif /* not __SCHTEAM__ */
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2868
%}.
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2869
    index > 0 ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2870
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2871
	 index less than 1 - not allowed
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2872
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2873
	^ self primitiveFailed
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2874
    ].
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2875
    ^ 0
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2876
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2877
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2878
     (10 digitByteAt:1) printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2879
     (10 digitByteAt:3) printStringRadix:16
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2880
     (-10 digitByteAt:1) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2881
     (-10 digitByteAt:3) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2882
    "
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2883
!
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2884
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2885
digitBytes
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2886
    "return a byteArray filled with the receiver's bits
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2887
     (8 bits of the absolute value per element),
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2888
     least significant byte is first"
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2889
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2890
    |absValue
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2891
     b1 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2892
     b2 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2893
     b3 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2894
     b4 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2895
     b5 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2896
     b6 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2897
     b7 "{ Class: SmallInteger }" digitByteArray|
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2898
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2899
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2900
     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
  2901
     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
  2902
     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
  2903
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2904
    self == 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2905
	^ ByteArray with:0.
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2906
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2907
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2908
    self < 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2909
	absValue := self negated
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2910
    ] ifFalse: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2911
	absValue := self.
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2912
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2913
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2914
    b1 := absValue bitAnd:16rFF.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2915
    absValue := absValue bitShift:-8.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2916
    absValue == 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2917
	digitByteArray := ByteArray with:b1
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2918
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2919
	b2 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2920
	absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2921
	absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2922
	    digitByteArray := ByteArray with:b1 with:b2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2923
	] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2924
	    b3 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2925
	    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2926
	    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2927
		digitByteArray := ByteArray with:b1 with:b2 with:b3
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2928
	    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2929
		b4 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2930
		absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2931
		absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2932
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2933
		] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2934
		    b5 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2935
		    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2936
		    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2937
			digitByteArray := ByteArray new:5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2938
			digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2939
			digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2940
			digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2941
			digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2942
			digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2943
		    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2944
			b6 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2945
			absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2946
			absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2947
			    digitByteArray := ByteArray new:6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2948
			    digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2949
			    digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2950
			    digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2951
			    digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2952
			    digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2953
			    digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2954
			] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2955
			    b7 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2956
			    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2957
			    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2958
				digitByteArray := ByteArray new:7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2959
				digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2960
				digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2961
				digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2962
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2963
				digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2964
				digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2965
				digitByteArray at:7 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2966
			    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2967
				digitByteArray := ByteArray new:8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2968
				digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2969
				digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2970
				digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2971
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2972
				digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2973
				digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2974
				digitByteArray at:7 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2975
				digitByteArray at:8 put:absValue.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2976
			    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2977
			]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2978
		    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2979
		]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2980
	    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2981
	]
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2982
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2983
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2984
    ^ digitByteArray
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2985
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2986
    "
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2987
      16r12 digitBytes hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2988
      16r1234 digitBytes hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2989
      16r12345678 digitBytes hexPrintString
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2990
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2991
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2992
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2993
digitBytesMSB
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2994
    "return a byteArray filled with the receiver's bits
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2995
     (8 bits of the absolute value per element),
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2996
     most significant byte is first"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2997
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2998
    |absValue
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2999
     b1 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3000
     b2 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3001
     b3 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3002
     b4 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3003
     b5 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3004
     b6 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3005
     b7 "{ Class: SmallInteger }" digitByteArray|
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3006
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3007
    "
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3008
     could have simply created a 4-byte largeinteger and normalize it.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3009
     The code below does the normalize right away, avoiding the
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3010
     overhead of producing any intermediate byte-arrays (and the scanning)
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3011
    "
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3012
    self == 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3013
	^ ByteArray with:0.
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3014
    ].
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3015
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3016
    self < 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3017
	absValue := self negated
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3018
    ] ifFalse: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3019
	absValue := self.
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3020
    ].
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3021
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3022
    b1 := absValue bitAnd:16rFF.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3023
    absValue := absValue bitShift:-8.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3024
    absValue == 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3025
	digitByteArray := ByteArray with:b1
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3026
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3027
	b2 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3028
	absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3029
	absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3030
	    digitByteArray := ByteArray with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3031
	] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3032
	    b3 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3033
	    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3034
	    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3035
		digitByteArray := ByteArray with:b3 with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3036
	    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3037
		b4 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3038
		absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3039
		absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3040
		    digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3041
		] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3042
		    b5 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3043
		    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3044
		    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3045
			digitByteArray := ByteArray new:5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3046
			digitByteArray at:1 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3047
			digitByteArray at:2 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3048
			digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3049
			digitByteArray at:4 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3050
			digitByteArray at:5 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3051
		    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3052
			b6 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3053
			absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3054
			absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3055
			    digitByteArray := ByteArray new:6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3056
			    digitByteArray at:1 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3057
			    digitByteArray at:2 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3058
			    digitByteArray at:3 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3059
			    digitByteArray at:4 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3060
			    digitByteArray at:5 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3061
			    digitByteArray at:6 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3062
			] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3063
			    b7 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3064
			    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3065
			    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3066
				digitByteArray := ByteArray new:7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3067
				digitByteArray at:1 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3068
				digitByteArray at:2 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3069
				digitByteArray at:3 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3070
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3071
				digitByteArray at:5 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3072
				digitByteArray at:6 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3073
				digitByteArray at:7 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3074
			    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3075
				digitByteArray := ByteArray new:8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3076
				digitByteArray at:1 put:absValue.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3077
				digitByteArray at:2 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3078
				digitByteArray at:3 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3079
				digitByteArray at:4 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3080
				digitByteArray at:5 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3081
				digitByteArray at:6 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3082
				digitByteArray at:7 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3083
				digitByteArray at:8 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3084
			    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3085
			]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3086
		    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3087
		]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3088
	    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3089
	]
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3090
    ].
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3091
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3092
    ^ digitByteArray
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3093
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3094
    "
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3095
      16r12 digitBytesMSB hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3096
      16r1234 digitBytesMSB hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3097
      16r12345678 digitBytesMSB hexPrintString
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3098
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3099
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3100
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3101
digitLength
19321
1948c58602d0 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19318
diff changeset
  3102
    "return the number of bytes needed for the unsigned binary representation of the receiver.
1948c58602d0 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19318
diff changeset
  3103
     For negative receivers, the result is not defined by the language standard.
1948c58602d0 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19318
diff changeset
  3104
     ST/X returns the digitLength of its absolute value."
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3105
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3106
%{  /* NOCONTEXT */
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3107
#ifdef __SCHTEAM__
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3108
    long val = self.longValue();
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3109
    int offs = 0;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3110
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3111
    if (val < 0) val = -val;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3112
    if ((val & 0xFFFFFFFF00000000L) != 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3113
        val >>= 32;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3114
        offs = 4;
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3115
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3116
    if ((val & 0xFFFF0000) != 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3117
        if ((val & 0xFF000000) != 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3118
            offs += 4;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3119
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3120
            offs += 3;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3121
        }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3122
    } else {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3123
        if ((val & 0x0000FF00)!= 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3124
            offs += 2;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3125
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3126
            offs += 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3127
        }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3128
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3129
    return __c__._RETURN( STInteger._qnew(offs) );
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3130
#else
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3131
    INT val = __intVal(self);
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3132
    int offs = 0;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3133
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3134
    if (val < 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3135
        val = -val;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3136
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3137
# if __POINTER_SIZE__ == 8
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3138
    if (val & 0xFFFFFFFF00000000L) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3139
        val >>= 32;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3140
        offs = 4;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3141
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3142
# endif
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3143
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3144
    if (val & 0xFFFF0000) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3145
        if (val & 0xFF000000) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3146
            RETURN ( __mkSmallInteger(4+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3147
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3148
            RETURN ( __mkSmallInteger(3+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3149
        }
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3150
    } else {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3151
        if (val & 0x0000FF00) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3152
            RETURN ( __mkSmallInteger(2+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3153
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3154
            RETURN ( __mkSmallInteger(1+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3155
        }
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3156
    }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3157
#endif /* not SCHTEAM */
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3158
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3159
    ^ self abs highBit - 1 // 8 + 1
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3160
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3161
    "
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3162
     16rFF00000000000000 digitLength
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3163
     16r-FF00000000000000 digitLength
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3164
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3165
     16rFF000000 digitLength
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3166
     16rFF0000 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3167
     16rFF00 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3168
     16rFF digitLength
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3169
     16r-FF000000 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3170
     16r-FF0000 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3171
     16r-FF00 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3172
     16r-FF digitLength
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3173
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3174
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3175
    "Modified: / 19-09-2017 / 16:34:26 / stefan"
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3176
!
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3177
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3178
swapBytes
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3179
    "swap bytes pair-wise in a positive integer
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3180
     i.e. a.b.c.d -> b.a.d.c.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3181
     The name may be misleading; actually a new integer is returned,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3182
     and the receiver is not modified.
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  3183
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3184
     Redefined here for speed.
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3185
     Swapping of negative integers is undefined and therefore not supported.
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3186
     This case is handled in the superclass."
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3187
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3188
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3189
#ifndef __SCHTEAM__
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  3190
    unsigned INT v = __intVal(self);
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3191
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3192
    if ((INT)v >= 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3193
	unsigned INT swapped;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3194
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3195
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3196
	swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3197
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3198
	swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3199
# endif /* __POINTER_SIZE__ */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3200
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3201
	//if (__ISVALIDINTEGER(swapped)) {   // sorry, but this does not work here if (INT)swapped would be negative
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3202
	if (swapped <= _MAX_INT) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3203
	    RETURN ( __mkSmallInteger(swapped) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3204
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3205
	RETURN (__MKUINT(swapped));
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  3206
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3207
#endif
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3208
%}.
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3209
    ^ super swapBytes
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3210
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3211
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3212
     -1 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3213
     16r11223344 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3214
     16r44332211 swapBytes hexPrintString
16873
50dc076eea8f class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16537
diff changeset
  3215
     self maxVal swapBytes hexPrintString
50dc076eea8f class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16537
diff changeset
  3216
     self maxVal swapBytes swapBytes hexPrintString
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3217
     16r1122334455667788 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3218
     16r11223344556677889900 swapBytes hexPrintString
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3219
    "
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3220
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3221
    "Created: / 09-01-2012 / 23:01:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3222
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3223
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3224
!SmallInteger methodsFor:'catching messages'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3225
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3226
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3227
    "catch indexed access - report an error
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3228
     defined here since basicAt: in Object omits the SmallInteger check."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3229
14540
84fc4b759ad8 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14492
diff changeset
  3230
    ^ self notIndexed
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3231
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3232
    "Modified (comment): / 17-05-2017 / 16:34:34 / mawalch"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3233
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3234
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3235
basicAt:index put:anObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3236
    "catch indexed access - report an error
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3237
     defined here since basicAt:put: in Object omits the SmallInteger check."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3238
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3239
    self notIndexed
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3240
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3241
    "Modified (comment): / 17-05-2017 / 16:34:40 / mawalch"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3242
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3243
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3244
basicSize
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3245
    "return the number of indexed instvars - SmallIntegers have none.
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3246
     Defined here since basicSize in Object omits the SmallInteger check."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3247
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3248
    ^ 0
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3249
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3250
    "Modified (comment): / 17-05-2017 / 16:34:49 / mawalch"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3251
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3252
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3253
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3254
    "return the number of indexed instvars - SmallIntegers have none."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3255
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3256
    ^ 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3257
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3258
5240
2a91958ba1f1 categories
Claus Gittinger <cg@exept.de>
parents: 5209
diff changeset
  3259
!SmallInteger methodsFor:'coercing & converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3260
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3261
asCharacter
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3262
    "Return a character with the receiver as ascii (actually: unicode) value"
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
  3263
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3264
    ^ Character value:self
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3265
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3266
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3267
     Character value:16r61
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3268
     Character value:16r161
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3269
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3270
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3271
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3272
asFloat
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3273
    "return a Float with same value as the receiver.
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3274
     Redefined for performance (machine can do it faster)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3275
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3276
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3277
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3278
    return context._RETURN( STDouble._new((double)(self.longValue())) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3279
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3280
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  3281
    double dVal = (double)__intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3282
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3283
    __qMKFLOAT(newFloat, dVal);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3284
    RETURN ( newFloat );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3285
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3286
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3287
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3288
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3289
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3290
asLargeInteger
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3291
    "return a LargeInteger with same value as receiver.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3292
     Not for general use:
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3293
       Notice, that this returns an unnormalized large int (i.e. a large with a smallint value),
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3294
       which are normally not present in the system, and not handled correctly by many functions.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3295
       This exists only as a helper for some algorithms and converters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3296
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3297
    ^ LargeInteger value:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3298
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3299
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3300
asShortFloat
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3301
    "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
  3302
     Redefined for performance (machine can do it faster)"
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3303
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3304
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3305
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3306
    return context._RETURN( STFloat._new((float)(self.longValue())) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3307
#else
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3308
    OBJ dummy = @global(ShortFloat);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3309
    OBJ newFloat;
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3310
    float fVal = (float)__intVal(self);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3311
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3312
    __qMKSFLOAT(newFloat, fVal);
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3313
    RETURN ( newFloat );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3314
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3315
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3316
    ^ self primitiveFailed
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3317
!
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3318
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3319
asUnsignedInt
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  3320
    "return an integer representing my unsigned INT value.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3321
     Notice, that the returned integer's size
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3322
     depends heavily on the underlying INT size;
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3323
     You will get 16rFFFFFFFF on 32bit machines,
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3324
     but 16rFFFFFFFFFFFFFFFF on 64 bit machines.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3325
     So use this only for printing or certain bit operations (emulating C semantics)."
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3326
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3327
%{  /* NOCONTEXT */
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3328
    INT iVal = __intVal(self);
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3329
    OBJ uiVal;
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3330
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3331
    uiVal = __MKUINT( (unsigned INT)iVal );
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3332
    RETURN ( uiVal );
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3333
%}.
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3334
    ^ self primitiveFailed
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3335
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3336
    "
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3337
     -1 asUnsignedInt hexPrintString -> 'FFFFFFFFFFFFFFFF'
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3338
     16r-8000 asUnsignedInt hexPrintString -> ''FFFFFFFFFFFF8000''
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3339
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3340
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3341
    "Modified (comment): / 19-09-2017 / 16:34:01 / stefan"
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3342
!
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3343
8408
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3344
codePoint
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3345
    "for compatibility with Characters.
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3346
     (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
  3347
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3348
    ^ self
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3349
!
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3350
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3351
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3352
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3353
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3354
    ^ 20
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3355
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3356
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3357
signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3358
    "return a smallInteger from sign-extending the 24'th bit.
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3359
     May be useful for communication interfaces"
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3360
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3361
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3362
#ifndef __SCHTEAM__
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3363
    INT i = __intVal(self);
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3364
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  3365
    if (i & 0x800000L) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3366
	i = i | ~((INT)0xFFFFFF);
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3367
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3368
	i = i & 0x7FFFFF;
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3369
    }
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3370
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3371
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3372
#endif
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3373
%}.
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3374
    ^ self primitiveFailed
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3375
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3376
    "
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3377
     16rFFFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3378
     16r800000 signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3379
     16r7FFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3380
    "
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3381
!
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3382
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3383
signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3384
    "return a smallInteger from sign-extending the 8'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3385
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3386
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3387
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3388
#ifndef __SCHTEAM__
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3389
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3390
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3391
    if (i & 0x80) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3392
	i = i | ~((INT)0xFF);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3393
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3394
	i = i & 0x7F;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3395
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3396
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3397
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3398
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3399
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3400
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3401
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3402
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3403
     16rFF signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3404
     16r80 signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3405
     16r7F signExtendedByteValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3406
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3407
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3408
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3409
signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3410
    "return a smallInteger from sign-extending the 32'th bit.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3411
     May be useful for communication interfaces"
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3412
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3413
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3414
#ifndef __SCHTEAM__
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3415
    INT i = __intVal(self);
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3416
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  3417
    if (i & 0x80000000L) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3418
	i = i | ~((INT)0xFFFFFFFF);
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3419
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3420
	i = i & 0x7FFFFFFFL;
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3421
    }
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3422
19264
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3423
    RETURN (__MKINT(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3424
#endif
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3425
%}.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3426
    ^ self primitiveFailed
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3427
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3428
    "
19264
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3429
     16rFFFFFFFF signExtendedLongValue -> -1
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3430
     16r80000000 signExtendedLongValue -> -2147483648
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3431
     16r7FFFFFFF signExtendedLongValue -> 2147483647
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3432
    "
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3433
!
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3434
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3435
signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3436
    "return a smallInteger from sign-extending the 16'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3437
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3438
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3439
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3440
#ifndef __SCHTEAM__
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3441
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3442
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3443
    if (i & 0x8000) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3444
	i = i | ~((INT)0xFFFF);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3445
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3446
	i = i & 0x7FFF;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3447
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3448
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3449
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3450
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3451
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3452
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3453
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3454
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3455
     16rFFFF signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3456
     16r8000 signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3457
     16r7FFF signExtendedShortValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3458
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3459
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3461
!SmallInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3462
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3463
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3464
    "return true, if the argument is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3465
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3466
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3467
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3468
    return context._RETURN( self.ltP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3469
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3470
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3471
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3472
	RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3473
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3474
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3475
	RETURN ( ((INT)self < (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3476
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3477
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3478
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3479
	RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3480
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3481
#endif /* not __SCHTEAM__ */
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3482
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3483
    ^ aNumber lessFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3484
    "^ self retry:#< coercing:aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3485
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3486
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3487
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3488
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3489
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3490
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3491
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3492
    return context._RETURN( self.leP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3493
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3494
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3495
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3496
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3497
	RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3498
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3499
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3500
	RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3501
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3502
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3503
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3504
	RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3505
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3506
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3507
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3508
    ^ (self > aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3509
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3510
    "Modified: / 31.7.2002 / 10:07:17 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3511
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3512
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3513
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3514
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3515
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3516
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3517
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3518
#ifdef __SCHTEAM__
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3519
    if (aNumber.isNumber()) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3520
	return context._RETURN( aNumber.eqvP( self.longValue() ));
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3521
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3522
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3523
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3524
    if (aNumber == self) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3525
	RETURN ( true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3526
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3527
    if (! __isNonNilObject(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3528
	/* a smallint or nil */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3529
	RETURN ( false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3530
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3531
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3532
    if (__qIsFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3533
	RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3534
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3535
    if (__qIsShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3536
	RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3537
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3538
#endif /* not __SCHTEAM__ */
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3539
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3540
    ^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3541
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3542
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3543
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3544
    "return true, if the argument is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3545
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3546
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3547
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3548
    return context._RETURN( self.gtP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3549
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3550
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3551
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3552
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3553
	RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3554
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3555
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3556
	RETURN ( ((INT)self > (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3557
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3558
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3559
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3560
	RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3561
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3562
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3563
%}.
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3564
    ^ (aNumber < self)
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3565
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3566
    "Modified: / 31.7.2002 / 10:07:05 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3567
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3568
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3569
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3570
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3571
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3572
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3573
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3574
    return context._RETURN( self.geP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3575
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3576
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3577
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3578
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3579
	RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3580
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3581
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3582
	RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3583
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3584
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3585
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3586
	RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3587
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3588
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3589
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3590
    ^ (self < aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3591
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3592
    "Modified: / 31.7.2002 / 10:07:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3593
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3594
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3595
hash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3596
    "return an integer useful for hashing on value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3597
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3598
    self >= 0 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3599
    ^ self negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3600
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3601
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3602
hashMultiply
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3603
    "used in some squeak code to generate an alternative hash value for integers"
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3604
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3605
    |low|
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3606
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3607
    low := self bitAnd: 16r3FFF.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3608
    ^ (9741 * low
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3609
      + ((9741 * (self bitShift: -14) + (101 * low) bitAnd: 16383) * 16384))
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3610
	bitAnd: 16r0FFFFFFF
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3611
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3612
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3613
     1 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3614
     2 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3615
     3 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3616
     100 hashMultiply
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3617
    "
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3618
!
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3619
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3620
identityHash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3621
    "return an integer useful for hashing on identity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3622
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3623
     self >= 0 ifTrue:[^ self].
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3624
     ^ self negated
1963
ea26c7b9ca1d experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  3625
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3626
    "Modified: 11.11.1996 / 18:42:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3627
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3628
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3629
max:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3630
    "return the receiver or the argument, whichever is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3631
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3632
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3633
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3634
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3635
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3636
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3637
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3638
	if ((INT)(self) > (INT)(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3639
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3640
	if (__intVal(self) > __intVal(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3641
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3642
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3643
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3644
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3645
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3646
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3647
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3648
	if ( (double)__intVal(self) > __floatVal(aNumber) ) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3649
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3650
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3651
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3652
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3653
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3654
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3655
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3656
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3657
    (self > aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3658
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3659
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3660
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3661
min:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3662
    "return the receiver or the argument, whichever is smaller"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3663
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3664
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3665
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3666
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3667
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3668
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3669
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3670
	if ((INT)(self) < (INT)(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3671
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3672
	if (__intVal(self) < __intVal(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3673
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3674
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3675
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3676
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3677
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3678
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3679
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3680
	if ( (double)__intVal(self) < __floatVal(aNumber) ) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3681
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3682
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3683
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3684
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3685
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3686
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3687
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3688
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3689
    (self < aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3690
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3691
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3692
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3693
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3694
    "return true, if the arguments value is not equal to mine"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3695
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3696
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3697
#ifdef __SCHTEAM__
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3698
    if (aNumber.isNumber()) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3699
	return context._RETURN( (aNumber.isEqv( self.longValue() )) ? STObject.False : STObject.True);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3700
	/* NOTREACHED */
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3701
    }
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3702
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3703
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3704
    if (aNumber == self) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3705
	RETURN ( false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3706
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3707
    if (! __isNonNilObject(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3708
	/* a smallint or nil */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3709
	RETURN ( true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3710
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3711
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3712
    if (__qIsFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3713
	RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3714
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3715
    if (__qIsShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3716
	RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3717
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3718
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3719
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3720
    ^ (self = aNumber) not
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3721
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3722
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3723
!SmallInteger methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3724
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3725
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3726
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3727
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3728
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3729
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3730
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3731
10947
e01ba2c3533f deepCopy change
ab
parents: 10487
diff changeset
  3732
deepCopyUsing:aDictionary postCopySelector:postCopySelector
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3733
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3734
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3735
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3736
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3737
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3738
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3739
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3740
    "return a shallow copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3741
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3742
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3743
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3744
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3745
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3746
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3747
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3748
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3749
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3750
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3751
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3752
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  3753
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  3754
!SmallInteger methodsFor:'iteration'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3755
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3756
timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  3757
    "evaluate the argument, aBlock self times.
claus
parents: 329
diff changeset
  3758
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3759
357
claus
parents: 329
diff changeset
  3760
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3761
#ifndef __SCHTEAM__
357
claus
parents: 329
diff changeset
  3762
    REGISTER INT tmp;
claus
parents: 329
diff changeset
  3763
    static struct inlineCache blockVal = __ILC0(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3764
357
claus
parents: 329
diff changeset
  3765
    tmp = __intVal(self);
claus
parents: 329
diff changeset
  3766
    if (tmp > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3767
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3768
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3769
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3770
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3771
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3772
		/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3773
		 * specially tuned version for compiled blocks,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3774
		 * (the most common case)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3775
		 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3776
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3777
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3778
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3779
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3780
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3781
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3782
# 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
  3783
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3784
#                   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
  3785
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3786
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3787
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3788
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3789
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3790
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3791
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3792
		     * home on stack - no need to refetch
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3793
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3794
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3795
		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3796
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3797
		    {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3798
# ifdef __UNROLL_LOOPS__
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3799
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3800
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3801
			 * you are not supposed to program like this - I know what I do
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3802
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3803
			while (tmp > 8) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3804
			    if (InterruptPending != nil) goto interrupted0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3805
	continue0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3806
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3807
			    if (InterruptPending != nil) goto interrupted1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3808
	continue1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3809
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3810
			    if (InterruptPending != nil) goto interrupted2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3811
	continue2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3812
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3813
			    if (InterruptPending != nil) goto interrupted3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3814
	continue3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3815
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3816
			    if (InterruptPending != nil) goto interrupted4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3817
	continue4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3818
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3819
			    if (InterruptPending != nil) goto interrupted5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3820
	continue5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3821
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3822
			    if (InterruptPending != nil) goto interrupted6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3823
	continue6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3824
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3825
			    if (InterruptPending != nil) goto interrupted7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3826
	continue7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3827
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3828
			    tmp -= 8;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3829
			}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3830
# endif /* __UNROLL_LOOPS__ */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3831
			do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3832
			    if (InterruptPending != nil) goto interruptedX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3833
	continueX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3834
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3835
			} while(--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3836
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3837
			RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3838
			if (0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3839
# ifdef __UNROLL_LOOPS__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3840
			    interrupted0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3841
						__interruptL(@line); goto continue0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3842
			    interrupted1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3843
						__interruptL(@line); goto continue1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3844
			    interrupted2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3845
						__interruptL(@line); goto continue2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3846
			    interrupted3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3847
						__interruptL(@line); goto continue3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3848
			    interrupted4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3849
						__interruptL(@line); goto continue4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3850
			    interrupted5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3851
						__interruptL(@line); goto continue5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3852
			    interrupted6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3853
						__interruptL(@line); goto continue6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3854
			    interrupted7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3855
						__interruptL(@line); goto continue7;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3856
# endif /* __UNROLL_LOOPS__ */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3857
			    interruptedX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3858
						__interruptL(@line); goto continueX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3859
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3860
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3861
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3862
	    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  3863
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3864
#           undef BLOCK_ARG
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  3865
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3866
# ifdef NEW_BLOCK_CALL
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3867
#           define BLOCK_ARG  aBlock
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3868
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3869
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3870
#           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3871
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3872
# endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  3873
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3874
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3875
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3876
	     * it could be recompiled or flushed (in the interrupt)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3877
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3878
	    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3879
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3880
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3881
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3882
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3883
		     * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3884
		     * directly call it without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3885
		     * however, if there is an interrupt, refetch the code pointer.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3886
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3887
		    /* stay here, while no interrupts are pending ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3888
		    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3889
			(*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3890
			if (InterruptPending != nil) goto outerLoop;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3891
		    } while (--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3892
		    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3893
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3894
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3895
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3896
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3897
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3898
			 * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3899
			 * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3900
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3901
			__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3902
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3903
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3904
			 * arg is something else - call it with #value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3905
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3906
			(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3907
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3908
		}
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3909
    outerLoop: ;
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3910
	    } while (--tmp);
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3911
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3912
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3913
#           undef IBLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3914
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3915
	    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3916
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3917
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3918
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3919
	 * not a block-like thingy - call it with #value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3920
	 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3921
	do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3922
	    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3923
	    (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3924
	} while(--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3925
	RETURN (self);
357
claus
parents: 329
diff changeset
  3926
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3927
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3928
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3929
    ^ super timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  3930
claus
parents: 329
diff changeset
  3931
"/    |count "{ Class: SmallInteger }" |
claus
parents: 329
diff changeset
  3932
"/
claus
parents: 329
diff changeset
  3933
"/    count := self.
claus
parents: 329
diff changeset
  3934
"/    [count > 0] whileTrue:[
claus
parents: 329
diff changeset
  3935
"/        aBlock value.
claus
parents: 329
diff changeset
  3936
"/        count := count - 1
claus
parents: 329
diff changeset
  3937
"/    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3938
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3939
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3940
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3941
    "reimplemented as primitive for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3942
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3943
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3944
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3945
    REGISTER INT tmp, step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3946
    REGISTER INT final;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3947
    static struct inlineCache blockVal = __ILC1(0);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3948
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3949
    if (__bothSmallInteger(incr, stop)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3950
	tmp = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3951
	final = __intVal(stop);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3952
	step = __intVal(incr);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3953
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3954
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3955
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3956
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3957
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3958
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3959
		/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3960
		 * specially tuned version for static compiled blocks, called with
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3961
		 * home on the stack (the most common case)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3962
		 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3963
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3964
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3965
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3966
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3967
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3968
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3969
# 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
  3970
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3971
#                   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
  3972
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3973
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3974
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3975
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3976
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3977
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3978
		    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
  3979
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3980
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3981
		    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3982
			if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3983
			    if (step == -1) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3984
				while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3985
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3986
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3987
				    tmp--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3988
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3989
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3990
				while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3991
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3992
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3993
				    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3994
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3995
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3996
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3997
			    if (step == 1) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3998
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3999
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4000
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4001
				    tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4002
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4003
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4004
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4005
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4006
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4007
				    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4008
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4009
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4010
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4011
			RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4012
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4013
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4014
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4015
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4016
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4017
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4018
	     * it could be recompiled or flushed (in the interrupt)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4019
	     */
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4020
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4021
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4022
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4023
# 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
  4024
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4025
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4026
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4027
#           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
  4028
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4029
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4030
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4031
	    if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4032
		while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4033
		    REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4034
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4035
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4036
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4037
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4038
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4039
			 * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4040
			 * directly call it without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4041
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4042
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4043
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4044
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4045
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4046
			     * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4047
			     * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4048
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4049
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4050
			    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4051
				OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4052
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4053
				idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4054
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4055
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4056
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4057
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4058
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4059
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4060
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4061
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4062
			     * arg is something else - call it with #value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4063
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4064
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4065
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4066
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4067
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4068
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4069
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4070
		while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4071
		    REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4072
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4073
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4074
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4075
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4076
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4077
			 * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4078
			 * directly call it without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4079
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4080
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4081
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4082
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4083
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4084
			     * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4085
			     * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4086
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4087
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4088
			    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4089
				OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4090
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4091
				idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4092
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4093
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4094
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4095
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4096
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4097
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4098
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4099
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4100
			     * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4101
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4102
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4103
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4104
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4105
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4106
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4107
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4108
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4109
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4110
#           undef IBLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4111
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4112
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4113
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4114
	     * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4115
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4116
	    if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4117
		while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4118
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4119
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4120
		    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4121
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4122
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4123
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4124
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4125
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4126
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4127
		while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4128
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4129
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4130
		    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4131
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4132
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4133
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4134
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4135
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4136
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4137
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4138
	RETURN ( self );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4139
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4140
#endif
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  4141
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4142
    "/
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4143
    "/ 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
  4144
    "/ pass on to super ...
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4145
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4146
    ^ super to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4147
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4148
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4149
     1 to:10 by:3 do:[:i | i printNewline]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4150
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4151
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4152
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4153
to:stop do:aBlock
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4154
    "evaluate aBlock for every integer between (and including) the receiver
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4155
     and the argument, stop.
357
claus
parents: 329
diff changeset
  4156
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4157
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4158
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4159
#ifndef __SCHTEAM__
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4160
    REGISTER INT tmp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4161
    INT final;
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4162
    static struct inlineCache blockVal = __ILC1(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4163
252
  4164
    if (__isSmallInteger(stop)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4165
	tmp = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4166
	final = __intVal(stop);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4167
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4168
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4169
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4170
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4171
		/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4172
		 * specially tuned version for the most common case,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4173
		 * where called with home on the stack
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4174
		 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4175
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4176
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4177
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  4178
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4179
# 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
  4180
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4181
#                   define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4182
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4183
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4184
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4185
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4186
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4187
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4188
		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4189
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4190
		    {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4191
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4192
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4193
			if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4194
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4195
			{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4196
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4197
			     * static compiled blocks ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4198
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4199
# ifdef __UNROLL_LOOPS__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4200
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4201
			     * The following code is designed to run as fast as possible;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4202
			     *  - taken branches only if interrupts are pending
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4203
			     *  - only forward branches (which are usually predicted as not taken)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4204
			     *  - unrolled the loop
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4205
			     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4206
			     * you are not supposed to program like this - I know what I do
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4207
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4208
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4209
			    INT t8 = (INT)(__mkSmallInteger(tmp+8));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4210
			    tmp = (INT)(__mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4211
			    final = (INT)(__mkSmallInteger(final));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4212
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4213
			    INT t8 = tmp+8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4214
#  endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4215
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4216
			    for (;;) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4217
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4218
				while (t8 <= final) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4219
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4220
				    t8 += (INT)(__MASKSMALLINT(8));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4221
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4222
				    t8 += 8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4223
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4224
				    if (InterruptPending != nil) goto interrupted0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4225
	continue0:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4226
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4227
				    (*codeVal)(BLOCK_ARG, tmp);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4228
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4229
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4230
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4231
				    if (InterruptPending != nil) goto interrupted1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4232
	continue1:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4233
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4234
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4235
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4236
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4237
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4238
				    if (InterruptPending != nil) goto interrupted2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4239
	continue2:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4240
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4241
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4242
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4243
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4244
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4245
				    if (InterruptPending != nil) goto interrupted3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4246
	continue3:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4247
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4248
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4249
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4250
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4251
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4252
				    if (InterruptPending != nil) goto interrupted4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4253
	continue4:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4254
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4255
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4256
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4257
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4258
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4259
				    if (InterruptPending != nil) goto interrupted5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4260
	continue5:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4261
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4262
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4263
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4264
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4265
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4266
				    if (InterruptPending != nil) goto interrupted6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4267
	continue6:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4268
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4269
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4270
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4271
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4272
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4273
				    if (InterruptPending != nil) goto interrupted7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4274
	continue7:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4275
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4276
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4277
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4278
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4279
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4280
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4281
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4282
				    tmp += (INT)(__MASKSMALLINT(8));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4283
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4284
				    tmp += 8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4285
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4286
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4287
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4288
				    if (InterruptPending != nil) goto interruptedX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4289
	continueX:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4290
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4291
				    (*codeVal)(BLOCK_ARG, tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4292
				    tmp += (INT)(__MASKSMALLINT(1));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4293
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4294
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4295
				    tmp++;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4296
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4297
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4298
				RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4299
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4300
				if (0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4301
				    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4302
				     * no discussion about those gotos ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4303
				     * ... its better for your CPU's pipelines
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4304
				     * (if you don't understand why, just don't argue).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4305
				     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4306
				    interrupted7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4307
						    __interruptL(@line); goto continue7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4308
				    interrupted6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4309
						    __interruptL(@line); goto continue6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4310
				    interrupted5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4311
						    __interruptL(@line); goto continue5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4312
				    interrupted4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4313
						    __interruptL(@line); goto continue4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4314
				    interrupted3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4315
						    __interruptL(@line); goto continue3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4316
				    interrupted2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4317
						    __interruptL(@line); goto continue2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4318
				    interrupted1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4319
						    __interruptL(@line); goto continue1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4320
				    interrupted0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4321
						    __interruptL(@line); goto continue0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4322
				    interruptedX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4323
						    __interruptL(@line); goto continueX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4324
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4325
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4326
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4327
			    while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4328
				if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4329
				(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4330
				tmp ++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4331
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4332
			    RETURN (self);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4333
# endif /* __UNROLL_LOOPS__ */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4334
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4335
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4336
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4337
			 * mhmh - seems to be a block with dynamic code
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4338
			 * must refetch, to allow dynamic recompilation or code flush.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4339
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4340
			while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4341
			    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4342
			    if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4343
			    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4344
			    tmp ++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4345
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4346
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4347
			if (tmp > final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4348
			    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4349
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4350
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4351
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4352
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4353
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4354
#           undef BLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4355
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4356
# 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
  4357
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4358
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4359
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4360
#           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
  4361
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4362
# endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  4363
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4364
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4365
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4366
	     * it could be recompiled or flushed (in the interrupt)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4367
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4368
	    while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4369
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4370
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4371
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4372
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4373
		     * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4374
		     * directly call it without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4375
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4376
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4377
		    /* stay here, while no interrupts are pending ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4378
		    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4379
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4380
			if (InterruptPending != nil) goto outerLoop;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4381
			tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4382
		    } while (tmp <= final);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4383
		    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4384
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4385
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4386
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4387
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4388
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4389
			 * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4390
			 * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4391
			 */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4392
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4393
			{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4394
			    OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4395
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4396
			    idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4397
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4398
			}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4399
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4400
			__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4401
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4402
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4403
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4404
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4405
			 * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4406
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4407
			(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4408
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4409
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4410
	    outerLoop: ;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4411
		tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4412
	    }
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  4413
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4414
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4415
#           undef IBLOCK_ARG
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4416
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4417
	    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4418
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4419
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4420
	 * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4421
	 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4422
	while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4423
	    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4424
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4425
	    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4426
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4427
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4428
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4429
	    tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4430
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4431
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4432
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4433
#endif /* not __SCHTEAM__ */
400
claus
parents: 394
diff changeset
  4434
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4435
400
claus
parents: 394
diff changeset
  4436
    "/
claus
parents: 394
diff changeset
  4437
    "/ 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
  4438
    "/ pass on to super ...
400
claus
parents: 394
diff changeset
  4439
    "/
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4440
    ^ super to:stop do:aBlock
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4441
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4442
    "
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4443
     1 to:10 do:[:i | i printNewline]
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4444
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4445
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4446
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4447
!SmallInteger methodsFor:'misc math'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4448
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4449
bernoulli
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4450
    "returns the nth Bernoulli number.
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4451
     The series runs this:
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4452
	 1, 1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0, 5/66, 0, -691/2730, etc
21917
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4453
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4454
     Uses a table of the first 20 even bernoulli numbers.
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4455
     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
  4456
     Used with taylor series for tan"
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4457
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4458
    |table p|
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4459
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4460
    table := #(
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4461
		(1 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4462
		(-1 30)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4463
		(1 42)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4464
		(-1 30)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4465
		(5 66)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4466
		(-691 2730)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4467
		(7 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4468
		(-3617 510)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4469
		(43867 798)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4470
		(-174611 330)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4471
		(854513 138)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4472
		(-236364091 2730)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4473
		(8553103 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4474
		(-23749461029 870)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4475
		(8615841276005 14322)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4476
		(-7709321041217 510)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4477
		(2577687858367 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4478
		(-26315271553053477373 1919190)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4479
		(2929993913841559 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4480
		(-261082718496449122051 13530)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4481
	      ).
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4482
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4483
    self even ifTrue:[
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4484
	self == 0 ifTrue:[^1].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4485
	p := table at:(self / 2).
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4486
	^ 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
  4487
    ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4488
    self == 1 ifTrue:[ ^ (1 / 2) ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4489
    ^ 0.
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4490
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4491
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4492
     0 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4493
     1 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4494
     2 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4495
     3 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4496
     4 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4497
     5 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4498
     6 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4499
     8 bernoulli
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4500
     38 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4501
     40 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4502
     41 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4503
     42 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4504
    "
21917
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4505
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4506
    "Modified (comment): / 22-06-2017 / 14:38:09 / cg"
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4507
!
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4508
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4509
divMod:aNumber
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4510
    "return an array filled with
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4511
	(self // aNumber) and (self \\ aNumber).
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4512
     The returned remainder has the same sign as aNumber.
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4513
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4514
	(receiver // something) * something + (receiver \\ something) = receiver
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4515
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4516
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4517
     Especially surprising:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4518
	-1 \\ 10 -> 9  (because -(1/10) is truncated towards next smaller integer, which is -1,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4519
			and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4520
	-10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4521
			and -4 * 4 gives -12, so we need to add 2 to get the original -10.
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4522
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4523
     This is redefined here for more performance"
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4524
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4525
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4526
#ifndef __SCHTEAM__
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4527
    INT val, div, mod, mySelf;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4528
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4529
    if (__isSmallInteger(aNumber)
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4530
     && ((val = __intVal(aNumber)) > 0)
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4531
     && ((mySelf = __intVal(self)) >= 0)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4532
	div = mySelf / val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4533
	mod = mySelf % val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4534
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4535
	RETURN (__ARRAY_WITH2( __mkSmallInteger(div), __mkSmallInteger(mod)));
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4536
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4537
#endif
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4538
%}.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4539
    ^ super divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4540
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4541
    "
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4542
     10 // 3           -> 3
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4543
     10 \\ 3           -> 1
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4544
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4545
     10 // -3          -> -4
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4546
     10 \\ -3          -> -2
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4547
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4548
     -10 // 3          -> -4
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4549
     -10 \\ 3          -> 2
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4550
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4551
     -10 // -3         -> 3
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4552
     -10 \\ -3         -> -1
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4553
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4554
     -78 \\ 10         2
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4555
     -78 // 10         -8
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4556
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4557
     10 divMod:3       -> #(3 1)   because 3*3 + 1 = 10
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4558
     10 divMod:-3      -> #(-4 -2) because -4*-3 + (-2) = 10
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4559
     -10 divMod:3      -> #(-4 2)  because -4*3 + 2 = -10
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4560
     -10 divMod:-3     -> #(3 -1)  because -3*3 + (-1) = -10
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4561
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4562
     1000000000000000000000 divMod:3   -> #(333333333333333333333 1)
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4563
     1000000000000000000000 divMod:-3  -> #(-333333333333333333334 -2)
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4564
     -1000000000000000000000 divMod:3  -> #(-333333333333333333334 2)
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4565
     -1000000000000000000000 divMod:-3 -> #(333333333333333333333 -1)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4566
     100 factorial divMod:103
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4567
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4568
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4569
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4570
gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4571
    "return the greatest common divisor (Euclid's algorithm).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4572
     This has been redefined here for more speed since due to the
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4573
     use of gcd in Fraction code, it has become time-critical for
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4574
     some code. (thanx to MessageTally)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4575
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4576
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4577
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4578
    if (__isSmallInteger(anInteger)) {
23616
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4579
        INT orgArg, ttt, selfInt, orgSelfInt, temp;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4580
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4581
        ttt = orgArg = __intVal(anInteger);
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4582
        if (ttt) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4583
            selfInt = orgSelfInt = __intVal(self);
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4584
            while (ttt != 0) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4585
                temp = selfInt % ttt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4586
                selfInt = ttt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4587
                ttt = temp;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4588
            }
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4589
            /*
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4590
             * since its not defined in C, what the sign of
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4591
             * a modulus result is when the arg is negative,
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4592
             * change it explicitely here ...
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4593
             */
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4594
            if ((orgArg < 0) != (orgSelfInt < 0)) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4595
                /* flip result's sign */
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4596
                selfInt = -selfInt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4597
            }
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4598
            RETURN ( __mkSmallInteger(selfInt) );
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4599
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4600
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4601
#endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4602
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4603
    ^ super gcd:anInteger
23616
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4604
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4605
    "
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4606
     45 gcd:30 15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4607
     -45 gcd:30 15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4608
     45 gcd:-30 -15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4609
     -45 gcd:-30 -15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4610
    "
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4611
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4612
    "Modified: / 18-01-2019 / 16:08:31 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4613
!
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4614
2430
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4615
gcd_helper:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4616
    "same as gcd - see knuth & Integer>>gcd:"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4617
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4618
    ^ self gcd:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4619
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4620
    "Created: 1.3.1997 / 16:58:01 / cg"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4621
!
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4622
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4623
integerLog10
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4624
    "return the truncation of log10 of the receiver.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4625
     The same as (self log:10) floor.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4626
     Stupid implementation, which is used to find out the number of digits needed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4627
     to print a number/and for conversion to a LargeInteger.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  4628
     Implemented that way, to allow for tiny systems (PDAs) without a Float class
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4629
     (i.e. without log)."
2
claus
parents: 1
diff changeset
  4630
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4631
    self > 0 ifTrue:[
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4632
	self < 10000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4633
	    self < 10 ifTrue:[^ 0].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4634
	    self < 100 ifTrue:[^ 1].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4635
	    self < 1000 ifTrue:[^ 2].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4636
	    ^ 3
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4637
	].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4638
	self < 100000000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4639
	    self < 100000 ifTrue:[^ 4].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4640
	    self < 1000000 ifTrue:[^ 5].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4641
	    self < 10000000 ifTrue:[^ 6].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4642
	    ^ 7
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4643
	].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4644
	self < 1000000000 ifTrue:[^ 8].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4645
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4646
	SmallInteger maxBytes == 4 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4647
	    "/ on a 32 bit machine, SmallInt cannot be larger
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4648
	    ^ 9
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4649
	] ifFalse:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4650
	    "/ 64 bit machine
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4651
	    self < 100000000000000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4652
		self < 10000000000 ifTrue:[^ 9].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4653
		self < 100000000000 ifTrue:[^ 10].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4654
		self < 1000000000000 ifTrue:[^ 11].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4655
		self < 10000000000000 ifTrue:[^ 12].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4656
		^ 13
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4657
	    ].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4658
	    self < 1000000000000000 ifTrue:[^ 14].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4659
	    self < 10000000000000000 ifTrue:[^ 15].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4660
	    self < 100000000000000000 ifTrue:[^ 16].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4661
	    self < 1000000000000000000 ifTrue:[^ 17].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4662
	    ^ 18.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4663
	].
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4664
    ].
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4665
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4666
    ^ self class
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4667
	raise:(self = 0 ifTrue:[#infiniteResultSignal] ifFalse:[#domainErrorSignal])
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4668
	receiver:self
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4669
	selector:#integerLog10
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4670
	arguments:#()
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4671
	errorString:'bad receiver in log10 (not strictly positive)'
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4672
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4673
    "
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4674
      99 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4675
      100 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4676
      101 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4677
      (101 log:10) floor
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4678
      120 integerLog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4679
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4680
      -1 integerLog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4681
      0 integerLog10
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4682
      Number trapInfinity:[ 0 integerLog10 ]
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4683
    "
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4684
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4685
    "Created: / 02-07-2017 / 01:19:09 / cg"
22218
d501998293f7 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22211
diff changeset
  4686
    "Modified: / 28-08-2017 / 13:53:32 / cg"
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4687
!
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4688
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4689
intlog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4690
    <resource: #obsolete>
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4691
    "return the truncation of log10 of the receiver.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4692
     The same as (self log:10) floor.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4693
     Stupid implementation, which is used to find out the number of digits needed
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4694
     to print a number/and for conversion to a LargeInteger.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4695
     Implemented that way, to allow for tiny systems (PDAs) without a Float class
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4696
     (i.e. without log)."
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4697
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4698
    ^ self integerLog10
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4699
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4700
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4701
      99 intlog10
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4702
      100 intlog10
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4703
      101 intlog10
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4704
      (101 log:10) floor
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4705
      120 intlog10
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  4706
      -1 intlog10
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  4707
    "
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4708
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4709
    "Modified: / 02-07-2017 / 01:19:05 / cg"
2
claus
parents: 1
diff changeset
  4710
! !
claus
parents: 1
diff changeset
  4711
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4712
!SmallInteger methodsFor:'printing & storing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4713
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4714
asBCD
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4715
    "return an integer which represents the BCD encoded value of the receiver;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4716
     that is: each digit of its decimal representation is placed into a nibble
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4717
     of the result. (aka 162 -> 0x162). The BCD hex string looks like the original decimal.
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4718
     This conversion is useful for some communication protocols,
16041
989a985b6f61 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16039
diff changeset
  4719
     or control systems, which represent numbers this way..."
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4720
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4721
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4722
#ifndef __SCHTEAM__
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4723
    // the following code is a leftover from times when division was expensive;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4724
    // in modern cpu's, conditional branches are often more expensive than divisions,
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4725
    // so it is questionable, if the effort below is still worth it.
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4726
    // (and asBCD is really used seldom in some serial communication protocols
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4727
    // for control systems)
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4728
    int i;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4729
    INT _10000000s = 0, _1000000s = 0;
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4730
    INT _100000s = 0, _10000s = 0, _1000s = 0;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4731
    INT _100s = 0, _10s = 0, _1s = 0;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4732
    INT b = __intVal(self);
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4733
    unsigned INT rslt;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4734
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4735
    if (b <= 99999999) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4736
	if (b <= 255) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4737
	    // the most common case: convert bytes
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4738
	    for (i=7; i>=0; i--) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4739
		if (_100s >= 5)       _100s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4740
		if (_10s >= 5)        _10s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4741
		if (_1s >= 5)         _1s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4742
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4743
		_100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4744
		_10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4745
		_1s      =    (_1s<<1)         | (b >> 7 & 1);          _1s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4746
		b <<= 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4747
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4748
	    rslt = (_100s<<8) | (_10s<<4) | _1s;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4749
	    RETURN (__MKSMALLINT( rslt) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4750
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4751
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4752
	for (i=26; i>=0; i--) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4753
	    if (_10000000s >= 5)  _10000000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4754
	    if (_1000000s >= 5)   _1000000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4755
	    if (_100000s >= 5)    _100000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4756
	    if (_10000s >= 5)     _10000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4757
	    if (_1000s >= 5)      _1000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4758
	    if (_100s >= 5)       _100s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4759
	    if (_10s >= 5)        _10s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4760
	    if (_1s >= 5)         _1s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4761
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4762
	    _10000000s =  (_10000000s<<1)  | (_1000000s >> 3 & 1);  _10000000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4763
	    _1000000s =   (_1000000s<<1)   | (_100000s >> 3 & 1);   _1000000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4764
	    _100000s =    (_100000s<<1)    | (_10000s >> 3 & 1);    _100000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4765
	    _10000s  =    (_10000s<<1)     | (_1000s >> 3 & 1);     _10000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4766
	    _1000s   =    (_1000s<<1)      | (_100s >> 3 & 1);      _1000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4767
	    _100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4768
	    _10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4769
	    _1s      =    (_1s<<1)         | (b >> 26 & 1);         _1s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4770
	    b <<= 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4771
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4772
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4773
	rslt = (_10000000s<<28)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4774
	       | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4775
	       | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4776
	RETURN (__MKUINT( rslt) );
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4777
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4778
#endif
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4779
%}.
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4780
    ^ super asBCD.
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4781
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4782
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4783
      99999999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4784
      12812345 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4785
      128123 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4786
      128901 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4787
      12890 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4788
      1289 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4789
      999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4790
      256 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4791
      255 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4792
      128 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4793
      162 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4794
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4795
      999999999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4796
      128123456 asBCD hexPrintString
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4797
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4798
    "
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4799
!
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4800
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4801
printOn:aStream
22304
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4802
    "append my printstring (base 10) to aStream.
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4803
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4804
     I use #printString instead of #printOn: as basic print mechanism."
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4805
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4806
    aStream nextPutAll:(self printString)
22304
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4807
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4808
    "Modified (comment): / 10-10-2017 / 14:09:00 / cg"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4809
!
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4810
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4811
printOn:aStream base:base showRadix:showRadix
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4812
    "append a string representation of the receiver in the specified numberBase to aStream
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4813
     (if showRadix is true, with initial XXr)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4814
     The base argument should be between 2 and 36."
6144
35b772717356 check for bad radix
james
parents: 6092
diff changeset
  4815
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4816
    |absBase|
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4817
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4818
    (base isInteger and:[absBase := base abs. absBase between:2 and:36]) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4819
	showRadix ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4820
	    absBase printOn:aStream.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4821
	    aStream nextPut:$r.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4822
	].
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4823
	aStream nextPutAll:(self printStringRadix:base)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4824
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4825
	super printOn:aStream base:base showRadix:true.
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4826
    ].
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4827
12977
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  4828
    "Created: / 07-09-2001 / 13:54:40 / cg"
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  4829
    "Modified: / 02-08-2010 / 12:25:20 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4830
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4831
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4832
printString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4833
    "return my printstring (base 10)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4834
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4835
    "since this was heavily used in some applications,
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4836
     here is an exception to the rule of basing printString
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4837
     upon the printOn: method."
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4838
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4839
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4840
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4841
    return context._RETURN( new STString( java.lang.Long.toString(self.longValue()) ));
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4842
#else
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  4843
    char buffer[30];    /* enough for 64 bit integers (21 would be enough)  */
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4844
    char *cp;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4845
    OBJ newString = nil;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4846
    INT myValue;
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4847
    int negative = 0;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4848
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4849
    if (self == __MKSMALLINT(0)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4850
	RETURN (@global(ZeroString));
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4851
//        RETURN (__MKSTRING_L("0", 1));
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4852
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4853
    myValue = __intVal(self);
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4854
    if (myValue < 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4855
	negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4856
	myValue = -myValue;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4857
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4858
    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
  4859
    *cp-- = '\0';
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  4860
    for ( ; myValue != 0; cp--) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4861
	*cp = '0' + (myValue % 10);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4862
	myValue /= 10;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4863
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4864
    if (negative) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4865
	*cp-- = '-';
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4866
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4867
    newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4868
    if (newString != nil) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4869
	RETURN (newString);
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4870
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4871
#endif /* not __SCHTEAM__ */
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4872
%}.
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4873
    "/ only arrive here,
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4874
    "/  when having memory problems (i.e. no space for string) ...
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4875
    ^ super printString
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4876
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4877
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4878
     1234 printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4879
     0    printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4880
     -100 printString
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4881
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4882
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 123456789012 printString ]] 180 180 180 170 180
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4883
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 12345678 printString ]]     140 150 140 150 140
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4884
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 1234 printString ]]         130 140 130 130 130
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4885
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 12 printString ]]           130 120 120 120 110
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4886
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 5 printString ]]            110 110 100 110 90
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4887
    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
  4888
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4889
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4890
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  4891
printStringRadix:base
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4892
    "return my printstring (optimized for bases 16, 10 and 8).
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4893
     Print digits > 0 as uppercase chars if base > 0,
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4894
     as lowercase chars if base < 0."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4895
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4896
    |s|
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4897
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4898
%{
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4899
#ifdef __SCHTEAM__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4900
    int __base = Math.abs(base.intValue());
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4901
    long myValue = self.longValue();
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4902
    java.lang.String __s;
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4903
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4904
    switch (__base) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4905
        case 2:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4906
            __s = java.lang.Long.toBinaryString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4907
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4908
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4909
        case 8:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4910
            __s = java.lang.Long.toOctalString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4911
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4912
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4913
        case 10:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4914
            __s = java.lang.Long.toString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4915
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4916
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4917
        case 16:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4918
            __s = java.lang.Long.toHexString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4919
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4920
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4921
        default:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4922
        {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4923
            boolean negative = false;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4924
            __s = "";
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4925
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4926
            if ((__base > 36) || (__base < 2)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4927
                throw new SmalltalkError("invalid base: ", base);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4928
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4929
            if (myValue < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4930
                negative = true;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4931
                myValue = -myValue;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4932
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4933
            while (myValue != 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4934
                int digit;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4935
                char ch;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4936
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4937
                digit = (int)(myValue % __base);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4938
                if (digit <= 9) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4939
                    ch = (char)('0' + digit);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4940
                } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4941
                    ch = (char)('A' + digit - 10);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4942
                }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4943
                __s = ch + __s;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4944
                myValue = myValue / __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4945
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4946
            if (negative) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4947
                __s = "-" + __s;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4948
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4949
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4950
        }
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4951
    }
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4952
    return context._RETURN( new STString( __s ));
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4953
#else
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4954
    static char ucDigits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4955
    static char lcDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4956
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  4957
    if (__isSmallInteger(base)) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4958
        char *digits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4959
        INT __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4960
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4961
        if (self == __MKSMALLINT(0)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4962
            RETURN (@global(ZeroString));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4963
        }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4964
        __base = __intVal(base);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4965
        if (__base < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4966
            __base = - __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4967
            digits = lcDigits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4968
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4969
            digits = ucDigits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4970
        }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4971
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4972
        if ((__base < sizeof(ucDigits)) && (__base > 1)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4973
            char buffer[64+5];  /* for 64bit machines, base 2, plus sign, plus 0-byte */
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4974
            char *cp;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4975
            OBJ newString;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4976
            int negative = 0;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4977
            INT myValue = __intVal(self);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4978
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4979
            if (myValue < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4980
                negative = 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4981
                myValue = -myValue;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4982
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4983
            cp = buffer + sizeof(buffer) - 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4984
            *cp-- = '\0';
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4985
            for (; myValue != 0; cp--) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4986
                *cp = digits[myValue % __base];
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4987
                myValue /= __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4988
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4989
            if (negative) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4990
                *cp-- = '-';
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4991
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4992
            newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4993
            if (newString != nil) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4994
                RETURN (newString);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4995
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4996
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4997
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4998
#endif /* not __SCHTEAM__ */
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  4999
%}.
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5000
    "/ arrive here, for bad base,
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5001
    "/ or when having memory problems (i.e. no space for string) ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5002
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5003
    "/
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5004
    "/ fall back for seldom used bases
20330
01cc21bb516f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20262
diff changeset
  5005
    "/ Notice: cannot use super>>printStringRadix: here,
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5006
    "/ since that would lead to endless recursion ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5007
    "/ (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
  5008
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5009
    s := WriteStream on:(String new:10).
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5010
    super printOn:s base:base.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5011
    ^ s contents.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5012
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5013
    "
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5014
      127 printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5015
      127 printStringRadix:-16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5016
      -127 printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5017
      -127 printStringRadix:-16
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5018
      123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5019
      123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5020
      123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5021
      123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5022
      123 printStringRadix:2
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5023
      123 printStringRadix:1
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5024
      35 printStringRadix:36
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5025
      123 printStringRadix:37
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5026
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5027
      -127 printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5028
      -123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5029
      -123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5030
      -123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5031
      -123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5032
      -123 printStringRadix:2
20330
01cc21bb516f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20262
diff changeset
  5033
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5034
      16r3FFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5035
      16r7FFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5036
      16rFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5037
      16r3FFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5038
      16r7FFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5039
      16rFFFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5040
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5041
      16r-3FFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5042
      16r-40000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5043
      16r-7FFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5044
      16r-80000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5045
      16r-FFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5046
      16r-3FFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5047
      16r-7FFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5048
      16r-FFFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5049
      16r-4000000000000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5050
      16r-8000000000000000 printStringRadix:16
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5051
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5052
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5053
    "Modified: / 19-09-2017 / 16:34:40 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5054
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5055
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5056
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  5057
    "non-standard, but sometimes useful.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5058
     return a printed representation of the receiver
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5059
     as specified by formatString, which is defined by the C-function 'printf'.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5060
     No checking for string overrun - the resulting string
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  5061
     must be shorter than 256 chars or else ...
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5062
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  5063
     Notice that a conversion may not be portable; for example,
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  5064
     to correctly convert an int on a 64-bit alpha, a %ld is required,
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5065
     on 64bit mingw or visualc, %lld is required,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5066
     while other systems may be happy with a %d.
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5067
     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
  5068
     Use at your own risk (if at all).
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5069
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5070
     This method is NONSTANDARD and may be removed without notice;
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5071
     it is provided to allow special conversions in very special situations.
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5072
     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
  5073
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5074
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  5075
%{  /* STACK: 400 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5076
#ifndef __SCHTEAM__
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5077
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  5078
    OBJ s;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5079
    int len;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5080
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5081
    if (__isStringLike(formatString)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5082
	/*
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5083
	 * actually only needed on sparc: since thisContext is
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5084
	 * in a global register, which gets destroyed by printf,
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5085
	 * manually save it here - very stupid ...
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5086
	 */
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5087
	__BEGIN_PROTECT_REGISTERS__
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5088
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5089
	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self));
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5090
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5091
	__END_PROTECT_REGISTERS__
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5092
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5093
	if (len < 0) goto fail;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5094
	if (len >= sizeof(buffer)) goto fail;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5095
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5096
	s = __MKSTRING_L(buffer, len);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5097
	if (s != nil) {
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5098
	    RETURN (s);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5099
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5100
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5101
fail: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5102
#endif /* not __SCHTEAM__ */
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  5103
%}.
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5104
    ^ super printfPrintString:formatString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5105
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5106
    "
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5107
	123 printfPrintString:'%%d -> %d'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5108
	123 printfPrintString:'%%6d -> %6d'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5109
	123 printfPrintString:'%%x -> %x'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5110
	123 printfPrintString:'%%4x -> %4x'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5111
	123 printfPrintString:'%%04x -> %04x'
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5112
    "
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5113
21949
ce997689ab94 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21939
diff changeset
  5114
    "Modified: / 03-07-2017 / 15:07:37 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5115
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5116
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5117
!SmallInteger methodsFor:'private'!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5118
23498
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5119
numberOfDigits:n8BitDigits
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5120
    "initialize the instance to store n8BitDigits.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5121
     It is a no-op for SmallIntegers."
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5122
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5123
    ^ self.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5124
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5125
    "Created: / 01-11-2018 / 11:29:45 / Stefan Vogel"
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5126
!
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5127
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5128
numberOfDigits:n8BitDigits sign:sign
18382
4b0ff5d95702 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18370
diff changeset
  5129
    "private: for protocol completeness with LargeIntegers.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5130
     Returns a smallInteger with my absValue and the sign of the argument.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5131
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5132
     but a new number is returned."
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5133
23498
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5134
    ^ self setSign:sign.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5135
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5136
    "Created: / 01-11-2018 / 12:15:17 / Stefan Vogel"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5137
! !
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5138
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5139
!SmallInteger methodsFor:'special modulo arithmetic'!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5140
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5141
plus32:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5142
    "return the sum of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5143
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5144
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5145
     This is of course not always correct, but allows for C/Java behavior to be emulated."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5146
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5147
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5148
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5149
    INT sum;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5150
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5151
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5152
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5153
    sum &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5154
# endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5155
    RETURN ( __MKUINT(sum));
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5156
#endif /* not __SCHTEAM__ */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5157
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5158
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5159
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5160
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5161
     16r7FFFFFFF + 1          2147483648
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5162
     16r7FFFFFFF plus32: 1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5163
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5164
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5165
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5166
plus:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5167
    "return the sum of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5168
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5169
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5170
     smallInteger range is returned (i.e. the low bits of the sum).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5171
     This is of course not always correct, but some code does a modulo anyway
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5172
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5173
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5174
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5175
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5176
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5177
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5178
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5179
	long sum = myValue + otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5180
	return context._RETURN( STInteger._new(sum) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5181
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5182
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5183
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5184
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5185
	INT sum;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5186
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5187
	sum =  __intVal(self) + __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5188
	if (!__ISVALIDINTEGER(sum)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5189
	    /* keep the sign */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5190
	    sum %= _MAX_INT;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5191
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5192
	RETURN ( __mkSmallInteger(sum));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5193
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5194
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5195
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5196
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5197
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5198
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5199
	5 plus:-1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5200
	5 plus:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5201
	1 plus:-5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5202
	self maxVal plus:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5203
	self maxVal + 1
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5204
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5205
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5206
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5207
subtract:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5208
    "return the difference of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5209
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5210
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5211
     smallInteger range is returned (i.e. the low bits of the sum).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5212
     This is of course not always correct, but some code does a modulo anyway
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5213
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5214
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5215
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5216
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5217
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5218
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5219
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5220
	long diference = myValue - otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5221
	return context._RETURN( STInteger._new(diference) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5222
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5223
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5224
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5225
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5226
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5227
	INT diff;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5228
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5229
	diff = __intVal(self) - __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5230
	if (!__ISVALIDINTEGER(diff)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5231
	    /* keep the sign */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5232
	    diff %= _MAX_INT;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5233
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5234
	RETURN ( __mkSmallInteger(diff));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5235
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5236
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5237
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5238
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5239
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5240
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5241
	-1 subtract:5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5242
	5 subtract:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5243
	1 subtract:-5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5244
	self minVal subtract:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5245
	self minVal - 1
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5246
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5247
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5248
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5249
times:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5250
    "return the product of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5251
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5252
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5253
     smallInteger range is returned (i.e. the low bits of the product).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5254
     This is of course not always correct, but some code does a modulo anyway
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5255
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5256
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5257
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5258
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5259
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5260
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5261
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5262
	long product = myValue * otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5263
	return context._RETURN( STInteger._new(product) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5264
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5265
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5266
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5267
    INT myValue, otherValue;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5268
    unsigned INT productLow, productHi;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5269
    int negative;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5270
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5271
#   define low16Bits(foo)  ((foo) & 0xFFFF)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5272
#   define hi16Bits(foo)   ((foo) >> 16)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5273
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5274
#   define hi32Bits(foo)   ((foo) >> 32)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5275
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5276
    /*
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5277
     * can we use long long arithmetic ?
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5278
     *
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5279
     * long-long arithmetic seems to be buggy with some systems
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5280
     * (took me a while to find this out :-(
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5281
     * (try 10000 * 10000)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5282
     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5283
# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5284
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5285
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5286
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5287
# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5288
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5289
# endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5290
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5291
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5292
	myValue = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5293
	otherValue = __intVal(aNumber);
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5294
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5295
# if defined(USE_LONGLONG_FOR_MUL)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5296
	{
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5297
#  if defined(__alpha__) && !defined(__alpha64__)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5298
#   define LONGLONG      INT64
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5299
#  else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5300
#   define LONGLONG      long long
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5301
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5302
	    LONGLONG product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5303
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5304
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5305
	    if (product < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5306
		RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5307
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5308
	    RETURN ( __mkSmallInteger((INT)(product & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5309
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5310
# else /* no long-long */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5311
	negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5312
	if (myValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5313
	    negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5314
	    myValue = -myValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5315
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5316
	if (otherValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5317
	    negative = -negative;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5318
	    otherValue = -otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5319
	}
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5320
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5321
#  if defined(__GNUC__) && defined(__mc68k__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5322
	asm ("mulu%.l %3,%1:%0"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5323
		: "=d"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5324
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5325
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5326
		  "dmi" ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5327
#  else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5328
#   if defined (__GNUC__) && defined(__x86__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5329
	asm ("mull %3"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5330
		: "=a"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5331
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5332
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5333
		  "rm"  ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5334
#   else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5335
#    if defined(__win32__) && defined(__BORLANDC__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5336
	asm {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5337
	    mov   eax, myValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5338
	    mov   edx, otherValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5339
	    mul   edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5340
	    mov   productLow, eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5341
	    mov   productHi, edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5342
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5343
#    else /* generic */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5344
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5345
	    unsigned INT pHH, pHL, pLH, pLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5346
	    unsigned INT low1, low2, hi1, hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5347
	    unsigned INT t;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5348
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5349
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5350
	     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5351
	     * this is too slow:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5352
	     * since most machines can do 32*32 to 64 bit multiply,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5353
	     * (or at least 32*32 with Overflow check)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5354
	     * - need more assembler (inline) functions here
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5355
	     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5356
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5357
	    low1 = low32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5358
	    hi1 = hi32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5359
	    low2 = low32Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5360
	    hi2 = hi32Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5361
#      undef LLMASK
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5362
#      define LLMASK 0xC000000000000000LL
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5363
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5364
	    low1 = low16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5365
	    hi1 = hi16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5366
	    low2 = low16Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5367
	    hi2 = hi16Bits((unsigned INT)otherValue);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5368
#      define LLMASK 0xC0000000
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5369
#     endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5370
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5371
	    pLH = low1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5372
	    pHL = hi1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5373
	    pLL = low1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5374
	    pHH = hi1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5375
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5376
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5377
	     * the common case ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5378
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5379
	    if ((pHL == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5380
	     && (pLH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5381
	     && (pHH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5382
	     && ((pLL & LLMASK) == 0)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5383
		if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5384
		    RETURN ( __mkSmallInteger(- ((INT)pLL)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5385
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5386
		RETURN ( __mkSmallInteger((INT)pLL) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5387
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5388
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5389
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5390
	     *   pHH |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5391
	     *   pLH          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5392
	     *   pHL          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5393
	     *   pLL                   |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5394
	     */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5395
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5396
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5397
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5398
	    productLow = (t << 32) + low32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5399
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5400
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5401
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5402
	    productLow = (t << 16) + low16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5403
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5404
#     endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5405
	}
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5406
#    endif /* ! __win32__ */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5407
#   endif /* ! (__GNUC__ && __x86__) */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5408
#  endif /* ! (__GNUC__ && __mc68k__) */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5409
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5410
	if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5411
	    RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5412
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5413
	RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5414
# endif /* ! USE_LONGLONG */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5415
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5416
#endif /* not __SCHTEAM__ */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5417
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5418
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5419
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5420
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5421
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5422
	5 times:-1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5423
	5 times:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5424
	self maxVal-1 times:2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5425
	self maxVal-1 times:-2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5426
	self maxVal-1 * 2  bitAnd:16r3fffffff
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5427
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5428
! !
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5429
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5430
!SmallInteger methodsFor:'special modulo bit operators'!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5431
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5432
bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5433
    "return the value of the receiver with all bits inverted in 32bit signed int space
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5434
     (changes the sign)"
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5435
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5436
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5437
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5438
    unsigned INT v;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5439
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5440
    v = __intVal(self);
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5441
    v = ~v;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5442
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5443
    v &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5444
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5445
    RETURN ( __MKUINT(v) );
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5446
#endif
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5447
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5448
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5449
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5450
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5451
     1 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5452
     16r40000000 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5453
     16r80000000 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5454
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5455
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5456
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5457
bitRotate32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5458
    "return the value of the receiver rotated by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5459
     but only within 32 bits, rotating left for positive, right for negative counts.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5460
     Rotates through the sign bit.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5461
     Useful for crypt algorithms, or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5462
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5463
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5464
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5465
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5466
    unsigned INT bits;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5467
    int count;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5468
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5469
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5470
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5471
	count = count % 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5472
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5473
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5474
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5475
	    bits = (bits << count) | (bits >> (32-count));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5476
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5477
	    bits = (bits >> (-count)) | (bits << (32-(-count)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5478
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5479
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5480
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5481
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5482
	RETURN (__MKUINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5483
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5484
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5485
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5486
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5487
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5488
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5489
     128 rotate32:1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5490
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5491
     1 rotate32:1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5492
     1 rotate32:2
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5493
     1 rotate32:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5494
     1 rotate32:32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5495
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5496
     1 rotate32:-1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5497
     1 rotate32:-2
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5498
     1 rotate32:-3
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5499
     1 rotate32:-32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5500
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5501
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5502
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5503
bitShift32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5504
    "return the value of the receiver shifted by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5505
     but only within 32 bits, shifting into/out-of the sign bit.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5506
     May be useful for communication interfaces, to create ST-numbers
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5507
     from a signed 32bit int value given as individual bytes,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5508
     or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5509
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5510
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5511
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5512
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5513
    INT bits, count;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5514
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5515
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5516
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5517
	if (count >= 32) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5518
	    RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5519
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5520
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5521
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5522
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5523
	    bits = bits << count;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5524
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5525
	    bits = bits >> (-count);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5526
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5527
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5528
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5529
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5530
	RETURN (__MKINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5531
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5532
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5533
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5534
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5535
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5536
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5537
     128 bitShift:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5538
     128 bitShift32:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5539
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5540
     1 bitShift:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5541
     1 bitShift32:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5542
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5543
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5544
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5545
bitXor32:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5546
    "return the xor of the receiver and the argument.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5547
     The argument must be another SmallInteger or a 4-byte LargeInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5548
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5549
     This is of course not always correct, but allows for C/Java behavior to be emulated."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5550
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5551
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5552
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5553
    INT rslt;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5554
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5555
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5556
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5557
    rslt &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5558
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5559
    RETURN ( __MKUINT(rslt));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5560
#endif
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5561
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5562
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5563
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5564
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5565
     16r7FFFFFFF bitXor: 16r80000000          4294967295
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5566
     16r7FFFFFFF bitXor32: 16r80000000
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5567
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5568
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5569
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5570
unsignedBitShift32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5571
    "return the value of the receiver shifted by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5572
     but only within 32 unsigned bits.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5573
     May be useful for communication interfaces, to create ST-numbers
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5574
     from an unsigned 32bit int value given as individual byte,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5575
     or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5576
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5577
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5578
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5579
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5580
    unsigned INT bits;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5581
    INT count;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5582
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5583
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5584
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5585
	if (count >= 32) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5586
	    RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5587
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5588
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5589
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5590
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5591
	    bits = bits << count;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5592
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5593
	    bits = bits >> (-count);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5594
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5595
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5596
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5597
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5598
	RETURN (__MKUINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5599
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5600
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5601
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5602
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5603
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5604
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5605
     128 unsignedBitShift:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5606
     128 unsignedBitShift32:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5607
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5608
     1 unsignedBitShift:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5609
     1 unsignedBitShift32:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5610
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5611
     -1 unsignedBitShift32:-1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5612
     -1 unsignedBitShift32:1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5613
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5614
! !
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5615
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5616
!SmallInteger methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5617
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5618
between:min and:max
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5619
    "return true if the receiver is greater than or equal to the argument min
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5620
     and less than or equal to the argument max.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5621
     - reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5622
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5623
%{  /* NOCONTEXT */
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5624
#ifdef __SCHTEAM__
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5625
    if (STObject.bothSmallInteger(min, max)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5626
	long myVal = ((STInteger)self).longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5627
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5628
	if (myVal >= ((STInteger)min).longValue()) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5629
	    if (myVal <= ((STInteger)max).longValue()) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5630
		return __c__._RETURN_true();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5631
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5632
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5633
	return __c__._RETURN_false();
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5634
    }
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5635
#else /* not SCHTEAM */
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5636
    if (__bothSmallInteger(min, max)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5637
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5638
	// tag bit does not change the magnitude order
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5639
	if ((INT)self < (INT)(min)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5640
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5641
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5642
	if ((INT)self > (INT)(max)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5643
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5644
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5645
	RETURN ( true );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5646
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5647
	REGISTER INT selfVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5648
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5649
	selfVal = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5650
	if (selfVal < __intVal(min)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5651
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5652
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5653
	if (selfVal > __intVal(max)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5654
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5655
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5656
	RETURN ( true );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5657
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5658
    }
18289
Claus Gittinger <cg@exept.de>
parents: 18255
diff changeset
  5659
#endif /* not SCHTEAM */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5660
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5661
    (self < min) ifTrue:[^ false].
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5662
    (max < self) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5663
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5664
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5665
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5666
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5667
    "return true, if the receiver is even"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5668
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5669
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5670
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5671
    return __c__._RETURN( self.isEven() ? STObject.True : STObject.False );
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5672
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5673
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5674
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true );
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5675
#endif /* not SCHTEAM */
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5676
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5677
    ^ super even
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5678
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5679
23357
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5680
isImmediate
24186
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5681
    "return true if I am an immediate object
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5682
     i.e. I am represented in the pointer itself and
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5683
     no real object header/storage is used by me."
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5684
23357
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5685
    ^ true
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5686
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5687
    "Created: / 18-09-2018 / 14:48:22 / Stefan Vogel"
24186
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5688
    "Modified (comment): / 27-05-2019 / 15:38:29 / Claus Gittinger"
23357
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5689
!
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5690
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5691
isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5692
    "return true, if the receiver is a power of 2"
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5693
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5694
    "/ 0 is not a power of two, because ld(0) is -INF
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5695
    ^ ((self bitAnd:(self - 1)) == 0) and:[self ~~ 0]
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5696
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5697
    "
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5698
     0 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5699
     1 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5700
     2 isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5701
     3 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5702
     4 isPowerOfTwo
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5703
     5 isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5704
     16r8000000000000000 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5705
     16r8000000000000001 isPowerOfTwo
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5706
     16r40000000 isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5707
     16r80000000 isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5708
     16r100000000 isPowerOfTwo
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5709
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5710
     10000 factorial isPowerOfTwo
24100
9949ffc76053 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24006
diff changeset
  5711
     |n| n := 10000 factorial. Time millisecondsToRun:[10000 timesRepeat:[ n isPowerOfTwo]]
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5712
    "
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5713
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5714
    "Modified: / 20-06-2011 / 12:41:18 / cg"
24100
9949ffc76053 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24006
diff changeset
  5715
    "Modified (comment): / 30-04-2019 / 23:13:01 / Claus Gittinger"
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5716
!
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5717
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5718
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5719
    "return true, if the receiver is less than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5720
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5721
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5722
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5723
#ifdef __SCHTEAM__
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5724
    return context._RETURN( self.isLt_0() ? STObject.True : STObject.False);
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5725
    /* NOTREACHED */
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5726
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5727
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5728
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5729
    RETURN ( ((INT)(self) < 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5730
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5731
    RETURN ( (__intVal(self) < 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5732
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5733
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5734
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5735
    ^ self < 0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5736
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5737
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5738
nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5739
    "return the power of 2 at or above the receiver.
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5740
     Useful for padding.
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5741
     Notice, that for a powerOf2, the receiver is returned.
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  5742
     Also notice, that (because it is used for padding),
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5743
     0 is returned for zero."
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5744
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5745
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5746
#ifndef __SCHTEAM__
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5747
    INT x;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5748
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5749
    x = __intVal(self) - 1;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5750
    x |= (x >> 1);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5751
    x |= (x >> 2);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5752
    x |= (x >> 4);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5753
    x |= (x >> 8);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5754
    x |= (x >> 16);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5755
# if __POINTER_SIZE__ == 8
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5756
    x |= (x >> 32);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5757
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5758
    RETURN (__MKINT(x + 1));
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5759
#endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5760
%}.
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5761
    ^ super nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5762
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5763
    "
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5764
     0 nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5765
     1 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5766
     2 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5767
     3 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5768
     4 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5769
     5 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5770
     6 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5771
     7 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5772
     8 nextPowerOf2
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5773
     9 nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5774
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5775
     22 nextPowerOf2
21107
079804a17e43 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20819
diff changeset
  5776
     32 nextPowerOf2
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5777
     16rFFFF nextPowerOf2 = 16r10000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5778
     16rFFFFFFFF nextPowerOf2 = 16r100000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5779
     16r1FFFFFFFFFFFFFFF nextPowerOf2 = 16r2000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5780
     16r3FFFFFFFFFFFFFFF nextPowerOf2 = 16r4000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5781
     16r7FFFFFFFFFFFFFFF nextPowerOf2 = 16r8000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5782
     16rFFFFFFFFFFFFFFFF nextPowerOf2 = 16r10000000000000000
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5783
     10 factorial nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5784
     20 factorial nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5785
     100 factorial nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5786
    "
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5787
!
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5788
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5789
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5790
    "return true, if the receiver is odd"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5791
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5792
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5793
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5794
    return __c__._RETURN( self.isEven() ? STObject.False : STObject.True );
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5795
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5796
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5797
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5798
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5799
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5800
    ^ super odd
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5801
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5802
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5803
parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5804
    "return true, if an odd number of bits are set in the receiver, false otherwise.
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5805
     (i.e. true for odd parity)
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5806
     Undefined for negative values (smalltalk does not require the machine to use 2's complement)"
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5807
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5808
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5809
#ifndef __SCHTEAM__
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5810
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5811
    // tricky, but very fast (google for it, to understand)
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5812
    unsigned INT v = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5813
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5814
# if __POINTER_SIZE__ == 8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5815
    v ^= v >> 32;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5816
# endif
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5817
    v ^= v >> 16;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5818
    v ^= v >> 8;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5819
    v ^= v >> 4;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5820
    v &= 0xf;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5821
    RETURN ( ( (0x6996 >> v) & 1 ) ? true : false );
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5822
#endif
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5823
%}.
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5824
    ^ super parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5825
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5826
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5827
	self assert:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5828
	 (((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0])
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5829
	    asByteArray collect:[:c | c + $0 asciiValue]) asString
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5830
	 =
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5831
	    '0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110'
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5832
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5833
	self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5834
	self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5835
	self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5836
	self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5837
	self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5838
	self assert:(16r3FFFFFFFFFFFFFFF parityOdd = 16r3FFFFFFFFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5839
	self assert:(16r7FFFFFFFFFFFFFFF parityOdd = 16r7FFFFFFFFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5840
	self assert:(16rFFFFFFFFFFFFFFFF parityOdd = 16rFFFFFFFFFFFFFFFF bitCount odd).
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5841
    "
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5842
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5843
    "Modified (comment): / 09-01-2012 / 19:55:37 / cg"
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5844
!
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5845
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5846
positive
18864
5f4e0d1f6df1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18849
diff changeset
  5847
    "return true, if the receiver is greater or equal to zero (not negative)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5848
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5849
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5850
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5851
#ifdef __SCHTEAM__
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5852
    return context._RETURN( self.isGe_0() ? STObject.True : STObject.False);
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5853
    /* NOTREACHED */
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5854
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5855
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5856
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5857
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5858
    RETURN ( ((INT)(self) >= 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5859
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5860
    RETURN ( (__intVal(self) >= 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5861
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5862
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5863
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5864
    ^ super positive
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5865
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5866
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5867
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7438
diff changeset
  5868
    "return the sign of the receiver (-1, 0 or 1).
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5869
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5870
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5871
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5872
#ifndef __SCHTEAM__
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5873
# if TAG_INT <= 1 /* tag in low bit */
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5874
    RETURN ( __mkSmallInteger( (((INT)self) > TAG_INT) - (((INT)self) < 0) ) );
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5875
# else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  5876
    INT val = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5877
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5878
    RETURN ( __mkSmallInteger( (val > 0) - (val < 0) ) );
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5879
# endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5880
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5881
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5882
    ^ super sign
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5883
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5884
    "
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5885
     -5 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5886
     -1 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5887
     0 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5888
     1 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5889
     5 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5890
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5891
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5892
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5893
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5894
    "return true, if the receiver is greater than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5895
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5896
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5897
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5898
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5899
    return context._RETURN( self.isGt_0() ? STObject.True : STObject.False);
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5900
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5901
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5902
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5903
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5904
    /* tag bit does not change sign */
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5905
    RETURN ( ((INT)(self) > (INT)(__mkSmallInteger(0))) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5906
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5907
    RETURN ( (__intVal(self) > 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5908
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5909
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5910
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5911
    ^ super strictlyPositive
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5912
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5913
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5914
     0 strictlyPositive
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5915
     1 strictlyPositive
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5916
     -1 strictlyPositive
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5917
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5918
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5919
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  5920
!SmallInteger class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5921
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5922
version
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5923
    ^ '$Header$'
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5924
!
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5925
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5926
version_CVS
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5927
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5928
! !
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
  5929
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5930
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5931
SmallInteger initialize!