SmallInteger.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24406 588966201b30
child 24554 1841effd762b
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24406
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
     1
"{ Encoding: utf8 }"
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1988 by Claus Gittinger
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    14
"{ Package: 'stx:libbasic' }"
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    15
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
    16
"{ NameSpace: Smalltalk }"
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
Integer subclass:#SmallInteger
20819
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    19
	instanceVariableNames:''
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    20
	classVariableNames:'ZeroString'
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    21
	poolDictionaries:''
b64a4707d4ea #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20339
diff changeset
    22
	category:'Magnitude-Numbers'
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
    23
!
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    24
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    25
!SmallInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 COPYRIGHT (c) 1988 by Claus Gittinger
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    41
documentation
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    42
"
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    43
    SmallIntegers are Integers in the range of at least +/- 2^30
19318
Claus Gittinger <cg@exept.de>
parents: 19317
diff changeset
    44
    i.e. 31 bits, but this is not a guaranteed:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    45
	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
    46
	under the Schteam-VM, 64 bits are used (i.e. a full long integer)
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    48
    These are no real objects - they have no instances (not even storage !!)
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    49
    and cannot be subclassed.
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    50
    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
    51
    garbage collecting SmallIntegers in the system.
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    52
    SmallInts are marked by having the TAG_INT
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    53
    bit set, in contrast to all other objects which do not.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    54
    Since this knowledge is hardwired into the system (and there is no
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    55
    class-field stored with SmallIntegers) there can be no subclass of
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    56
    SmallInteger (sorry).
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    57
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    58
    If you really need this kind of thing, create a subclass of Integer,
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    59
    with an instance variable holding the value.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    60
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    61
    Because the range and sharing of SmallIntegers is different among implementations
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    62
    (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
    63
    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
    64
    For portable code, when comparing integers, use #'=' and #'~=' (instead of #'==' / #'~~'),
21155
248f28201689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21107
diff changeset
    65
    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
    66
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    67
    [author:]
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    68
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    69
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    70
    [see also:]
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    71
	Number
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    72
	Float Fraction FixedPoint
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
    73
	LargeInteger
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    74
"
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    75
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    77
!SmallInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
basicNew:size
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
    self error:'instances of SmallInteger cannot be created with new'
23476
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    91
!
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    92
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    93
fastFromString:aString at:startIndex
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    94
    "return the next SmallInteger from the string starting at startIndex.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    95
     No spaces are skipped.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    96
     Raises an error, if the index is out of bounds,
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    97
     Returns garbage if the argument string is not a valid integer.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    98
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
    99
     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
   100
     It has been added to allow high speed string decomposition into 
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   101
     numbers, especially for mass-data (reading millions of numbers)."
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   102
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   103
%{   /* NOCONTEXT */
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   104
     if (__isStringLike(aString) && __isSmallInteger(startIndex)) {
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   105
        char *cp = (char *)(__stringVal(aString));
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   106
        int idx = __intVal(startIndex) - 1;
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   107
        long atol(const char *);
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   108
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   109
        if ((unsigned)idx < __stringSize(aString)) {
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   110
            long val = atol(cp + idx);
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   111
            RETURN (__MKINT(val));
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
     }
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
     self primitiveFailed.
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   116
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   117
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   118
     SmallInteger fastFromString:'hello12345' at:6
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   119
     SmallInteger fastFromString:'12345' at:1
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   120
     SmallInteger fastFromString:'12345' at:2
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   121
     SmallInteger fastFromString:'12345' at:3
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   122
     SmallInteger fastFromString:'12345' at:4
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   123
     SmallInteger fastFromString:'12345' at:5
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   124
     SmallInteger fastFromString:'12345' at:6
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   125
     SmallInteger fastFromString:'12345' at:0
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   126
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   127
     Time millisecondsToRun:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   128
        1000000 timesRepeat:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   129
            SmallInteger readFrom:'12345'
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
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   134
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   135
     Time millisecondsToRun:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   136
        1000000 timesRepeat:[
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   137
            SmallInteger fastFromString:'12345' at:1
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
    "
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   141
93b798639100 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23357
diff changeset
   142
    "Created: / 27-10-2018 / 08:52:32 / Claus Gittinger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   145
!SmallInteger class methodsFor:'bit mask constants'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   146
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   147
bitMaskFor:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   148
    "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
   149
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   150
    (index between:1 and:SmallInteger maxBits) ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   151
	^ SubscriptOutOfBoundsSignal
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   152
		raiseRequestWith:index
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   153
		errorString:'index out of bounds'
701
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
    ^ 1 bitShift:(index - 1)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   156
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   157
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   158
!SmallInteger class methodsFor:'class initialization'!
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   159
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   160
initialize
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   161
    ZeroString := '0'
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   162
! !
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
   163
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   164
!SmallInteger class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
maxBits
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   167
    "return the number of bits in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   168
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   171
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   172
    // longs are always 64bits
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   173
    return context._RETURN ( STInteger._new(64) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   174
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   175
    RETURN ( __mkSmallInteger(N_INT_BITS) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   176
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   177
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   178
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   179
     SmallInteger maxBits
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   180
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
a27a279701f8 Initial revision
claus
parents:
diff changeset
   183
maxBytes
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   184
    "return the number of bytes in instances of me.
19486
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   185
     For very special uses only - not constant across implementations.
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   186
     Notice: this is inlined by the compiler(s) as a constant,
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   187
     therefore, a query like 'SmallInteger maxBytes == 8'
359a8beaee4e #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19321
diff changeset
   188
     costs nothing; it is compiled in as a constant."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   189
a27a279701f8 Initial revision
claus
parents:
diff changeset
   190
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   191
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   192
    // longs are always 8 bytes
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   193
    return context._RETURN ( STInteger._new(8) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   194
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   195
    RETURN ( __mkSmallInteger(N_INT_BITS / 8 + 1) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   196
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   197
%}
3684
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   198
    "
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   199
     SmallInteger maxBytes
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   200
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   202
a27a279701f8 Initial revision
claus
parents:
diff changeset
   203
maxVal
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   204
    "return the largest Integer representable as SmallInteger.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   205
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   206
a27a279701f8 Initial revision
claus
parents:
diff changeset
   207
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   208
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   209
    return context._RETURN ( STInteger._MAX_INTVAL );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   210
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   211
    RETURN ( __mkSmallInteger(_MAX_INT) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   212
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   213
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   214
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   215
     SmallInteger maxVal
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   216
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   217
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   218
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   219
minVal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   220
    "return the smallest Integer representable as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   221
     For very special uses only - not constant across implementations"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   222
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   223
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   224
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   225
    return context._RETURN ( STInteger._MIN_INTVAL );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   226
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   227
    RETURN ( __mkSmallInteger(_MIN_INT) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   228
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   229
%}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   230
    "
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   231
     SmallInteger minVal
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   232
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   233
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   235
!SmallInteger class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   236
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   237
canBeSubclassed
21444
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   238
    "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
   239
     Return false here - since it is NOT possible for SmallInteger
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   240
     (due to the tagged representation of SmallIntegers)"
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   241
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   242
    ^ false
3914
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   243
21444
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   244
    "Modified: / 05-11-1998 / 16:11:27 / cg"
1fc538e9d70e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21155
diff changeset
   245
    "Modified (comment): / 13-02-2017 / 20:30:46 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   246
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
2672
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   248
hasImmediateInstances
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   249
    "return true if this class has immediate instances
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   250
     i.e. if the instances are represented in the pointer itself and
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   251
     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
   252
     Redefined from Behavior"
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
    ^ true
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
    "Created: 3.6.1997 / 12:01:26 / cg"
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   257
!
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   258
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   259
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   260
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   261
     Here, true is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   265
    "Modified: 23.4.1996 / 16:00:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
!SmallInteger methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
* aNumber
11728
0c197f1c3cd0 comment
Claus Gittinger <cg@exept.de>
parents: 11718
diff changeset
   271
    "return the product of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   274
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   275
    return context._RETURN( self.times( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   276
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   277
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   278
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   279
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   280
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   281
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   282
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   283
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   284
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   285
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   286
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   287
    INT myValue, otherValue;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   288
    unsigned INT productLow, productHi;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   289
    int negative;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   290
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   291
    myValue = __intVal(self);
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   292
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   293
#   define low16Bits(foo)  ((foo) & 0xFFFF)
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   294
#   define hi16Bits(foo)   ((foo) >> 16)
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   295
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   296
#   define hi32Bits(foo)   ((foo) >> 32)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   297
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   298
    /*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   299
     * can we use long long arithmetic ?
4176
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   300
     *
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   301
     * long-long arithmetic seems to be buggy with some systems
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   302
     * (took me a while to find this out :-(
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   303
     * (try 10000 * 10000)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   304
     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   305
# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   306
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   307
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   308
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   309
# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   310
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   311
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   312
252
   313
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   314
	otherValue = __intVal(aNumber);
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   315
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   316
# if defined(USE_LONGLONG_FOR_MUL)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   317
	{
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   318
#  if defined(__alpha__) && !defined(__alpha64__)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   319
#   define LONGLONG      INT64
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   320
#  else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   321
#   define LONGLONG      long long
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   322
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   323
	    LONGLONG product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   324
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   325
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   326
	    if ((product >= (LONGLONG)_MIN_INT)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   327
	     && (product <= (LONGLONG)_MAX_INT)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   328
		RETURN ( __mkSmallInteger((INT)product) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   329
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   330
	    if (product < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   331
		negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   332
		product = -product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   333
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   334
		negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   335
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   336
	    productHi = product >> 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   337
	    productLow = product & 0xFFFFFFFFLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   338
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   339
# else /* no long-long */
21700
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
	if (myValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   342
	    negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   343
	    myValue = -myValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   344
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   345
	if (otherValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   346
	    negative = -negative;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   347
	    otherValue = -otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   348
	}
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   349
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   350
#  if defined(__GNUC__) && defined(__mc68k__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   351
	asm ("mulu%.l %3,%1:%0"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   352
		: "=d"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   353
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   354
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   355
		  "dmi" ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   356
#  else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   357
#   if defined (__GNUC__) && defined(__x86__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   358
	asm ("mull %3"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   359
		: "=a"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   360
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   361
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   362
		  "rm"  ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   363
#   else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   364
#    if defined(__win32__) && defined(__BORLANDC__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   365
	asm {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   366
	    mov   eax, myValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   367
	    mov   edx, otherValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   368
	    mul   edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   369
	    mov   productLow, eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   370
	    mov   productHi, edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   371
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   372
#    else /* generic */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   373
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   374
	    unsigned INT pHH, pHL, pLH, pLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   375
	    unsigned INT low1, low2, hi1, hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   376
	    unsigned INT t;
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
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   379
	     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   380
	     * this is too slow:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   381
	     * since most machines can do 32*32 to 64 bit multiply,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   382
	     * (or at least 32*32 with Overflow check)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   383
	     * - need more assembler (inline) functions here
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   384
	     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   385
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   386
	    low1 = low32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   387
	    hi1 = hi32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   388
	    low2 = low32Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   389
	    hi2 = hi32Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
   390
#      define LLMASK 0xC000000000000000LL
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   391
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   392
	    low1 = low16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   393
	    hi1 = hi16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   394
	    low2 = low16Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   395
	    hi2 = hi16Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
   396
#      define LLMASK 0xC0000000L
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   397
#     endif
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   398
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   399
	    pLH = low1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   400
	    pHL = hi1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   401
	    pLL = low1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   402
	    pHH = hi1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   403
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
	     * the common case ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   406
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   407
	    if ((pHL == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   408
	     && (pLH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   409
	     && (pHH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   410
	     && ((pLL & LLMASK) == 0)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   411
		if (negative < 0) {
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
		RETURN ( __mkSmallInteger((INT)pLL) );
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
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   417
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   418
	     *   pHH |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   419
	     *   pLH          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   420
	     *   pHL          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   421
	     *   pLL                   |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   422
	     */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   423
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   424
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   425
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   426
	    productLow = (t << 32) + low32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   427
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   428
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   429
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   430
	    productLow = (t << 16) + low16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   431
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   432
#     endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   433
	}
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   434
#    endif /* ! __win32__ */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
   435
#   endif /* ! (__GNUC__ && __x86__) */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   436
#  endif /* ! (__GNUC__ && __mc68k__) */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   437
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   438
	if (productHi == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   439
	    if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   440
		if (productLow <= -(_MIN_INT)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   441
		    RETURN ( __mkSmallInteger(-((INT)productLow)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   442
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   443
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   444
		if (productLow <= _MAX_INT) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   445
		    RETURN ( __mkSmallInteger(productLow) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   446
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   447
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   448
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   449
# endif /* ! USE_LONGLONG */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   450
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   451
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   452
	RETURN (__MKLARGEINT128(negative, productLow, productHi));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   453
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   454
	RETURN (__MKLARGEINT64(negative, productLow, productHi));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   455
# endif
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   456
    } else if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   457
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   458
	double val = (double)myValue * __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   459
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   460
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   461
	RETURN ( newFloat );
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   462
    } else if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   463
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   464
	float val = (float)myValue * __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   465
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   466
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   467
	RETURN ( newFloat );
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   468
    } else if (__isFractionLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   469
	OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   470
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   471
	if (myValue == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   472
	    RETURN(__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   473
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   474
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   475
	if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   476
	    INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   477
	    t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   478
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   479
		INT prod = myValue * num;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   480
		if (prod / myValue == num) { // check for overflow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   481
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   482
		    INT quo = prod / den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   483
		    if (quo * den == prod) {        // check for integer result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   484
			RETURN ( __mkSmallInteger(quo) );
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
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   487
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   488
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   490
#endif /* not __SCHTEAM__ */
2641
Claus Gittinger <cg@exept.de>
parents: 2640
diff changeset
   491
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   492
    ^ aNumber productFromInteger:self
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   493
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   494
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   495
	3 * (1/2)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   496
	6 * (1/2)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   497
	6 * (-1/2)
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   498
   "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   499
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   500
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   501
+ aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   502
    "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
   503
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   504
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   505
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   506
    return context._RETURN( self.plus( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   507
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   508
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   509
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   510
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   511
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   512
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   513
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   514
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   515
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   516
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   517
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   518
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   519
# ifdef _ADD_IO_IO
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   520
	RETURN ( _ADD_IO_IO(self, aNumber) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   521
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   522
	REGISTER INT sum;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   523
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   524
	sum =  __intVal(self) + __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   525
	if (__ISVALIDINTEGER(sum)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   526
	    RETURN ( __mkSmallInteger(sum) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   527
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   528
	RETURN ( __MKLARGEINT(sum) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   529
# endif
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   530
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   531
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   532
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   533
	double val = (double)__intVal(self) + __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   534
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   535
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   536
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   537
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   538
    if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   539
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   540
	float val = (float)__intVal(self) + __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   541
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   542
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   543
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   544
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   545
#endif /* not __SCHTEAM__ */
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   546
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   547
    ^ aNumber sumFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   548
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   549
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   550
- aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   551
    "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
   552
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   553
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   554
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   555
    return context._RETURN( self.minus( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   556
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   557
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   558
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   559
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   560
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   561
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   562
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   563
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   564
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   565
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   566
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   567
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   568
# ifdef _SUB_IO_IO
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   569
	RETURN ( _SUB_IO_IO(self, aNumber) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   570
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   571
	REGISTER INT diff =  __intVal(self) - __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   572
	if (__ISVALIDINTEGER(diff)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   573
	    RETURN ( __mkSmallInteger(diff) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   574
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   575
	RETURN ( __MKLARGEINT(diff) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   576
# endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   577
    }
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   578
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   579
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   580
	double val = (double)__intVal(self) - __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   581
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   582
	__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   583
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   584
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   585
    if (__isShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   586
	OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   587
	float val = (float)__intVal(self) - __shortFloatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   588
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   589
	__qMKSFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   590
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   591
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   592
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   593
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   594
    ^ aNumber differenceFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   595
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   596
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   597
/ aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   598
    "return the quotient of the receiver's value and the argument's value"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   601
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   602
    return context._RETURN( self.quotient( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   603
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   604
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   605
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   606
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   607
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   608
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   609
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   610
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   611
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   612
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   613
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   614
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   615
    INT t, val;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   616
    double dval;
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   617
    INT myValue = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   618
252
   619
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   620
	val = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   621
	if (val != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   622
	    t = myValue / val;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   623
# ifdef GOOD_OPTIMIZER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   624
	    if (myValue % val == 0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   625
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   626
	    /* 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
   627
	       but most compilers are too stupid and generate an extra modulus
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   628
	       instruction for "if (me % val)".
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   629
	       Even if most divide instructions already leave the remainder in
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   630
	       some register.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   631
	       Therefore I use a multiplication which is faster than a modulo
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   632
	       on most machines. Hint to GNU people :-)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   633
	    */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   634
	    if ((t * val) == myValue) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   635
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   636
		RETURN ( __mkSmallInteger(t) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   637
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   638
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   639
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   640
	if (__isFloatLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   641
	    dval = __floatVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   642
	    if (dval != 0.0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   643
		OBJ newFloat;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   644
		double val = (double)myValue / dval;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   645
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   646
		__qMKFLOAT(newFloat, val);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   647
		RETURN ( newFloat );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   648
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   649
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   650
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   651
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   652
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   653
    aNumber isInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   654
	aNumber == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   655
	    ^ ZeroDivide raiseRequestWith:thisContext.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   656
	].
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   657
	^ Fraction numerator:self denominator:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
    ^ aNumber quotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   660
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   661
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   662
     8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   663
     9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   664
     9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   665
     9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   666
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   667
     -8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   668
     -9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   669
     -9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   670
     -9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   671
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   672
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   673
2
claus
parents: 1
diff changeset
   674
// aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   675
    "return the integer part of the quotient of the receiver's value
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   676
     and the argument's value.
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   677
     The result is truncated toward negative infinity
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   678
     and will be negative, if the operands signs differ.
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   679
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   680
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   681
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   682
     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
   683
     Especially surprising (because of truncation toward negative infinity):
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   684
	-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
   685
	-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
   686
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   687
     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
   688
     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
   689
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   690
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   691
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   692
    return context._RETURN( self.quotientTruncated( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   693
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   694
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   695
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   696
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   697
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   698
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   699
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   700
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   701
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   702
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   703
19994
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   704
    INT divisor, rslt;
1d96d9406342 compiler warnings
Claus Gittinger <cg@exept.de>
parents: 19860
diff changeset
   705
    INT dividend = __intVal(self);
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   706
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   707
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   708
	divisor = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   709
	if (divisor != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   710
	    rslt = dividend / divisor;
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
	     * Optimized to speed up positive result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   713
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   714
	    if (rslt <= 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   715
		if (rslt == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   716
		    if ((dividend ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   717
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   718
			 * result (negative) has been truncated toward 0.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   719
			 * Return -1, because we truncate toward negative inf.
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
			 rslt = -1;
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
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   724
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   725
		     * If result (negative) has been truncated toward 0,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   726
		     * subtract 1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   727
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   728
		    if (divisor > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   729
			if (rslt * divisor > dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   730
			    rslt--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   731
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   732
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   733
			if (rslt * divisor < dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   734
			    rslt--;
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
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   738
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   739
	    RETURN ( __mkSmallInteger(rslt) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   740
	}
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   741
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   742
	if (__isFractionLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   743
	    OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   744
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   745
		INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   746
		t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   747
		if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   748
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   749
		    INT prod;
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   750
#if 0 && defined(__GNUC__) // supported from GCC 5
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   751
		    if (!__builtin_mul_overflow(myself, den, &prod)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   752
			goto out;   // overflow, try harder...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   753
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   754
#else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   755
		    prod = dividend * den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   756
		    // make sure, that no overflow occurred
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   757
		    if (prod / den != dividend) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   758
			goto out;   // overflow, try harder...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   759
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   760
#endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   761
		    rslt = prod / num;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   762
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
		     * Optimized to speed up positive result
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   765
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   766
		    if (rslt <= 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   767
			if (rslt == 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   768
			    if ((dividend ^ num) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   769
				/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   770
				 * result (negative) has been truncated toward 0.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   771
				 * Return -1, because we truncate toward negative inf.
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
				 rslt = -1;
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
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   776
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   777
			     * If result (negative) has been truncated toward 0,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   778
			     * subtract 1, because we truncate toward negative inf.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   779
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   780
			    if (num > 0) {
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
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   783
				if (rslt * num < prod) rslt--;
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
			}
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
		    RETURN ( __mkSmallInteger(rslt) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   788
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   789
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   790
	}
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   791
    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   792
out:;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   793
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   794
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   795
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   796
	^ ZeroDivide raiseRequestWith:thisContext.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   797
    ].
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   798
    ^ aNumber integerQuotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   799
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   800
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   801
     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
   802
     -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
   803
     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
   804
     -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
   805
     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
   806
     -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
   807
     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
   808
     -1 // -2   ~~ 0 ifTrue:[self halt].
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   809
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   810
     -7 // (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   811
     -7 quo: (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   812
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   813
     7 // (-4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
   814
     7 quo: (-4/3)
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   815
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   816
     10000 // 3600000 ~~ 0 ifTrue:[self halt].
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   817
     12 // (1 / 1000000000000000000)
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   818
     12 // (1 / 100000000000000)
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   819
     12 // 0.00000000000001s
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   820
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
     9 quo:-4  => -2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   824
     -9 quo:-4 => 2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   825
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   826
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   827
    "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
   828
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   829
2
claus
parents: 1
diff changeset
   830
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   831
    "Answer the integer remainder m defined by division with truncation toward
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   832
     negative infinity.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   833
     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
   834
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   835
     The returned remainder has the same sign as aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   836
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   837
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   838
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   839
     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
   840
     Especially surprising:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   841
	-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
   842
			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
   843
	-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
   844
			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
   845
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   846
     See #rem: which is the corresponding remainder for division via #quo:.
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   847
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
   848
     Redefined here for speed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   849
a27a279701f8 Initial revision
claus
parents:
diff changeset
   850
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   851
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   852
    return context._RETURN( self.remainder( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   853
#else
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   854
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   855
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   856
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   857
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   858
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   859
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   860
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   861
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   862
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   863
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   864
    INT dividend, divisor, rem;
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   865
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   866
    if (__isSmallInteger(aNumber)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   867
	&& (divisor = __intVal(aNumber)) != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   868
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   869
	 * 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
   870
	 * in C!
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   871
	 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   872
	dividend = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   873
	rem = dividend % divisor;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   874
	if (rem) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   875
	    if ((rem ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   876
		/* sign of remainder is different from sign of divisor */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   877
		rem = -rem;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   878
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   879
	    if ((dividend ^ divisor) < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   880
		/* different signs, so division would have returned a
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   881
		 * negative number.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   882
		 * C rounds toward zero, this code will simulate
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   883
		 * rounding towards negative infinity.
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
		rem = divisor - rem;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   886
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   887
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   888
	RETURN ( __mkSmallInteger(rem) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   890
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   891
%}.
2
claus
parents: 1
diff changeset
   892
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   893
	^ ZeroDivide raiseRequestWith:thisContext.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   894
    ].
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   895
    ^ aNumber moduloFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   896
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   897
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   898
     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
   899
     -9 \\ 4 == 3 ifFalse:[self halt].
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   900
     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
   901
     -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
   902
     (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
   903
     (-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
   904
     1000 \\ 3600000 == 1000 ifFalse:[self halt]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   905
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   906
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   907
    "Modified: / 12-02-2012 / 20:43:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   908
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   909
a27a279701f8 Initial revision
claus
parents:
diff changeset
   910
abs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   911
    "return the absolute value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   912
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   913
a27a279701f8 Initial revision
claus
parents:
diff changeset
   914
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   915
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   916
    return context._RETURN( self.abs());
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   917
#else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   918
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   919
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   920
    if (val >= 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   921
	RETURN (self);
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   922
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   923
    if (val != _MIN_INT) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   924
	RETURN ( __mkSmallInteger(-val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   925
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   926
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   927
    RETURN( __MKLARGEINT(-_MIN_INT));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   928
#endif
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   929
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   930
    ^ super abs
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   931
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   932
a27a279701f8 Initial revision
claus
parents:
diff changeset
   933
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   934
    "return the negative value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   935
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   936
a27a279701f8 Initial revision
claus
parents:
diff changeset
   937
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   938
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   939
    return context._RETURN( self.negated());
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   940
#else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   941
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   942
a27a279701f8 Initial revision
claus
parents:
diff changeset
   943
    if (val != _MIN_INT) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   944
	RETURN ( __mkSmallInteger(- val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   945
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   946
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   947
    RETURN (__MKLARGEINT( -_MIN_INT));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   948
#endif
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   949
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   950
    ^ 0 - self
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   951
!
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   952
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   953
quo:aNumber
18849
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   954
    "return the integer part of the quotient of the receiver's value
646aee8aa03a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18846
diff changeset
   955
     and the argument's value. The result is truncated towards zero
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   956
     and negative, if the operands signs differ..
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   957
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   958
	(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
   959
     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
   960
     for negative results, the remainder is ignored.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   961
     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
   962
     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
   963
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   964
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   965
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
   966
    return context._RETURN( self.quotient(aNumber));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
   967
#else
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   968
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   969
	INT val = __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   970
	if (val != 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   971
	    RETURN ( __mkSmallInteger(__intVal(self) / val) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   972
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   973
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   974
	if (__isFractionLike(aNumber)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   975
	    OBJ t = __FractionInstPtr(aNumber)->f_numerator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   976
	    if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   977
		INT num = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   978
		t = __FractionInstPtr(aNumber)->f_denominator;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   979
		if (__isSmallInteger(t)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   980
		    INT den = __intVal(t);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   981
		    INT myself = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   982
		    INT prod;
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   983
#if 0 && defined(__GNUC__) // supported from GCC 5
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   984
		    if (__builtin_mul_overflow(myself, den, &prod)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   985
			RETURN ( __mkSmallInteger(prod / num ));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   986
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   987
#else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   988
		    prod = myself * den;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   989
		    // make sure, that no overflow occurred
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   990
		    if (prod / den == myself) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   991
			RETURN ( __mkSmallInteger(prod / num ));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   992
		    }
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
   993
#endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   994
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   995
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
   996
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   997
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
   998
#endif /* not __SCHTEAM__ */
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   999
%}.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1000
    (aNumber = 0) ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1001
	^ ZeroDivide raiseRequestWith:thisContext.
1036
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
    ^ self retry:#quo: coercing:aNumber
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1004
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1005
    "
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1006
     9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1007
     -9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1008
     9 quo:4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1009
     -9 quo:4
18815
085878786453 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 18760
diff changeset
  1010
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1011
     -7 // (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1012
     -7 quo: (4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1013
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1014
     7 // (-4/3)
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1015
     7 quo: (-4/3)
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1016
    "
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1017
!
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1018
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1019
sqrt
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1020
    "return the square root value of the receiver
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1021
     reimplemented here for speed"
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1022
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1023
%{  /* NOCONTEXT */
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1024
#ifdef __SCHTEAM__
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1025
    return context._RETURN( self.sqrt());
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1026
#else
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1027
    double val = __intVal(self);
21744
4ffcc8930e88 #BUGFIX by ca
ca
parents: 21743
diff changeset
  1028
    extern double sqrt();
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1029
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1030
    if (val >= 0.0) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1031
	RETURN (__MKFLOAT(sqrt(val)));
21743
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
#endif
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1034
%}.
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1035
    ^ self class
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1036
	raise:#imaginaryResultSignal
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1037
	receiver:self
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1038
	selector:#sqrt
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1039
	arguments:#()
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1040
	errorString:'bad (negative) receiver in sqrt'
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1041
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1042
    "
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1043
	2 sqrt
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1044
	-2 sqrt
21743
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1045
    "
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1046
987bc81dfb42 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21700
diff changeset
  1047
    "Created: / 08-05-2017 / 14:57:07 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1048
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1049
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1050
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1051
!SmallInteger methodsFor:'bit operators'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1052
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1053
bitAnd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1054
    "return the bitwise-and of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1055
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1056
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1057
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1058
    return context._RETURN( self.bitAnd(anInteger));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1059
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1060
    /* anding the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1061
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1062
	RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1064
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1065
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1066
    anInteger class == LargeInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1067
	^ anInteger bitAnd:self
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1068
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1069
    ^ self retry:#bitAnd: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1070
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1071
    "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1072
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1073
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1074
bitClear:anInteger
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1075
    "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
  1076
     returning the receiver with bits of the argument cleared.
19070
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1077
     (i.e. the same as self bitAnd:aMaskInteger bitInvert).
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1078
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1079
     but a new number is returned. Should be named #withBitCleared:"
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1080
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1081
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1082
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1083
    return context._RETURN( self.bitClear(anInteger));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1084
#else
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1085
    /* anding the tags doesn't change it */
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1086
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1087
	RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1088
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1089
#endif /* not __SCHTEAM__ */
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1090
%}.
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1091
    ^ self retry:#bitClear: coercing:anInteger
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
    "
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1094
     (2r001010100 bitClear:2r00001111) radixPrintStringRadix:2
5458
2aa89d4fad64 example
Claus Gittinger <cg@exept.de>
parents: 5447
diff changeset
  1095
     (2r111111111 bitClear:2r00001000) radixPrintStringRadix:2
19070
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1096
9cabcfcb9ada #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19069
diff changeset
  1097
     (2r001010100 bitAnd:2r00001111 bitInvert) radixPrintStringRadix:2
3156
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
!
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
  1100
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1101
bitCount
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1102
    "return the number of 1-bits in the receiver"
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1103
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1104
%{  /* NOCONTEXT */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1105
#ifdef __SCHTEAM__
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1106
    long _v1, _v2;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1107
    long _self = self.longValue();
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1108
    long _cnt;
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1109
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1110
    _v1 = _self & 0xFFFFFFFF;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1111
    _v1 = _v1 - ((_v1 >> 1) & 0x55555555);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1112
    _v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1113
    _v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1114
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  1115
    _v2 = (_self >> 32) & 0xFFFFFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1116
    _v2 = _v2 - ((_v2 >> 1) & 0x55555555);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1117
    _v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1118
    _v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1119
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1120
    _cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24);
18948
cab22236fc65 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18947
diff changeset
  1121
    return __c__._RETURN( STInteger._qnew( (byte)(_cnt) ) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1122
#else
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1123
    unsigned int _cnt;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1124
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1125
    // popcnt is actually slower on some cpus;
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1126
    // and almost equal to ALG3 on modern intel hardware.
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1127
    // So ALGO3 is good for all
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
diff changeset
  1128
# 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
  1129
#  define ALGORITHM_4
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1130
# else
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1131
#  define ALGORITHM_3
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1132
# endif
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  1133
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1134
# if defined( ALGORITHM_1 )
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1135
    // old k&r code; might be better if only one or two bits are set
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1136
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1137
    unsigned INT _self = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1138
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1139
    _cnt = 0;
11666
f30bc3b65e88 tricky bitCount
Claus Gittinger <cg@exept.de>
parents: 11519
diff changeset
  1140
    while (_self) {
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1141
        _cnt++;
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1142
        _self = _self & (_self - 1);
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
  1143
    }
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1144
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1145
# elif defined( ALGORITHM_2 )
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1146
    // seems to be faster on the average (and has better worst case)
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1147
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1148
    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
  1149
    unsigned INT _self = __intVal(self);
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1150
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1151
    _cnt = 0;
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1152
    while (_self) {
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1153
        _cnt += table[ _self & 0x0F ];
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1154
        _self >>= 4;
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1155
    }
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1156
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1157
# elif defined( ALGORITHM_3 )
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1158
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1159
    // 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
  1160
18898
0dc54d84ac92 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18897
diff changeset
  1161
    unsigned INT _self = __intVal(self);
0dc54d84ac92 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18897
diff changeset
  1162
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1163
#  if __POINTER_SIZE__ == 8
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1164
    unsigned int _v1, _v2;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1165
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1166
    _v1 = _self & 0xFFFFFFFF;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1167
    _v1 = _v1 - ((_v1 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1168
    _v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1169
    _v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1170
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1171
    _v2 = (unsigned int)(_self >> 32);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1172
    _v2 = _v2 - ((_v2 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1173
    _v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1174
    _v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1175
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1176
    _cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24);
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1177
#  else // POINTER_SIZE not 8
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1178
    _cnt = _self - ((_self >> 1) & 0x55555555);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1179
    _cnt = (_cnt & 0x33333333) + ((_cnt >> 2) & 0x33333333);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
  1180
    _cnt = ((_cnt + (_cnt >> 4)) & 0x0F0F0F0F);
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
  1181
    _cnt = (_cnt * 0x01010101) >> 24;
22784
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1182
#  endif
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1183
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1184
# elif defined( ALGORITHM_4 )
46a73ec92977 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22304
diff changeset
  1185
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1186
     // using the popcnt instruction (x86 only); strange enough, this is slower than ALGO3
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
        ].
23942
d453cd166c2b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23616
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
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
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:
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1310
	aN ... a2 a1 a0
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1311
	bN ... b2 b1 b0
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1312
	cN ... c2 c1 c0."
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1313
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1314
%{
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1315
#if __POINTER_SIZE__ == 8
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
# define M5555555555555555 0x5555555555555555
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1318
# define M3333333333333333 0x3333333333333333
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1319
# define M0f0f0f0f0f0f0f0f 0x0f0f0f0f0f0f0f0f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1320
# define M00ff00ff00ff00ff 0x00ff00ff00ff00ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1321
# define M0000ffff0000ffff 0x0000ffff0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1322
# define M00000000ffffffff 0x00000000ffffffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1323
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1324
# define M9249249249249249 0x9249249249249249
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1325
# define M30c30c30c30c30c3 0x30c30c30c30c30c3
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1326
# define Mf00f00f00f00f00f 0xf00f00f00f00f00f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1327
# define M00ff0000ff0000ff 0x00ff0000ff0000ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1328
# define Mffff00000000ffff 0xffff00000000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1329
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1330
#else
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1331
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1332
# define M5555555555555555 0x55555555
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1333
# define M3333333333333333 0x33333333
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1334
# define M0f0f0f0f0f0f0f0f 0x0f0f0f0f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1335
# define M00ff00ff00ff00ff 0x00ff00ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1336
# define M0000ffff0000ffff 0x0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1337
# define M00000000ffffffff 0
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1338
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1339
# define M9249249249249249 0x49249249
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1340
# define M30c30c30c30c30c3 0xc30c30c3
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1341
# define Mf00f00f00f00f00f 0x0f00f00f
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1342
# define M00ff0000ff0000ff 0xff0000ff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1343
# define Mffff00000000ffff 0x0000ffff
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1344
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1345
#endif
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1346
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1347
    unsigned INT bits = __intVal(self);
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1348
    unsigned INT a, b;
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1349
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1350
    if (n == __MKSMALLINT(2)) {
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1351
#       define morton2(x,dst) \
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1352
	    { \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1353
		unsigned INT t; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1354
		t = (x) & M5555555555555555; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1355
		t = (t | (t >> 1))  & M3333333333333333; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1356
		t = (t | (t >> 2))  & M0f0f0f0f0f0f0f0f; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1357
		t = (t | (t >> 4))  & M00ff00ff00ff00ff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1358
		t = (t | (t >> 8))  & M0000ffff0000ffff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1359
		t = (t | (t >> 16)) & M00000000ffffffff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1360
		dst = t; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1361
	    }
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1362
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1363
	morton2(bits, a);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1364
	morton2(bits>>1, b);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1365
	RETURN (__ARRAY_WITH2(__MKSMALLINT(a), __MKSMALLINT(b)));
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1366
    }
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1367
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1368
    if (n == __MKSMALLINT(3)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1369
	unsigned INT c;
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1370
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1371
#       define morton3(x,dst) \
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1372
	    { \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1373
		unsigned INT t; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1374
		t = (x) & M9249249249249249; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1375
		t = (t | (t >> 2))  & M30c30c30c30c30c3; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1376
		t = (t | (t >> 4))  & Mf00f00f00f00f00f; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1377
		t = (t | (t >> 8))  & M00ff0000ff0000ff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1378
		t = (t | (t >> 16)) & Mffff00000000ffff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1379
		t = (t | (t >> 32)) & M00000000ffffffff; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1380
		dst = t; \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1381
	    }
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1382
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1383
	morton3(bits, a);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1384
	morton3(bits>>1, b);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1385
	morton3(bits>>2, c);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1386
	RETURN (__ARRAY_WITH3(__MKSMALLINT(a), __MKSMALLINT(b), __MKSMALLINT(c)));
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1387
    }
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1388
done: ;
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1389
%}.
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1390
    ^ super bitDeinterleave:n
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1391
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
     (2r1100 bitInterleaveWith:2r1001) bitDeinterleave:2 -> #(12 9)
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1394
     (197 bitInterleaveWith:144) bitDeinterleave:2 -> #(197 144)
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
     (197 bitInterleaveWith:144 and:62) bitDeinterleave:3 -> #(197 144 62)
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1397
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1398
     |a b|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1399
     (0 to:31) do:[:bitA |
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1400
	 a := 1 << bitA.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1401
	 (0 to:31) do:[:bitB |
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1402
	    b := 1 << bitB.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1403
	    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
  1404
	 ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1405
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1406
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1407
     |a b c|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1408
     (0 to:31) do:[:bitA |
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1409
	 a := 1 << bitA.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1410
	 (0 to:31) do:[:bitB |
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1411
	     b := 1 << bitB.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1412
	     (0 to:31) do:[:bitC |
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1413
		 c := 1 << bitC.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1414
		 self assert:( (a bitInterleaveWith:b and:c) bitDeinterleave:3 ) = {a . b . c}
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1415
	     ].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1416
	 ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1417
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1418
    "
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1419
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1420
    "Created: / 28-08-2017 / 18:32:48 / cg"
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
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1423
bitInterleaveWith:anInteger
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1424
    "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
  1425
     by interleaving bits of the receiver
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1426
     (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
  1427
     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
  1428
	aN ... a2 a1 a0
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1429
     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
  1430
	bN ... b2 b1 b0
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1431
     the result is
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1432
	bN aN ... b2 a2 b1 a1 b0 a0.
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1433
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1434
     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
  1435
     eg. to sort 2D points by distances"
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
%{
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1438
#if __POINTER_SIZE__ == 8
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1439
# define __SLOW_MULTIPLY__
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1440
# ifndef __SLOW_MULTIPLY__
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1441
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1442
    // 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
  1443
    if (__isSmallInteger(anInteger)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1444
	INT _a = __intVal(self);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1445
	INT _b = __intVal(anInteger);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1446
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1447
	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
  1448
	    int shift = 0;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1449
	    unsigned INT val = 0;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1450
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1451
	    // 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
  1452
	    // 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
  1453
	    // resulting in a 16-bit Morton Number.
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1454
#           define interleaveBytes(a,b) \
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1455
		((((a * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL >> 49) & 0x5555) \
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1456
		| (((b * 0x0101010101010101ULL & 0x8040201008040201ULL) * 0x0102040810204081ULL >> 48) & 0xAAAA))
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1457
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1458
	    while (_a | _b) {
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1459
		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
  1460
		_a = _a >> 8;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1461
		_b = _b >> 8;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1462
		shift += 16;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1463
	    }
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1464
	    RETURN (__MKUINT(val) );
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1465
	}
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1466
    }
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1467
# else
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1468
#  if __POINTER_SIZE__ == 8
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1469
#   define HALF_INT_MAX     0xFFFFFFFFFFFFFFFFLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1470
#   define M55555555        0x5555555555555555LL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1471
#   define M33333333        0x3333333333333333LL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1472
#   define M0F0F0F0F        0x0F0F0F0F0F0F0F0FLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1473
#   define M00FF00FF        0x00FF00FF00FF00FFLL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1474
#   define M0000FFFF        0x0000FFFF0000FFFFLL
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1475
#  else
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1476
#   define HALF_INT_MAX     0xFFFFFFFFL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1477
#   define M55555555        0x55555555L
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1478
#   define M33333333        0x33333333L
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1479
#   define M0F0F0F0F        0x0F0F0F0FL
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1480
#   define M00FF00FF        0x00FF00FFL
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1481
#   define M0000FFFF        0
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1482
#  endif
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1483
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1484
    if (__isSmallInteger(anInteger)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1485
	INT _a = __intVal(self);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1486
	INT _b = __intVal(anInteger);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1487
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1488
	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
  1489
	    unsigned INT val;
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
	    // spread the bits (...xxx -> ...0x0x0x)
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1492
	    _a = (_a | (_a << 16)) & M0000FFFF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1493
	    _a = (_a | (_a << 8))  & M00FF00FF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1494
	    _a = (_a | (_a << 4))  & M0F0F0F0F;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1495
	    _a = (_a | (_a << 2))  & M33333333;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1496
	    _a = (_a | (_a << 1))  & M55555555;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1497
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1498
	    _b = (_b | (_b << 16)) & M0000FFFF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1499
	    _b = (_b | (_b << 8))  & M00FF00FF;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1500
	    _b = (_b | (_b << 4))  & M0F0F0F0F;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1501
	    _b = (_b | (_b << 2))  & M33333333;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1502
	    _b = (_b | (_b << 1))  & M55555555;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1503
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1504
	    // 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
  1505
	    val = _a | (_b << 1);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1506
	    RETURN (__MKUINT(val) );
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1507
	}
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1508
    }
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1509
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1510
# endif
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1511
#endif
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1512
%}.
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1513
    ^ super bitInterleaveWith:anInteger
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1514
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
     (2r1100 bitInterleaveWith:2r1001) printStringRadix:2 -> '11 01 00 10'
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1517
     (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
  1518
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1519
     |a b|
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1520
     (0 to:31) do:[:bitA |
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1521
	 a := 1 << bitA.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1522
	 (0 to:31) do:[:bitB |
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1523
	    b := 1 << bitB.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  1524
	    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
  1525
	 ].
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1526
     ].
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1527
22220
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1528
    "
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1529
afff1eb8cb71 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22218
diff changeset
  1530
    "Created: / 28-08-2017 / 14:33:52 / cg"
22221
ffeed1814b34 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22220
diff changeset
  1531
    "Modified (comment): / 28-08-2017 / 19:30:14 / cg"
22220
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
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1534
bitInvert
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1535
    "return the value of the receiver with all bits inverted.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1536
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1537
     but a new number is returned. Could be named #withBitsInverted"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1538
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1539
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1540
#ifdef __SCHTEAM__
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1541
    long _self = self.longValue();
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1542
    return __c__._RETURN( STInteger._new( ~_self ) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1543
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1544
    /* invert anything except tag bits */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1545
    RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1546
#endif /* not __SCHTEAM__ */
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  1547
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1548
    ^ super bitInvert
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1549
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1550
19069
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1551
bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1552
    "return a new integer, where the low 8 bits are masked and complemented.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1553
     This returns an unsigned version of what bitInvert would return.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1554
     (i.e. same as self bitInvert bitAnd:16rFF)"
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1555
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1556
%{  /* NOCONTEXT */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1557
#ifdef __SCHTEAM__
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1558
    long _self = self.longValue();
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1559
    return __c__._RETURN( STInteger._new( ~_self & 0xFF) );
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1560
#else
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1561
    /* invert anything except tag bits */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1562
    RETURN ( (OBJ) (((INT)self ^ ~TAG_MASK) & (INT)(__mkSmallInteger(0xFF))) );
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1563
#endif /* not __SCHTEAM__ */
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1564
%}.
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1565
    ^ super bitInvertByte
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  1566
19069
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1567
    "
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1568
     16r7f bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1569
     16r7f bitInvertByte
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1570
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1571
     16r80 bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1572
     16r80 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
     16rff bitInvert
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1575
     16rff 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
!
0c0fcb9e0760 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19060
diff changeset
  1578
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1579
bitOr:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1580
    "return the bitwise-or of the receiver and the argument, anInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1581
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1582
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1583
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1584
    return context._RETURN( self.bitOr( anInteger ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1585
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1586
    /* oring the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1587
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1588
	RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1589
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1590
#endif /* not __SCHTEAM__ */
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1591
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1592
    ^ self retry:#bitOr: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1593
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1594
    "
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1595
     (2r000000100 bitOr:2r00000011) radixPrintStringRadix:2
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1596
     (0 bitOr:16r20000000) hexPrintString
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1597
     (0 bitOr:16r40000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1598
     (0 bitOr:16r80000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1599
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1600
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1601
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1602
bitReversed
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1603
    "swap (i.e. reverse) bits in an integer
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1604
     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
  1605
     Warning: 
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1606
        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
  1607
        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
  1608
        Better use one of the bitReversedXX methods.
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1609
        This my vanish or be replaced by something better"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1610
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1611
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1612
#ifndef __SCHTEAM__
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1613
    unsigned INT v = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1614
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1615
# if __POINTER_SIZE__ == 8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1616
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1617
    v = ((v >> 1) & 0x5555555555555555) | ((v & 0x5555555555555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1618
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1619
    v = ((v >> 2) & 0x3333333333333333) | ((v & 0x3333333333333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1620
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1621
    v = ((v >> 4) & 0x0F0F0F0F0F0F0F0F) | ((v & 0x0F0F0F0F0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1622
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1623
    v = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1624
    // swap 2-byte pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1625
    v = ((v >> 16) & 0x0000FFFF0000FFFF) | (( v & 0x0000FFFF0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1626
    // swap 4-byte long pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1627
    v = ((v >> 32) & 0x00000000FFFFFFFF) | (( v & 0x00000000FFFFFFFF) << 32);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1628
# else
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1629
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1630
    v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1631
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1632
    v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1633
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1634
    v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1635
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1636
    v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1637
    // swap 2-byte long pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1638
    v = ((v >> 16) & 0x0000FFFF) | ((v & 0x0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1639
# endif
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1640
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1641
    if (v <= _MAX_INT) {
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1642
        RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1643
    }
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1644
    RETURN (__MKUINT(v));
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1645
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1646
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1647
    ^ super bitReversed
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1648
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1649
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1650
     2r1001 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1651
     2r100111010011 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1652
     -1 bitReversed printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1653
    "
23993
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1654
e460b1c11d6a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23991
diff changeset
  1655
    "Modified (comment): / 27-03-2019 / 18:28:47 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1656
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1657
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1658
bitReversed16
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1659
    "swap (i.e. reverse) the low 16 bits in an integer
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1660
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1661
     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
  1662
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1663
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1664
#ifndef __SCHTEAM__
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1665
    unsigned int v = __intVal(self) & 0xFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1666
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1667
    // swap odd and even bits
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1668
    v = ((v >> 1) & 0x5555) | ((v & 0x5555) << 1);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1669
    // swap consecutive pairs
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1670
    v = ((v >> 2) & 0x3333) | ((v & 0x3333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1671
    // swap nibbles ...
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1672
    v = ((v >> 4) & 0x0F0F) | ((v & 0x0F0F) << 4);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1673
    // swap bytes
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1674
    v = ((v >> 8) & 0x00FF) | ((v & 0x00FF) << 8);
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1675
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1676
    RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1677
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1678
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1679
    ^ super bitReversed16
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1680
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1681
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1682
     2r1001 bitReversed16 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1683
     2r100111010011 bitReversed16 printStringRadix:2
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1684
     16r1ABCD bitReversed16 printStringRadix:2
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1685
     -1 bitReversed16 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1686
    "
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1687
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1688
    "Modified: / 24-03-2019 / 11:55:34 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1689
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1690
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1691
bitReversed32
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1692
    "swap (i.e. reverse) the low 32 bits in an integer
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1693
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1694
     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
  1695
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1696
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1697
#ifndef __SCHTEAM__
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1698
    unsigned int v = __intVal(self) & 0xFFFFFFFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1699
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1700
    // swap odd and even bits
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1701
    v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1702
    // swap consecutive pairs
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1703
    v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1704
    // swap nibbles ...
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1705
    v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1706
    // swap bytes
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1707
    v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1708
    // swap 16bit words
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1709
    v = ((v >> 16) & 0x0000FFFF) | ((v & 0x0000FFFF) << 16);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1710
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1711
# if __POINTER_SIZE__ == 8
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1712
    RETURN ( __mkSmallInteger(v) );
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1713
# else
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1714
    if (v <= _MAX_INT) {
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1715
        RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1716
    }
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1717
    RETURN (__MKUINT(v));
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1718
# endif /* not __SCHTEAM__ */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1719
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1720
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1721
    ^ super bitReversed32
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1722
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1723
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1724
     2r1001 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1725
     2r100111010011 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1726
     -1 bitReversed32 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1727
    "
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1728
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1729
    "Modified (format): / 27-03-2019 / 17:54:43 / Claus Gittinger"
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1730
!
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
bitReversed64
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1733
    "swap (i.e. reverse) the low 64 bits in an integer
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1734
     the high bits are ignored and clear in the result
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1735
     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
  1736
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1737
%{  /* NOCONTEXT */
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1738
#ifndef __SCHTEAM__
23996
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1739
    unsigned INT v = __intVal(self);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1740
# if __POINTER_SIZE__ == 8
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1741
    // swap odd and even bits
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1742
    v = ((v >> 1) & 0x5555555555555555ULL) | ((v & 0x5555555555555555ULL) << 1);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1743
    // swap consecutive pairs
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1744
    v = ((v >> 2) & 0x3333333333333333ULL) | ((v & 0x3333333333333333ULL) << 2);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1745
    // swap nibbles ...
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1746
    v = ((v >> 4) & 0x0F0F0F0F0F0F0F0FULL) | ((v & 0x0F0F0F0F0F0F0F0FULL) << 4);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1747
    // swap bytes
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1748
    v = ((v >> 8) & 0x00FF00FF00FF00FFULL) | ((v & 0x00FF00FF00FF00FFULL) << 8);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1749
    // swap 16bit words
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1750
    v = ((v >> 16) & 0x0000FFFF0000FFFFULL) | ((v & 0x0000FFFF0000FFFFULL) << 16);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1751
    // swap 32bit words
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1752
    v = ((v >> 32) & 0x00000000FFFFFFFFULL) | ((v & 0x00000000FFFFFFFFULL) << 32);
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1753
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1754
    if (v <= _MAX_INT) {
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1755
        RETURN ( __mkSmallInteger(v) );
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
    RETURN (__MKUINT(v));
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1758
# else
23996
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1759
    // swap odd and even bits
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1760
    v = ((v >> 1) & 0x55555555UL) | ((v & 0x55555555UL) << 1);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1761
    // swap consecutive pairs
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1762
    v = ((v >> 2) & 0x33333333UL) | ((v & 0x33333333UL) << 2);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1763
    // swap nibbles ...
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1764
    v = ((v >> 4) & 0x0F0F0F0FUL) | ((v & 0x0F0F0F0FUL) << 4);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1765
    // swap bytes
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1766
    v = ((v >> 8) & 0x00FF00FFUL) | ((v & 0x00FF00FFUL) << 8);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1767
    // swap 16bit words
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1768
    v = ((v >> 16) & 0x0000FFFFUL) | ((v & 0x0000FFFFUL) << 16);
0e2c9990b86f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23995
diff changeset
  1769
    // swap 32bit words
24006
5eedbb97db6a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 24004
diff changeset
  1770
    RETURN (__MKLARGEINT64(1, (INT)0, (INT)v));
23990
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1771
# endif
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1772
#endif /* not __SCHTEAM__ */
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1773
%}.
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1774
    ^ super bitReversed64
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1775
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
     2r1001 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1778
     2r100111010011 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1779
     -1 bitReversed64 printStringRadix:2
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1780
    "
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1781
70e4e762b3e2 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23961
diff changeset
  1782
    "Created: / 27-03-2019 / 18:11:11 / Claus Gittinger"
24004
7a3254568d7f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23996
diff changeset
  1783
    "Modified: / 27-03-2019 / 15:25:26 / stefan"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1784
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1785
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1786
bitReversed8
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1787
    "swap (i.e. reverse) the low 8 bits in an integer
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1788
     the high bits are ignored and clear in the result
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1789
     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
  1790
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1791
%{  /* NOCONTEXT */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1792
#ifndef __SCHTEAM__
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1793
    unsigned int v = __intVal(self) & 0xFF;
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1794
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1795
    // swap odd and even bits
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1796
    v = ((v >> 1) & 0x55) | ((v & 0x55) << 1);
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1797
    // swap consecutive pairs
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1798
    v = ((v >> 2) & 0x33) | ((v & 0x33) << 2);
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  1799
    // swap nibbles ...
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1800
    v = ((v >> 4) & 0x0F) | ((v & 0x0F) << 4);
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1801
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1802
    RETURN ( __mkSmallInteger(v) );
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1803
#endif /* not __SCHTEAM__ */
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1804
%}.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1805
    ^ super bitReversed8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1806
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1807
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1808
     2r1001 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1809
     2r10011101 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1810
     2r111110011101 bitReversed8 printStringRadix:2
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1811
     16r1234 bitReversed8 printStringRadix:2
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1812
     -1 bitReversed8 printStringRadix:2
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1813
    "
23961
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1814
7e0c1ebaf951 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23942
diff changeset
  1815
    "Modified: / 24-03-2019 / 11:57:14 / Claus Gittinger"
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1816
!
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  1817
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1818
bitShift:shiftCount
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1819
    "return the value of the receiver shifted by shiftCount bits;
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1820
     leftShift if shiftCount > 0; rightShift otherwise.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1821
     Notice: the result of bitShift: on negative receivers is not
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1822
             defined in the language standard (since the implementation
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1823
             is free to choose any internal representation for integers).
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1824
             However, ST/X preserves the sign;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1825
             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
  1826
             number of bits supported by the platform."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1827
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1828
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1829
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1830
    return context._RETURN( self.bitShift( shiftCount ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1831
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1832
    INT bits, count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1833
252
  1834
    if (__isSmallInteger(shiftCount)) {
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1835
        bits = __intVal(self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1836
        if (bits == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1837
            RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1838
        }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1839
        count = __intVal(shiftCount);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1840
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1841
        if (count > 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1842
            INT sign = 1;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1843
            if (bits < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1844
                bits = -bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1845
                sign = -1;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1846
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1847
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1848
             * a left shift
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1849
             */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1850
# if defined(USE_LONGLONG_FOR_SHIFT)
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1851
            if (count <= N_INT_BITS) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1852
                unsigned LONGLONG result;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1853
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1854
                result = (unsigned LONGLONG)bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1855
                result <<= count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1856
                if (result <= _MAX_INT) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1857
                    if (sign < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1858
                        RETURN ( __MKINT(-result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1859
                    }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1860
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1861
                }
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 (__MKLARGEINT64(sign, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
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
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1866
# else
24245
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
             * check for overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1869
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1870
            if (count < (N_INT_BITS-1)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1871
                if (! (bits >> (N_INT_BITS - 1 - count))) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1872
                    INT result = bits << count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1873
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1874
                    if (sign < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1875
                        RETURN ( __MKINT(-result) );
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
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1878
                }
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
                 * so, there is an overflow ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1881
                 * handle it as largeInteger
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
                /* FALL THROUGH */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1884
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1885
# endif
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1886
        } else {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1887
            if (count == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1888
                RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1889
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1890
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1891
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1892
             * right shifts cannot overflow
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
             * some machines ignore shifts bigger than
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1895
             * the number of bits in an int ...
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
            count = -count;
24406
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1898
            if (count > N_INT_BITS) {
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1899
                RETURN (__mkSmallInteger(bits < 0 ? -1 : 0));
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1900
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1901
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1902
            RETURN ( __mkSmallInteger(bits >> count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1903
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1904
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1905
#endif /* not __SCHTEAM__ */
85
claus
parents: 77
diff changeset
  1906
%}.
claus
parents: 77
diff changeset
  1907
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1908
        ^ (LargeInteger value:self) bitShift:shiftCount
85
claus
parents: 77
diff changeset
  1909
    ].
16448
52a24c07dc59 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16294
diff changeset
  1910
    ^ self bitShift:shiftCount asInteger   "/ is this a good idea ?
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1911
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1912
    "
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1913
       16 bitShift:-1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1914
       16 bitShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1915
       16 bitShift:-63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1916
       
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1917
       -16 bitShift:-1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1918
       -16 bitShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1919
       -16 bitShift:-63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1920
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1921
         4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1922
        -4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1923
        -4 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1924
    "
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1925
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  1926
    "Modified (comment): / 03-06-2019 / 17:49:15 / Claus Gittinger"
24406
588966201b30 #BUGFIX by Stefan Reise
sr
parents: 24288
diff changeset
  1927
    "Modified: / 09-07-2019 / 14:24:07 / Stefan Reise"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1928
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1929
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1930
bitTest:aMask
5782
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1931
    "return true, if any bit from aMask is set in the receiver.
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1932
     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
  1933
     is non-0, false otherwise."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1934
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1935
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1936
#ifdef __SCHTEAM__
18232
Claus Gittinger <cg@exept.de>
parents: 18227
diff changeset
  1937
    return context._RETURN(
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1938
	    ( self.bitAnd( aMask ) == STInteger._0 )
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1939
	    ? STObject.False : STObject.True );
18232
Claus Gittinger <cg@exept.de>
parents: 18227
diff changeset
  1940
    /* NOTREACHED */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1941
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1942
    /* and all bits except tag */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1943
    if (__isSmallInteger(aMask)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1944
	RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1945
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1946
#endif /* not __SCHTEAM__ */
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1947
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1948
    aMask class == LargeInteger ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1949
	^ (aMask bitAnd:self) ~~ 0
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1950
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1951
    ^ self retry:#bitTest: coercing:aMask
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1952
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1953
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1954
     2r10001 bitTest:2r00001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1955
     2r10001 bitTest:2r00010
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1956
     2r10001 bitTest:2r00100
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1957
     2r10001 bitTest:2r01000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1958
     2r10001 bitTest:2r10000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1959
     2r10001 bitTest:2r10001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1960
     2r10001 bitTest:2r10010
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1961
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1962
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1963
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1964
bitXor:anInteger
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1965
    "return the bitwise-exclusive-or of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1966
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1967
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1968
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  1969
    return context._RETURN( self.bitXor( anInteger ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  1970
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1971
    /* xoring the tags turns it off - or it in again */
252
  1972
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  1973
	RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1974
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1975
#endif /* not __SCHTEAM__ */
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1976
%}.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1977
    ^ self retry:#bitXor: coercing:anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1978
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1979
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1980
highBit
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  1981
    "return the bitIndex of the highest bit set.
19601
bcce77592dae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19486
diff changeset
  1982
     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
  1983
     Returns 0 if no bit is set.
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1984
     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
  1985
     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
  1986
     But because we use a sign-magnitude representation for large integers, 
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  1987
     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
  1988
     range, in contrast to the highbit of the negative number if within the SmallInt range."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1989
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1990
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  1991
#ifdef __SCHTEAM__
18234
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  1992
    {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1993
        long bits = self.longValue();
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1994
        int bitNr = 0;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1995
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1996
        if (bits != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1997
            if ((bits & 0xFFFFFFFF00000000L) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1998
                bitNr += 32; bits >>= 32;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  1999
            }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2000
            if ((bits & 0xFFFF0000L) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2001
                bitNr += 16; bits >>= 16;
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 & 0xFF00) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2004
                bitNr += 8; bits >>= 8;
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 & 0xF0) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2007
                bitNr += 4; bits >>= 4;
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 & 0xC) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2010
                bitNr += 2; bits >>= 2;
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 & 0x2) != 0) {
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2013
                bitNr += 1; bits >>= 1;
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
            bitNr += 1;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2016
        }
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2017
        return context._RETURN( STInteger._new(bitNr) );
18234
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  2018
    }
34f00359de08 experimental java support
Claus Gittinger <cg@exept.de>
parents: 18232
diff changeset
  2019
    /* NOTREACHED */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2020
#else
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2021
    unsigned INT bits;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2022
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2023
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2024
# ifdef __BSR
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2025
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2026
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2027
     * 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
  2028
     * (but saves a few code-bytes, though)
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2029
     */
21984
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2030
    index = __BSR((INT)self);
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2031
    RETURN ( __mkSmallInteger(index) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2032
# else
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  2033
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2034
    /*
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2035
     * this uses the FPU, which counts the bits during the normalization
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2036
     * and leaves the high bitnumber in the exponent...
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2037
     * Notice: due to rounding mode details,
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2038
     * 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
  2039
     * 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
  2040
     */
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2041
#  if (POINTER_SIZE == 4) && defined( USE_IEE_FLOAT_BITS )
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2042
    union {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2043
        double ff;
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2044
        int ll[2];
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2045
    } uu;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2046
    int bNr;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2047
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2048
    uu.ff=(double)((INT)(self));
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2049
    bNr = (uu.ll[1]>>20)-1023;
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2050
    return __mkSmallInteger(bNr);  // assumes x86 endianness
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2051
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2052
#  else
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2053
    /*
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2054
     * general fallback; not super-fast,
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2055
     * 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
  2056
     * Notice, the code runs completely in registers,
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2057
     * 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
  2058
     */
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  2059
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2060
    index = 0;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2061
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2062
    bits = __intVal(self);
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2063
    if (bits == 0) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2064
        RETURN ( __mkSmallInteger(0) );
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2065
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2066
#  if __POINTER_SIZE__ == 8
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2067
    if (bits & 0xFFFFFFFF00000000L) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2068
        index += 32; bits >>= 32;
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2069
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2070
#  endif
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2071
    if (bits & 0xFFFF0000L) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2072
        index += 16; bits >>= 16;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2073
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2074
    if (bits & 0xFF00) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2075
        index += 8; bits >>= 8;
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 & 0xF0) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2078
        index += 4; bits >>= 4;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2079
    }
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2080
    if (bits & 0xC) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2081
        index += 2; bits >>= 2;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2082
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2083
    if (bits & 0x2) {
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2084
        index += 1; bits >>= 1;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2085
    }
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2086
#  endif /* not IEE float */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2087
# endif /* no BSR instruction */
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2088
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2089
    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
  2090
#endif /* not __SCHTEAM__ */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2091
%}.
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2092
    ^ super highBit
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2093
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2094
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2095
     2r0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2096
     2r1 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2097
     2r10 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2098
     2r100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2099
     2r1000 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2100
     2r100000000000 highBit
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  2101
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2102
     ((0 to:64) collect:[:s | 1 bitShift:s])
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2103
        collect:[:n | n highBit]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2104
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]) = (1 to:65)
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2107
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2108
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2109
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2110
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2111
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2112
            2r1 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2113
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2114
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2115
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2116
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2117
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2118
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2119
            2r1111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2120
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2121
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2122
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2123
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2124
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2125
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2126
            2r11111111111111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2127
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2128
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2129
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2130
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2131
     Time millisecondsToRun:[
24168
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2132
        1000000 timesRepeat:[
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2133
            2r11111111111111111111111111 highBit
7b016046fdb9 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24100
diff changeset
  2134
        ]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2135
     ]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2136
    "
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2137
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2138
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2139
     2r000100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2140
     2r010100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2141
     2r000001 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2142
     0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2143
     SmallInteger maxVal highBit
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  2144
    "
21983
27b59dd4c7fa #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21966
diff changeset
  2145
21984
f0c07acc75df #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 21983
diff changeset
  2146
    "Modified: / 05-07-2017 / 16:56:08 / cg"
24288
6ea528fc3cb4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24245
diff changeset
  2147
    "Modified (comment): / 08-06-2019 / 02:07:54 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2148
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2149
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2150
lowBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2151
    "return the bitIndex of the lowest bit set. The returned bitIndex
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2152
     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
  2153
     Returns 0 if no bit is set."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2154
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2155
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2156
#ifdef __SCHTEAM__
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2157
    long bits = self.longValue();
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2158
    int index = 0;
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2159
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2160
    if (bits != 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2161
	if ((bits & 0xFFFFFFFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2162
	    index += 32; bits >>= 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2163
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2164
	if ((bits & 0xFFFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2165
	    index += 16; bits >>= 16;
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 & 0xFFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2168
	    index += 8; bits >>= 8;
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 & 0xFL)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2171
	    index += 4; bits >>= 4;
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 & 0x3L)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2174
	    index += 2; bits >>= 2;
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 & 0x1L)==0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2177
	    index += 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2178
	}
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2179
    }
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2180
    return __c__._RETURN( STInteger._qnew( index ) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2181
#else
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2182
    unsigned INT bits;
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2183
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2184
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2185
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2186
    if (bits == 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2187
	RETURN ( __mkSmallInteger(0) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2188
    }
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  2189
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2190
# ifdef __BSF
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2191
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2192
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2193
     * 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
  2194
     * (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
  2195
     * but saves a few code-bytes, though.
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2196
     */
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  2197
    index = __BSF(bits);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2198
    RETURN ( __mkSmallInteger(index + 1) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2199
# else
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2200
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2201
    index = 1;
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  2202
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2203
#  if __POINTER_SIZE__ == 8
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2204
    if ((bits<<32) == 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2205
	index += 32; bits >>= 32;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2206
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2207
#  endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2208
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2209
    if ((bits & 0xFFFF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2210
	index += 16; bits >>= 16;
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 & 0xFF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2213
	index += 8; bits >>= 8;
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 & 0xF)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2216
	index += 4; bits >>= 4;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2217
    }
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2218
    if ((bits & 0x3)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2219
	index += 2; bits >>= 2;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2220
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2221
    if ((bits & 0x1)==0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2222
	index += 1;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2223
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2224
# endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2225
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2226
    RETURN ( __mkSmallInteger(index) );
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2227
#endif /* not __SCHTEAM__ */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2228
%}.
18370
0ffb12e5f1b4 comments only
Claus Gittinger <cg@exept.de>
parents: 18289
diff changeset
  2229
    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
  2230
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2231
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2232
     0 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2233
     2r0001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2234
     2r0010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2235
     2r0100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2236
     2r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2237
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2238
     2r000100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2239
     2r010010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2240
     2r100001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2241
     16r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2242
     16r1000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2243
     16r1000000000000000 lowBit
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2244
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2245
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2246
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2247
	    2r1000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2248
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2249
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2250
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2251
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2252
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2253
	    2r11110000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2254
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2255
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2256
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2257
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2258
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2259
	    2r1000000000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2260
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2261
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  2262
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2263
     Time millisecondsToRun:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2264
	1000000 timesRepeat:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2265
	    2r1000000000000000000000000000 lowBit
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2266
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2267
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  2268
    "
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2269
!
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2270
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2271
rightShift:shiftCount
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2272
    "return the value of the receiver shifted by shiftCount bits;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2273
     right shift if shiftCount > 0; left shift  otherwise.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2274
     Notice: the result of bitShift: on negative receivers is not
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2275
             defined in the language standard (since the implementation
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2276
             is free to choose any internal representation for integers).
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2277
             However, ST/X preserves the sign,
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2278
             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
  2279
             number of bits supported by the platform."
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2280
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2281
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2282
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2283
#else
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2284
    INT bits, count;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2285
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2286
    if (__isSmallInteger(shiftCount)) {
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2287
        bits = __intVal(self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2288
        if (bits == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2289
            RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2290
        }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2291
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2292
        count = __intVal(shiftCount);
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
        if (count < 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2295
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2296
             * a left shift
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2297
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2298
            count = -count;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2299
# if defined(USE_LONGLONG_FOR_SHIFT)
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2300
            if (count <= N_INT_BITS) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2301
                unsigned LONGLONG result;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2302
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2303
                result = (unsigned LONGLONG)bits;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2304
                result <<= count;
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2305
                if (result <= _MAX_INT) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2306
                    RETURN ( __mkSmallInteger(result) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2307
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2308
                {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2309
                    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
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
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2312
# else
24245
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
             * check for overflow
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2315
             */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2316
            if (count < (N_INT_BITS-1)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2317
                if (! (bits >> (N_INT_BITS - 1 - count))) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2318
                    RETURN ( __mkSmallInteger(bits << count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2319
                }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2320
                /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2321
                 * so, there is an overflow ...
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2322
                 * handle it as largeInteger
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
                /* FALL THROUGH */
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2325
            }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2326
# endif
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2327
        } else {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2328
            if (count == 0) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2329
                RETURN (self);
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2330
            }
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2331
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2332
            /*
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2333
             * right shifts cannot overflow
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
             * some machines ignore shifts bigger than
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2336
             * the number of bits in an int ...
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
            if (count >= (__POINTER_SIZE__*8)) {
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2339
                RETURN (__mkSmallInteger(0));
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
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2342
            RETURN ( __mkSmallInteger(bits >> count) );
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2343
        }
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2344
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2345
#endif /* not __SCHTEAM__ */
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2346
%}.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2347
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2348
        ^ (LargeInteger value:self) rightShift:shiftCount
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2349
    ].
16448
52a24c07dc59 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16294
diff changeset
  2350
    ^ self rightShift:shiftCount asInteger   "/ is this a good idea ?
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2351
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2352
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2353
    "
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2354
        16 rightShift:1
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2355
        16 rightShift:2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2356
        16 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2357
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2358
       -16 rightShift:1
22211
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2359
       -16 rightShift:2
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2360
       -16 rightShift:63
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2361
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2362
        1 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2363
       -1 rightShift:-2
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
         4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2366
        -4 rightShift:-2
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2367
        -4 rightShift:63
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2368
    "
22211
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2369
8fb52fc26e1a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21984
diff changeset
  2370
    "Modified: / 25-08-2017 / 12:30:42 / cg"
24245
987981c3e50d #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24193
diff changeset
  2371
    "Modified (comment): / 03-06-2019 / 17:50:22 / Claus Gittinger"
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2372
! !
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2373
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2374
!SmallInteger methodsFor:'bit operators - indexed'!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2375
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2376
bitAt:anIntegerIndex
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2377
    "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
  2378
     Notice: the result of bitAt: on negative receivers is not
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2379
	     defined in the language standard (since the implementation
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2380
	     is free to choose any internal representation for integers)"
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2381
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2382
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2383
#ifdef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2384
    return context._RETURN( self.bitAt(anIntegerIndex));
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2385
#else
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2386
    if (__isSmallInteger(anIntegerIndex)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2387
	INT idx = __smallIntegerVal(anIntegerIndex);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2388
	if (idx > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2389
	    if (idx > N_INT_BITS) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2390
		RETURN(__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2391
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2392
	    RETURN((__smallIntegerVal(self) & ((INT)1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2393
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2394
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2395
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2396
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2397
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2398
    ^ SubscriptOutOfBoundsError
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2399
	    raiseRequestWith:anIntegerIndex
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2400
	    errorString:'index out of bounds'
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2401
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2402
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2403
     16r000000001 bitAt:0 -> error
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2404
     16r000000001 bitAt:1
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2405
     16r000000001 bitAt:2
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2406
     16r000008000 bitAt:16
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2407
     16r000800000 bitAt:24
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2408
     16r008000000 bitAt:28
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2409
     16r010000000 bitAt:29
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2410
     16r020000000 bitAt:30
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2411
     16r040000000 bitAt:31
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2412
     16r080000000 bitAt:32
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2413
     16r100000000 bitAt:33
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2414
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2415
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2416
" Smalltalk implementation:
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2417
    |mask|
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2418
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2419
    anIntegerIndex <= 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2420
	^ SubscriptOutOfBoundsSignal
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2421
		raiseRequestWith:anIntegerIndex
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2422
		errorString:'index out of bounds'
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2423
    ].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2424
    (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2425
    mask := 1 bitShift:(anIntegerIndex - 1).
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2426
    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2427
    ^ 1
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2428
"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2429
!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2430
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2431
clearBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2432
    "return a new integer where the specified bit is off.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2433
     Bits are counted from 1 starting with the least significant.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2434
     The method's name may be misleading: the receiver is not changed,
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2435
     but a new number is returned. Should be named #withBitCleared:"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2436
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2437
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2438
#ifndef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2439
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2440
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2441
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2442
	if (index > 0) {
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2443
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2444
	    if (index <= 62)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2445
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2446
	    if (index <= 30)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2447
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2448
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2449
		INT mask = __MASKSMALLINT( ((INT)1 << (index-1)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2450
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2451
		RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2452
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2453
	    RETURN (self);  /* nothing to do ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2454
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2455
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2456
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2457
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2458
    ^ super clearBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2459
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2460
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2461
     (16r401 clearBit:1     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2462
     (16r401 clearBit:0     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2463
     (16r3fffffff clearBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2464
     (16r3fffffff clearBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2465
     (16r3fffffff clearBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2466
     (16r3fffffff clearBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2467
     (16r3fffffff bitAt:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2468
     (16r3fffffff bitAt:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2469
     (16r3fffffff bitAt:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2470
     (16r40000001 clearBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2471
     (16rF0000001 clearBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2472
     (16rF0000001 clearBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2473
     (16rF0000001 clearBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2474
     (16rF0000001 clearBit:32) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2475
     (16r1F0000001 clearBit:33) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2476
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2477
!
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2478
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2479
invertBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2480
    "return a new number where the specified bit is inverted.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2481
     Bits are counted from 1 starting with the least significant.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2482
     The method's name may be misleading: the receiver is not changed,
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2483
     but a new number is returned. Should be named #withBitInverted:"
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2484
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2485
%{  /* NOCONTEXT */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2486
#ifndef __SCHTEAM__
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2487
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2488
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2489
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2490
	if (index > 0) {
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2491
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2492
	    if (index <= 62)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2493
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2494
	    if (index <= 30)
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2495
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2496
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2497
		INT mask = __MASKSMALLINT((INT)1 << (index-1));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2498
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2499
		RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2500
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2501
	}
19051
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2502
    }
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2503
#endif /* not __SCHTEAM__ */
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2504
%}.
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2505
    ^ super invertBit:anInteger
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2506
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2507
    "
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2508
     (16r401 invertBit:2     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2509
     (16r401 invertBit:1     ) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2510
     (16r30000000 invertBit:1) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2511
     (16r40000000 invertBit:0) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2512
     (16r0 invertBit:29) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2513
     (16r0 invertBit:30) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2514
     (16r0 invertBit:31) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2515
     (16r0 invertBit:32) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2516
     (16r0 invertBit:33) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2517
     (16r0 invertBit:100) hexPrintString
29a3a26970e8 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19050
diff changeset
  2518
    "
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2519
!
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  2520
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2521
setBit:anInteger
8937
4f2508548327 comment
Claus Gittinger <cg@exept.de>
parents: 8919
diff changeset
  2522
    "return a new integer where the specified bit is on.
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2523
     Bits are counted from 1 starting with the least significant.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2524
     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
  2525
     but a new number is returned. Should be named #withBitSet:"
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2526
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2527
%{  /* NOCONTEXT */
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2528
#ifndef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2529
    if (__isSmallInteger(anInteger)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2530
	int index = __intVal(anInteger);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2531
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2532
	if (index > 0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2533
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2534
	    if (index <= 62)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2535
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2536
	    if (index <= 30)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2537
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2538
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2539
		INT mask = __MASKSMALLINT((INT)1 << (index-1));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2540
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2541
		RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2542
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2543
	}
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2544
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2545
#endif /* not __SCHTEAM__ */
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2546
%}.
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  2547
    ^ super setBit:anInteger
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2548
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2549
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2550
     (16r401 setBit:2     ) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2551
     (16r30000000 setBit:1) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2552
     (16r40000000 setBit:0) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2553
     (16r0 setBit:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2554
     (16r0 setBit:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2555
     (16r0 setBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2556
     (16r0 setBit:32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2557
     (16r0 setBit:33) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2558
     (16r0 setBit:100) hexPrintString
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  2559
    "
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  2560
! !
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  2561
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2562
!SmallInteger methodsFor:'byte access'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2563
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2564
byteSwapped
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2565
    "lsb -> msb;
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2566
     i.e. a.b.c.d -> d.c.b.a"
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2567
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2568
    SmallInteger maxBytes == 8 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2569
	^ self byteSwapped64
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2570
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2571
	^ self byteSwapped32
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2572
    ].
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2573
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2574
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2575
     16r11223344 byteSwapped hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2576
     16r44332211 byteSwapped hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2577
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2578
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2579
    "Created: / 09-01-2012 / 23:01:33 / cg"
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
byteSwapped16
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2583
    "for 16bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2584
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2585
     i.e. a.b -> b.a"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2586
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2587
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2588
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2589
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2590
    unsigned INT swapped;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2591
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2592
    swapped = ((v>>8)&0xFF) | ((v & 0xFF)<<8);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2593
    RETURN (__mkSmallInteger(swapped));
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2594
#endif /* not __SCHTEAM__ */
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2595
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2596
    ^ super byteSwapped16
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2597
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
     16r1122 byteSwapped16 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2600
     16r2211 byteSwapped16 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2601
     16r332211 byteSwapped16 hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2602
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2603
!
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2604
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2605
byteSwapped32
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2606
    "for 32bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2607
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2608
     i.e. a.b.c.d -> d.c.b.a"
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2609
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2610
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2611
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2612
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2613
    unsigned INT swapped;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2614
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2615
# undef HAVE_BSWAP
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2616
# if __POINTER_SIZE__ == 4
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2617
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2618
#  if defined(USE_BSWAP) && defined(__BORLANDC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2619
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2620
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2621
    _asm {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2622
	mov eax, v
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2623
	bswap eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2624
	mov swapped, eax
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2625
    };
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2626
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2627
#  if defined(USE_BSWAP) && defined(__VISUALC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2628
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2629
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2630
    _asm {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2631
	mov eax, v
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2632
	xchg al, ah
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2633
	rol eax, 16
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2634
	xchg al, ah
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2635
	mov swapped, eax
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2636
    };
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2637
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2638
#  if defined(USE_BSWAP) && defined(__GNUC__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2639
#   define HAVE_BSWAP
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2640
16537
d05618865bab class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16521
diff changeset
  2641
    asm("movl %1, %%eax \n\
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2642
	 bswap %%eax    \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2643
	 movl %%eax, %0 \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2644
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2645
	: "=rm"  (swapped)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2646
	: "rm"   (v));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2647
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2648
# endif /* __POINTER_SIZE__ == 4 */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2649
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2650
# if __POINTER_SIZE__ == 8
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2651
    v &= 0xFFFFFFFF;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2652
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  2653
#  if defined(__x86_64__) && defined(__GNUC__) && !defined(__CLANG__)
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2654
#   define HAVE_BSWAP
19133
Claus Gittinger <cg@exept.de>
parents: 19070
diff changeset
  2655
16537
d05618865bab class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16521
diff changeset
  2656
    asm("movq %1, %%rax \n\
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2657
	 bswap %%eax    \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2658
	 movq %%rax, %0 \n\
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2659
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2660
	: "=rm"  (swapped)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2661
	: "rm"   (v));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2662
#  endif
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2663
# endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2664
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2665
# ifndef HAVE_BSWAP
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2666
    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
  2667
# endif
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2668
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2669
    RETURN (__MKUINT(swapped));
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2670
#endif /* not __SCHTEAM__ */
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2671
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2672
    ^ super byteSwapped32
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2673
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
     16r11223344 byteSwapped32 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2676
     16r44332211 byteSwapped32 hexPrintString
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2677
    "
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2678
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2679
    "Created: / 09-01-2012 / 23:01:33 / cg"
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
byteSwapped64
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2683
    "for 64bit values only:
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2684
     lsb -> msb;
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2685
     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
  2686
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2687
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2688
#ifndef __SCHTEAM__
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2689
    unsigned INT v = __intVal(self);
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2690
    unsigned INT swapped;
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2691
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2692
# if __POINTER_SIZE__ == 4
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2693
    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2694
    //            xxxxxxxx                                        xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2695
    //                     xxxxxxxx                      xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2696
    //                              xxxxxxxx    xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2697
    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
  2698
    RETURN(__MKLARGEINT64(1, 0, swapped));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2699
# else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2700
    //   xxxxxxxx 00000000 00000000 00000000 -> 00000000 00000000 00000000 xxxxxxxx
15910
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2701
    //            xxxxxxxx                                        xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2702
    //                     xxxxxxxx                      xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2703
    //                              xxxxxxxx    xxxxxxxx
33ea5acc0934 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15600
diff changeset
  2704
    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
  2705
		| ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2706
		| ((v & 0xFF)<<56);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2707
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2708
    RETURN(__MKUINT( swapped ));
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  2709
#endif /* not __SCHTEAM__ */
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2710
%}.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2711
    ^ super byteSwapped64
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2712
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
     16r11223344 byteSwapped64 hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2715
     16r44332211 byteSwapped64 hexPrintString
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2716
    "
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2717
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  2718
    "Created: / 09-01-2012 / 23:01:33 / cg"
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2721
digitAt:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2722
    "return 8 bits of value, starting at byte index"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2723
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2724
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2725
#ifdef __SCHTEAM__
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2726
    int idx0Based = index.intValue() - 1;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2727
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2728
    if (idx0Based <= 7) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2729
	long myVal = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2730
	if (myVal < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2731
	    myVal = -myVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2732
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2733
	int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2734
	return __c__._RETURN( STInteger._qnew(byteVal) );
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2735
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2736
    if (idx0Based > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2737
	return __c__._RETURN( STInteger._0 );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2738
    }
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2739
#else
357
claus
parents: 329
diff changeset
  2740
    REGISTER INT val;
claus
parents: 329
diff changeset
  2741
    INT idx;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2742
252
  2743
    if (__isSmallInteger(index)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2744
	val = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2745
	if (val < 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2746
	    val = -val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2747
	switch (idx = __intVal(index)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2748
	    case 1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2749
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2750
	    case 2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2751
		val = (val >> 8);
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 3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2754
		val = (val >> 16);
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 4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2757
		val = (val >> 24);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2758
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2759
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2760
	    case 5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2761
		val = (val >> 32);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2762
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2763
	    case 6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2764
		val = (val >> 40);
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 7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2767
		val = (val >> 48);
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 8:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2770
		val = (val >> 56);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2771
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2772
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2773
	    default:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2774
		if (idx < 1)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2775
		    goto bad;   /* sorry */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2776
		RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2777
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2778
	RETURN ( __mkSmallInteger( val & 0xFF) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2779
    }
357
claus
parents: 329
diff changeset
  2780
  bad: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2781
#endif /* not __SCHTEAM__ */
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2782
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2783
    index > 0 ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2784
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2785
	 index less than 1 - not allowed
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2786
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2787
	^ self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2788
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2789
    ^ 0
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  2790
357
claus
parents: 329
diff changeset
  2791
    "
claus
parents: 329
diff changeset
  2792
     (16r12345678 digitAt:1) printStringRadix:16
claus
parents: 329
diff changeset
  2793
     (16r12345678 digitAt:3) printStringRadix:16
claus
parents: 329
diff changeset
  2794
     (16r12345678 digitAt:15) printStringRadix:16
claus
parents: 329
diff changeset
  2795
     (16r12345678 digitAt:0) printStringRadix:16
claus
parents: 329
diff changeset
  2796
     (16r12345678 digitAt:-10) printStringRadix:16
claus
parents: 329
diff changeset
  2797
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2798
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2799
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2800
digitByteAt:index
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2801
    "return 8 bits of my signed value, starting at byte index.
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2802
     For positive receivers, this is the same as #digitAt:;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2803
     for negative ones, the actual bit representation is returned."
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2804
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2805
%{  /* NOCONTEXT */
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2806
#ifdef __SCHTEAM__
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2807
    int idx0Based = index.intValue() - 1;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2808
    long myVal = self.longValue();
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2809
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2810
    if (idx0Based <= 7) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2811
	int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2812
	return __c__._RETURN( STInteger._qnew(byteVal) );
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2813
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2814
    if (idx0Based > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2815
	if (myVal < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2816
	    return __c__._RETURN( STInteger._M1 );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2817
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2818
	    return __c__._RETURN( STInteger._0 );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2819
	}
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2820
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2821
#else
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2822
    REGISTER INT val;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2823
    INT idx;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2824
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2825
    if (__isSmallInteger(index)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2826
	val = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2827
	switch (idx = __intVal(index)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2828
	    case 1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2829
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2830
	    case 2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2831
		val = (val >> 8);
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 3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2834
		val = (val >> 16);
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 4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2837
		val = (val >> 24);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2838
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2839
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2840
	    case 5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2841
		val = (val >> 32);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2842
		break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2843
	    case 6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2844
		val = (val >> 40);
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 7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2847
		val = (val >> 48);
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 8:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2850
		val = (val >> 56);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2851
		break;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  2852
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2853
	    default:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2854
		if (idx < 1)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2855
		    goto bad;   /* sorry */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2856
		if (val < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2857
		    RETURN (__mkSmallInteger(0xFF));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2858
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2859
		RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2860
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2861
	RETURN ( __mkSmallInteger( val & 0xFF) );
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2862
    }
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2863
  bad: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  2864
#endif /* not __SCHTEAM__ */
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
    index > 0 ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2867
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2868
	 index less than 1 - not allowed
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2869
	"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2870
	^ self primitiveFailed
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2871
    ].
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2872
    ^ 0
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2873
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2874
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2875
     (10 digitByteAt:1) printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2876
     (10 digitByteAt:3) printStringRadix:16
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2877
     (-10 digitByteAt:1) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2878
     (-10 digitByteAt:3) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2879
    "
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2880
!
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  2881
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2882
digitBytes
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2883
    "return a byteArray filled with the receiver's bits
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2884
     (8 bits of the absolute value per element),
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2885
     least significant byte is first"
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2886
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2887
    |absValue
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2888
     b1 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2889
     b2 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2890
     b3 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2891
     b4 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2892
     b5 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2893
     b6 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2894
     b7 "{ Class: SmallInteger }" digitByteArray|
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2895
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2896
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2897
     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
  2898
     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
  2899
     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
  2900
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2901
    self == 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2902
	^ ByteArray with:0.
10487
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
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2905
    self < 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2906
	absValue := self negated
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2907
    ] ifFalse: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2908
	absValue := self.
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2909
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2910
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2911
    b1 := absValue bitAnd:16rFF.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2912
    absValue := absValue bitShift:-8.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2913
    absValue == 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2914
	digitByteArray := ByteArray with:b1
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2915
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2916
	b2 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2917
	absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2918
	absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2919
	    digitByteArray := ByteArray with:b1 with:b2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2920
	] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2921
	    b3 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2922
	    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2923
	    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2924
		digitByteArray := ByteArray with:b1 with:b2 with:b3
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2925
	    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2926
		b4 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2927
		absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2928
		absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2929
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2930
		] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2931
		    b5 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2932
		    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2933
		    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2934
			digitByteArray := ByteArray new:5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2935
			digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2936
			digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2937
			digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2938
			digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2939
			digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2940
		    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2941
			b6 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2942
			absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2943
			absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2944
			    digitByteArray := ByteArray new:6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2945
			    digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2946
			    digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2947
			    digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2948
			    digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2949
			    digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2950
			    digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2951
			] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2952
			    b7 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2953
			    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2954
			    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2955
				digitByteArray := ByteArray new:7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2956
				digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2957
				digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2958
				digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2959
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2960
				digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2961
				digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2962
				digitByteArray at:7 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2963
			    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2964
				digitByteArray := ByteArray new:8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2965
				digitByteArray at:1 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2966
				digitByteArray at:2 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2967
				digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2968
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2969
				digitByteArray at:5 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2970
				digitByteArray at:6 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2971
				digitByteArray at:7 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2972
				digitByteArray at:8 put:absValue.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2973
			    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2974
			]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  2975
		    ]
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
	]
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2979
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2980
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2981
    ^ digitByteArray
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2982
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2983
    "
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2984
      16r12 digitBytes hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2985
      16r1234 digitBytes hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2986
      16r12345678 digitBytes hexPrintString
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2987
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2988
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2989
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2990
digitBytesMSB
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  2991
    "return a byteArray filled with the receiver's bits
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2992
     (8 bits of the absolute value per element),
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2993
     most significant byte is first"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2994
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2995
    |absValue
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2996
     b1 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2997
     b2 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2998
     b3 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  2999
     b4 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3000
     b5 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3001
     b6 "{ Class: SmallInteger }"
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3002
     b7 "{ Class: SmallInteger }" digitByteArray|
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3003
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3004
    "
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3005
     could have simply created a 4-byte largeinteger and normalize it.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3006
     The code below does the normalize right away, avoiding the
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3007
     overhead of producing any intermediate byte-arrays (and the scanning)
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3008
    "
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3009
    self == 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3010
	^ ByteArray with:0.
15568
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
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3013
    self < 0 ifTrue: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3014
	absValue := self negated
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3015
    ] ifFalse: [
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3016
	absValue := self.
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3017
    ].
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3018
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3019
    b1 := absValue bitAnd:16rFF.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3020
    absValue := absValue bitShift:-8.
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3021
    absValue == 0 ifTrue:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3022
	digitByteArray := ByteArray with:b1
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3023
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3024
	b2 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3025
	absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3026
	absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3027
	    digitByteArray := ByteArray with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3028
	] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3029
	    b3 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3030
	    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3031
	    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3032
		digitByteArray := ByteArray with:b3 with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3033
	    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3034
		b4 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3035
		absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3036
		absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3037
		    digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3038
		] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3039
		    b5 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3040
		    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3041
		    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3042
			digitByteArray := ByteArray new:5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3043
			digitByteArray at:1 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3044
			digitByteArray at:2 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3045
			digitByteArray at:3 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3046
			digitByteArray at:4 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3047
			digitByteArray at:5 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3048
		    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3049
			b6 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3050
			absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3051
			absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3052
			    digitByteArray := ByteArray new:6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3053
			    digitByteArray at:1 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3054
			    digitByteArray at:2 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3055
			    digitByteArray at:3 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3056
			    digitByteArray at:4 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3057
			    digitByteArray at:5 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3058
			    digitByteArray at:6 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3059
			] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3060
			    b7 := absValue bitAnd:16rFF.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3061
			    absValue := absValue bitShift:-8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3062
			    absValue == 0 ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3063
				digitByteArray := ByteArray new:7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3064
				digitByteArray at:1 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3065
				digitByteArray at:2 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3066
				digitByteArray at:3 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3067
				digitByteArray at:4 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3068
				digitByteArray at:5 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3069
				digitByteArray at:6 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3070
				digitByteArray at:7 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3071
			    ] ifFalse:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3072
				digitByteArray := ByteArray new:8.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3073
				digitByteArray at:1 put:absValue.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3074
				digitByteArray at:2 put:b7.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3075
				digitByteArray at:3 put:b6.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3076
				digitByteArray at:4 put:b5.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3077
				digitByteArray at:5 put:b4.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3078
				digitByteArray at:6 put:b3.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3079
				digitByteArray at:7 put:b2.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3080
				digitByteArray at:8 put:b1.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3081
			    ]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3082
			]
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3083
		    ]
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
	]
15568
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3087
    ].
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3088
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3089
    ^ digitByteArray
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
      16r12 digitBytesMSB hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3093
      16r1234 digitBytesMSB hexPrintString
e6ce93f948be new: #digitBytesMSB
Stefan Vogel <sv@exept.de>
parents: 15560
diff changeset
  3094
      16r12345678 digitBytesMSB hexPrintString
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3095
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3096
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  3097
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3098
digitLength
19321
1948c58602d0 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19318
diff changeset
  3099
    "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
  3100
     For negative receivers, the result is not defined by the language standard.
1948c58602d0 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19318
diff changeset
  3101
     ST/X returns the digitLength of its absolute value."
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3102
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3103
%{  /* NOCONTEXT */
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3104
#ifdef __SCHTEAM__
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3105
    long val = self.longValue();
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3106
    int offs = 0;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3107
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3108
    if (val < 0) val = -val;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3109
    if ((val & 0xFFFFFFFF00000000L) != 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3110
        val >>= 32;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3111
        offs = 4;
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3112
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3113
    if ((val & 0xFFFF0000) != 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3114
        if ((val & 0xFF000000) != 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3115
            offs += 4;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3116
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3117
            offs += 3;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3118
        }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3119
    } else {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3120
        if ((val & 0x0000FF00)!= 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3121
            offs += 2;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3122
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3123
            offs += 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3124
        }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3125
    }
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3126
    return __c__._RETURN( STInteger._qnew(offs) );
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3127
#else
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3128
    INT val = __intVal(self);
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3129
    int offs = 0;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3130
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3131
    if (val < 0) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3132
        val = -val;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3133
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3134
# if __POINTER_SIZE__ == 8
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3135
    if (val & 0xFFFFFFFF00000000L) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3136
        val >>= 32;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3137
        offs = 4;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3138
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3139
# endif
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3140
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3141
    if (val & 0xFFFF0000) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3142
        if (val & 0xFF000000) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3143
            RETURN ( __mkSmallInteger(4+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3144
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3145
            RETURN ( __mkSmallInteger(3+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3146
        }
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3147
    } else {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3148
        if (val & 0x0000FF00) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3149
            RETURN ( __mkSmallInteger(2+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3150
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3151
            RETURN ( __mkSmallInteger(1+offs));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3152
        }
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3153
    }
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  3154
#endif /* not SCHTEAM */
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3155
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3156
    ^ self abs highBit - 1 // 8 + 1
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3157
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3158
    "
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3159
     16rFF00000000000000 digitLength
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3160
     16r-FF00000000000000 digitLength
2815
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
     16rFF000000 digitLength
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3163
     16rFF0000 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3164
     16rFF00 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3165
     16rFF digitLength
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3166
     16r-FF000000 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3167
     16r-FF0000 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3168
     16r-FF00 digitLength
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3169
     16r-FF digitLength
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  3170
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3171
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3172
    "Modified: / 19-09-2017 / 16:34:26 / stefan"
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3173
!
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3174
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3175
swapBytes
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3176
    "swap bytes pair-wise in a positive integer
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3177
     i.e. a.b.c.d -> b.a.d.c.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3178
     The name may be misleading; actually a new integer is returned,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3179
     and the receiver is not modified.
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  3180
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3181
     Redefined here for speed.
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3182
     Swapping of negative integers is undefined and therefore not supported.
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3183
     This case is handled in the superclass."
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3184
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3185
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3186
#ifndef __SCHTEAM__
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  3187
    unsigned INT v = __intVal(self);
16885
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3188
c8a865e3c540 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16873
diff changeset
  3189
    if ((INT)v >= 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3190
	unsigned INT swapped;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3191
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3192
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3193
	swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3194
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3195
	swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3196
# endif /* __POINTER_SIZE__ */
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3197
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3198
	//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
  3199
	if (swapped <= _MAX_INT) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3200
	    RETURN ( __mkSmallInteger(swapped) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3201
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3202
	RETURN (__MKUINT(swapped));
15322
986b2cc65f2e class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15309
diff changeset
  3203
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3204
#endif
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3205
%}.
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3206
    ^ super swapBytes
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3207
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3208
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3209
     -1 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3210
     16r11223344 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3211
     16r44332211 swapBytes hexPrintString
16873
50dc076eea8f class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16537
diff changeset
  3212
     self maxVal swapBytes hexPrintString
50dc076eea8f class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 16537
diff changeset
  3213
     self maxVal swapBytes swapBytes hexPrintString
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3214
     16r1122334455667788 swapBytes hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3215
     16r11223344556677889900 swapBytes hexPrintString
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3216
    "
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3217
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  3218
    "Created: / 09-01-2012 / 23:01:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3219
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3220
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3221
!SmallInteger methodsFor:'catching messages'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3222
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3223
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3224
    "catch indexed access - report an error
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3225
     defined here since basicAt: in Object omits the SmallInteger check."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3226
14540
84fc4b759ad8 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14492
diff changeset
  3227
    ^ self notIndexed
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3228
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3229
    "Modified (comment): / 17-05-2017 / 16:34:34 / mawalch"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3230
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3231
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3232
basicAt:index put:anObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3233
    "catch indexed access - report an error
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3234
     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
  3235
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3236
    self notIndexed
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3237
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3238
    "Modified (comment): / 17-05-2017 / 16:34:40 / mawalch"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3239
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3240
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3241
basicSize
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3242
    "return the number of indexed instvars - SmallIntegers have none.
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3243
     Defined here since basicSize in Object omits the SmallInteger check."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3244
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3245
    ^ 0
21756
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3246
19fdb5bfa327 #OTHER by mawalch
mawalch
parents: 21744
diff changeset
  3247
    "Modified (comment): / 17-05-2017 / 16:34:49 / mawalch"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3248
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3249
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3250
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3251
    "return the number of indexed instvars - SmallIntegers have none."
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
    ^ 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3254
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3255
5240
2a91958ba1f1 categories
Claus Gittinger <cg@exept.de>
parents: 5209
diff changeset
  3256
!SmallInteger methodsFor:'coercing & converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3257
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3258
asCharacter
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3259
    "Return a character with the receiver as ascii (actually: unicode) value"
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
  3260
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3261
    ^ Character value:self
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3262
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3263
    "
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3264
     Character value:16r61
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3265
     Character value:16r161
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3266
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3267
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3268
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3269
asFloat
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3270
    "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
  3271
     Redefined for performance (machine can do it faster)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3272
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3273
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3274
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3275
    return context._RETURN( STDouble._new((double)(self.longValue())) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3276
#else
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3277
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  3278
    double dVal = (double)__intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3279
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3280
    __qMKFLOAT(newFloat, dVal);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3281
    RETURN ( newFloat );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3282
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3283
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3284
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3285
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3286
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3287
asLargeInteger
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3288
    "return a LargeInteger with same value as receiver.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3289
     Not for general use:
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3290
       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
  3291
       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
  3292
       This exists only as a helper for some algorithms and converters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3293
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3294
    ^ LargeInteger value:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3295
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3296
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3297
asShortFloat
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3298
    "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
  3299
     Redefined for performance (machine can do it faster)"
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3300
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3301
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3302
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3303
    return context._RETURN( STFloat._new((float)(self.longValue())) );
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3304
#else
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3305
    OBJ dummy = @global(ShortFloat);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3306
    OBJ newFloat;
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3307
    float fVal = (float)__intVal(self);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3308
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  3309
    __qMKSFLOAT(newFloat, fVal);
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3310
    RETURN ( newFloat );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3311
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3312
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3313
    ^ self primitiveFailed
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3314
!
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  3315
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3316
asUnsignedInt
18947
1d8cd5b315b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18946
diff changeset
  3317
    "return an integer representing my unsigned INT value.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3318
     Notice, that the returned integer's size
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3319
     depends heavily on the underlying INT size;
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3320
     You will get 16rFFFFFFFF on 32bit machines,
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3321
     but 16rFFFFFFFFFFFFFFFF on 64 bit machines.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3322
     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
  3323
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3324
%{  /* NOCONTEXT */
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3325
    INT iVal = __intVal(self);
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3326
    OBJ uiVal;
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3327
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3328
    uiVal = __MKUINT( (unsigned INT)iVal );
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3329
    RETURN ( 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
    ^ self primitiveFailed
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3332
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
     -1 asUnsignedInt hexPrintString -> 'FFFFFFFFFFFFFFFF'
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3335
     16r-8000 asUnsignedInt hexPrintString -> ''FFFFFFFFFFFF8000''
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3336
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3337
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  3338
    "Modified (comment): / 19-09-2017 / 16:34:01 / stefan"
18676
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3339
!
151a213c4113 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18592
diff changeset
  3340
8408
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3341
codePoint
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3342
    "for compatibility with Characters.
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3343
     (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
  3344
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3345
    ^ self
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3346
!
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  3347
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3348
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3349
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3350
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3351
    ^ 20
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3352
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3353
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3354
signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3355
    "return a smallInteger from sign-extending the 24'th bit.
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3356
     May be useful for communication interfaces"
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3357
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3358
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3359
#ifndef __SCHTEAM__
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3360
    INT i = __intVal(self);
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3361
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  3362
    if (i & 0x800000L) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3363
	i = i | ~((INT)0xFFFFFF);
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3364
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3365
	i = i & 0x7FFFFF;
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3366
    }
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3367
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3368
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3369
#endif
12866
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
    ^ self primitiveFailed
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3372
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
     16rFFFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3375
     16r800000 signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3376
     16r7FFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3377
    "
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3378
!
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  3379
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3380
signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3381
    "return a smallInteger from sign-extending the 8'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3382
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3383
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3384
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3385
#ifndef __SCHTEAM__
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3386
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3387
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3388
    if (i & 0x80) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3389
	i = i | ~((INT)0xFF);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3390
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3391
	i = i & 0x7F;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3392
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3393
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3394
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3395
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3396
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3397
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3398
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3399
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3400
     16rFF signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3401
     16r80 signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3402
     16r7F signExtendedByteValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3403
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3404
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3405
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3406
signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3407
    "return a smallInteger from sign-extending the 32'th bit.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3408
     May be useful for communication interfaces"
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3409
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3410
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3411
#ifndef __SCHTEAM__
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3412
    INT i = __intVal(self);
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3413
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  3414
    if (i & 0x80000000L) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3415
	i = i | ~((INT)0xFFFFFFFF);
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3416
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3417
	i = i & 0x7FFFFFFFL;
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3418
    }
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3419
19264
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3420
    RETURN (__MKINT(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3421
#endif
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3422
%}.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3423
    ^ self primitiveFailed
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3424
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3425
    "
19264
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3426
     16rFFFFFFFF signExtendedLongValue -> -1
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3427
     16r80000000 signExtendedLongValue -> -2147483648
11160ea2c8b3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19263
diff changeset
  3428
     16r7FFFFFFF signExtendedLongValue -> 2147483647
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3429
    "
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3430
!
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  3431
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3432
signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3433
    "return a smallInteger from sign-extending the 16'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3434
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3435
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3436
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3437
#ifndef __SCHTEAM__
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3438
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3439
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3440
    if (i & 0x8000) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3441
	i = i | ~((INT)0xFFFF);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3442
    } else {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3443
	i = i & 0x7FFF;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3444
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3445
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3446
    RETURN (__mkSmallInteger(i));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3447
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3448
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3449
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3450
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3451
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3452
     16rFFFF signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3453
     16r8000 signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3454
     16r7FFF signExtendedShortValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3455
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3456
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3457
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3458
!SmallInteger methodsFor:'comparing'!
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
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3461
    "return true, if the argument is greater than the receiver"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3464
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3465
    return context._RETURN( self.ltP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3466
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3467
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3468
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3469
	RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3470
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3471
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3472
	RETURN ( ((INT)self < (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3473
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3474
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3475
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3476
	RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3477
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3478
#endif /* not __SCHTEAM__ */
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3479
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3480
    ^ aNumber lessFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3481
    "^ self retry:#< coercing:aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3482
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3483
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3484
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3485
    "return true, if the argument is greater or equal"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3488
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3489
    return context._RETURN( self.leP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3490
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3491
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3492
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3493
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3494
	RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3495
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3496
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3497
	RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3498
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3499
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3500
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3501
	RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3502
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3503
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3504
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3505
    ^ (self > aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3506
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3507
    "Modified: / 31.7.2002 / 10:07:17 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3508
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3509
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3510
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3511
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3512
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3513
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3514
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3515
#ifdef __SCHTEAM__
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3516
    if (aNumber.isNumber()) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3517
	return context._RETURN( aNumber.eqvP( self.longValue() ));
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3518
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3519
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3520
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3521
    if (aNumber == self) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3522
	RETURN ( true );
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 (! __isNonNilObject(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3525
	/* a smallint or nil */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3526
	RETURN ( false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3527
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3528
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3529
    if (__qIsFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3530
	RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
701
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 (__qIsShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3533
	RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3534
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3535
#endif /* not __SCHTEAM__ */
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3536
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3537
    ^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3538
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3539
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3540
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3541
    "return true, if the argument is less than the receiver"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3544
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3545
    return context._RETURN( self.gtP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3546
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3547
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3548
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3549
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3550
	RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3551
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3552
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3553
	RETURN ( ((INT)self > (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3554
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3555
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3556
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3557
	RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3558
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3559
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3560
%}.
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3561
    ^ (aNumber < self)
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3562
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3563
    "Modified: / 31.7.2002 / 10:07:05 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3564
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3565
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3566
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3567
    "return true, if the argument is less or equal"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3570
#ifdef __SCHTEAM__
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3571
    return context._RETURN( self.geP( aNumber ));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3572
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3573
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3574
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3575
# ifdef POSITIVE_ADDRESSES
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3576
	RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3577
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3578
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3579
	RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3580
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3581
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3582
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3583
	RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3584
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3585
#endif /* not __SCHTEAM__ */
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3586
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  3587
    ^ (self < aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3588
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  3589
    "Modified: / 31.7.2002 / 10:07:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3590
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3591
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3592
hash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3593
    "return an integer useful for hashing on value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3594
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3595
    self >= 0 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3596
    ^ self negated
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
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3599
hashMultiply
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3600
    "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
  3601
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3602
    |low|
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3603
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3604
    low := self bitAnd: 16r3FFF.
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3605
    ^ (9741 * low
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3606
      + ((9741 * (self bitShift: -14) + (101 * low) bitAnd: 16383) * 16384))
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3607
	bitAnd: 16r0FFFFFFF
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3608
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3609
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3610
     1 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3611
     2 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3612
     3 hashMultiply
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3613
     100 hashMultiply
17247
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3614
    "
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3615
!
e4e29302c10a class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17036
diff changeset
  3616
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3617
identityHash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3618
    "return an integer useful for hashing on identity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3619
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3620
     self >= 0 ifTrue:[^ self].
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3621
     ^ self negated
1963
ea26c7b9ca1d experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  3622
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  3623
    "Modified: 11.11.1996 / 18:42:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3624
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3625
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3626
max:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3627
    "return the receiver or the argument, whichever is greater"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3630
#ifndef __SCHTEAM__
701
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
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3633
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3634
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3635
	if ((INT)(self) > (INT)(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3636
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3637
	if (__intVal(self) > __intVal(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3638
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3639
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3640
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3641
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3642
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3643
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3644
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3645
	if ( (double)__intVal(self) > __floatVal(aNumber) ) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3646
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3647
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3648
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3649
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3650
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3651
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3652
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3653
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3654
    (self > aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3655
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3656
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3657
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3658
min:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3659
    "return the receiver or the argument, whichever is smaller"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3662
#ifndef __SCHTEAM__
701
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
    if (__isSmallInteger(aNumber)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3665
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3666
	/* tag bit does not change ordering */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3667
	if ((INT)(self) < (INT)(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3668
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3669
	if (__intVal(self) < __intVal(aNumber))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3670
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3671
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3672
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3673
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3674
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3675
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3676
    if (__isFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3677
	if ( (double)__intVal(self) < __floatVal(aNumber) ) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3678
	    RETURN ( self );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3679
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3680
	RETURN ( aNumber );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3681
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3682
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3683
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3684
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3685
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3686
    (self < aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3687
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3688
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3689
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
    "return true, if the arguments value is not equal to mine"
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
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3694
#ifdef __SCHTEAM__
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3695
    if (aNumber.isNumber()) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3696
	return context._RETURN( (aNumber.isEqv( self.longValue() )) ? STObject.False : STObject.True);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3697
	/* NOTREACHED */
18699
24b9c15dc6aa steam stuff
Claus Gittinger <cg@exept.de>
parents: 18676
diff changeset
  3698
    }
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  3699
#else
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3700
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3701
    if (aNumber == self) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3702
	RETURN ( false );
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 (! __isNonNilObject(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3705
	/* a smallint or nil */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3706
	RETURN ( true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3707
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3708
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3709
    if (__qIsFloatLike(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3710
	RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3711
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3712
    if (__qIsShortFloat(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3713
	RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3714
    }
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  3715
#endif /* not __SCHTEAM__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3716
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3717
    ^ (self = aNumber) not
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3718
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3719
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3720
!SmallInteger methodsFor:'copying'!
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
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3723
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3724
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3725
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3726
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3727
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3728
10947
e01ba2c3533f deepCopy change
ab
parents: 10487
diff changeset
  3729
deepCopyUsing:aDictionary postCopySelector:postCopySelector
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3730
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3731
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3732
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3733
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3734
!
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
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3737
    "return a shallow copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3738
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3739
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3740
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3741
!
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
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3744
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3745
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3746
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3747
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3748
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3749
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  3750
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  3751
!SmallInteger methodsFor:'iteration'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3752
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3753
timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  3754
    "evaluate the argument, aBlock self times.
claus
parents: 329
diff changeset
  3755
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3756
357
claus
parents: 329
diff changeset
  3757
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3758
#ifndef __SCHTEAM__
357
claus
parents: 329
diff changeset
  3759
    REGISTER INT tmp;
claus
parents: 329
diff changeset
  3760
    static struct inlineCache blockVal = __ILC0(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3761
357
claus
parents: 329
diff changeset
  3762
    tmp = __intVal(self);
claus
parents: 329
diff changeset
  3763
    if (tmp > 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3764
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3765
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3766
	    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3767
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3768
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
		 * specially tuned version for compiled blocks,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3771
		 * (the most common case)
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
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3774
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3775
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3776
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3777
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3778
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3779
# 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
  3780
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3781
#                   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
  3782
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3783
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3784
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3785
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3786
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3787
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3788
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3789
		     * home on stack - no need to refetch
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
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3792
		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3793
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3794
		    {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3795
# ifdef __UNROLL_LOOPS__
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3796
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3797
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3798
			 * 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
  3799
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3800
			while (tmp > 8) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3801
			    if (InterruptPending != nil) goto interrupted0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3802
	continue0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3803
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3804
			    if (InterruptPending != nil) goto interrupted1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3805
	continue1:
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 interrupted2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3808
	continue2:
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 interrupted3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3811
	continue3:
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 interrupted4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3814
	continue4:
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 interrupted5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3817
	continue5:
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 interrupted6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3820
	continue6:
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 interrupted7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3823
	continue7:
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
			    tmp -= 8;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3826
			}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3827
# endif /* __UNROLL_LOOPS__ */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3828
			do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3829
			    if (InterruptPending != nil) goto interruptedX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3830
	continueX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3831
			    (*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3832
			} while(--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3833
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3834
			RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3835
			if (0) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3836
# ifdef __UNROLL_LOOPS__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3837
			    interrupted0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3838
						__interruptL(@line); goto continue0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3839
			    interrupted1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3840
						__interruptL(@line); goto continue1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3841
			    interrupted2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3842
						__interruptL(@line); goto continue2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3843
			    interrupted3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3844
						__interruptL(@line); goto continue3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3845
			    interrupted4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3846
						__interruptL(@line); goto continue4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3847
			    interrupted5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3848
						__interruptL(@line); goto continue5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3849
			    interrupted6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3850
						__interruptL(@line); goto continue6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3851
			    interrupted7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3852
						__interruptL(@line); goto continue7;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3853
# endif /* __UNROLL_LOOPS__ */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3854
			    interruptedX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3855
						__interruptL(@line); goto continueX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3856
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3857
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3858
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3859
	    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  3860
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3861
#           undef BLOCK_ARG
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  3862
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3863
# ifdef NEW_BLOCK_CALL
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3864
#           define BLOCK_ARG  aBlock
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3865
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3866
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3867
#           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3868
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3869
# endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  3870
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3871
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3872
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3873
	     * it could be recompiled or flushed (in the interrupt)
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
	    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3876
		REGISTER OBJFUNC codeVal;
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
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3879
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3880
		     * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3881
		     * directly call it without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3882
		     * however, if there is an interrupt, refetch the code pointer.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3883
		     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3884
		    /* stay here, while no interrupts are pending ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3885
		    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3886
			(*codeVal)(BLOCK_ARG);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3887
			if (InterruptPending != nil) goto outerLoop;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3888
		    } while (--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3889
		    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3890
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3891
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3892
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3893
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3894
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3895
			 * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3896
			 * directly call interpreter without going through Block>>value
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
			__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3899
		    } else {
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
			 * arg is something else - call it with #value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3902
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3903
			(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3904
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3905
		}
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3906
    outerLoop: ;
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3907
	    } while (--tmp);
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3908
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3909
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3910
#           undef IBLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3911
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3912
	    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3913
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3914
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3915
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3916
	 * not a block-like thingy - call it with #value
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
	do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3919
	    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3920
	    (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3921
	} while(--tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3922
	RETURN (self);
357
claus
parents: 329
diff changeset
  3923
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3924
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3925
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  3926
    ^ super timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  3927
claus
parents: 329
diff changeset
  3928
"/    |count "{ Class: SmallInteger }" |
claus
parents: 329
diff changeset
  3929
"/
claus
parents: 329
diff changeset
  3930
"/    count := self.
claus
parents: 329
diff changeset
  3931
"/    [count > 0] whileTrue:[
claus
parents: 329
diff changeset
  3932
"/        aBlock value.
claus
parents: 329
diff changeset
  3933
"/        count := count - 1
claus
parents: 329
diff changeset
  3934
"/    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3935
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3936
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3937
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3938
    "reimplemented as primitive for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3939
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3940
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  3941
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3942
    REGISTER INT tmp, step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3943
    REGISTER INT final;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3944
    static struct inlineCache blockVal = __ILC1(0);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3945
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3946
    if (__bothSmallInteger(incr, stop)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3947
	tmp = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3948
	final = __intVal(stop);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3949
	step = __intVal(incr);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3950
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3951
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3952
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
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
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3955
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
		 * specially tuned version for static compiled blocks, called with
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3958
		 * home on the stack (the most common case)
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
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3961
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3962
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3963
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3964
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3965
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3966
# 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
  3967
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3968
#                   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
  3969
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3970
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3971
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3972
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3973
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3974
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3975
		    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
  3976
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  3977
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3978
		    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3979
			if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3980
			    if (step == -1) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3981
				while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3982
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3983
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3984
				    tmp--;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3985
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3986
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3987
				while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3988
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3989
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3990
				    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3991
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3992
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3993
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3994
			    if (step == 1) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3995
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3996
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3997
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3998
				    tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  3999
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4000
			    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4001
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4002
				    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4003
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4004
				    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4005
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4006
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4007
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4008
			RETURN (self);
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
	    }
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
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4015
	     * it could be recompiled or flushed (in the interrupt)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4016
	     */
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4017
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4018
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4019
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4020
# 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
  4021
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4022
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4023
# else
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  (__BlockInstPtr(aBlock)->b_home)
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4025
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4026
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4027
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4028
	    if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4029
		while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4030
		    REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4031
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4032
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4033
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4034
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4035
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4036
			 * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4037
			 * directly call it without going through Block>>value
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
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4040
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4041
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4042
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4043
			     * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4044
			     * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4045
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4046
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4047
			    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4048
				OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4049
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4050
				idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4051
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4052
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4053
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4054
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4055
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4056
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4057
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4058
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4059
			     * arg is something else - call it with #value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4060
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4061
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4062
			}
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
		    tmp += step;
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
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4067
		while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4068
		    REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4069
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4070
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4071
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4072
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4073
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4074
			 * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4075
			 * directly call it without going through Block>>value
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
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4078
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4079
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4080
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4081
			     * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4082
			     * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4083
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4084
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4085
			    {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4086
				OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4087
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4088
				idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4089
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4090
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4091
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4092
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4093
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4094
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4095
			} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4096
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4097
			     * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4098
			     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4099
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4100
			}
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
		    tmp += step;
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
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4105
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4106
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4107
#           undef IBLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4108
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4109
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4110
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4111
	     * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4112
	     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4113
	    if (step < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4114
		while (tmp >= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4115
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4116
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4117
		    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4118
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4119
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4120
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4121
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4122
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4123
	    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4124
		while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4125
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4126
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4127
		    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4128
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4129
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4130
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4131
		    tmp += step;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4132
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4133
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4134
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4135
	RETURN ( self );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4136
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4137
#endif
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  4138
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4139
    "/
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4140
    "/ 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
  4141
    "/ pass on to super ...
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4142
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4143
    ^ super to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4144
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4145
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4146
     1 to:10 by:3 do:[:i | i printNewline]
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
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4150
to:stop do:aBlock
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4151
    "evaluate aBlock for every integer between (and including) the receiver
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4152
     and the argument, stop.
357
claus
parents: 329
diff changeset
  4153
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4154
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4155
%{
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4156
#ifndef __SCHTEAM__
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4157
    REGISTER INT tmp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4158
    INT final;
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4159
    static struct inlineCache blockVal = __ILC1(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4160
252
  4161
    if (__isSmallInteger(stop)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4162
	tmp = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4163
	final = __intVal(stop);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4164
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4165
	if (__isBlockLike(aBlock)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4166
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
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
		/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4169
		 * specially tuned version for the most common case,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4170
		 * where called with home on the stack
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
		REGISTER OBJFUNC codeVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4173
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4174
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  4175
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4176
# 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
  4177
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4178
#                   define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4179
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4180
# else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4181
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4182
#                   define BLOCK_ARG  rHome
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4183
		    REGISTER OBJ rHome;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4184
		    rHome = __BlockInstPtr(aBlock)->b_home;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4185
		    if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4186
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4187
		    {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4188
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4189
# ifdef PARANOIA
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4190
			if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4191
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4192
			{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4193
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4194
			     * static compiled blocks ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4195
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4196
# ifdef __UNROLL_LOOPS__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4197
			    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4198
			     * The following code is designed to run as fast as possible;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4199
			     *  - taken branches only if interrupts are pending
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4200
			     *  - only forward branches (which are usually predicted as not taken)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4201
			     *  - unrolled the loop
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4202
			     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4203
			     * 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
  4204
			     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4205
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4206
			    INT t8 = (INT)(__mkSmallInteger(tmp+8));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4207
			    tmp = (INT)(__mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4208
			    final = (INT)(__mkSmallInteger(final));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4209
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4210
			    INT t8 = tmp+8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4211
#  endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4212
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4213
			    for (;;) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4214
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4215
				while (t8 <= final) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4216
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4217
				    t8 += (INT)(__MASKSMALLINT(8));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4218
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4219
				    t8 += 8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4220
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4221
				    if (InterruptPending != nil) goto interrupted0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4222
	continue0:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4223
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4224
				    (*codeVal)(BLOCK_ARG, tmp);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4225
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4226
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4227
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4228
				    if (InterruptPending != nil) goto interrupted1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4229
	continue1:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4230
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4231
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4232
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4233
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4234
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4235
				    if (InterruptPending != nil) goto interrupted2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4236
	continue2:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4237
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4238
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4239
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4240
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4241
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4242
				    if (InterruptPending != nil) goto interrupted3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4243
	continue3:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4244
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4245
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4246
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4247
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4248
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4249
				    if (InterruptPending != nil) goto interrupted4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4250
	continue4:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4251
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4252
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4253
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4254
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4255
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4256
				    if (InterruptPending != nil) goto interrupted5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4257
	continue5:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4258
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4259
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4260
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4261
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4262
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4263
				    if (InterruptPending != nil) goto interrupted6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4264
	continue6:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4265
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4266
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4267
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4268
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4269
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4270
				    if (InterruptPending != nil) goto interrupted7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4271
	continue7:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4272
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4273
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4274
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4275
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4276
#  endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4277
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4278
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4279
				    tmp += (INT)(__MASKSMALLINT(8));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4280
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4281
				    tmp += 8;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4282
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4283
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4284
				while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4285
				    if (InterruptPending != nil) goto interruptedX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4286
	continueX:
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4287
#  if TAG_INT==1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4288
				    (*codeVal)(BLOCK_ARG, tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4289
				    tmp += (INT)(__MASKSMALLINT(1));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4290
#  else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4291
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4292
				    tmp++;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4293
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4294
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4295
				RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4296
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4297
				if (0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4298
				    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4299
				     * no discussion about those gotos ...
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4300
				     * ... its better for your CPU's pipelines
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4301
				     * (if you don't understand why, just don't argue).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4302
				     */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4303
				    interrupted7:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4304
						    __interruptL(@line); goto continue7;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4305
				    interrupted6:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4306
						    __interruptL(@line); goto continue6;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4307
				    interrupted5:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4308
						    __interruptL(@line); goto continue5;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4309
				    interrupted4:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4310
						    __interruptL(@line); goto continue4;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4311
				    interrupted3:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4312
						    __interruptL(@line); goto continue3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4313
				    interrupted2:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4314
						    __interruptL(@line); goto continue2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4315
				    interrupted1:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4316
						    __interruptL(@line); goto continue1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4317
				    interrupted0:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4318
						    __interruptL(@line); goto continue0;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4319
				    interruptedX:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4320
						    __interruptL(@line); goto continueX;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4321
				}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4322
			    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4323
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4324
			    while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4325
				if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4326
				(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4327
				tmp ++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4328
			    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4329
			    RETURN (self);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4330
# endif /* __UNROLL_LOOPS__ */
21700
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
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4333
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4334
			 * mhmh - seems to be a block with dynamic code
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4335
			 * must refetch, to allow dynamic recompilation or code flush.
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
			while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4338
			    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4339
			    if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4340
			    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4341
			    tmp ++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4342
			}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4343
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4344
			if (tmp > final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4345
			    RETURN (self);
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
		    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4348
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4349
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4350
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4351
#           undef BLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4352
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4353
# 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
  4354
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4355
#           define IBLOCK_ARG nil
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4356
# else
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  (__BlockInstPtr(aBlock)->b_home)
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4358
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4359
# endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  4360
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4361
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4362
	     * sorry - must check for the blocks code within the loops;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4363
	     * it could be recompiled or flushed (in the interrupt)
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
	    while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4366
		REGISTER OBJFUNC codeVal;
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
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4369
		    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4370
		     * arg is a compiled block with code -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4371
		     * directly call it without going through Block>>value
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
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4374
		    /* stay here, while no interrupts are pending ... */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4375
		    do {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4376
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4377
			if (InterruptPending != nil) goto outerLoop;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4378
			tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4379
		    } while (tmp <= final);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4380
		    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4381
		} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4382
		    if (InterruptPending != nil) __interruptL(@line);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4383
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4384
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4385
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4386
			 * arg is a compiled block with bytecode -
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4387
			 * directly call interpreter without going through Block>>value
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4388
			 */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4389
# ifdef PASS_ARG_POINTER
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4390
			{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4391
			    OBJ idx;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4392
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4393
			    idx = __mkSmallInteger(tmp);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4394
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4395
			}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4396
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4397
			__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4398
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4399
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4400
		    } else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4401
			/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4402
			 * arg is something else - call it with #value:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4403
			 */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4404
			(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4405
		    }
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
	    outerLoop: ;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4408
		tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4409
	    }
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  4410
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4411
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4412
#           undef IBLOCK_ARG
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4413
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4414
	    RETURN (self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4415
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4416
	/*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4417
	 * arg is something else - call it with #value:
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
	while (tmp <= final) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4420
	    if (InterruptPending != nil) __interruptL(@line);
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
	    (*blockVal.ilc_func)(aBlock,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4423
					 @symbol(value:),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4424
					 nil, &blockVal,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4425
					 __mkSmallInteger(tmp));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4426
	    tmp++;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4427
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4428
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4429
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4430
#endif /* not __SCHTEAM__ */
400
claus
parents: 394
diff changeset
  4431
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  4432
400
claus
parents: 394
diff changeset
  4433
    "/
claus
parents: 394
diff changeset
  4434
    "/ 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
  4435
    "/ pass on to super ...
400
claus
parents: 394
diff changeset
  4436
    "/
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4437
    ^ super to:stop do:aBlock
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4438
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4439
    "
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4440
     1 to:10 do:[:i | i printNewline]
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  4441
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4442
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4443
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4444
!SmallInteger methodsFor:'misc math'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4445
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4446
bernoulli
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4447
    "returns the nth Bernoulli number.
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4448
     The series runs this:
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4449
	 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
  4450
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4451
     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
  4452
     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
  4453
     Used with taylor series for tan"
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4454
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4455
    |table p|
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4456
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4457
    table := #(
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4458
		(1 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4459
		(-1 30)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4460
		(1 42)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4461
		(-1 30)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4462
		(5 66)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4463
		(-691 2730)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4464
		(7 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4465
		(-3617 510)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4466
		(43867 798)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4467
		(-174611 330)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4468
		(854513 138)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4469
		(-236364091 2730)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4470
		(8553103 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4471
		(-23749461029 870)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4472
		(8615841276005 14322)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4473
		(-7709321041217 510)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4474
		(2577687858367 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4475
		(-26315271553053477373 1919190)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4476
		(2929993913841559 6)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4477
		(-261082718496449122051 13530)
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4478
	      ).
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4479
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4480
    self even ifTrue:[
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4481
	self == 0 ifTrue:[^1].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4482
	p := table at:(self / 2).
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4483
	^ 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
  4484
    ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4485
    self == 1 ifTrue:[ ^ (1 / 2) ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4486
    ^ 0.
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
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4489
     0 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4490
     1 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4491
     2 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4492
     3 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4493
     4 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4494
     5 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4495
     6 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4496
     8 bernoulli
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4497
     38 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4498
     40 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4499
     41 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4500
     42 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4501
    "
21917
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4502
00931f45bfff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21905
diff changeset
  4503
    "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
  4504
!
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  4505
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4506
divMod:aNumber
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4507
    "return an array filled with
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4508
	(self // aNumber) and (self \\ aNumber).
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4509
     The returned remainder has the same sign as aNumber.
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4510
     The following is always true:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4511
	(receiver // something) * something + (receiver \\ something) = receiver
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4512
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4513
     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
  4514
     Especially surprising:
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4515
	-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
  4516
			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
  4517
	-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
  4518
			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
  4519
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4520
     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
  4521
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4522
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4523
#ifndef __SCHTEAM__
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4524
    INT val, div, mod, mySelf;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4525
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4526
    if (__isSmallInteger(aNumber)
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4527
     && ((val = __intVal(aNumber)) > 0)
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4528
     && ((mySelf = __intVal(self)) >= 0)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4529
	div = mySelf / val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4530
	mod = mySelf % val;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4531
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4532
	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
  4533
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4534
#endif
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4535
%}.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4536
    ^ super divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4537
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4538
    "
17033
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4539
     10 // 3           -> 3
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4540
     10 \\ 3           -> 1
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4541
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4542
     10 // -3          -> -4
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4543
     10 \\ -3          -> -2
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         -> 3
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4549
     -10 \\ -3         -> -1
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
     -78 \\ 10         2
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4552
     -78 // 10         -8
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
     10 divMod:3       -> #(3 1)   because 3*3 + 1 = 10
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4555
     10 divMod:-3      -> #(-4 -2) because -4*-3 + (-2) = 10
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4556
     -10 divMod:3      -> #(-4 2)  because -4*3 + 2 = -10
17033
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
9190f2b40619 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16885
diff changeset
  4559
     1000000000000000000000 divMod:3   -> #(333333333333333333333 1)
17036
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4560
     1000000000000000000000 divMod:-3  -> #(-333333333333333333334 -2)
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4561
     -1000000000000000000000 divMod:3  -> #(-333333333333333333334 2)
ef45fc0336fc class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17034
diff changeset
  4562
     -1000000000000000000000 divMod:-3 -> #(333333333333333333333 -1)
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4563
     100 factorial divMod:103
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4564
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4565
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4566
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4567
gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4568
    "return the greatest common divisor (Euclid's algorithm).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4569
     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
  4570
     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
  4571
     some code. (thanx to MessageTally)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4572
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4573
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4574
#ifndef __SCHTEAM__
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4575
    if (__isSmallInteger(anInteger)) {
23616
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4576
        INT orgArg, ttt, selfInt, orgSelfInt, temp;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4577
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4578
        ttt = orgArg = __intVal(anInteger);
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4579
        if (ttt) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4580
            selfInt = orgSelfInt = __intVal(self);
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4581
            while (ttt != 0) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4582
                temp = selfInt % ttt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4583
                selfInt = ttt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4584
                ttt = temp;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4585
            }
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4586
            /*
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4587
             * since its not defined in C, what the sign of
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4588
             * a modulus result is when the arg is negative,
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4589
             * change it explicitely here ...
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4590
             */
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4591
            if ((orgArg < 0) != (orgSelfInt < 0)) {
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4592
                /* flip result's sign */
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4593
                selfInt = -selfInt;
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4594
            }
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4595
            RETURN ( __mkSmallInteger(selfInt) );
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4596
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4597
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4598
#endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4599
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4600
    ^ super gcd:anInteger
23616
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4601
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4602
    "
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4603
     45 gcd:30 15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4604
     -45 gcd:30 15
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4605
     45 gcd:-30 -15
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
    "
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4608
af0ae1b23128 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 23498
diff changeset
  4609
    "Modified: / 18-01-2019 / 16:08:31 / Claus Gittinger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4610
!
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4611
2430
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4612
gcd_helper:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4613
    "same as gcd - see knuth & Integer>>gcd:"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4614
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4615
    ^ self gcd:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4616
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4617
    "Created: 1.3.1997 / 16:58:01 / cg"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4618
!
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  4619
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4620
integerLog10
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4621
    "return the truncation of log10 of the receiver.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4622
     The same as (self log:10) floor.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4623
     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
  4624
     to print a number/and for conversion to a LargeInteger.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  4625
     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
  4626
     (i.e. without log)."
2
claus
parents: 1
diff changeset
  4627
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4628
    self > 0 ifTrue:[
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4629
	self < 10000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4630
	    self < 10 ifTrue:[^ 0].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4631
	    self < 100 ifTrue:[^ 1].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4632
	    self < 1000 ifTrue:[^ 2].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4633
	    ^ 3
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4634
	].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4635
	self < 100000000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4636
	    self < 100000 ifTrue:[^ 4].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4637
	    self < 1000000 ifTrue:[^ 5].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4638
	    self < 10000000 ifTrue:[^ 6].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4639
	    ^ 7
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4640
	].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4641
	self < 1000000000 ifTrue:[^ 8].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4642
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4643
	SmallInteger maxBytes == 4 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4644
	    "/ 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
  4645
	    ^ 9
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4646
	] ifFalse:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4647
	    "/ 64 bit machine
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4648
	    self < 100000000000000 ifTrue:[
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4649
		self < 10000000000 ifTrue:[^ 9].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4650
		self < 100000000000 ifTrue:[^ 10].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4651
		self < 1000000000000 ifTrue:[^ 11].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4652
		self < 10000000000000 ifTrue:[^ 12].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4653
		^ 13
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4654
	    ].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4655
	    self < 1000000000000000 ifTrue:[^ 14].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4656
	    self < 10000000000000000 ifTrue:[^ 15].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4657
	    self < 100000000000000000 ifTrue:[^ 16].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4658
	    self < 1000000000000000000 ifTrue:[^ 17].
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4659
	    ^ 18.
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4660
	].
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  4661
    ].
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4662
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4663
    ^ self class
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4664
	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
  4665
	receiver:self
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4666
	selector:#integerLog10
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4667
	arguments:#()
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  4668
	errorString:'bad receiver in log10 (not strictly positive)'
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4669
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4670
    "
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4671
      99 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4672
      100 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4673
      101 integerLog10
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4674
      (101 log:10) floor
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4675
      120 integerLog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4676
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4677
      -1 integerLog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4678
      0 integerLog10
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4679
      Number trapInfinity:[ 0 integerLog10 ]
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4680
    "
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4681
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4682
    "Created: / 02-07-2017 / 01:19:09 / cg"
22218
d501998293f7 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 22211
diff changeset
  4683
    "Modified: / 28-08-2017 / 13:53:32 / cg"
21939
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
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4686
intlog10
21966
0772f7aae516 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 21949
diff changeset
  4687
    <resource: #obsolete>
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4688
    "return the truncation of log10 of the receiver.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4689
     The same as (self log:10) floor.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4690
     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
  4691
     to print a number/and for conversion to a LargeInteger.
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4692
     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
  4693
     (i.e. without log)."
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4694
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4695
    ^ self integerLog10
15600
da24d2390c03 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15568
diff changeset
  4696
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4697
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4698
      99 intlog10
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4699
      100 intlog10
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4700
      101 intlog10
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4701
      (101 log:10) floor
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4702
      120 intlog10
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  4703
      -1 intlog10
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  4704
    "
21939
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4705
8c7600a5fc60 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21917
diff changeset
  4706
    "Modified: / 02-07-2017 / 01:19:05 / cg"
2
claus
parents: 1
diff changeset
  4707
! !
claus
parents: 1
diff changeset
  4708
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4709
!SmallInteger methodsFor:'printing & storing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4710
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4711
asBCD
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4712
    "return an integer which represents the BCD encoded value of the receiver;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4713
     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
  4714
     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
  4715
     This conversion is useful for some communication protocols,
16041
989a985b6f61 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16039
diff changeset
  4716
     or control systems, which represent numbers this way..."
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4717
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4718
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4719
#ifndef __SCHTEAM__
18410
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4720
    // the following code is a leftover from times when division was expensive;
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4721
    // in modern cpu's, conditional branches are often more expensive than divisions,
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4722
    // so it is questionable, if the effort below is still worth it.
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4723
    // (and asBCD is really used seldom in some serial communication protocols
6806b6ba1316 changed digitAt
Claus Gittinger <cg@exept.de>
parents: 18401
diff changeset
  4724
    // for control systems)
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4725
    int i;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4726
    INT _10000000s = 0, _1000000s = 0;
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4727
    INT _100000s = 0, _10000s = 0, _1000s = 0;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4728
    INT _100s = 0, _10s = 0, _1s = 0;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4729
    INT b = __intVal(self);
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4730
    unsigned INT rslt;
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4731
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4732
    if (b <= 99999999) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4733
	if (b <= 255) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4734
	    // the most common case: convert bytes
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4735
	    for (i=7; i>=0; i--) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4736
		if (_100s >= 5)       _100s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4737
		if (_10s >= 5)        _10s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4738
		if (_1s >= 5)         _1s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4739
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4740
		_100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4741
		_10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4742
		_1s      =    (_1s<<1)         | (b >> 7 & 1);          _1s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4743
		b <<= 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4744
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4745
	    rslt = (_100s<<8) | (_10s<<4) | _1s;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4746
	    RETURN (__MKSMALLINT( rslt) );
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
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4749
	for (i=26; i>=0; i--) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4750
	    if (_10000000s >= 5)  _10000000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4751
	    if (_1000000s >= 5)   _1000000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4752
	    if (_100000s >= 5)    _100000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4753
	    if (_10000s >= 5)     _10000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4754
	    if (_1000s >= 5)      _1000s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4755
	    if (_100s >= 5)       _100s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4756
	    if (_10s >= 5)        _10s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4757
	    if (_1s >= 5)         _1s += 3;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4758
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4759
	    _10000000s =  (_10000000s<<1)  | (_1000000s >> 3 & 1);  _10000000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4760
	    _1000000s =   (_1000000s<<1)   | (_100000s >> 3 & 1);   _1000000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4761
	    _100000s =    (_100000s<<1)    | (_10000s >> 3 & 1);    _100000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4762
	    _10000s  =    (_10000s<<1)     | (_1000s >> 3 & 1);     _10000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4763
	    _1000s   =    (_1000s<<1)      | (_100s >> 3 & 1);      _1000s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4764
	    _100s    =    (_100s<<1)       | (_10s >> 3 & 1);       _100s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4765
	    _10s     =    (_10s<<1)        | (_1s >> 3 & 1);        _10s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4766
	    _1s      =    (_1s<<1)         | (b >> 26 & 1);         _1s &= 0xF;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4767
	    b <<= 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4768
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4769
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4770
	rslt = (_10000000s<<28)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4771
	       | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4772
	       | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4773
	RETURN (__MKUINT( rslt) );
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4774
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4775
#endif
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4776
%}.
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4777
    ^ super asBCD.
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4778
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4779
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4780
      99999999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4781
      12812345 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4782
      128123 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4783
      128901 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4784
      12890 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4785
      1289 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4786
      999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4787
      256 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4788
      255 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4789
      128 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4790
      162 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4791
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4792
      999999999 asBCD hexPrintString
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4793
      128123456 asBCD hexPrintString
16039
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4794
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4795
    "
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4796
!
483922f17924 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15910
diff changeset
  4797
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4798
printOn:aStream
22304
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4799
    "append my printstring (base 10) to aStream.
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4800
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4801
     I use #printString instead of #printOn: as basic print mechanism."
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4802
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4803
    aStream nextPutAll:(self printString)
22304
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4804
2350a5693ec5 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22268
diff changeset
  4805
    "Modified (comment): / 10-10-2017 / 14:09:00 / cg"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4806
!
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  4807
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4808
printOn:aStream base:base showRadix:showRadix
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4809
    "append a string representation of the receiver in the specified numberBase to aStream
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4810
     (if showRadix is true, with initial XXr)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4811
     The base argument should be between 2 and 36."
6144
35b772717356 check for bad radix
james
parents: 6092
diff changeset
  4812
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4813
    |absBase|
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4814
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4815
    (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
  4816
	showRadix ifTrue:[
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4817
	    absBase printOn:aStream.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4818
	    aStream nextPut:$r.
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4819
	].
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4820
	aStream nextPutAll:(self printStringRadix:base)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4821
    ] ifFalse:[
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4822
	super printOn:aStream base:base showRadix:true.
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  4823
    ].
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  4824
12977
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  4825
    "Created: / 07-09-2001 / 13:54:40 / cg"
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  4826
    "Modified: / 02-08-2010 / 12:25:20 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4827
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4828
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4829
printString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4830
    "return my printstring (base 10)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4831
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4832
    "since this was heavily used in some applications,
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4833
     here is an exception to the rule of basing printString
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4834
     upon the printOn: method."
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  4835
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4836
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4837
#ifdef __SCHTEAM__
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4838
    return context._RETURN( new STString( java.lang.Long.toString(self.longValue()) ));
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4839
#else
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  4840
    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
  4841
    char *cp;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4842
    OBJ newString = nil;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4843
    INT myValue;
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4844
    int negative = 0;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4845
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4846
    if (self == __MKSMALLINT(0)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4847
	RETURN (@global(ZeroString));
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4848
//        RETURN (__MKSTRING_L("0", 1));
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4849
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  4850
    myValue = __intVal(self);
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4851
    if (myValue < 0) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4852
	negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4853
	myValue = -myValue;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4854
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4855
    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
  4856
    *cp-- = '\0';
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  4857
    for ( ; myValue != 0; cp--) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4858
	*cp = '0' + (myValue % 10);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4859
	myValue /= 10;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4860
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4861
    if (negative) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4862
	*cp-- = '-';
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
    newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4865
    if (newString != nil) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4866
	RETURN (newString);
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4867
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4868
#endif /* not __SCHTEAM__ */
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4869
%}.
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4870
    "/ only arrive here,
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4871
    "/  when having memory problems (i.e. no space for string) ...
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  4872
    ^ super printString
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4873
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  4874
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4875
     1234 printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4876
     0    printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4877
     -100 printString
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4878
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4879
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 123456789012 printString ]] 180 180 180 170 180
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4880
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 12345678 printString ]]     140 150 140 150 140
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4881
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 1234 printString ]]         130 140 130 130 130
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4882
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 12 printString ]]           130 120 120 120 110
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  4883
    Time millisecondsToRun:[ 1000000 timesRepeat:[ 5 printString ]]            110 110 100 110 90
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  4884
    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
  4885
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4886
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4887
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  4888
printStringRadix:base
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4889
    "return my printstring (optimized for bases 16, 10 and 8).
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4890
     Print digits > 0 as uppercase chars if base > 0,
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4891
     as lowercase chars if base < 0."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4892
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4893
    |s|
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4894
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4895
%{
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4896
#ifdef __SCHTEAM__
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  4897
    int __base = Math.abs(base.intValue());
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4898
    long myValue = self.longValue();
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4899
    java.lang.String __s;
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4900
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4901
    switch (__base) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4902
        case 2:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4903
            __s = java.lang.Long.toBinaryString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4904
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4905
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4906
        case 8:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4907
            __s = java.lang.Long.toOctalString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4908
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4909
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4910
        case 10:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4911
            __s = java.lang.Long.toString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4912
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4913
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4914
        case 16:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4915
            __s = java.lang.Long.toHexString(myValue);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4916
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4917
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4918
        default:
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4919
        {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4920
            boolean negative = false;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4921
            __s = "";
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
            if ((__base > 36) || (__base < 2)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4924
                throw new SmalltalkError("invalid base: ", base);
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 (myValue < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4927
                negative = true;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4928
                myValue = -myValue;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4929
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4930
            while (myValue != 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4931
                int digit;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4932
                char ch;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4933
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4934
                digit = (int)(myValue % __base);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4935
                if (digit <= 9) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4936
                    ch = (char)('0' + digit);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4937
                } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4938
                    ch = (char)('A' + digit - 10);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4939
                }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4940
                __s = ch + __s;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4941
                myValue = myValue / __base;
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
            if (negative) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4944
                __s = "-" + __s;
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
            break;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4947
        }
18401
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4948
    }
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4949
    return context._RETURN( new STString( __s ));
4eee1a43ffb7 comments only
Claus Gittinger <cg@exept.de>
parents: 18395
diff changeset
  4950
#else
20141
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4951
    static char ucDigits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
063019f72480 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 19994
diff changeset
  4952
    static char lcDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4953
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  4954
    if (__isSmallInteger(base)) {
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4955
        char *digits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4956
        INT __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4957
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4958
        if (self == __MKSMALLINT(0)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4959
            RETURN (@global(ZeroString));
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
        __base = __intVal(base);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4962
        if (__base < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4963
            __base = - __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4964
            digits = lcDigits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4965
        } else {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4966
            digits = ucDigits;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4967
        }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4968
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4969
        if ((__base < sizeof(ucDigits)) && (__base > 1)) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4970
            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
  4971
            char *cp;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4972
            OBJ newString;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4973
            int negative = 0;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4974
            INT myValue = __intVal(self);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4975
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4976
            if (myValue < 0) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4977
                negative = 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4978
                myValue = -myValue;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4979
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4980
            cp = buffer + sizeof(buffer) - 1;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4981
            *cp-- = '\0';
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4982
            for (; myValue != 0; cp--) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4983
                *cp = digits[myValue % __base];
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4984
                myValue /= __base;
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4985
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4986
            if (negative) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4987
                *cp-- = '-';
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
            newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4990
            if (newString != nil) {
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4991
                RETURN (newString);
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4992
            }
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  4993
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4994
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  4995
#endif /* not __SCHTEAM__ */
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  4996
%}.
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4997
    "/ arrive here, for bad base,
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4998
    "/ or when having memory problems (i.e. no space for string) ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  4999
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5000
    "/
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5001
    "/ fall back for seldom used bases
20330
01cc21bb516f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20262
diff changeset
  5002
    "/ Notice: cannot use super>>printStringRadix: here,
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5003
    "/ since that would lead to endless recursion ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5004
    "/ (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
  5005
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5006
    s := WriteStream on:(String new:10).
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5007
    super printOn:s base:base.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5008
    ^ s contents.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5009
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5010
    "
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5011
      127 printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5012
      127 printStringRadix:-16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5013
      -127 printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5014
      -127 printStringRadix:-16
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5015
      123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5016
      123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5017
      123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5018
      123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5019
      123 printStringRadix:2
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5020
      123 printStringRadix:1
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5021
      35 printStringRadix:36
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5022
      123 printStringRadix:37
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  5023
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5024
      -127 printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5025
      -123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5026
      -123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5027
      -123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5028
      -123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5029
      -123 printStringRadix:2
20330
01cc21bb516f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20262
diff changeset
  5030
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5031
      16r3FFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5032
      16r7FFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5033
      16rFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5034
      16r3FFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5035
      16r7FFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5036
      16rFFFFFFFFFFFFFFFF printStringRadix:16
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5037
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5038
      16r-3FFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5039
      16r-40000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5040
      16r-7FFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5041
      16r-80000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5042
      16r-FFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5043
      16r-3FFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5044
      16r-7FFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5045
      16r-FFFFFFFFFFFFFFFF printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5046
      16r-4000000000000000 printStringRadix:16
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5047
      16r-8000000000000000 printStringRadix:16
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  5048
    "
22268
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5049
fe294972157a #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22227
diff changeset
  5050
    "Modified: / 19-09-2017 / 16:34:40 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5051
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5052
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5053
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  5054
    "non-standard, but sometimes useful.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5055
     return a printed representation of the receiver
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5056
     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
  5057
     No checking for string overrun - the resulting string
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  5058
     must be shorter than 256 chars or else ...
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5059
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  5060
     Notice that a conversion may not be portable; for example,
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  5061
     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
  5062
     on 64bit mingw or visualc, %lld is required,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5063
     while other systems may be happy with a %d.
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5064
     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
  5065
     Use at your own risk (if at all).
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5066
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5067
     This method is NONSTANDARD and may be removed without notice;
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5068
     it is provided to allow special conversions in very special situations.
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5069
     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
  5070
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5071
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  5072
%{  /* STACK: 400 */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5073
#ifndef __SCHTEAM__
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5074
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  5075
    OBJ s;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5076
    int len;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5077
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5078
    if (__isStringLike(formatString)) {
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5079
	/*
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5080
	 * 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
  5081
	 * 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
  5082
	 * manually save it here - very stupid ...
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5083
	 */
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5084
	__BEGIN_PROTECT_REGISTERS__
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5085
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5086
	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
  5087
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5088
	__END_PROTECT_REGISTERS__
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5089
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5090
	if (len < 0) goto fail;
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5091
	if (len >= sizeof(buffer)) goto fail;
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
	s = __MKSTRING_L(buffer, len);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5094
	if (s != nil) {
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5095
	    RETURN (s);
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5096
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5097
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5098
fail: ;
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5099
#endif /* not __SCHTEAM__ */
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  5100
%}.
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5101
    ^ super printfPrintString:formatString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5102
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5103
    "
22227
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5104
	123 printfPrintString:'%%d -> %d'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5105
	123 printfPrintString:'%%6d -> %6d'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5106
	123 printfPrintString:'%%x -> %x'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5107
	123 printfPrintString:'%%4x -> %4x'
eae082846c10 Remove " " after "\" at end of line in macro
Stefan Vogel <sv@exept.de>
parents: 22221
diff changeset
  5108
	123 printfPrintString:'%%04x -> %04x'
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  5109
    "
21905
16dbb55ee5f8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21823
diff changeset
  5110
21949
ce997689ab94 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21939
diff changeset
  5111
    "Modified: / 03-07-2017 / 15:07:37 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5112
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5113
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5114
!SmallInteger methodsFor:'private'!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5115
23498
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5116
numberOfDigits:n8BitDigits
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5117
    "initialize the instance to store n8BitDigits.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5118
     It is a no-op for SmallIntegers."
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5119
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5120
    ^ self.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5121
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5122
    "Created: / 01-11-2018 / 11:29:45 / Stefan Vogel"
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5123
!
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
numberOfDigits:n8BitDigits sign:sign
18382
4b0ff5d95702 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 18370
diff changeset
  5126
    "private: for protocol completeness with LargeIntegers.
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5127
     Returns a smallInteger with my absValue and the sign of the argument.
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5128
     The method's name may be misleading: the receiver is not changed,
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5129
     but a new number is returned."
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5130
23498
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5131
    ^ self setSign:sign.
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5132
5ac499e2cc2e #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23476
diff changeset
  5133
    "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
  5134
! !
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  5135
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5136
!SmallInteger methodsFor:'special modulo arithmetic'!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5137
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5138
plus32:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5139
    "return the sum of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5140
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5141
     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
  5142
     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
  5143
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5144
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5145
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5146
    INT sum;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5147
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5148
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5149
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5150
    sum &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5151
# endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5152
    RETURN ( __MKUINT(sum));
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5153
#endif /* not __SCHTEAM__ */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5154
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5155
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5156
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
     16r7FFFFFFF + 1          2147483648
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5159
     16r7FFFFFFF plus32: 1
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
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5162
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5163
plus:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5164
    "return the sum of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5165
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5166
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5167
     smallInteger range is returned (i.e. the low bits of the sum).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5168
     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
  5169
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5170
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5171
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5172
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5173
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5174
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5175
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5176
	long sum = myValue + otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5177
	return context._RETURN( STInteger._new(sum) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5178
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5179
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5180
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5181
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5182
	INT sum;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5183
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5184
	sum =  __intVal(self) + __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5185
	if (!__ISVALIDINTEGER(sum)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5186
	    /* keep the sign */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5187
	    sum %= _MAX_INT;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5188
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5189
	RETURN ( __mkSmallInteger(sum));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5190
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5191
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5192
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5193
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5194
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5195
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5196
	5 plus:-1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5197
	5 plus:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5198
	1 plus:-5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5199
	self maxVal plus:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5200
	self maxVal + 1
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5201
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5202
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5203
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5204
subtract:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5205
    "return the difference of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5206
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5207
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5208
     smallInteger range is returned (i.e. the low bits of the sum).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5209
     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
  5210
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5211
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5212
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5213
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5214
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5215
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5216
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5217
	long diference = myValue - otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5218
	return context._RETURN( STInteger._new(diference) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5219
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5220
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5221
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5222
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5223
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5224
	INT diff;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5225
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5226
	diff = __intVal(self) - __intVal(aNumber);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5227
	if (!__ISVALIDINTEGER(diff)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5228
	    /* keep the sign */
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5229
	    diff %= _MAX_INT;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5230
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5231
	RETURN ( __mkSmallInteger(diff));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5232
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5233
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5234
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5235
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5236
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5237
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5238
	-1 subtract:5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5239
	5 subtract:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5240
	1 subtract:-5
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5241
	self minVal subtract:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5242
	self minVal - 1
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5243
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5244
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5245
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5246
times:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5247
    "return the product of the receiver and the argument, as SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5248
     The argument must be another SmallInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5249
     If the result overflows the smallInteger range, the value modulo the
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5250
     smallInteger range is returned (i.e. the low bits of the product).
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5251
     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
  5252
     and can therefore speed things up by not going through LargeIntegers."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5253
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5254
%{  /* NOCONTEXT */
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5255
#ifdef __SCHTEAM__
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5256
    {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5257
	long myValue = self.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5258
	long otherValue = aNumber.longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5259
	long product = myValue * otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5260
	return context._RETURN( STInteger._new(product) );
18255
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5261
    }
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5262
    /* NOT REACHED */
aedbc27ea6c0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 18240
diff changeset
  5263
#else
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5264
    INT myValue, otherValue;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5265
    unsigned INT productLow, productHi;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5266
    int negative;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5267
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5268
#   define low16Bits(foo)  ((foo) & 0xFFFF)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5269
#   define hi16Bits(foo)   ((foo) >> 16)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5270
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5271
#   define hi32Bits(foo)   ((foo) >> 32)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5272
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5273
    /*
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5274
     * can we use long long arithmetic ?
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
     * long-long arithmetic seems to be buggy with some systems
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5277
     * (took me a while to find this out :-(
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5278
     * (try 10000 * 10000)
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5279
     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5280
# if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5281
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5282
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5283
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5284
# if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5285
#  define USE_LONGLONG_FOR_MUL
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5286
# endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5287
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5288
    if (__isSmallInteger(aNumber)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5289
	myValue = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5290
	otherValue = __intVal(aNumber);
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5291
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5292
# if defined(USE_LONGLONG_FOR_MUL)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5293
	{
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5294
#  if defined(__alpha__) && !defined(__alpha64__)
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5295
#   define LONGLONG      INT64
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5296
#  else
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5297
#   define LONGLONG      long long
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5298
#  endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5299
	    LONGLONG product;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5300
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5301
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5302
	    if (product < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5303
		RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5304
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5305
	    RETURN ( __mkSmallInteger((INT)(product & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5306
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5307
# else /* no long-long */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5308
	negative = 1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5309
	if (myValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5310
	    negative = -1;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5311
	    myValue = -myValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5312
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5313
	if (otherValue < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5314
	    negative = -negative;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5315
	    otherValue = -otherValue;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5316
	}
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5317
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5318
#  if defined(__GNUC__) && defined(__mc68k__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5319
	asm ("mulu%.l %3,%1:%0"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5320
		: "=d"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5321
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5322
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5323
		  "dmi" ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5324
#  else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5325
#   if defined (__GNUC__) && defined(__x86__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5326
	asm ("mull %3"
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5327
		: "=a"  ((unsigned long)(productLow)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5328
		  "=d"  ((unsigned long)(productHi))
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5329
		: "%0"  ((unsigned long)(myValue)),
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5330
		  "rm"  ((unsigned long)(otherValue)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5331
#   else
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5332
#    if defined(__win32__) && defined(__BORLANDC__)
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5333
	asm {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5334
	    mov   eax, myValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5335
	    mov   edx, otherValue
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5336
	    mul   edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5337
	    mov   productLow, eax
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5338
	    mov   productHi, edx
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5339
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5340
#    else /* generic */
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5341
	{
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5342
	    unsigned INT pHH, pHL, pLH, pLL;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5343
	    unsigned INT low1, low2, hi1, hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5344
	    unsigned INT t;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5345
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5346
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5347
	     *
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5348
	     * this is too slow:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5349
	     * since most machines can do 32*32 to 64 bit multiply,
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5350
	     * (or at least 32*32 with Overflow check)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5351
	     * - need more assembler (inline) functions here
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5352
	     */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5353
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5354
	    low1 = low32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5355
	    hi1 = hi32Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5356
	    low2 = low32Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5357
	    hi2 = hi32Bits((unsigned INT)otherValue);
20333
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5358
#      undef LLMASK
8b2b36463804 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 20330
diff changeset
  5359
#      define LLMASK 0xC000000000000000LL
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5360
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5361
	    low1 = low16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5362
	    hi1 = hi16Bits((unsigned INT)myValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5363
	    low2 = low16Bits((unsigned INT)otherValue);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5364
	    hi2 = hi16Bits((unsigned INT)otherValue);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5365
#      define LLMASK 0xC0000000
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5366
#     endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5367
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5368
	    pLH = low1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5369
	    pHL = hi1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5370
	    pLL = low1 * low2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5371
	    pHH = hi1 * hi2;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5372
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5373
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5374
	     * the common case ...
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
	    if ((pHL == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5377
	     && (pLH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5378
	     && (pHH == 0)
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5379
	     && ((pLL & LLMASK) == 0)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5380
		if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5381
		    RETURN ( __mkSmallInteger(- ((INT)pLL)) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5382
		}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5383
		RETURN ( __mkSmallInteger((INT)pLL) );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5384
	    }
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
	    /*
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5387
	     *   pHH |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5388
	     *   pLH          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5389
	     *   pHL          |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5390
	     *   pLL                   |--------|--------|
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5391
	     */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5392
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5393
#     if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5394
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5395
	    productLow = (t << 32) + low32Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5396
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5397
#     else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5398
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5399
	    productLow = (t << 16) + low16Bits(pLL);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5400
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5401
#     endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5402
	}
19860
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5403
#    endif /* ! __win32__ */
324edacff5cc unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents: 19601
diff changeset
  5404
#   endif /* ! (__GNUC__ && __x86__) */
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5405
#  endif /* ! (__GNUC__ && __mc68k__) */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5406
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5407
	if (negative < 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5408
	    RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5409
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5410
	RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT)));
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5411
# endif /* ! USE_LONGLONG */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5412
    }
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5413
#endif /* not __SCHTEAM__ */
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5414
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5415
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5416
    self primitiveFailed
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
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5419
	5 times:-1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5420
	5 times:1
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5421
	self maxVal-1 times:2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5422
	self maxVal-1 times:-2
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5423
	self maxVal-1 * 2  bitAnd:16r3fffffff
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5424
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5425
! !
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5426
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5427
!SmallInteger methodsFor:'special modulo bit operators'!
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
bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5430
    "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
  5431
     (changes the sign)"
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5432
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5433
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5434
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5435
    unsigned INT v;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5436
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5437
    v = __intVal(self);
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5438
    v = ~v;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5439
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5440
    v &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5441
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5442
    RETURN ( __MKUINT(v) );
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5443
#endif
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5444
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5445
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5446
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
     1 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5449
     16r40000000 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5450
     16r80000000 bitInvert32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5451
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5452
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5453
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5454
bitRotate32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5455
    "return the value of the receiver rotated by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5456
     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
  5457
     Rotates through the sign bit.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5458
     Useful for crypt algorithms, or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5459
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5460
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5461
#ifndef __SCHTEAM__
16294
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
    unsigned INT bits;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5464
    int count;
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
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5467
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5468
	count = count % 32;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5469
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5470
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5471
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5472
	    bits = (bits << count) | (bits >> (32-count));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5473
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5474
	    bits = (bits >> (-count)) | (bits << (32-(-count)));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5475
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5476
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5477
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5478
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5479
	RETURN (__MKUINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5480
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5481
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5482
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5483
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5484
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
     128 rotate32:1
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
     1 rotate32:1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5489
     1 rotate32:2
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5490
     1 rotate32:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5491
     1 rotate32:32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5492
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5493
     1 rotate32:-1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5494
     1 rotate32:-2
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5495
     1 rotate32:-3
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5496
     1 rotate32:-32
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5497
    "
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5498
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5499
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5500
bitShift32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5501
    "return the value of the receiver shifted by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5502
     but only within 32 bits, shifting into/out-of the sign bit.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5503
     May be useful for communication interfaces, to create ST-numbers
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5504
     from a signed 32bit int value given as individual bytes,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5505
     or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5506
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5507
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5508
#ifndef __SCHTEAM__
16294
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
    INT bits, count;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5511
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5512
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5513
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5514
	if (count >= 32) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5515
	    RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5516
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5517
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5518
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5519
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5520
	    bits = bits << count;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5521
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5522
	    bits = bits >> (-count);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5523
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5524
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5525
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5526
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5527
	RETURN (__MKINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5528
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5529
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5530
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5531
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5532
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
     128 bitShift:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5535
     128 bitShift32:24
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
     1 bitShift:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5538
     1 bitShift32:31
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
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5541
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5542
bitXor32:aNumber
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5543
    "return the xor of the receiver and the argument.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5544
     The argument must be another SmallInteger or a 4-byte LargeInteger.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5545
     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
  5546
     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
  5547
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5548
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5549
#ifndef __SCHTEAM__
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5550
    INT rslt;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5551
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5552
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5553
# if __POINTER_SIZE__ == 8
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5554
    rslt &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5555
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5556
    RETURN ( __MKUINT(rslt));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5557
#endif
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5558
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5559
    self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5560
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
     16r7FFFFFFF bitXor: 16r80000000          4294967295
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5563
     16r7FFFFFFF bitXor32: 16r80000000
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
!
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5566
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5567
unsignedBitShift32:shiftCount
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5568
    "return the value of the receiver shifted by shiftCount bits,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5569
     but only within 32 unsigned bits.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5570
     May be useful for communication interfaces, to create ST-numbers
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5571
     from an unsigned 32bit int value given as individual byte,
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5572
     or to emulate C/Java semantics."
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5573
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5574
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5575
#ifndef __SCHTEAM__
16294
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
    unsigned INT bits;
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5578
    INT count;
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
    if (__isSmallInteger(shiftCount)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5581
	count = __intVal(shiftCount);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5582
	if (count >= 32) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5583
	    RETURN (__mkSmallInteger(0));
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5584
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5585
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5586
	bits = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5587
	if (count > 0) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5588
	    bits = bits << count;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5589
	} else {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5590
	    bits = bits >> (-count);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5591
	}
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5592
# if __POINTER_SIZE__ == 8
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5593
	bits &= 0xFFFFFFFFL;
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5594
# endif
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5595
	RETURN (__MKUINT(bits));
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5596
    }
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5597
#endif
16294
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5598
%}.
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5599
    ^ self primitiveFailed
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5600
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
     128 unsignedBitShift:24
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5603
     128 unsignedBitShift32:24
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
     1 unsignedBitShift:31
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5606
     1 unsignedBitShift32:31
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 unsignedBitShift32:-1
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5609
     -1 unsignedBitShift32:1
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
! !
a08b0365a4f1 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 16041
diff changeset
  5612
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5613
!SmallInteger methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5614
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5615
between:min and:max
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5616
    "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
  5617
     and less than or equal to the argument max.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5618
     - reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5619
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5620
%{  /* NOCONTEXT */
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5621
#ifdef __SCHTEAM__
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5622
    if (STObject.bothSmallInteger(min, max)) {
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5623
	long myVal = ((STInteger)self).longValue();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5624
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5625
	if (myVal >= ((STInteger)min).longValue()) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5626
	    if (myVal <= ((STInteger)max).longValue()) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5627
		return __c__._RETURN_true();
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5628
	    }
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5629
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5630
	return __c__._RETURN_false();
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5631
    }
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5632
#else /* not SCHTEAM */
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5633
    if (__bothSmallInteger(min, max)) {
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5634
# if TAG_INT == 1
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5635
	// tag bit does not change the magnitude order
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5636
	if ((INT)self < (INT)(min)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5637
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5638
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5639
	if ((INT)self > (INT)(max)) {
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
	RETURN ( true );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5643
# else
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5644
	REGISTER INT selfVal;
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5645
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5646
	selfVal = __intVal(self);
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5647
	if (selfVal < __intVal(min)) {
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5648
	     RETURN ( false );
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5649
	}
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5650
	if (selfVal > __intVal(max)) {
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
	RETURN ( true );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5654
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5655
    }
18289
Claus Gittinger <cg@exept.de>
parents: 18255
diff changeset
  5656
#endif /* not SCHTEAM */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5657
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5658
    (self < min) ifTrue:[^ false].
18395
b9ba2c56b13b comment
Claus Gittinger <cg@exept.de>
parents: 18382
diff changeset
  5659
    (max < self) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5660
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5661
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5662
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5663
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5664
    "return true, if the receiver is even"
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
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5667
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5668
    return __c__._RETURN( self.isEven() ? STObject.True : STObject.False );
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5669
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5670
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5671
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true );
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5672
#endif /* not SCHTEAM */
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5673
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5674
    ^ super even
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5675
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5676
23357
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5677
isImmediate
24186
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5678
    "return true if I am an immediate object
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5679
     i.e. I am represented in the pointer itself and
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5680
     no real object header/storage is used by me."
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5681
23357
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5682
    ^ true
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5683
ec2dcc40a786 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 22784
diff changeset
  5684
    "Created: / 18-09-2018 / 14:48:22 / Stefan Vogel"
24186
b3f0d3eb4ec0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24168
diff changeset
  5685
    "Modified (comment): / 27-05-2019 / 15:38:29 / Claus Gittinger"
23357
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
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5688
isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5689
    "return true, if the receiver is a power of 2"
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5690
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5691
    "/ 0 is not a power of two, because ld(0) is -INF
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5692
    ^ ((self bitAnd:(self - 1)) == 0) and:[self ~~ 0]
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5693
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5694
    "
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5695
     0 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5696
     1 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5697
     2 isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5698
     3 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5699
     4 isPowerOfTwo
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5700
     5 isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5701
     16r8000000000000000 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  5702
     16r8000000000000001 isPowerOfTwo
19057
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5703
     16r40000000 isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5704
     16r80000000 isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 19051
diff changeset
  5705
     16r100000000 isPowerOfTwo
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5706
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5707
     10000 factorial isPowerOfTwo
24100
9949ffc76053 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24006
diff changeset
  5708
     |n| n := 10000 factorial. Time millisecondsToRun:[10000 timesRepeat:[ n 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
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  5711
    "Modified: / 20-06-2011 / 12:41:18 / cg"
24100
9949ffc76053 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24006
diff changeset
  5712
    "Modified (comment): / 30-04-2019 / 23:13:01 / Claus Gittinger"
13386
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
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5715
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5716
    "return true, if the receiver is less than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5717
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5718
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5719
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5720
#ifdef __SCHTEAM__
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5721
    return context._RETURN( self.isLt_0() ? STObject.True : STObject.False);
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5722
    /* NOTREACHED */
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5723
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5724
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5725
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5726
    RETURN ( ((INT)(self) < 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5727
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5728
    RETURN ( (__intVal(self) < 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5729
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5730
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5731
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5732
    ^ self < 0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5733
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5734
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5735
nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5736
    "return the power of 2 at or above the receiver.
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5737
     Useful for padding.
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5738
     Notice, that for a powerOf2, the receiver is returned.
19263
6b090dfa8c32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 19133
diff changeset
  5739
     Also notice, that (because it is used for padding),
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5740
     0 is returned for zero."
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5741
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5742
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5743
#ifndef __SCHTEAM__
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5744
    INT x;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5745
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5746
    x = __intVal(self) - 1;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5747
    x |= (x >> 1);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5748
    x |= (x >> 2);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5749
    x |= (x >> 4);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5750
    x |= (x >> 8);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5751
    x |= (x >> 16);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5752
# if __POINTER_SIZE__ == 8
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5753
    x |= (x >> 32);
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5754
# endif
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5755
    RETURN (__MKINT(x + 1));
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5756
#endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5757
%}.
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5758
    ^ super nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5759
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5760
    "
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5761
     0 nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5762
     1 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5763
     2 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5764
     3 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5765
     4 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5766
     5 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5767
     6 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5768
     7 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5769
     8 nextPowerOf2
19060
2fe260c4796a #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19057
diff changeset
  5770
     9 nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5771
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5772
     22 nextPowerOf2
21107
079804a17e43 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20819
diff changeset
  5773
     32 nextPowerOf2
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5774
     16rFFFF nextPowerOf2 = 16r10000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5775
     16rFFFFFFFF nextPowerOf2 = 16r100000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5776
     16r1FFFFFFFFFFFFFFF nextPowerOf2 = 16r2000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5777
     16r3FFFFFFFFFFFFFFF nextPowerOf2 = 16r4000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5778
     16r7FFFFFFFFFFFFFFF nextPowerOf2 = 16r8000000000000000
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5779
     16rFFFFFFFFFFFFFFFF nextPowerOf2 = 16r10000000000000000
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5780
     10 factorial nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5781
     20 factorial nextPowerOf2
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5782
     100 factorial nextPowerOf2
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5783
    "
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5784
!
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  5785
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5786
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5787
    "return true, if the receiver is odd"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5788
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5789
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5790
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5791
    return __c__._RETURN( self.isEven() ? STObject.False : STObject.True );
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5792
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5793
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5794
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5795
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5796
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5797
    ^ super odd
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5798
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5799
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5800
parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5801
    "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
  5802
     (i.e. true for odd parity)
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5803
     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
  5804
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5805
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5806
#ifndef __SCHTEAM__
13913
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
    // tricky, but very fast (google for it, to understand)
18897
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5809
    unsigned INT v = __intVal(self);
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5810
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5811
# if __POINTER_SIZE__ == 8
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5812
    v ^= v >> 32;
562b990d5773 #REFACTORING
Claus Gittinger <cg@exept.de>
parents: 18864
diff changeset
  5813
# endif
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5814
    v ^= v >> 16;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5815
    v ^= v >> 8;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5816
    v ^= v >> 4;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5817
    v &= 0xf;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5818
    RETURN ( ( (0x6996 >> v) & 1 ) ? true : false );
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5819
#endif
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5820
%}.
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5821
    ^ super parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5822
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5823
    "
21700
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5824
	self assert:
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5825
	 (((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0])
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5826
	    asByteArray collect:[:c | c + $0 asciiValue]) asString
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5827
	 =
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5828
	    '0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110'
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5829
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5830
	self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5831
	self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5832
	self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5833
	self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5834
	self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5835
	self assert:(16r3FFFFFFFFFFFFFFF parityOdd = 16r3FFFFFFFFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5836
	self assert:(16r7FFFFFFFFFFFFFFF parityOdd = 16r7FFFFFFFFFFFFFFF bitCount odd).
bbf70646dfb6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 21444
diff changeset
  5837
	self assert:(16rFFFFFFFFFFFFFFFF parityOdd = 16rFFFFFFFFFFFFFFFF bitCount odd).
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5838
    "
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5839
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  5840
    "Modified (comment): / 09-01-2012 / 19:55:37 / cg"
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
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5843
positive
18864
5f4e0d1f6df1 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 18849
diff changeset
  5844
    "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
  5845
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5846
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5847
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5848
#ifdef __SCHTEAM__
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5849
    return context._RETURN( self.isGe_0() ? STObject.True : STObject.False);
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5850
    /* NOTREACHED */
18236
f5b870afebf4 java stuff
Claus Gittinger <cg@exept.de>
parents: 18234
diff changeset
  5851
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5852
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5853
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5854
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5855
    RETURN ( ((INT)(self) >= 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5856
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5857
    RETURN ( (__intVal(self) >= 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5858
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5859
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5860
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5861
    ^ super positive
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5862
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5863
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5864
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7438
diff changeset
  5865
    "return the sign of the receiver (-1, 0 or 1).
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5866
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5867
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5868
%{  /* NOCONTEXT */
18240
28af09029a8b ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents: 18236
diff changeset
  5869
#ifndef __SCHTEAM__
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5870
# if TAG_INT <= 1 /* tag in low bit */
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5871
    RETURN ( __mkSmallInteger( (((INT)self) > TAG_INT) - (((INT)self) < 0) ) );
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5872
# else
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  5873
    INT val = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5874
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5875
    RETURN ( __mkSmallInteger( (val > 0) - (val < 0) ) );
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5876
# endif
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5877
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5878
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5879
    ^ super sign
18760
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5880
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5881
    "
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5882
     -5 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5883
     -1 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5884
     0 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5885
     1 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5886
     5 sign
9b0b0c157e4c #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18699
diff changeset
  5887
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5888
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5889
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5890
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5891
    "return true, if the receiver is greater than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5892
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5893
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5894
%{  /* NOCONTEXT */
18904
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5895
#ifdef __SCHTEAM__
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5896
    return context._RETURN( self.isGt_0() ? STObject.True : STObject.False);
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5897
    /* NOTREACHED */
1c2c3d3d381e #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18898
diff changeset
  5898
#else
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5899
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5900
# if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5901
    /* tag bit does not change sign */
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5902
    RETURN ( ((INT)(self) > (INT)(__mkSmallInteger(0))) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5903
# else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  5904
    RETURN ( (__intVal(self) > 0) ? true : false );
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5905
# endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5906
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5907
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  5908
    ^ super strictlyPositive
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5909
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5910
    "
18227
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5911
     0 strictlyPositive
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5912
     1 strictlyPositive
709752f92664 java support
Claus Gittinger <cg@exept.de>
parents: 17689
diff changeset
  5913
     -1 strictlyPositive
17689
bf06c9fb45d2 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 17247
diff changeset
  5914
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5915
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5916
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  5917
!SmallInteger class methodsFor:'documentation'!
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
version
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5920
    ^ '$Header$'
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5921
!
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5922
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  5923
version_CVS
18592
43c80b6eb3f9 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 18410
diff changeset
  5924
    ^ '$Header$'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  5925
! !
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
  5926
15259
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5927
24161cb445cf class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 15131
diff changeset
  5928
SmallInteger initialize!