SmallInteger.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 18 Apr 2013 20:41:50 +0200
branchjv
changeset 18045 c0c600e0d3b3
parent 18027 3621469cc5e8
parent 15083 0b700edf1d1b
child 18053 e0683b878c4c
permissions -rw-r--r--
Merged d5a532ec3746 and 40a747a170c5 (branch default - CVS HEAD)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    12
"{ Package: 'stx:libbasic' }"
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Integer subclass:#SmallInteger
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
    15
	instanceVariableNames:''
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
    16
	classVariableNames:''
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
    17
	poolDictionaries:''
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
    18
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    21
!SmallInteger primitiveDefinitions!
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    22
%{
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    23
#include <stdio.h>
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    24
%}
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    25
! !
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
    26
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    27
!SmallInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 COPYRIGHT (c) 1988 by Claus Gittinger
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
    32
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    42
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    43
documentation
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    44
"
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    45
    SmallIntegers are Integers in the range of at least +/- 2^30
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
    46
    (i.e. 31 bits, which is not a guaranteed: on an alpha, 63 bits are used,
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
    47
     if the system was configured for 64bit mode).
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    48
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    49
    These are no real objects - they have no instances (not even storage !!)
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    50
    and cannot be subclassed.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    51
    The reason is to save both storage and runtime by not collecting
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    52
    SmallIntegers in the system. SmallInts are marked by having the TAG_INT
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
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    61
    [author:]
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
    62
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    63
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    64
    [see also:]
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
    65
	Number
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
    66
	Float Fraction FixedPoint
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
    67
	LargeInteger
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    68
"
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    69
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    71
!SmallInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
basicNew:size
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    82
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    83
a27a279701f8 Initial revision
claus
parents:
diff changeset
    84
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    87
!SmallInteger class methodsFor:'bit mask constants'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    88
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    89
bitMaskFor:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    90
    "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
    91
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    92
    (index between:1 and:SmallInteger maxBits) ifFalse:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    93
	^ SubscriptOutOfBoundsSignal
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    94
		raiseRequestWith:index
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    95
		errorString:'index out of bounds'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    96
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    97
    ^ 1 bitShift:(index - 1)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    98
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    99
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   100
!SmallInteger class methodsFor:'constants'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   101
a27a279701f8 Initial revision
claus
parents:
diff changeset
   102
maxBits
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   103
    "return the number of bits in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   104
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   107
    RETURN ( __mkSmallInteger(N_INT_BITS) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   108
%}
2
claus
parents: 1
diff changeset
   109
claus
parents: 1
diff changeset
   110
    "SmallInteger maxBits"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
maxBytes
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   114
    "return the number of bytes in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   115
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   118
    RETURN ( __mkSmallInteger(N_INT_BITS / 8 + 1) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
%}
2
claus
parents: 1
diff changeset
   120
3684
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   121
    "
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   122
     SmallInteger maxBytes
5ee1baf09f4f comment
Claus Gittinger <cg@exept.de>
parents: 3683
diff changeset
   123
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
maxVal
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   127
    "return the largest Integer representable as SmallInteger.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   128
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   131
    RETURN ( __mkSmallInteger(_MAX_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
%}
2
claus
parents: 1
diff changeset
   133
claus
parents: 1
diff changeset
   134
    "SmallInteger maxVal"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   135
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   136
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   137
minVal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   138
    "return the smallest Integer representable as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   139
     For very special uses only - not constant across implementations"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   140
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   141
%{  /* NOCONTEXT */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   142
    RETURN ( __mkSmallInteger(_MIN_INT) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   143
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   144
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   145
    "SmallInteger minVal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
   148
!SmallInteger class methodsFor:'queries'!
3
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   149
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   150
canBeSubclassed
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   151
    "return true, if its allowed to create subclasses of the receiver.
3914
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   152
     Return false here - since it is NOT possible for SmallInteger
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   153
     (due to the tagged representation of SmallIntegers)"
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   154
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   155
    ^ false
3914
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   156
1aa1ab6edb7e comment change
Claus Gittinger <cg@exept.de>
parents: 3909
diff changeset
   157
    "Modified: / 5.11.1998 / 16:11:27 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
2672
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   160
hasImmediateInstances
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   161
    "return true if this class has immediate instances
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   162
     i.e. if the instances are represented in the pointer itself and
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4644
diff changeset
   163
     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
   164
     Redefined from Behavior"
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   165
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   166
    ^ true
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   167
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   168
    "Created: 3.6.1997 / 12:01:26 / cg"
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   169
!
dc3662188b2c added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents: 2653
diff changeset
   170
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   171
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   172
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   173
     Here, true is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   174
a27a279701f8 Initial revision
claus
parents:
diff changeset
   175
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   176
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   177
    "Modified: 23.4.1996 / 16:00:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   178
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   179
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
!SmallInteger methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
a27a279701f8 Initial revision
claus
parents:
diff changeset
   182
* aNumber
11728
0c197f1c3cd0 comment
Claus Gittinger <cg@exept.de>
parents: 11718
diff changeset
   183
    "return the product of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   184
a27a279701f8 Initial revision
claus
parents:
diff changeset
   185
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   186
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   187
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   188
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   189
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   190
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   191
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   192
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   193
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   194
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   195
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   196
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   197
    INT myValue, otherValue;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   198
    unsigned INT productLow, productHi;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   199
    int negative;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   200
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   201
#   define low16Bits(foo)  ((foo) & 0xFFFF)
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   202
#   define hi16Bits(foo)   ((foo) >> 16)
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   203
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   204
#   define hi32Bits(foo)   ((foo) >> 32)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   205
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   206
    /*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   207
     * can we use long long arithmetic ?
4176
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   208
     *
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   209
     * long-long arithmetic seems to be buggy with some systems
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   210
     * (took me a while to find this out :-(
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   211
     * (try 10000 * 10000)
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   212
     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   213
#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
4184
c7ee6f329db2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4183
diff changeset
   214
# define USE_LONGLONG_FOR_MUL
4176
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   215
#endif
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   216
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   217
#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
4184
c7ee6f329db2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4183
diff changeset
   218
# define USE_LONGLONG_FOR_MUL
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   219
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
252
   221
    if (__isSmallInteger(aNumber)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   222
	myValue = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   223
	otherValue = __intVal(aNumber);
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   224
4184
c7ee6f329db2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4183
diff changeset
   225
#if defined(USE_LONGLONG_FOR_MUL)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   226
	{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   227
# if defined(__alpha__) && !defined(__alpha64__)
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   228
#  define LONGLONG      INT64
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   229
# else
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   230
#  define LONGLONG      long long
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
   231
# endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   232
	    LONGLONG product;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   233
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   234
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   235
	    if ((product >= (LONGLONG)_MIN_INT)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   236
	     && (product <= (LONGLONG)_MAX_INT)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   237
		RETURN ( __mkSmallInteger((INT)product) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   238
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   239
	    if (product < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   240
		negative = -1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   241
		product = -product;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   242
	    } else {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   243
		negative = 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   244
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   245
	    productHi = product >> 32;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   246
	    productLow = product & 0xFFFFFFFFL;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   247
	}
4176
561cf576eb0a fixed * (for sparc)
Claus Gittinger <cg@exept.de>
parents: 4167
diff changeset
   248
#else /* no long-long */
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   249
	negative = 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   250
	if (myValue < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   251
	    negative = -1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   252
	    myValue = -myValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   253
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   254
	if (otherValue < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   255
	    negative = -negative;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   256
	    otherValue = -otherValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   257
	}
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   258
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   259
# if defined(__GNUC__) && defined(__mc68k__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   260
	asm ("mulu%.l %3,%1:%0"
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   261
		: "=d"  ((unsigned long)(productLow)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   262
		  "=d"  ((unsigned long)(productHi))
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   263
		: "%0"  ((unsigned long)(myValue)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   264
		  "dmi" ((unsigned long)(otherValue)));
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   265
# else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   266
#  if defined (__GNUC__) && defined(__i386__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   267
	asm ("mull %3"
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   268
		: "=a"  ((unsigned long)(productLow)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   269
		  "=d"  ((unsigned long)(productHi))
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   270
		: "%0"  ((unsigned long)(myValue)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   271
		  "rm"  ((unsigned long)(otherValue)));
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   272
#  else
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
   273
#   if defined(WIN32) && defined(__BORLANDC__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   274
	asm {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   275
	    mov   eax, myValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   276
	    mov   edx, otherValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   277
	    mul   edx
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   278
	    mov   productLow, eax
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   279
	    mov   productHi, edx
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   280
	}
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   281
#   else /* generic */
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   282
	{
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   283
	    unsigned INT pHH, pHL, pLH, pLL;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   284
	    unsigned INT low1, low2, hi1, hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   285
	    unsigned INT t;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   286
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   287
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   288
	     *
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   289
	     * this is too slow:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   290
	     * since most machines can do 32*32 to 64 bit multiply,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   291
	     * (or at least 32*32 with Overflow check)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   292
	     * - need more assembler (inline) functions here
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   293
	     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   294
#    if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   295
	    low1 = low32Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   296
	    hi1 = hi32Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   297
	    low2 = low32Bits((unsigned INT)otherValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   298
	    hi2 = hi32Bits((unsigned INT)otherValue);
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   299
#     define LLMASK 0xC000000000000000L
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   300
#    else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   301
	    low1 = low16Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   302
	    hi1 = hi16Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   303
	    low2 = low16Bits((unsigned INT)otherValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   304
	    hi2 = hi16Bits((unsigned INT)otherValue);
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   305
#     define LLMASK 0xC0000000
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   306
#    endif
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   307
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   308
	    pLH = low1 * hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   309
	    pHL = hi1 * low2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   310
	    pLL = low1 * low2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   311
	    pHH = hi1 * hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   312
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   313
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   314
	     * the common case ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   315
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   316
	    if ((pHL == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   317
	     && (pLH == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   318
	     && (pHH == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   319
	     && ((pLL & LLMASK) == 0)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   320
		if (negative < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   321
		    RETURN ( __mkSmallInteger(- ((INT)pLL)) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   322
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   323
		RETURN ( __mkSmallInteger((INT)pLL) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   324
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   325
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   326
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   327
	     *   pHH |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   328
	     *   pLH          |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   329
	     *   pHL          |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   330
	     *   pLL                   |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   331
	     */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   332
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   333
#    if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   334
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   335
	    productLow = (t << 32) + low32Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   336
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   337
#    else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   338
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   339
	    productLow = (t << 16) + low16Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   340
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   341
#    endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   342
	}
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   343
#   endif /* ! WIN32 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   344
#  endif /* ! (__GNUC__ && __i386__) */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   345
# endif /* ! (__GNUC__ && __mc68k__) */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   346
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   347
	if (productHi == 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   348
	    if (negative < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   349
		if (productLow <= -(_MIN_INT)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   350
		    RETURN ( __mkSmallInteger(-((INT)productLow)) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   351
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   352
	    } else {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   353
		if (productLow <= _MAX_INT) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   354
		    RETURN ( __mkSmallInteger(productLow) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   355
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   356
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   357
	}
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   358
#endif /* ! USE_LONGLONG */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   359
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
   360
#if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   361
	RETURN (__MKLARGEINT128(negative, productLow, productHi));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
   362
#else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   363
	RETURN (__MKLARGEINT64(negative, productLow, productHi));
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   364
#endif
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   365
    } else if (__isFloatLike(aNumber)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   366
	OBJ newFloat;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   367
	double val = (double)__intVal(self) * __floatVal(aNumber);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   368
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   369
	__qMKFLOAT(newFloat, val);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   370
	RETURN ( newFloat );
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   371
    } else if (__isShortFloat(aNumber)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   372
	OBJ newFloat;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   373
	float val = (float)__intVal(self) * __shortFloatVal(aNumber);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   374
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   375
	__qMKSFLOAT(newFloat, val);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   376
	RETURN ( newFloat );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   377
    }
2641
Claus Gittinger <cg@exept.de>
parents: 2640
diff changeset
   378
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
    ^ aNumber productFromInteger:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   380
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   382
+ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   383
    "return the sum of the receivers value and the arguments value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   384
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   385
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   386
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   387
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   388
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   389
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   390
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   391
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   392
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   393
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   394
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   395
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   396
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   397
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   398
#ifdef _ADD_IO_IO
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   399
	RETURN ( _ADD_IO_IO(self, aNumber) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   400
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   401
	REGISTER INT sum;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   402
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   403
	sum =  __intVal(self) + __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   404
	if (__ISVALIDINTEGER(sum)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   405
	    RETURN ( __mkSmallInteger(sum) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   406
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   407
	RETURN ( __MKLARGEINT(sum) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   408
#endif
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   409
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   410
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   411
	OBJ newFloat;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   412
	double val = (double)__intVal(self) + __floatVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   413
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   414
	__qMKFLOAT(newFloat, val);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   415
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   416
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   417
    if (__isShortFloat(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   418
	OBJ newFloat;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   419
	float val = (float)__intVal(self) + __shortFloatVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   420
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   421
	__qMKSFLOAT(newFloat, val);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   422
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   423
    }
3532
4b1a5cc57f8f added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents: 3458
diff changeset
   424
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   425
    ^ aNumber sumFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   426
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   427
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   428
- aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   429
    "return the difference of the receivers value and the arguments value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   430
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   431
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   432
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   433
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   434
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   435
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   436
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   437
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   438
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   439
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   440
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   441
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   442
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   443
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   444
#ifdef _SUB_IO_IO
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   445
	RETURN ( _SUB_IO_IO(self, aNumber) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   446
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   447
	REGISTER INT diff;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   448
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   449
	diff =  __intVal(self) - __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   450
	if (__ISVALIDINTEGER(diff)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   451
	    RETURN ( __mkSmallInteger(diff) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   452
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   453
	RETURN ( __MKLARGEINT(diff) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   454
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   455
    }
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   456
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   457
	OBJ newFloat;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   458
	double val = (double)__intVal(self) - __floatVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   459
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   460
	__qMKFLOAT(newFloat, val);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   461
	RETURN ( newFloat );
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   462
    }
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   463
    if (__isShortFloat(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   464
	OBJ newFloat;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   465
	float val = (float)__intVal(self) - __shortFloatVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   466
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   467
	__qMKSFLOAT(newFloat, val);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   468
	RETURN ( newFloat );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   469
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   470
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   471
    ^ aNumber differenceFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   472
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   473
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
    "return the quotient of the receivers value and the arguments value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
a27a279701f8 Initial revision
claus
parents:
diff changeset
   477
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   478
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   479
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   480
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   481
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   482
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   483
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   484
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   485
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   486
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   487
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   488
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
    INT me, t, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
    double dval;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
252
   492
    if (__isSmallInteger(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   493
	val = __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   494
	if (val != 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   495
	    me = __intVal(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   496
	    t = me / val;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   497
#ifdef GOOD_OPTIMIZER
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   498
	    if (me % val == 0) {
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   499
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   500
	    /* this is stupid - all I want is to look for a remainder ...
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   501
	       but most compilers are too stupid and generate an extra modulus
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   502
	       instruction for "if (me % val)".
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   503
	       Even if most divide instructions already leave the remainder in
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   504
	       some register.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   505
	       Therefore I use a multiplication which is faster than a modulo
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   506
	       on most machines. Hint to GNU people :-)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   507
	    */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   508
	    if ((t * val) == me) {
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   509
#endif
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   510
		RETURN ( __mkSmallInteger(t) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   511
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   512
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   513
    } else {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   514
	if (__isFloatLike(aNumber)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   515
	    dval = __floatVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   516
	    if (dval != 0.0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   517
		OBJ newFloat;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   518
		double val = (double)__intVal(self) / dval;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   519
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   520
		__qMKFLOAT(newFloat, val);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   521
		RETURN ( newFloat );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   522
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   523
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   524
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   525
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   526
    aNumber isInteger ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   527
	aNumber == 0 ifTrue:[
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   528
	    ^ ZeroDivide raiseRequestWith:thisContext.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   529
	].
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   530
	^ Fraction numerator:self denominator:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   532
    ^ aNumber quotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   533
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   534
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   535
     8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   536
     9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   537
     9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   538
     9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   539
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   540
     -8 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   541
     -9 / 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   542
     -9 // 4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   543
     -9 quo:4
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   544
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
2
claus
parents: 1
diff changeset
   547
// aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
    "return the integer part of the quotient of the receivers value
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   549
     and the arguments value. The result is truncated toward negative infinity
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   550
     and negative, if the operands signs differ.
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   551
     Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   552
     Especially surprising:     
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   553
        -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   554
     The following is always true:
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   555
        (receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   556
     See #quo: which returns -2 in the latter."
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   557
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   558
%{  /* NOCONTEXT */
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   559
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   560
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   561
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   562
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   563
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   564
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   565
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   566
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   567
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   568
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   569
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   570
    INT dividend, divisor, rslt;
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   571
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   572
    if (__isSmallInteger(aNumber)) {
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   573
        divisor = __intVal(aNumber);
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   574
        if (divisor != 0) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   575
            dividend = __intVal(self);
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   576
            rslt = dividend / divisor;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   577
            /*
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   578
             * Optimized to speed up positive result
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   579
             */
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   580
            if (rslt <= 0) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   581
                if (rslt == 0) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   582
                    if ((dividend ^ divisor) < 0) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   583
                        /*
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   584
                         * result (negative) has been truncated toward 0.
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   585
                         * Return -1, because we truncate toward negative inf.
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   586
                         */
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   587
                         rslt = -1;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   588
                    }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   589
                } else {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   590
                    /*
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   591
                     * If result (negative) has been truncated toward 0,
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   592
                     * subtract 1, because we truncate toward negative inf.
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   593
                     */
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   594
                    if (divisor > 0) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   595
                        if (rslt * divisor > dividend) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   596
                            rslt--;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   597
                        }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   598
                    } else {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   599
                        if (rslt * divisor < dividend) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   600
                            rslt--;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   601
                        }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   602
                    }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   603
                }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   604
            }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   605
            RETURN ( __mkSmallInteger(rslt) );
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   606
        }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   607
    } else {
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   608
        if (__isFraction(aNumber)) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   609
            OBJ t;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   610
            INT num, den;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   611
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   612
            t = __FractionInstPtr(aNumber)->f_numerator;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   613
            if (__isSmallInteger(t)) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   614
                num = __intVal(t);
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   615
                t = __FractionInstPtr(aNumber)->f_denominator;
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   616
                if (__isSmallInteger(t)) {
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   617
                    den = __intVal(t);
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   618
                    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   619
                }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   620
            }
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   621
        }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   622
    }
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   623
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   624
    (aNumber = 0) ifTrue:[
14795
21ddbafc7a30 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14755
diff changeset
   625
        ^ ZeroDivide raiseRequestWith:thisContext.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   626
    ].
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   627
    ^ aNumber integerQuotientFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   628
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   629
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   630
     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
   631
     -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
   632
     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
   633
     -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
   634
     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
   635
     -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
   636
     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
   637
     -1 // -2   ~~ 0 ifTrue:[self halt].
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   638
     10000 // 3600000 ~~ 0 ifTrue:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   639
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   640
     9 quo:4   => 2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   641
     -9 quo:4  => -2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   642
     9 quo:-4  => -2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   643
     -9 quo:-4 => 2
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   644
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   645
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   646
    "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
   647
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   648
2
claus
parents: 1
diff changeset
   649
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   650
    "Answer the integer remainder m defined by division with truncation toward
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   651
     negative infinity. The remainder has the same sign as aNumber.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   652
     m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   653
     The following is always true:
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   654
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   655
     Compare with #rem:
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   656
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   657
     Redefined for speed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
%{  /* NOCONTEXT */
6064
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   660
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   661
    /*
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   662
     * notice:
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   663
     * the following inline code handles some common cases,
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   664
     * and exists as an optimization, to speed up those cases.
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   665
     *
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   666
     * Conceptionally, (and for most other argument types),
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   667
     * mixed arithmetic is implemented by double dispatching
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   668
     * (see the message send at the bottom)
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   669
     */
04bde2eeb749 comments about double dispatching
Claus Gittinger <cg@exept.de>
parents: 5988
diff changeset
   670
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   671
    INT dividend, divisor, rem;
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   672
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   673
    if (__isSmallInteger(aNumber)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   674
	&& (divisor = __intVal(aNumber)) != 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   675
	/*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   676
	 * Note that the sign of something modulo a negative number is undefined
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   677
	 * in C!
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   678
	 */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   679
	dividend = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   680
	rem = dividend % divisor;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   681
	if (rem) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   682
	    if ((rem ^ divisor) < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   683
		/* sign of remainder is different from sign of divisor */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   684
		rem = -rem;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   685
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   686
	    if ((dividend ^ divisor) < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   687
		/* different signs, so division would have returned a
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   688
		 * negative number.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   689
		 * C rounds toward zero, this code will simulate
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   690
		 * rounding towards negative infinity.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   691
		 */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   692
		rem = divisor - rem;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   693
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   694
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   695
	RETURN ( __mkSmallInteger(rem) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   696
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   697
%}.
2
claus
parents: 1
diff changeset
   698
    (aNumber = 0) ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   699
	^ ZeroDivide raiseRequestWith:thisContext.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   700
    ].
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   701
    ^ aNumber moduloFromInteger:self
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   702
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   703
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
   704
     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
   705
     -9 \\ 4 == 3 ifFalse:[self halt].
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   706
     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
   707
     -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
   708
     (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
   709
     (-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
   710
     1000 \\ 3600000 == 1000 ifFalse:[self halt]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   711
    "
13006
fee441070661 changed:
Claus Gittinger <cg@exept.de>
parents: 12977
diff changeset
   712
14003
727df70aa9f5 changed: #\\
Claus Gittinger <cg@exept.de>
parents: 13991
diff changeset
   713
    "Modified: / 12-02-2012 / 20:43:40 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   715
a27a279701f8 Initial revision
claus
parents:
diff changeset
   716
abs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   717
    "return the absolute value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   718
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
a27a279701f8 Initial revision
claus
parents:
diff changeset
   720
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   721
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   722
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   723
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   724
    if (val >= 0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   725
	RETURN (self);
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   726
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
    if (val != _MIN_INT) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   728
	RETURN ( __mkSmallInteger(-val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   729
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   730
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   731
    RETURN( __MKLARGEINT(-_MIN_INT));
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   732
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   733
    ^ super abs
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   734
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   735
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   737
    "return the negative value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   738
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   739
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   742
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   743
a27a279701f8 Initial revision
claus
parents:
diff changeset
   744
    if (val != _MIN_INT) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   745
	RETURN ( __mkSmallInteger(- val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   746
    }
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   747
    /* only reached for minVal */
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   748
    RETURN (__MKLARGEINT( -_MIN_INT));
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   749
%}.
5410
859c010edb47 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5240
diff changeset
   750
    ^ 0 - self
3430
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   751
"/    "only reached for minVal"
e42beefa71e7 better abs & negated
Claus Gittinger <cg@exept.de>
parents: 3189
diff changeset
   752
"/    ^ (LargeInteger value:(SmallInteger maxVal)) + 1
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   753
!
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   754
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   755
quo:aNumber
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   756
    "return the integer part of the quotient of the receivers value
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   757
     and the arguments value. The result is truncated towards zero
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   758
     and negative, if the operands signs differ..
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6064
diff changeset
   759
     The following is always true:
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   760
	(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
   761
     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
   762
     for negative results, the remainder is ignored.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   763
     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
   764
     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
   765
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   766
%{  /* NOCONTEXT */
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   767
    INT val;
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   768
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   769
    if (__isSmallInteger(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   770
	val = __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   771
	if (val != 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   772
	    RETURN ( __mkSmallInteger(__intVal(self) / val) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   773
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   774
    } else {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   775
	if (__isFraction(aNumber)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   776
	    OBJ t;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   777
	    INT num, den;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   778
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   779
	    t = __FractionInstPtr(aNumber)->f_numerator;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   780
	    if (__isSmallInteger(t)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   781
		num = __intVal(t);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   782
		t = __FractionInstPtr(aNumber)->f_denominator;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   783
		if (__isSmallInteger(t)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   784
		    den = __intVal(t);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   785
		    RETURN ( __mkSmallInteger(__intVal(self) * den / num ));
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   786
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   787
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   788
	}
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   789
    }
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   790
%}.
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   791
    (aNumber = 0) ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   792
	^ ZeroDivide raiseRequestWith:thisContext.
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   793
    ].
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   794
    ^ self retry:#quo: coercing:aNumber
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   795
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   796
    "
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   797
     9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   798
     -9 // 4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   799
     9 quo:4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   800
     -9 quo:4
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   801
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   802
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   803
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   804
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   805
!SmallInteger methodsFor:'bit operators'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   806
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   807
bitAnd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   808
    "return the bitwise-and of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   809
a27a279701f8 Initial revision
claus
parents:
diff changeset
   810
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   811
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   812
    /* anding the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   813
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   814
	RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   815
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   816
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
   817
    anInteger class == LargeInteger ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   818
	^ anInteger bitAnd:self
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
   819
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   820
    ^ self retry:#bitAnd: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   821
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   822
    "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   823
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   824
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   825
bitAt:anIntegerIndex
11500
6afe4d6e867c changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11493
diff changeset
   826
    "return the value of the index's bit (index starts at 1) as 0 or 1.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   827
     Notice: the result of bitAt: on negative receivers is not
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   828
	     defined in the language standard (since the implementation
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   829
	     is free to choose any internal representation for integers)"
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
   830
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   831
%{  /* NOCONTEXT */
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   832
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   833
    if (__isSmallInteger(anIntegerIndex)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   834
	INT idx = __smallIntegerVal(anIntegerIndex);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   835
	if (idx > 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   836
	    if (idx > N_INT_BITS) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   837
		RETURN(__mkSmallInteger(0));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   838
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   839
	    RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   840
	}
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   841
    }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   842
%}.
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   843
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   844
    ^ SubscriptOutOfBoundsSignal
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   845
	    raiseRequestWith:anIntegerIndex
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   846
	    errorString:'index out of bounds'
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
   847
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
   848
    "
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
   849
     16r00000001 bitAt:0
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   850
     16r00000001 bitAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   851
     16r00000001 bitAt:2
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   852
     16r00008000 bitAt:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   853
     16r00800000 bitAt:24
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   854
     16r08000000 bitAt:28
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
   855
     16r10000000 bitAt:29
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   856
     16r20000000 bitAt:30
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   857
     16r40000000 bitAt:31
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   858
     16r80000000 bitAt:32
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   859
     16r100000000 bitAt:33
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
   860
    "
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   861
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   862
" Smalltalk implementation:
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   863
    |mask|
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   864
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   865
    anIntegerIndex <= 0 ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   866
	^ SubscriptOutOfBoundsSignal
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   867
		raiseRequestWith:anIntegerIndex
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   868
		errorString:'index out of bounds'
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   869
    ].
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   870
    (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0].
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   871
    mask := 1 bitShift:(anIntegerIndex - 1).
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   872
    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   873
    ^ 1
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7746
diff changeset
   874
"
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
   875
!
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
   876
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   877
bitClear:anInteger
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   878
    "return the bitwise-and of the receiver and the complement of the argument, anInteger,
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   879
     returning the receiver with bits of the argument cleared."
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   880
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   881
%{  /* NOCONTEXT */
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   882
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   883
    /* anding the tags doesn't change it */
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   884
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   885
	RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   886
    }
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   887
%}.
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   888
    ^ self retry:#bitClear: coercing:anInteger
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   889
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   890
    "
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   891
     (2r001010100 bitClear:2r00001111) radixPrintStringRadix:2
5458
2aa89d4fad64 example
Claus Gittinger <cg@exept.de>
parents: 5447
diff changeset
   892
     (2r111111111 bitClear:2r00001000) radixPrintStringRadix:2
3156
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   893
    "
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   894
!
3d63afe752e5 added #bitClear:
Claus Gittinger <cg@exept.de>
parents: 3135
diff changeset
   895
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   896
bitCount
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   897
    "return the number of 1-bits in the receiver"
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   898
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   899
%{  /* NOCONTEXT */
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   900
    unsigned int _cnt;
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   901
    unsigned INT _self = __intVal(self);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   902
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   903
#define ALGORIHTM_3
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   904
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   905
#ifdef ALGORITHM_1
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   906
    // old k&r code; might be better if only one or two bits are set
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   907
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   908
    _cnt = 0;
11666
f30bc3b65e88 tricky bitCount
Claus Gittinger <cg@exept.de>
parents: 11519
diff changeset
   909
    while (_self) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   910
	_cnt++;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   911
	_self = _self & (_self - 1);
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   912
    }
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   913
#else
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   914
# ifdef ALGORITHM_2
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   915
    // seems to be faster on the average (and has better worst case)
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   916
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   917
    static unsigned char table[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   918
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   919
    _cnt = 0;
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   920
    while (_self) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   921
	_cnt += table[ _self & 0x0F ];
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   922
	_self >>= 4;
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   923
    }
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   924
# else
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   925
#  ifdef ALGORIHTM_3
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   926
    // the fastest, but hard (impossible) to understand (google for fastest bit count)
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   927
#   if __POINTER_SIZE__ == 8
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   928
    unsigned int _v1, _v2;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   929
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   930
    _v1 = _self & 0xFFFFFFFF;
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   931
    _v1 = _v1 - ((_v1 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   932
    _v1 = (_v1 & 0x33333333) + ((_v1 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   933
    _v1 = ((_v1 + (_v1 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   934
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   935
    _v2 = (unsigned int)(_self >> 32);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   936
    _v2 = _v2 - ((_v2 >> 1) & 0x55555555);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   937
    _v2 = (_v2 & 0x33333333) + ((_v2 >> 2) & 0x33333333);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   938
    _v2 = ((_v2 + (_v2 >> 4)) & 0x0F0F0F0F);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   939
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   940
    _cnt = ((_v1 * 0x01010101) >> 24) + ((_v2 * 0x01010101) >> 24);
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   941
#   else
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   942
    _cnt = _self - ((_self >> 1) & 0x55555555);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   943
    _cnt = (_cnt & 0x33333333) + ((_cnt >> 2) & 0x33333333);
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   944
    _cnt = ((_cnt + (_cnt >> 4)) & 0x0F0F0F0F);
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   945
    _cnt = (_cnt * 0x01010101) >> 24;
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   946
#   endif
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   947
#  else
13911
9e50b24f059a changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13909
diff changeset
   948
     error error error
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   949
#  endif
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   950
# endif
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   951
#endif
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   952
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   953
    RETURN ( __MKSMALLINT(_cnt));
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   954
%}
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   955
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   956
    "
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   957
     1 to:1000000 do:[:n |
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   958
	self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
13909
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
   959
     ].
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
   960
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   961
     #(
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   962
	16r00010000 16r00100000 16r01000000 16r10000000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   963
	16r00020000 16r00200000 16r02000000 16r20000000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   964
	16r00040000 16r00400000 16r04000000 16r40000000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   965
	16r00080000 16r00800000 16r08000000 16r80000000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   966
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   967
	16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   968
	16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   969
	16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   970
	16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC
13909
8a4aee47b4ca changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13908
diff changeset
   971
     ) do:[:n |
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   972
	self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   973
     ]
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   974
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   975
     1 to:10000000 do:[:n |
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
   976
	(n bitCount)
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   977
     ]
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   978
    "
13908
Claus Gittinger <cg@exept.de>
parents: 13386
diff changeset
   979
13912
8a9a892c83a3 changed: #bitCount
Claus Gittinger <cg@exept.de>
parents: 13911
diff changeset
   980
    "Modified: / 09-01-2012 / 19:12:41 / cg"
11493
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   981
!
6496a8ef2fc9 +bitCount
Claus Gittinger <cg@exept.de>
parents: 10972
diff changeset
   982
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   983
bitInvert
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   984
    "return the value of the receiver with all bits inverted"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   985
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   986
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   987
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   988
    /* invert anything except tag bits */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   989
    RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   990
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   991
    ^ self primitiveFailed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   992
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   993
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   994
bitOr:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   995
    "return the bitwise-or of the receiver and the argument, anInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   996
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   997
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   998
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   999
    /* oring the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1000
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1001
	RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1002
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1003
%}.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1004
    ^ self retry:#bitOr: coercing:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1005
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1006
    "
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1007
     (2r000000100 bitOr:2r00000011) radixPrintStringRadix:2
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1008
     (0 bitOr:16r20000000) hexPrintString
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1009
     (0 bitOr:16r40000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1010
     (0 bitOr:16r80000000) hexPrintString
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1011
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1012
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1013
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1014
bitShift:shiftCount
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1015
    "return the value of the receiver shifted by shiftCount bits;
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1016
     leftShift if shiftCount > 0; rightShift otherwise.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1017
     Notice: the result of bitShift: on negative receivers is not
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1018
	     defined in the language standard (since the implementation
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1019
	     is free to choose any internal representation for integers).
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1020
	     However, ST/X preserves the sign."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1021
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1022
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1023
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1024
    INT bits, count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1025
252
  1026
    if (__isSmallInteger(shiftCount)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1027
	bits = __intVal(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1028
	if (bits == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1029
	    RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1030
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1031
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1032
	count = __intVal(shiftCount);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1033
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1034
	if (count > 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1035
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1036
	     * a left shift
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1037
	     */
4183
4a745f6f47b6 oops - longlong shift fails with i386,GCC
Claus Gittinger <cg@exept.de>
parents: 4177
diff changeset
  1038
#if defined(USE_LONGLONG_FOR_SHIFT)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1039
	    if (count <= N_INT_BITS) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1040
		unsigned LONGLONG result;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1041
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1042
		result = (unsigned LONGLONG)bits;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1043
		result <<= count;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1044
		if (result <= _MAX_INT) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1045
		    RETURN ( __mkSmallInteger(result) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1046
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1047
		{
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1048
		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1049
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1050
	    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1051
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1052
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1053
	     * check for overflow
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1054
	     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1055
	    if (count < (N_INT_BITS-1)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1056
		if (! (bits >> (N_INT_BITS - 1 - count))) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1057
		    RETURN ( __mkSmallInteger(bits << count) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1058
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1059
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1060
		 * so, there is an overflow ...
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1061
		 * handle it as largeInteger
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1062
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1063
		/* FALL THROUGH */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1064
	    }
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
  1065
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1066
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1067
	    if (count == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1068
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1069
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1070
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1071
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1072
	     * right shifts cannot overflow
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1073
	     *
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1074
	     * some machines ignore shifts bigger than
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1075
	     * the number of bits in an int ...
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1076
	     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1077
	    count = -count;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1078
	    if (count > (N_INT_BITS-1)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1079
		RETURN (__mkSmallInteger(0));
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1080
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1081
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1082
	    RETURN ( __mkSmallInteger(bits >> count) );
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1083
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1084
    }
85
claus
parents: 77
diff changeset
  1085
%}.
claus
parents: 77
diff changeset
  1086
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1087
	^ (LargeInteger value:self) bitShift:shiftCount
85
claus
parents: 77
diff changeset
  1088
    ].
6400
3746d31f044a bitShift:float trouble fixed.
Claus Gittinger <cg@exept.de>
parents: 6344
diff changeset
  1089
    ^ self bitShift:(1 coerce:shiftCount)   "/ is this a good idea ?
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1090
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1091
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1092
bitTest:aMask
5782
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1093
    "return true, if any bit from aMask is set in the receiver.
dcc037e5bdbf comment change
Claus Gittinger <cg@exept.de>
parents: 5496
diff changeset
  1094
     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
  1095
     is non-0, false otherwise."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1096
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1097
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1098
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1099
    /* and all bits except tag */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1100
    if (__isSmallInteger(aMask)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1101
	RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1102
    }
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1103
%}.
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1104
    aMask class == LargeInteger ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1105
	^ (aMask bitAnd:self) ~~ 0
4613
a722d598c1bb faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents: 4523
diff changeset
  1106
    ].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1107
    ^ self retry:#bitTest: coercing:aMask
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1108
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1109
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1110
     2r10001 bitTest:2r00001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1111
     2r10001 bitTest:2r00010
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1112
     2r10001 bitTest:2r00100
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1113
     2r10001 bitTest:2r01000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1114
     2r10001 bitTest:2r10000
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1115
     2r10001 bitTest:2r10001
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1116
     2r10001 bitTest:2r10010
11519
657e60b50dce comment in bitTest:
Claus Gittinger <cg@exept.de>
parents: 11506
diff changeset
  1117
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1118
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1119
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1120
bitXor:anInteger
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1121
    "return the bitwise-exclusive-or of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1122
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1123
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1124
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1125
    /* xoring the tags turns it off - or it in again */
252
  1126
    if (__isSmallInteger(anInteger)) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1127
	RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1128
    }
1716
52fc3e02c5bd use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  1129
%}.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  1130
    ^ self retry:#bitXor: coercing:anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1131
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1132
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1133
clearBit:anInteger
8937
4f2508548327 comment
Claus Gittinger <cg@exept.de>
parents: 8919
diff changeset
  1134
    "return a new integer where the specified bit is off.
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1135
     Bits are counted from 1 starting with the least significant.
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1136
     The methods name may be missleading: the receiver is not changed,
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1137
     but a new number is returned. Should be named #withBitCleared:"
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1138
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1139
%{  /* NOCONTEXT */
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1140
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1141
    if (__isSmallInteger(anInteger)) {
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1142
	int index = __intVal(anInteger);
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1143
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1144
	if (index > 0) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1145
#if __POINTER_SIZE__ == 8
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1146
	    if (index <= 62)
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1147
#else
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1148
	    if (index <= 30)
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1149
#endif
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1150
	    {
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1151
		INT mask = __MASKSMALLINT(1 << (index-1));
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1152
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1153
		RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1154
	    }
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1155
	    RETURN (self);  /* nothing to do ... */
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1156
	}
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1157
    }
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1158
%}.
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1159
    ^ super clearBit:anInteger
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1160
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1161
    "
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1162
     (16r401 clearBit:1     ) hexPrintString
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1163
     (16r401 clearBit:0     ) hexPrintString
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1164
     (16r3fffffff clearBit:1) hexPrintString
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1165
     (16r3fffffff clearBit:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1166
     (16r3fffffff clearBit:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1167
     (16r3fffffff clearBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1168
     (16r3fffffff bitAt:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1169
     (16r3fffffff bitAt:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1170
     (16r3fffffff bitAt:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1171
     (16r40000001 clearBit:1) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1172
     (16rF0000001 clearBit:29) hexPrintString
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1173
     (16rF0000001 clearBit:30) hexPrintString
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1174
     (16rF0000001 clearBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1175
     (16rF0000001 clearBit:32) hexPrintString
3683
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1176
    "
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1177
!
2eac599d04c1 fixed clearBit:
Claus Gittinger <cg@exept.de>
parents: 3532
diff changeset
  1178
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1179
highBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1180
    "return the bitIndex of the highest bit set. The returned bitIndex
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1181
     starts at 1 for the least significant bit.
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1182
     Returns 0 if no bit is set."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1183
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1184
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1185
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1186
    unsigned INT bits;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1187
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1188
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1189
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1190
    if (bits == 0) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1191
	RETURN ( __mkSmallInteger(0) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1192
    }
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
  1193
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1194
#ifdef __BSR
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1195
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1196
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1197
     * 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
  1198
     * (but saves a few code-bytes, though)
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1199
     */
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1200
    index = __BSR(bits);
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1201
#else
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1202
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1203
    index = 0;
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1204
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1205
# if __POINTER_SIZE__ == 8
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1206
    if (bits & 0xFFFFFFFF00000000L) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1207
	index += 32; bits = bits >> 32;
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1208
    }
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1209
# endif
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1210
    if (bits & 0xFFFF0000L) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1211
	index += 16; bits = bits >> 16;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1212
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1213
    if (bits & 0xFF00) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1214
	index += 8; bits = bits >> 8;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1215
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1216
    if (bits & 0xF0) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1217
	index += 4; bits = bits >> 4;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1218
    }
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1219
    if (bits & 0xC) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1220
	index += 2; bits = bits >> 2;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1221
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1222
    if (bits & 0x2) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1223
	index += 1; bits = bits >> 1;
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1224
    }
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1225
#endif /* no BSR instruction */
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1226
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1227
    RETURN ( __mkSmallInteger(index+1) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1228
%}
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1229
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1230
     2r0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1231
     2r1 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1232
     2r10 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1233
     2r100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1234
     2r1000 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1235
     2r100000000000 highBit
6481
d5c94e93067c highBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6480
diff changeset
  1236
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1237
     ((0 to:64) collect:[:s | 1 bitShift:s])
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1238
	collect:[:n | n highBit]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1239
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1240
     (((0 to:64) collect:[:s | 1 bitShift:s])
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1241
	collect:[:n | n highBit]) = (1 to:65)
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1242
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1243
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1244
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1245
     Time millisecondsToRun:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1246
	1000000 timesRepeat:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1247
	    2r1 highBit
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1248
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1249
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1250
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1251
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1252
     Time millisecondsToRun:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1253
	1000000 timesRepeat:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1254
	    2r1111 highBit
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1255
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1256
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1257
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1258
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1259
     Time millisecondsToRun:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1260
	1000000 timesRepeat:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1261
	    2r11111111111111 highBit
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1262
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1263
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1264
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1265
    "
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1266
     Time millisecondsToRun:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1267
	1000000 timesRepeat:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1268
	    2r11111111111111111111111111 highBit
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1269
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1270
     ]
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1271
    "
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1272
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1273
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1274
     2r000100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1275
     2r010100 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1276
     2r000001 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1277
     0 highBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1278
     SmallInteger maxVal highBit
4951
9943e85aa62a better #highBit
Claus Gittinger <cg@exept.de>
parents: 4827
diff changeset
  1279
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1280
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1281
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1282
invertBit:anInteger
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1283
    "return a new number where the specified bit is inverted.
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1284
     Bits are counted from 1 starting with the least significant.
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1285
     The methods name may be missleading: the receiver is not changed,
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1286
     but a new number is returned. Should be named #withBitInverted:"
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1287
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1288
%{  /* NOCONTEXT */
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1289
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1290
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1291
	int index = __intVal(anInteger);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1292
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1293
	if (index > 0) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1294
#if __POINTER_SIZE__ == 8
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1295
	    if (index <= 62)
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1296
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1297
	    if (index <= 30)
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1298
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1299
	    {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1300
		INT mask = __MASKSMALLINT(1 << (index-1));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1301
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1302
		RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1303
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1304
	}
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1305
    }
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1306
%}.
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1307
    ^ super invertBit:anInteger
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1308
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1309
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1310
     (16r401 invertBit:2     ) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1311
     (16r401 invertBit:1     ) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1312
     (16r30000000 invertBit:1) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1313
     (16r40000000 invertBit:0) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1314
     (16r0 invertBit:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1315
     (16r0 invertBit:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1316
     (16r0 invertBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1317
     (16r0 invertBit:32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1318
     (16r0 invertBit:33) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1319
     (16r0 invertBit:100) hexPrintString
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1320
    "
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1321
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1322
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1323
!
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1324
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1325
lowBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1326
    "return the bitIndex of the lowest bit set. The returned bitIndex
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1327
     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
  1328
     Returns 0 if no bit is set."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1329
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1330
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1331
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  1332
    unsigned INT bits;
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  1333
    int index;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1334
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1335
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1336
    if (bits == 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1337
	RETURN ( __mkSmallInteger(0) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1338
    }
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  1339
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1340
#ifdef __BSF
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1341
    /*
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1342
     * so much for CISC CPUS:
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1343
     * 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
  1344
     * (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
  1345
     * but saves a few code-bytes, though.
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1346
     */
6482
8b325f4a00fa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6481
diff changeset
  1347
    index = __BSF(bits);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1348
    RETURN ( __mkSmallInteger(index + 1) );
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1349
#else
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1350
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1351
    index = 1;
2431
09f32798910f better lowBit
Claus Gittinger <cg@exept.de>
parents: 2430
diff changeset
  1352
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1353
# if __POINTER_SIZE__ == 8
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1354
    if ((bits<<32) == 0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1355
	index += 32; bits >>= 32;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1356
    }
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1357
# endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1358
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1359
    if ((bits & 0xFFFF)==0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1360
	index += 16; bits >>= 16;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1361
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1362
    if ((bits & 0xFF)==0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1363
	index += 8; bits >>= 8;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1364
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1365
    if ((bits & 0xF)==0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1366
	index += 4; bits >>= 4;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1367
    }
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1368
    if ((bits & 0x3)==0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1369
	index += 2; bits >>= 2;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1370
    }
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1371
    if ((bits & 0x1)==0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1372
	index += 1;
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1373
    }
4955
a294a8a19434 slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4954
diff changeset
  1374
#endif
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1375
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1376
    RETURN ( __mkSmallInteger(index) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1377
%}
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1378
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1379
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1380
     0 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1381
     2r0001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1382
     2r0010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1383
     2r0100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1384
     2r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1385
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1386
     2r000100 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1387
     2r010010 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1388
     2r100001 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1389
     16r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1390
     16r1000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1391
     16r1000000000000000 lowBit
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1392
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1393
     Time millisecondsToRun:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1394
	1000000 timesRepeat:[
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1395
	    2r1000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1396
	]
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1397
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1398
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1399
     Time millisecondsToRun:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1400
	1000000 timesRepeat:[
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1401
	    2r11110000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1402
	]
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1403
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1404
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1405
     Time millisecondsToRun:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1406
	1000000 timesRepeat:[
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1407
	    2r1000000000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1408
	]
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1409
     ]
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6417
diff changeset
  1410
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1411
     Time millisecondsToRun:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1412
	1000000 timesRepeat:[
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1413
	    2r1000000000000000000000000000 lowBit
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1414
	]
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1415
     ]
4954
af47cd256ddf slightly better lowBit & highBit on intel
Claus Gittinger <cg@exept.de>
parents: 4953
diff changeset
  1416
    "
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1417
!
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1418
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1419
rightShift:shiftCount
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1420
    "return the value of the receiver shifted by shiftCount bits;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1421
     right shift if shiftCount > 0; left shift  otherwise.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1422
     Notice: the result of bitShift: on negative receivers is not
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1423
	     defined in the language standard (since the implementation
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1424
	     is free to choose any internal representation for integers).
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1425
	     However, ST/X preserves the sign."
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1426
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1427
%{  /* NOCONTEXT */
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1428
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1429
    INT bits, count;
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1430
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1431
    if (__isSmallInteger(shiftCount)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1432
	bits = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1433
	if (bits == 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1434
	    RETURN (self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1435
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1436
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1437
	count = __intVal(shiftCount);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1438
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1439
	if (count < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1440
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1441
	     * a left shift
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1442
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1443
	    count = -count;
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1444
#if defined(USE_LONGLONG_FOR_SHIFT)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1445
	    if (count <= N_INT_BITS) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1446
		unsigned LONGLONG result;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1447
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1448
		result = (unsigned LONGLONG)bits;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1449
		result <<= count;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1450
		if (result <= _MAX_INT) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1451
		    RETURN ( __mkSmallInteger(result) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1452
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1453
		{
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1454
		    RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1455
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1456
	    }
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1457
#else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1458
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1459
	     * check for overflow
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1460
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1461
	    if (count < (N_INT_BITS-1)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1462
		if (! (bits >> (N_INT_BITS - 1 - count))) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1463
		    RETURN ( __mkSmallInteger(bits << count) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1464
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1465
		/*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1466
		 * so, there is an overflow ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1467
		 * handle it as largeInteger
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1468
		 */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1469
		/* FALL THROUGH */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1470
	    }
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1471
#endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1472
	} else {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1473
	    if (count == 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1474
		RETURN (self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1475
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1476
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1477
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1478
	     * right shifts cannot overflow
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1479
	     *
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1480
	     * some machines ignore shifts bigger than
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1481
	     * the number of bits in an int ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1482
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1483
	    if (count > (N_INT_BITS-1)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1484
		RETURN (__mkSmallInteger(0));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1485
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1486
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1487
	    RETURN ( __mkSmallInteger(bits >> count) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1488
	}
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1489
    }
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1490
%}.
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1491
    (shiftCount isMemberOf:SmallInteger) ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1492
	^ (LargeInteger value:self) rightShift:shiftCount
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1493
    ].
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1494
    ^ self rightShift:(1 coerce:shiftCount)   "/ is this a good idea ?
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1495
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1496
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1497
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1498
	16 rightShift:2
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1499
	 4 rightShift:-2
10972
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1500
    "
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1501
!
bd9df21d6654 speed up #rightShift:
Stefan Vogel <sv@exept.de>
parents: 10947
diff changeset
  1502
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1503
setBit:anInteger
8937
4f2508548327 comment
Claus Gittinger <cg@exept.de>
parents: 8919
diff changeset
  1504
    "return a new integer where the specified bit is on.
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1505
     Bits are counted from 1 starting with the least significant.
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1506
     The methods name may be missleading: the receiver is not changed,
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1507
     but a new number is returned. Should be named #withBitSet:"
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1508
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1509
%{  /* NOCONTEXT */
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1510
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1511
    if (__isSmallInteger(anInteger)) {
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1512
	int index = __intVal(anInteger);
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1513
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1514
	if (index > 0) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1515
#if __POINTER_SIZE__ == 8
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1516
	    if (index <= 62)
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1517
#else
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1518
	    if (index <= 30)
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1519
#endif
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1520
	    {
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1521
		INT mask = __MASKSMALLINT(1 << (index-1));
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1522
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1523
		RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1524
	    }
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  1525
	}
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1526
    }
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1527
%}.
5496
338c81a04468 index bounds in bit operations;
Claus Gittinger <cg@exept.de>
parents: 5458
diff changeset
  1528
    ^ super setBit:anInteger
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1529
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1530
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1531
     (16r401 setBit:2     ) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1532
     (16r30000000 setBit:1) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1533
     (16r40000000 setBit:0) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1534
     (16r0 setBit:29) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1535
     (16r0 setBit:30) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1536
     (16r0 setBit:31) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1537
     (16r0 setBit:32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1538
     (16r0 setBit:33) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1539
     (16r0 setBit:100) hexPrintString
5209
3a52e2f97ec4 setBit/clearBit.
Claus Gittinger <cg@exept.de>
parents: 4967
diff changeset
  1540
    "
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1541
! !
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1542
7267
954ce6491c1a method category rename
Claus Gittinger <cg@exept.de>
parents: 7156
diff changeset
  1543
!SmallInteger methodsFor:'bit operators-32bit'!
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1544
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1545
asSigned32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1546
    "return a 32-bit integer with my bit-pattern. For protocol completeness."
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1547
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1548
    ^ self
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1549
!
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1550
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1551
asUnsigned32
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1552
    "return a 32-bit integer with my bit-pattern, but positive.
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1553
     May be required for bit operations on the sign-bit and/or to
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1554
     convert C/Java numbers."
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1555
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1556
    self < 0 ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1557
	^ 16r100000000 + self
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1558
    ].
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1559
    ^ self
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1560
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1561
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1562
     (-1 asUnsigned32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1563
     1 asUnsigned32
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1564
     (SmallInteger minVal asUnsigned32) hexPrintString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1565
     (SmallInteger maxVal asUnsigned32) hexPrintString
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1566
    "
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1567
!
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1568
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1569
bitInvert32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1570
    "return the value of the receiver with all bits inverted in 32bit signed int space
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1571
     (changes the sign)"
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1572
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1573
%{  /* NOCONTEXT */
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1574
    unsigned INT v;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1575
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1576
    v = __intVal(self);
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1577
    v = ~v;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1578
#if __POINTER_SIZE__ == 8
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1579
    v &= 0xFFFFFFFFL;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1580
#endif
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1581
    RETURN ( __MKUINT(v) );
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1582
%}.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1583
    ^ self primitiveFailed
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1584
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1585
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1586
     1 bitInvert32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1587
     16r40000000 bitInvert32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1588
     16r80000000 bitInvert32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1589
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1590
!
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1591
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1592
bitRotate32:shiftCount
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1593
    "return the value of the receiver rotated by shiftCount bits,
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1594
     but only within 32 bits, rotating left for positive, right for negative counts.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1595
     Rotates through the sign bit.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1596
     Useful for crypt algorithms, or to emulate C/Java semantics."
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1597
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1598
%{  /* NOCONTEXT */
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1599
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1600
    unsigned INT bits;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1601
    int count;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1602
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1603
    if (__isSmallInteger(shiftCount)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1604
	count = __intVal(shiftCount);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1605
	count = count % 32;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1606
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1607
	bits = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1608
	if (count > 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1609
	    bits = (bits << count) | (bits >> (32-count));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1610
	} else {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1611
	    bits = (bits >> (-count)) | (bits << (32-(-count)));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1612
	}
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1613
#if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1614
	bits &= 0xFFFFFFFFL;
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1615
#endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1616
	RETURN (__MKUINT(bits));
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1617
    }
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1618
%}.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1619
    ^ self primitiveFailed
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1620
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1621
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1622
     128 rotate32:1
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1623
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1624
     1 rotate32:1
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1625
     1 rotate32:2
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1626
     1 rotate32:31
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1627
     1 rotate32:32
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1628
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1629
     1 rotate32:-1
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1630
     1 rotate32:-2
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1631
     1 rotate32:-3
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1632
     1 rotate32:-32
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1633
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1634
!
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1635
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1636
bitShift32:shiftCount
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1637
    "return the value of the receiver shifted by shiftCount bits,
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1638
     but only within 32 bits, shifting into/out-of the sign bit.
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1639
     May be useful for communication interfaces, to create ST-numbers
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1640
     from a signed 32bit int value given as individual bytes,
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1641
     or to emulate C/Java semantics."
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1642
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1643
%{  /* NOCONTEXT */
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1644
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1645
    INT bits, count;
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1646
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1647
    if (__isSmallInteger(shiftCount)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1648
	count = __intVal(shiftCount);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1649
	if (count >= 32) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1650
	    RETURN (__mkSmallInteger(0));
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1651
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1652
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1653
	bits = __intVal(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1654
	if (count > 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1655
	    bits = bits << count;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1656
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1657
	    bits = bits >> (-count);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1658
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1659
#if __POINTER_SIZE__ == 8
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1660
	bits &= 0xFFFFFFFFL;
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1661
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1662
	RETURN (__MKINT(bits));
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1663
    }
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1664
%}.
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1665
    ^ self primitiveFailed
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1666
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1667
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1668
     128 bitShift:24
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1669
     128 bitShift32:24
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1670
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1671
     1 bitShift:31
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1672
     1 bitShift32:31
6417
10effd5ab612 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6416
diff changeset
  1673
    "
6415
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1674
!
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1675
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1676
bitXor32:aNumber
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1677
    "return the xor of the receiver and the argument.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1678
     The argument must be another SmallInteger or a 4-byte LargeInteger.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1679
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1680
     This is of course not always correct, but allows for C/Java behavior to be emulated."
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1681
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1682
%{  /* NOCONTEXT */
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1683
    INT rslt;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1684
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1685
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1686
#if __POINTER_SIZE__ == 8
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1687
    rslt &= 0xFFFFFFFFL;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1688
#endif
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1689
    RETURN ( __MKUINT(rslt));
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1690
%}.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1691
    self primitiveFailed
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1692
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1693
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1694
     16r7FFFFFFF bitXor: 16r80000000          4294967295
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1695
     16r7FFFFFFF bitXor32: 16r80000000
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1696
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1697
!
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  1698
6415
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1699
unsignedBitShift32:shiftCount
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1700
    "return the value of the receiver shifted by shiftCount bits,
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1701
     but only within 32 unsigned bits.
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1702
     May be useful for communication interfaces, to create ST-numbers
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1703
     from an unsigned 32bit int value given as individual byte,
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1704
     or to emulate C/Java semantics."
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1705
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1706
%{  /* NOCONTEXT */
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1707
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1708
    unsigned INT bits;
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1709
    INT count;
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1710
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1711
    if (__isSmallInteger(shiftCount)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1712
	count = __intVal(shiftCount);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1713
	if (count >= 32) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1714
	    RETURN (__mkSmallInteger(0));
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1715
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1716
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1717
	bits = __intVal(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1718
	if (count > 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1719
	    bits = bits << count;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1720
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1721
	    bits = bits >> (-count);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1722
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1723
#if __POINTER_SIZE__ == 8
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1724
	bits &= 0xFFFFFFFFL;
6415
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1725
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1726
	RETURN (__MKUINT(bits));
6415
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1727
    }
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1728
%}.
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1729
    ^ self primitiveFailed
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1730
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1731
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1732
     128 unsignedBitShift:24
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1733
     128 unsignedBitShift32:24
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1734
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1735
     1 unsignedBitShift:31
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1736
     1 unsignedBitShift32:31
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1737
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1738
     -1 unsignedBitShift32:-1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1739
     -1 unsignedBitShift32:1
6415
f163a6319b5f unsigned C/Java 32bit shifts
Claus Gittinger <cg@exept.de>
parents: 6400
diff changeset
  1740
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1741
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1742
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1743
!SmallInteger methodsFor:'byte access'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1744
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1745
byteSwapped
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1746
    "lsb -> msb;
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1747
     i.e. a.b.c.d -> d.c.b.a"
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1748
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1749
%{  /* NOCONTEXT */
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1750
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1751
#if __POINTER_SIZE__ == 4
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1752
    unsigned int v = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1753
    unsigned int swapped;
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1754
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1755
# ifdef __BORLANDC__
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1756
#  ifdef USE_BSWAP
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1757
    _asm {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1758
	mov eax, v
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1759
	bswap eax
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1760
	mov swapped, eax
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1761
    };
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1762
#  else
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1763
    _asm {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1764
	mov eax, v
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1765
	xchg al, ah
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1766
	rol eax, 16
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1767
	xchg al, ah
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1768
	mov swapped, eax
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1769
    };
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1770
#  endif
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1771
# else
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1772
    swapped = ((v>>24) | ((v>>8)&0xFF00) | ((v & 0xFF00)<<8) | ((v & 0xFF)<<24));
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1773
# endif
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1774
    RETURN (__MKUINT(swapped));
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1775
#endif /* __POINTER_SIZE__ */
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1776
%}.
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1777
    ^ super byteSwapped
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1778
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1779
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1780
     16r11223344 byteSwapped hexPrintString
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1781
     16r44332211 byteSwapped hexPrintString
13991
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1782
    "
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1783
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1784
    "Created: / 09-01-2012 / 23:01:33 / cg"
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1785
!
647fe34ce5a1 added: byteSwapped
Claus Gittinger <cg@exept.de>
parents: 13913
diff changeset
  1786
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1787
digitAt:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1788
    "return 8 bits of value, starting at byte index"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1789
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1790
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1791
357
claus
parents: 329
diff changeset
  1792
    REGISTER INT val;
claus
parents: 329
diff changeset
  1793
    INT idx;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1794
252
  1795
    if (__isSmallInteger(index)) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1796
	val = __intVal(self);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1797
	if (val < 0)
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1798
	    val = -val;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1799
	switch (idx = __intVal(index)) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1800
	    case 1:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1801
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1802
	    case 2:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1803
		val = (val >> 8);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1804
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1805
	    case 3:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1806
		val = (val >> 16);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1807
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1808
	    case 4:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1809
		val = (val >> 24);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1810
		break;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1811
#if __POINTER_SIZE__ == 8
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1812
	    case 5:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1813
		val = (val >> 32);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1814
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1815
	    case 6:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1816
		val = (val >> 40);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1817
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1818
	    case 7:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1819
		val = (val >> 48);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1820
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1821
	    case 8:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1822
		val = (val >> 56);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1823
		break;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1824
#endif
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1825
	    default:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1826
		if (idx < 1)
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1827
		    goto bad;   /* sorry */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1828
		RETURN (__mkSmallInteger(0));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1829
	}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1830
	RETURN ( __mkSmallInteger( val & 0xFF) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1831
    }
357
claus
parents: 329
diff changeset
  1832
  bad: ;
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1833
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1834
    index > 0 ifFalse:[
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1835
	"
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1836
	 index less than 1 - not allowed
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1837
	"
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1838
	^ self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1839
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1840
    ^ 0
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1841
357
claus
parents: 329
diff changeset
  1842
    "
claus
parents: 329
diff changeset
  1843
     (16r12345678 digitAt:1) printStringRadix:16
claus
parents: 329
diff changeset
  1844
     (16r12345678 digitAt:3) printStringRadix:16
claus
parents: 329
diff changeset
  1845
     (16r12345678 digitAt:15) printStringRadix:16
claus
parents: 329
diff changeset
  1846
     (16r12345678 digitAt:0) printStringRadix:16
claus
parents: 329
diff changeset
  1847
     (16r12345678 digitAt:-10) printStringRadix:16
claus
parents: 329
diff changeset
  1848
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1849
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1850
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1851
digitByteAt:index
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1852
    "return 8 bits of my signed value, starting at byte index.
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1853
     For positive receivers, this is the same as #digitAt:;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1854
     for negative ones, the actual bit representation is returned."
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1855
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1856
%{  /* NOCONTEXT */
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1857
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1858
    REGISTER INT val;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1859
    INT idx;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1860
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1861
    if (__isSmallInteger(index)) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1862
	val = __intVal(self);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1863
	switch (idx = __intVal(index)) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1864
	    case 1:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1865
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1866
	    case 2:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1867
		val = (val >> 8);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1868
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1869
	    case 3:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1870
		val = (val >> 16);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1871
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1872
	    case 4:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1873
		val = (val >> 24);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1874
		break;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  1875
#if __POINTER_SIZE__ == 8
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1876
	    case 5:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1877
		val = (val >> 32);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1878
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1879
	    case 6:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1880
		val = (val >> 40);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1881
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1882
	    case 7:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1883
		val = (val >> 48);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1884
		break;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1885
	    case 8:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1886
		val = (val >> 56);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1887
		break;
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1888
#endif
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1889
	    default:
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1890
		if (idx < 1)
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1891
		    goto bad;   /* sorry */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1892
		if (val < 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1893
		    RETURN (__mkSmallInteger(0xFF));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1894
		}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1895
		RETURN (__mkSmallInteger(0));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1896
	}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1897
	RETURN ( __mkSmallInteger( val & 0xFF) );
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1898
    }
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1899
  bad: ;
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1900
%}.
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1901
    index > 0 ifFalse:[
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1902
	"
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1903
	 index less than 1 - not allowed
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1904
	"
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  1905
	^ self primitiveFailed
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1906
    ].
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1907
    ^ 0
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1908
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1909
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1910
     (10 digitByteAt:1) printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1911
     (10 digitByteAt:3) printStringRadix:16
3892
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1912
     (-10 digitByteAt:1) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1913
     (-10 digitByteAt:3) printStringRadix:16
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1914
    "
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1915
!
ed306e60dfec added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3707
diff changeset
  1916
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  1917
digitBytes
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  1918
    "return a byteArray filled with the receivers bits
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  1919
     (8 bits of the absolute value per element),
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  1920
     least significant byte is first"
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  1921
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1922
    |absValue
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1923
     b1 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1924
     b2 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1925
     b3 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1926
     b4 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1927
     b5 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1928
     b6 "{ Class: SmallInteger }"
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1929
     b7 "{ Class: SmallInteger }" digitByteArray|
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1930
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1931
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1932
     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
  1933
     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
  1934
     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
  1935
    "
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1936
    self == 0 ifTrue: [
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1937
	^ ByteArray with:0.
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1938
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1939
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1940
    self < 0 ifTrue: [
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1941
	absValue := self negated
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1942
    ] ifFalse: [
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1943
	absValue := self.
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1944
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1945
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1946
    b1 := absValue bitAnd:16rFF.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1947
    absValue := absValue bitShift:-8.
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1948
    absValue == 0 ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1949
	digitByteArray := ByteArray with:b1
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  1950
    ] ifFalse:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1951
	b2 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1952
	absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1953
	absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1954
	    digitByteArray := ByteArray with:b1 with:b2
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1955
	] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1956
	    b3 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1957
	    absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1958
	    absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1959
		digitByteArray := ByteArray with:b1 with:b2 with:b3
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1960
	    ] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1961
		b4 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1962
		absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1963
		absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1964
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1965
		] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1966
		    b5 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1967
		    absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1968
		    absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1969
			digitByteArray := ByteArray new:5.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1970
			digitByteArray at:1 put:b1.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1971
			digitByteArray at:2 put:b2.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1972
			digitByteArray at:3 put:b3.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1973
			digitByteArray at:4 put:b4.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1974
			digitByteArray at:5 put:b5.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1975
		    ] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1976
			b6 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1977
			absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1978
			absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1979
			    digitByteArray := ByteArray new:6.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1980
			    digitByteArray at:1 put:b1.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1981
			    digitByteArray at:2 put:b2.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1982
			    digitByteArray at:3 put:b3.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1983
			    digitByteArray at:4 put:b4.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1984
			    digitByteArray at:5 put:b5.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1985
			    digitByteArray at:6 put:b6.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1986
			] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1987
			    b7 := absValue bitAnd:16rFF.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1988
			    absValue := absValue bitShift:-8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1989
			    absValue == 0 ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1990
				digitByteArray := ByteArray new:7.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1991
				digitByteArray at:1 put:b1.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1992
				digitByteArray at:2 put:b2.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1993
				digitByteArray at:3 put:b3.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1994
				digitByteArray at:4 put:b4.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1995
				digitByteArray at:5 put:b5.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1996
				digitByteArray at:6 put:b6.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1997
				digitByteArray at:7 put:b7.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1998
			    ] ifFalse:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  1999
				digitByteArray := ByteArray new:8.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2000
				digitByteArray at:1 put:b1.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2001
				digitByteArray at:2 put:b2.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2002
				digitByteArray at:3 put:b3.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2003
				digitByteArray at:4 put:b4.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2004
				digitByteArray at:5 put:b5.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2005
				digitByteArray at:6 put:b6.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2006
				digitByteArray at:7 put:b7.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2007
				digitByteArray at:8 put:absValue.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2008
			    ]
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2009
			]
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2010
		    ]
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2011
		]
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2012
	    ]
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2013
	]
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2014
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2015
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2016
    ^ digitByteArray
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2017
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2018
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2019
      16r12 digitBytes
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2020
      16r1234 digitBytes
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2021
      16r12345678 digitBytes
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2022
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2023
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2024
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2025
digitBytesMSB:msbFlag
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2026
    "return a byteArray filled with the receivers bits
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2027
     (8 bits of the absolute value per element),
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2028
     if msbflag = true, most significant byte is first,
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2029
     otherwise least significant byte is first"
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2030
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2031
    msbFlag ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2032
	^ self digitBytes reversed.  "digitBytes has been just created - reverse inplace"
10487
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2033
    ].
f6287f4b83c9 Redefined #digitBytes without using an intermediate LargeInteger
Stefan Vogel <sv@exept.de>
parents: 10342
diff changeset
  2034
    ^ self digitBytes
4827
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2035
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2036
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2037
      16r12 digitBytesMSB:true
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2038
      16r1234 digitBytesMSB:true
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2039
      16r1234 digitBytesMSB:false
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2040
      16r12345678 digitBytesMSB:true
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2041
      16r12345678 digitBytesMSB:false
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2042
    "
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2043
!
905b98a07798 New: #digitBytes and #digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4661
diff changeset
  2044
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2045
digitLength
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2046
    "return the number bytes required to represent this Integer.
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2047
     For negative receivers, the digitLength of its absolute value
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2048
     is returned."
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2049
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2050
%{  /* NOCONTEXT */
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2051
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2052
    INT val = __intVal(self);
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2053
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2054
    if (val < 0) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2055
	val = -val;
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2056
    }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  2057
#if __POINTER_SIZE__ == 8
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2058
    if (val & 0xFFFFFFFF00000000L) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2059
	if (val & 0xFFFF000000000000L) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2060
	    if (val & 0xFF00000000000000L) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2061
		RETURN ( __mkSmallInteger(8));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2062
	    } else {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2063
		RETURN ( __mkSmallInteger(7));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2064
	    }
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2065
	} else {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2066
	    if (val & 0x0000FF0000000000L) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2067
		RETURN ( __mkSmallInteger(6));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2068
	    } else {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2069
		RETURN ( __mkSmallInteger(5));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2070
	    }
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2071
	}
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2072
    }
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2073
#endif
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2074
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2075
    if (val & 0xFFFF0000) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2076
	if (val & 0xFF000000) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2077
	    RETURN ( __mkSmallInteger(4));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2078
	} else {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2079
	    RETURN ( __mkSmallInteger(3));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2080
	}
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2081
    } else {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2082
	if (val & 0x0000FF00) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2083
	    RETURN ( __mkSmallInteger(2));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2084
	} else {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2085
	    RETURN ( __mkSmallInteger(1));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2086
	}
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2087
    }
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2088
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2089
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2090
    ^ self abs highBit - 1 // 8 + 1
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2091
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2092
    "
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2093
     16rFF00000000000000 digitLength
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2094
     -16rFF00000000000000 digitLength
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2095
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2096
     16rFF000000 digitLength
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2097
     16rFF0000 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2098
     16rFF00 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2099
     16rFF digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2100
     -16rFF000000 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2101
     -16rFF0000 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2102
     -16rFF00 digitLength
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2103
     -16rFF digitLength
2815
6a562d0fb864 tined #digitLength
Claus Gittinger <cg@exept.de>
parents: 2791
diff changeset
  2104
    "
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2105
!
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2106
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2107
swapBytes
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2108
    "swap byte pair-wise in an integer
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2109
     i.e. a.b.c.d -> b.a.d.c"
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2110
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2111
%{  /* NOCONTEXT */
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2112
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2113
#if __POINTER_SIZE__ == 4
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2114
    unsigned int v = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2115
    unsigned int swapped;
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2116
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2117
    swapped = ((v&0xFF000000)>>8) | ((v&0xFF0000) << 8) | ((v & 0xFF00)>>8) | ((v & 0xFF)<<8);
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2118
    RETURN (__MKUINT(swapped));
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2119
#endif /* __POINTER_SIZE__ */
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2120
%}.
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2121
    ^ super swapBytes
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2122
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2123
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2124
     16r11223344 swapBytes hexPrintString
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2125
     16r44332211 swapBytes hexPrintString
14167
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2126
    "
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2127
4f6fd7a72967 added: #swapBytes
Stefan Vogel <sv@exept.de>
parents: 14003
diff changeset
  2128
    "Created: / 09-01-2012 / 23:01:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2129
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2130
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2131
!SmallInteger methodsFor:'catching messages'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2132
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2133
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2134
    "catch indexed access - report an error
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2135
     defined here since basicAt: in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2136
14540
84fc4b759ad8 class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14492
diff changeset
  2137
    ^ self notIndexed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2138
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2139
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2140
basicAt:index put:anObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2141
    "catch indexed access - report an error
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2142
     defined here since basicAt:put: in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2143
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2144
    self notIndexed
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2145
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2146
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2147
basicSize
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2148
    "return the number of indexed instvars - SmallIntegers have none.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2149
     Defined here since basicSize in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2150
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2151
    ^ 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2152
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2153
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2154
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2155
    "return the number of indexed instvars - SmallIntegers have none."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2156
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2157
    ^ 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2158
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2159
5240
2a91958ba1f1 categories
Claus Gittinger <cg@exept.de>
parents: 5209
diff changeset
  2160
!SmallInteger methodsFor:'coercing & converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2161
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2162
asCharacter
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2163
    "Return a character with the receiver as ascii value"
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
  2164
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2165
    ^ Character value:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2166
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2167
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2168
asFloat
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  2169
    "return a Float with same value as receiver.
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  2170
     Redefined for performance (machine can do it faster)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2171
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2172
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2173
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2174
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2175
    double dVal = (double)__intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2176
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2177
    __qMKFLOAT(newFloat, dVal);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2178
    RETURN ( newFloat );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2179
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2180
    ^ self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2181
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2182
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2183
asLargeInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2184
    "return a LargeInteger with same value as receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2185
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2186
    ^ LargeInteger value:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2187
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2188
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2189
asShortFloat
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  2190
    "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
  2191
     Redefined for performance (machine can do it faster)"
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2192
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2193
%{  /* NOCONTEXT */
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2194
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2195
    OBJ dummy = @global(ShortFloat);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2196
    OBJ newFloat;
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2197
    float fVal = (float)__intVal(self);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2198
1695
465e1eba8e8e removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  2199
    __qMKSFLOAT(newFloat, fVal);
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2200
    RETURN ( newFloat );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2201
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2202
    ^ self primitiveFailed
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2203
!
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  2204
8408
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2205
codePoint
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2206
    "for compatibility with Characters.
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2207
     (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
  2208
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2209
    ^ self
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2210
!
61f12d6c1ab0 juergen gmeiners bug fix for bug #69
Claus Gittinger <cg@exept.de>
parents: 8365
diff changeset
  2211
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2212
coerce:aNumber
11718
1128a869a77a comment
Claus Gittinger <cg@exept.de>
parents: 11666
diff changeset
  2213
    "convert the argument aNumber into an instance of the receivers class and return it."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2214
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2215
    ^ aNumber asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2216
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2217
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2218
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2219
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2220
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2221
    ^ 20
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2222
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2223
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2224
signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2225
    "return a smallInteger from sign-extending the 24'th bit.
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2226
     May be useful for communication interfaces"
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2227
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2228
%{  /* NOCONTEXT */
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2229
    INT i = __intVal(self);
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2230
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2231
    if (i & 0x800000) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2232
	i = i | ~0xFFFFFFL;
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2233
    } else {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2234
	i = i & 0x7FFFFF;
12866
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2235
    }
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2236
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2237
    RETURN (__mkSmallInteger(i));
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2238
%}.
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2239
    ^ self primitiveFailed
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2240
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2241
    "
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2242
     16rFFFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2243
     16r800000 signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2244
     16r7FFFFF signExtended24BitValue
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2245
    "
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2246
!
42e5e690c197 added: #signExtended24BitValue
Claus Gittinger <cg@exept.de>
parents: 12787
diff changeset
  2247
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2248
signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2249
    "return a smallInteger from sign-extending the 8'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2250
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2251
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2252
%{  /* NOCONTEXT */
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  2253
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2254
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2255
    if (i & 0x80) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2256
	i = i | ~0xFFL;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2257
    } else {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2258
	i = i & 0x7F;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2259
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2260
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2261
    RETURN (__mkSmallInteger(i));
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2262
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2263
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2264
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2265
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2266
     16rFF signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2267
     16r80 signExtendedByteValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2268
     16r7F signExtendedByteValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2269
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2270
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2271
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2272
signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2273
    "return a smallInteger from sign-extending the 32'th bit.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2274
     May be useful for communication interfaces"
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2275
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2276
%{  /* NOCONTEXT */
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2277
    INT i = __intVal(self);
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2278
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2279
    if (i & 0x80000000) {
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2280
        i = i | ~0xFFFFFFFFL;
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2281
    } else {
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2282
        i = i & 0x7FFFFFFF;
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2283
    }
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2284
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2285
    RETURN (__mkSmallInteger(i));
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2286
%}.
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2287
    ^ self primitiveFailed
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2288
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2289
    "
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2290
     16rFFFFFFFF signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2291
     16r80000000 signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2292
     16r7FFFFFFF signExtendedLongValue
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2293
    "
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2294
!
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  2295
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2296
signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2297
    "return a smallInteger from sign-extending the 16'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2298
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2299
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2300
%{  /* NOCONTEXT */
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  2301
    INT i = __intVal(self);
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2302
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2303
    if (i & 0x8000) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2304
	i = i | ~0xFFFFL;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2305
    } else {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2306
	i = i & 0x7FFF;
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2307
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2308
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2309
    RETURN (__mkSmallInteger(i));
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2310
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2311
    ^ self primitiveFailed
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2312
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2313
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2314
     16rFFFF signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2315
     16r8000 signExtendedShortValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  2316
     16r7FFF signExtendedShortValue
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2317
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2318
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2319
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2320
!SmallInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2321
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2322
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2323
    "return true, if the argument is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2324
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2325
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2326
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2327
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2328
#ifdef POSITIVE_ADDRESSES
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2329
	RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2330
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2331
	/* tag bit does not change ordering */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2332
	RETURN ( ((INT)self < (INT)aNumber) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2333
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2334
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2335
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2336
	RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2337
    }
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2338
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2339
    ^ aNumber lessFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2340
    "^ self retry:#< coercing:aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2341
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2342
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2343
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2344
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2345
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2346
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2347
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2348
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2349
#ifdef POSITIVE_ADDRESSES
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2350
	RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2351
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2352
	/* tag bit does not change ordering */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2353
	RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2354
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2355
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2356
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2357
	RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2358
    }
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  2359
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  2360
    ^ (self > aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2361
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2362
    "Modified: / 31.7.2002 / 10:07:17 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2363
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2364
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2365
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2366
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2367
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2368
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2369
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2370
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2371
    if (aNumber == self) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2372
	RETURN ( true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2373
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2374
    if (! __isNonNilObject(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2375
	/* a smallint or nil */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2376
	RETURN ( false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2377
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2378
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2379
    if (__qIsFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2380
	RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2381
    }
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2382
    if (__qIsShortFloat(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2383
	RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2384
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2385
%}.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2386
    ^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2387
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2388
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2389
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2390
    "return true, if the argument is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2391
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2392
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2393
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2394
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2395
#ifdef POSITIVE_ADDRESSES
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2396
	RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2397
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2398
	/* tag bit does not change ordering */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2399
	RETURN ( ((INT)self > (INT)aNumber) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2400
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2401
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2402
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2403
	RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2404
    }
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  2405
%}.
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2406
    ^ (aNumber < self)
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2407
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2408
    "Modified: / 31.7.2002 / 10:07:05 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2409
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2410
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2411
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2412
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2413
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2414
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2415
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2416
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2417
#ifdef POSITIVE_ADDRESSES
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2418
	RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2419
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2420
	/* tag bit does not change ordering */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2421
	RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2422
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2423
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2424
    if (__isFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2425
	RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2426
    }
5930
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  2427
%}.
d7728046c2e1 compare fallBacks changed to enable VW compatible double dispatching
Claus Gittinger <cg@exept.de>
parents: 5782
diff changeset
  2428
    ^ (self < aNumber) not
6676
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2429
15f2e3080e13 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6482
diff changeset
  2430
    "Modified: / 31.7.2002 / 10:07:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2431
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2432
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2433
hash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2434
    "return an integer useful for hashing on value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2435
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2436
    self >= 0 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2437
    ^ self negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2438
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2439
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2440
identityHash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2441
    "return an integer useful for hashing on identity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2442
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  2443
     self >= 0 ifTrue:[^ self].
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  2444
     ^ self negated
1963
ea26c7b9ca1d experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  2445
1964
20bb7197d19f oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents: 1963
diff changeset
  2446
    "Modified: 11.11.1996 / 18:42:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2447
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2448
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2449
max:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2450
    "return the receiver or the argument, whichever is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2451
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2452
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2453
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2454
    if (__isSmallInteger(aNumber)) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2455
#if TAG_INT == 1
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2456
	/* tag bit does not change ordering */
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2457
	if ((INT)(self) > (INT)(aNumber))
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2458
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2459
	if (__intVal(self) > __intVal(aNumber))
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2460
#endif
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2461
	{
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2462
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2463
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2464
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2465
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2466
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2467
	if ( (double)__intVal(self) > __floatVal(aNumber) ) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2468
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2469
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2470
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2471
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2472
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2473
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2474
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2475
    (self > aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2476
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2477
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2478
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2479
min:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2480
    "return the receiver or the argument, whichever is smaller"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2481
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2482
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2483
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2484
    if (__isSmallInteger(aNumber)) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2485
#if TAG_INT == 1
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2486
	/* tag bit does not change ordering */
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2487
	if ((INT)(self) < (INT)(aNumber))
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2488
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2489
	if (__intVal(self) < __intVal(aNumber))
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2490
#endif
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2491
	{
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2492
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2493
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2494
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2495
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2496
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2497
	if ( (double)__intVal(self) < __floatVal(aNumber) ) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2498
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2499
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2500
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2501
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2502
%}.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2503
    "/ fallback for non-smallInteger argument
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2504
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2505
    (self < aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2506
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2507
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2508
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2509
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2510
    "return true, if the arguments value is not equal to mine"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2511
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2512
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2513
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2514
    if (aNumber == self) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2515
	RETURN ( false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2516
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2517
    if (! __isNonNilObject(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2518
	/* a smallint or nil */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2519
	RETURN ( true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2520
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2521
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2522
    if (__qIsFloatLike(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2523
	RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false );
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2524
    }
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2525
    if (__qIsShortFloat(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2526
	RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2527
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2528
%}.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  2529
    ^ (self = aNumber) not
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2530
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2531
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2532
!SmallInteger methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2533
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2534
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2535
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2536
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2537
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2538
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2539
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2540
10947
e01ba2c3533f deepCopy change
ab
parents: 10487
diff changeset
  2541
deepCopyUsing:aDictionary postCopySelector:postCopySelector
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2542
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2543
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2544
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2545
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2546
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2547
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2548
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2549
    "return a shallow copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2550
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2551
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2552
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2553
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2554
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2555
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2556
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2557
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2558
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2559
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2560
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2561
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  2562
!SmallInteger methodsFor:'iteration'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2563
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2564
timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  2565
    "evaluate the argument, aBlock self times.
claus
parents: 329
diff changeset
  2566
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2567
357
claus
parents: 329
diff changeset
  2568
%{
claus
parents: 329
diff changeset
  2569
    REGISTER INT tmp;
claus
parents: 329
diff changeset
  2570
    static struct inlineCache blockVal = __ILC0(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2571
357
claus
parents: 329
diff changeset
  2572
    tmp = __intVal(self);
claus
parents: 329
diff changeset
  2573
    if (tmp > 0) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2574
	if (__isBlockLike(aBlock)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2575
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2576
	    {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2577
		REGISTER OBJFUNC codeVal;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2578
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2579
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2580
		 * specially tuned version for compiled blocks,
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2581
		 * (the most common case)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2582
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2583
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2584
#ifdef PARANOIA
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2585
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2586
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2587
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2588
357
claus
parents: 329
diff changeset
  2589
#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
  2590
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2591
#                   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
  2592
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2593
#else
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2594
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2595
#                   define BLOCK_ARG  rHome
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2596
		    REGISTER OBJ rHome;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2597
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2598
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2599
		     * home on stack - no need to refetch
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2600
		     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2601
		    rHome = __BlockInstPtr(aBlock)->b_home;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2602
		    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
  2603
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2604
		    {
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2605
#ifdef __UNROLL_LOOPS__
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2606
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2607
			/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2608
			 * you are not supposed to program like this - I know what I do
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2609
			 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2610
			while (tmp > 8) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2611
			    if (InterruptPending != nil) goto interrupted0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2612
	continue0:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2613
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2614
			    if (InterruptPending != nil) goto interrupted1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2615
	continue1:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2616
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2617
			    if (InterruptPending != nil) goto interrupted2;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2618
	continue2:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2619
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2620
			    if (InterruptPending != nil) goto interrupted3;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2621
	continue3:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2622
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2623
			    if (InterruptPending != nil) goto interrupted4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2624
	continue4:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2625
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2626
			    if (InterruptPending != nil) goto interrupted5;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2627
	continue5:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2628
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2629
			    if (InterruptPending != nil) goto interrupted6;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2630
	continue6:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2631
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2632
			    if (InterruptPending != nil) goto interrupted7;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2633
	continue7:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2634
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2635
			    tmp -= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2636
			}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2637
#endif /* __UNROLL_LOOPS__ */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2638
			do {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2639
			    if (InterruptPending != nil) goto interruptedX;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2640
	continueX:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2641
			    (*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2642
			} while(--tmp);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2643
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2644
			RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2645
			if (0) {
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2646
#ifdef __UNROLL_LOOPS__
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2647
			    interrupted0:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2648
						__interruptL(@line); goto continue0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2649
			    interrupted1:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2650
						__interruptL(@line); goto continue1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2651
			    interrupted2:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2652
						__interruptL(@line); goto continue2;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2653
			    interrupted3:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2654
						__interruptL(@line); goto continue3;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2655
			    interrupted4:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2656
						__interruptL(@line); goto continue4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2657
			    interrupted5:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2658
						__interruptL(@line); goto continue5;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2659
			    interrupted6:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2660
						__interruptL(@line); goto continue6;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2661
			    interrupted7:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2662
						__interruptL(@line); goto continue7;
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2663
#endif /* __UNROLL_LOOPS__ */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2664
			    interruptedX:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2665
						__interruptL(@line); goto continueX;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2666
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2667
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2668
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2669
	    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2670
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2671
#           undef BLOCK_ARG
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  2672
400
claus
parents: 394
diff changeset
  2673
#ifdef NEW_BLOCK_CALL
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2674
#           define BLOCK_ARG  aBlock
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2675
#           define IBLOCK_ARG nil
400
claus
parents: 394
diff changeset
  2676
#else
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2677
#           define BLOCK_ARG  (__BlockInstPtr(aBlock)->b_home)
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2678
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
400
claus
parents: 394
diff changeset
  2679
#endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  2680
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2681
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2682
	     * sorry - must check for the blocks code within the loops;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2683
	     * it could be recompiled or flushed (in the interrupt)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2684
	     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2685
	    do {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2686
		REGISTER OBJFUNC codeVal;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2687
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2688
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2689
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2690
		     * arg is a compiled block with code -
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2691
		     * directly call it without going through Block>>value
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2692
		     * however, if there is an interrupt, refetch the code pointer.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2693
		     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2694
		    /* stay here, while no interrupts are pending ... */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2695
		    do {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2696
			(*codeVal)(BLOCK_ARG);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2697
			if (InterruptPending != nil) goto outerLoop;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2698
		    } while (--tmp);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2699
		    RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2700
		} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2701
		    if (InterruptPending != nil) __interruptL(@line);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2702
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2703
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2704
			/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2705
			 * arg is a compiled block with bytecode -
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2706
			 * directly call interpreter without going through Block>>value
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2707
			 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2708
			__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2709
		    } else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2710
			/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2711
			 * arg is something else - call it with #value
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2712
			 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2713
			(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2714
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2715
		}
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  2716
    outerLoop: ;
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2717
	    } while (--tmp);
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2718
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2719
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2720
#           undef IBLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2721
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2722
	    RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2723
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2724
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2725
	/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2726
	 * not a block-like thingy - call it with #value
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2727
	 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2728
	do {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2729
	    if (InterruptPending != nil) __interruptL(@line);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2730
	    (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2731
	} while(--tmp);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2732
	RETURN (self);
357
claus
parents: 329
diff changeset
  2733
    }
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2734
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  2735
    ^ super timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  2736
claus
parents: 329
diff changeset
  2737
"/    |count "{ Class: SmallInteger }" |
claus
parents: 329
diff changeset
  2738
"/
claus
parents: 329
diff changeset
  2739
"/    count := self.
claus
parents: 329
diff changeset
  2740
"/    [count > 0] whileTrue:[
claus
parents: 329
diff changeset
  2741
"/        aBlock value.
claus
parents: 329
diff changeset
  2742
"/        count := count - 1
claus
parents: 329
diff changeset
  2743
"/    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2744
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2745
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2746
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2747
    "reimplemented as primitive for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2748
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2749
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2750
    REGISTER INT tmp, step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2751
    REGISTER INT final;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2752
    static struct inlineCache blockVal = __ILC1(0);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2753
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2754
    if (__bothSmallInteger(incr, stop)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2755
	tmp = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2756
	final = __intVal(stop);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2757
	step = __intVal(incr);
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2758
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2759
	if (__isBlockLike(aBlock)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2760
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2761
	    {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2762
		REGISTER OBJFUNC codeVal;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2763
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2764
		/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2765
		 * specially tuned version for static compiled blocks, called with
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2766
		 * home on the stack (the most common case)
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2767
		 */
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2768
		if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2769
#ifdef PARANOIA
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2770
		 && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2771
#endif
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2772
		) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2773
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2774
#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
  2775
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2776
#                   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
  2777
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2778
#else
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2779
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2780
#                   define BLOCK_ARG  rHome
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2781
		    REGISTER OBJ rHome;
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2782
		    rHome = __BlockInstPtr(aBlock)->b_home;
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2783
		    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
  2784
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2785
#endif
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2786
		    {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2787
			if (step < 0) {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2788
			    if (step == -1) {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2789
				while (tmp >= final) {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2790
				    if (InterruptPending != nil) __interruptL(@line);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2791
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2792
				    tmp--;
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2793
				}
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2794
			    } else {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2795
				while (tmp >= final) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2796
				    if (InterruptPending != nil) __interruptL(@line);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2797
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2798
				    tmp += step;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2799
				}
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2800
			    }
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2801
			} else {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2802
			    if (step == 1) {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2803
				while (tmp <= final) {
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2804
				    if (InterruptPending != nil) __interruptL(@line);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2805
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2806
				    tmp++;
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2807
				}
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2808
			    } else {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2809
				while (tmp <= final) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2810
				    if (InterruptPending != nil) __interruptL(@line);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2811
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2812
				    tmp += step;
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2813
				}
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2814
			    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2815
			}
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2816
			RETURN (self);
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2817
		    }
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2818
		}
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2819
	    }
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2820
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2821
	    /*
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2822
	     * sorry - must check for the blocks code within the loops;
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2823
	     * it could be recompiled or flushed (in the interrupt)
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2824
	     */
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2825
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2826
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2827
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2828
#ifdef NEW_BLOCK_CALL
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2829
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2830
#           define IBLOCK_ARG nil
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2831
#else
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2832
#           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
  2833
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2834
#endif
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2835
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2836
	    if (step < 0) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2837
		while (tmp >= final) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2838
		    REGISTER OBJFUNC codeVal;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2839
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2840
		    if (InterruptPending != nil) __interruptL(@line);
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2841
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2842
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2843
			/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2844
			 * arg is a compiled block with code -
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2845
			 * directly call it without going through Block>>value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2846
			 */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2847
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2848
		    } else {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2849
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2850
			    /*
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2851
			     * arg is a compiled block with bytecode -
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2852
			     * directly call interpreter without going through Block>>value
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2853
			     */
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2854
#ifdef PASS_ARG_POINTER
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2855
			    {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2856
				OBJ idx;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2857
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2858
				idx = __mkSmallInteger(tmp);
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2859
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2860
			    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2861
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2862
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2863
#endif
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2864
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2865
			} else {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2866
			    /*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2867
			     * arg is something else - call it with #value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2868
			     */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2869
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2870
			}
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2871
		    }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2872
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2873
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2874
	    } else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2875
		while (tmp <= final) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2876
		    REGISTER OBJFUNC codeVal;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2877
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2878
		    if (InterruptPending != nil) __interruptL(@line);
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2879
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2880
		    if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2881
			/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2882
			 * arg is a compiled block with code -
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2883
			 * directly call it without going through Block>>value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2884
			 */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2885
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2886
		    } else {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2887
			if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2888
			    /*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2889
			     * arg is a compiled block with bytecode -
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2890
			     * directly call interpreter without going through Block>>value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2891
			     */
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2892
#ifdef PASS_ARG_POINTER
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2893
			    {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2894
				OBJ idx;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2895
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2896
				idx = __mkSmallInteger(tmp);
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2897
				__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2898
			    }
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2899
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2900
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2901
#endif
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2902
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2903
			} else {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2904
			    /*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2905
			     * arg is something else - call it with #value:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2906
			     */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2907
			    (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2908
			}
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2909
		    }
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2910
		    tmp += step;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2911
		}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2912
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2913
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2914
#           undef BLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2915
#           undef IBLOCK_ARG
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2916
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2917
	} else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2918
	    /*
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2919
	     * arg is something else - call it with #value:
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2920
	     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2921
	    if (step < 0) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2922
		while (tmp >= final) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2923
		    if (InterruptPending != nil) __interruptL(@line);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2924
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2925
		    (*blockVal.ilc_func)(aBlock,
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2926
					 @symbol(value:),
1688
8a42db1eea60 removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 1672
diff changeset
  2927
					 nil, &blockVal,
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2928
					 __mkSmallInteger(tmp));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2929
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2930
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2931
	    } else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2932
		while (tmp <= final) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2933
		    if (InterruptPending != nil) __interruptL(@line);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2934
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2935
		    (*blockVal.ilc_func)(aBlock,
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2936
					 @symbol(value:),
1688
8a42db1eea60 removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 1672
diff changeset
  2937
					 nil, &blockVal,
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2938
					 __mkSmallInteger(tmp));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2939
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2940
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2941
	    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2942
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2943
	RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2944
    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2945
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2946
    "/
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2947
    "/ 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
  2948
    "/ pass on to super ...
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2949
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2950
    ^ super to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2951
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2952
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2953
     1 to:10 by:3 do:[:i | i printNewline]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2954
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2955
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2956
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2957
to:stop do:aBlock
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  2958
    "evaluate aBlock for every integer between (and including) the receiver
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  2959
     and the argument, stop.
357
claus
parents: 329
diff changeset
  2960
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2961
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2962
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2963
    REGISTER INT tmp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2964
    INT final;
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  2965
    static struct inlineCache blockVal = __ILC1(0);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2966
252
  2967
    if (__isSmallInteger(stop)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2968
	tmp = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2969
	final = __intVal(stop);
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2970
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  2971
	if (__isBlockLike(aBlock)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2972
	 && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2973
	    {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2974
		/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2975
		 * specially tuned version for the most common case,
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2976
		 * where called with home on the stack
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2977
		 */
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2978
		REGISTER OBJFUNC codeVal;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2979
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  2980
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  2981
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  2982
#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
  2983
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2984
#                   define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2985
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2986
#else
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2987
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2988
#                   define BLOCK_ARG  rHome
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2989
		    REGISTER OBJ rHome;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  2990
		    rHome = __BlockInstPtr(aBlock)->b_home;
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2991
		    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
  2992
#endif
400
claus
parents: 394
diff changeset
  2993
		    {
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2994
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2995
#ifdef PARANOIA
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2996
			if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
2678
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2997
#endif
37eec0043bdb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2672
diff changeset
  2998
			{
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  2999
			    /*
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3000
			     * static compiled blocks ...
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3001
			     */
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3002
#ifdef __UNROLL_LOOPS__
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3003
			    /*
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3004
			     * The following code is designed to run as fast as possible;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3005
			     *  - taken branches only if interrupts are pending
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3006
			     *  - only forward branches (which are usually predicted as not taken)
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3007
			     *  - unrolled the loop
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3008
			     *
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3009
			     * you are not supposed to program like this - I know what I do
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3010
			     */
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3011
# if TAG_INT==1
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3012
			    INT t8 = (INT)(__mkSmallInteger(tmp+8));
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3013
			    tmp = (INT)(__mkSmallInteger(tmp));
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3014
			    final = (INT)(__mkSmallInteger(final));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3015
# else
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3016
			    INT t8 = tmp+8;
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3017
# endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3018
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3019
			    for (;;) {
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3020
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3021
				while (t8 <= final) {
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3022
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3023
				    t8 += (INT)(__MASKSMALLINT(8));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3024
# else
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3025
				    t8 += 8;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3026
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3027
				    if (InterruptPending != nil) goto interrupted0;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3028
	continue0:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3029
# if TAG_INT==1
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3030
				    (*codeVal)(BLOCK_ARG, tmp);
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3031
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3032
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3033
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3034
				    if (InterruptPending != nil) goto interrupted1;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3035
	continue1:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3036
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3037
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3038
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3039
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3040
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3041
				    if (InterruptPending != nil) goto interrupted2;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3042
	continue2:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3043
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3044
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3045
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3046
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3047
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3048
				    if (InterruptPending != nil) goto interrupted3;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3049
	continue3:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3050
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3051
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3052
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3053
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3054
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3055
				    if (InterruptPending != nil) goto interrupted4;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3056
	continue4:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3057
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3058
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3059
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3060
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3061
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3062
				    if (InterruptPending != nil) goto interrupted5;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3063
	continue5:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3064
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3065
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3066
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3067
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3068
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3069
				    if (InterruptPending != nil) goto interrupted6;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3070
	continue6:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3071
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3072
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3073
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3074
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3075
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3076
				    if (InterruptPending != nil) goto interrupted7;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3077
	continue7:
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3078
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3079
				    (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3080
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3081
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3082
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3083
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3084
# if TAG_INT==1
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3085
				    tmp += (INT)(__MASKSMALLINT(8));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3086
# else
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3087
				    tmp += 8;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3088
# endif
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3089
				}
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3090
				while (tmp <= final) {
2824
5295fc0fddb7 oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents: 2815
diff changeset
  3091
				    if (InterruptPending != nil) goto interruptedX;
5295fc0fddb7 oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents: 2815
diff changeset
  3092
	continueX:
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3093
# if TAG_INT==1
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3094
				    (*codeVal)(BLOCK_ARG, tmp);
2770
7c4ab842329f alpha changes
Claus Gittinger <cg@exept.de>
parents: 2693
diff changeset
  3095
				    tmp += (INT)(__MASKSMALLINT(1));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3096
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3097
				    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3098
				    tmp++;
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3099
# endif
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3100
				}
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3101
				RETURN (self);
2693
8ffe0f4374d6 10% speedup in to:do:
Claus Gittinger <cg@exept.de>
parents: 2678
diff changeset
  3102
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3103
				if (0) {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3104
				    /*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3105
				     * no discussion about those gotos ...
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3106
				     * ... its better for your CPU's pipelines
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3107
				     * (if you dont understand why, just dont argue).
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3108
				     */
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3109
				    interrupted7:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3110
						    __interruptL(@line); goto continue7;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3111
				    interrupted6:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3112
						    __interruptL(@line); goto continue6;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3113
				    interrupted5:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3114
						    __interruptL(@line); goto continue5;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3115
				    interrupted4:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3116
						    __interruptL(@line); goto continue4;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3117
				    interrupted3:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3118
						    __interruptL(@line); goto continue3;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3119
				    interrupted2:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3120
						    __interruptL(@line); goto continue2;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3121
				    interrupted1:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3122
						    __interruptL(@line); goto continue1;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3123
				    interrupted0:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3124
						    __interruptL(@line); goto continue0;
2824
5295fc0fddb7 oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents: 2815
diff changeset
  3125
				    interruptedX:
5295fc0fddb7 oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents: 2815
diff changeset
  3126
						    __interruptL(@line); goto continueX;
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3127
				}
2640
99fe7b8d2b86 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2604
diff changeset
  3128
			    }
2641
Claus Gittinger <cg@exept.de>
parents: 2640
diff changeset
  3129
#else
2640
99fe7b8d2b86 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2604
diff changeset
  3130
			    while (tmp <= final) {
99fe7b8d2b86 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2604
diff changeset
  3131
				if (InterruptPending != nil) __interruptL(@line);
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3132
				(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2640
99fe7b8d2b86 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2604
diff changeset
  3133
				tmp ++;
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3134
			    }
2640
99fe7b8d2b86 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2604
diff changeset
  3135
			    RETURN (self);
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  3136
#endif /* __UNROLL_LOOPS__ */
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3137
			}
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3138
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3139
			/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3140
			 * mhmh - seems to be a block with dynamic code
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3141
			 * must refetch, to allow dynamic recompilation or code flush.
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3142
			 */
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3143
			while (tmp <= final) {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3144
			    if (InterruptPending != nil) __interruptL(@line);
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3145
			    if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3146
			    (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3147
			    tmp ++;
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3148
			}
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3149
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3150
			if (tmp > final) {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3151
			    RETURN (self);
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3152
			}
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3153
		    }
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3154
		}
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3155
	    }
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3156
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3157
#           undef BLOCK_ARG
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3158
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3159
#ifdef NEW_BLOCK_CALL
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3160
#           define BLOCK_ARG  aBlock
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3161
#           define IBLOCK_ARG nil
400
claus
parents: 394
diff changeset
  3162
#else
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3163
#           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
  3164
#           define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
400
claus
parents: 394
diff changeset
  3165
#endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  3166
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3167
	    /*
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3168
	     * sorry - must check for the blocks code within the loops;
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3169
	     * it could be recompiled or flushed (in the interrupt)
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3170
	     */
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3171
	    while (tmp <= final) {
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3172
		REGISTER OBJFUNC codeVal;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3173
2254
5e3cb9e7e682 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2216
diff changeset
  3174
		if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3175
		    /*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3176
		     * arg is a compiled block with code -
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3177
		     * directly call it without going through Block>>value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3178
		     */
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3179
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3180
		    /* stay here, while no interrupts are pending ... */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3181
		    do {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3182
			(*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3183
			if (InterruptPending != nil) goto outerLoop;
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3184
			tmp++;
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3185
		    } while (tmp <= final);
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3186
		    RETURN (self);
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3187
		} else {
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3188
		    if (InterruptPending != nil) __interruptL(@line);
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3189
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3190
		    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3191
			/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3192
			 * arg is a compiled block with bytecode -
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3193
			 * directly call interpreter without going through Block>>value
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3194
			 */
400
claus
parents: 394
diff changeset
  3195
#ifdef PASS_ARG_POINTER
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3196
			{
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3197
			    OBJ idx;
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3198
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3199
			    idx = __mkSmallInteger(tmp);
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3200
			    __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3201
			}
400
claus
parents: 394
diff changeset
  3202
#else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3203
			__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
400
claus
parents: 394
diff changeset
  3204
#endif
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3205
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3206
		    } else {
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3207
			/*
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3208
			 * arg is something else - call it with #value:
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3209
			 */
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3210
			(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3211
		    }
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3212
		}
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3213
	    outerLoop: ;
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3214
		tmp++;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  3215
	    }
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3216
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3217
#           undef BLOCK_ARG
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3218
#           undef IBLOCK_ARG
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3219
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3220
	    RETURN (self);
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3221
	}
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3222
	/*
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3223
	 * arg is something else - call it with #value:
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3224
	 */
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3225
	while (tmp <= final) {
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3226
	    if (InterruptPending != nil) __interruptL(@line);
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3227
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3228
	    (*blockVal.ilc_func)(aBlock,
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3229
					 @symbol(value:),
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3230
					 nil, &blockVal,
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3231
					 __mkSmallInteger(tmp));
2650
8a31202275ff oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents: 2649
diff changeset
  3232
	    tmp++;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  3233
	}
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  3234
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3235
    }
400
claus
parents: 394
diff changeset
  3236
%}.
2187
37b82d044439 care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents: 1964
diff changeset
  3237
400
claus
parents: 394
diff changeset
  3238
    "/
claus
parents: 394
diff changeset
  3239
    "/ 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
  3240
    "/ pass on to super ...
400
claus
parents: 394
diff changeset
  3241
    "/
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3242
    ^ super to:stop do:aBlock
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3243
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  3244
    "
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  3245
     1 to:10 do:[:i | i printNewline]
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  3246
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3247
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3248
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3249
!SmallInteger methodsFor:'misc math'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3250
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3251
bernoulli
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3252
    "returns the nth Bernoulli number.
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3253
     The series runs this:
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3254
	 1/6, 1/30, 1/42, 1/30, 5/66, 691/2730, etc
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3255
     Uses a table of the first 20 bernoulli numbers.
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3256
     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
  3257
     Used with taylor series for tan"
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3258
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3259
    |table p|
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3260
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3261
    table := #(
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3262
		(1 6)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3263
		(-1 30)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3264
		(1 42)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3265
		(-1 30)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3266
		(5 66)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3267
		(-691 2730)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3268
		(7 6)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3269
		(-3617 510)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3270
		(43867 798)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3271
		(-174611 330)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3272
		(854513 138)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3273
		(-236364091 2730)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3274
		(8553103 6)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3275
		(-23749461029 870)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3276
		(8615841276005 14322)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3277
		(-7709321041217 510)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3278
		(2577687858367 6)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3279
		(-26315271553053477373 1919190)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3280
		(2929993913841559 6)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3281
		(-261082718496449122051 13530)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3282
	      ).
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3283
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3284
    self even ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3285
	self == 0 ifTrue:[^1].
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3286
	p := table at:(self / 2).
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3287
	^ 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
  3288
    ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3289
    self == 1 ifTrue:[ ^ (1 / 2) ].
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3290
    ^ 0.
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3291
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3292
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3293
     0 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3294
     1 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3295
     2 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3296
     3 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3297
     4 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3298
     5 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3299
     6 bernoulli
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3300
     8 bernoulli
7438
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3301
     38 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3302
     40 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3303
     41 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3304
     42 bernoulli
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3305
    "
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3306
!
f5f6fd13b1df code refactoring for metaNumbers and complete double dispatch.
Claus Gittinger <cg@exept.de>
parents: 7356
diff changeset
  3307
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3308
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3309
    "return an array filled with self // aNumber and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3310
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3311
     The result is only defined for positive receiver and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3312
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3313
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3314
%{  /* NOCONTEXT */
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3315
    INT val, div, mod, mySelf;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3316
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3914
diff changeset
  3317
    if (__isSmallInteger(aNumber) &&
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3318
	(val = __intVal(aNumber)) > 0) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3319
	mySelf = __intVal(self);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3320
	div = mySelf / val;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3321
	mod = mySelf % val;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3322
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3323
	RETURN (__ARRAY_WITH2( __mkSmallInteger(div),
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3324
			       __mkSmallInteger(mod)));
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3325
    }
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3326
%}.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3327
    ^ super divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3328
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3329
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3330
     10 // 3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3331
     10 \\ 3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3332
     10 divMod:3
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3333
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3334
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  3335
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3336
gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3337
    "return the greatest common divisor (Euclid's algorithm).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3338
     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
  3339
     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
  3340
     some code. (thanx to MessageTally)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3341
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3342
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3343
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3344
    if (__isSmallInteger(anInteger)) {
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3345
	INT orgArg, ttt, selfInt, orgSelfInt, temp;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3346
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3347
	ttt = orgArg = __intVal(anInteger);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3348
	if (ttt) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3349
	    selfInt = orgSelfInt = __intVal(self);
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3350
	    while (ttt != 0) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3351
		temp = selfInt % ttt;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3352
		selfInt = ttt;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3353
		ttt = temp;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3354
	    }
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3355
	    /*
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3356
	     * since its not defined in C, what the sign of
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3357
	     * a modulus result is when the arg is negative,
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3358
	     * change it explicitely here ...
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3359
	     */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3360
	    if (orgArg < 0) {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3361
		/* result should be negative */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3362
		if (orgSelfInt > 0) selfInt = -selfInt;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3363
	    } else {
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3364
		/* result should be positive */
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3365
		if (orgSelfInt < 0) selfInt = -selfInt;
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3366
	    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3367
	    RETURN ( __mkSmallInteger(selfInt) );
4167
15e0629ba1f1 inline asm mul for WIN32
Claus Gittinger <cg@exept.de>
parents: 4065
diff changeset
  3368
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3369
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3370
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3371
.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3372
    ^ super gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3373
!
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3374
2430
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3375
gcd_helper:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3376
    "same as gcd - see knuth & Integer>>gcd:"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3377
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3378
    ^ self gcd:anInteger
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3379
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3380
    "Created: 1.3.1997 / 16:58:01 / cg"
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3381
!
cbbf16de1bd7 better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents: 2254
diff changeset
  3382
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3383
intlog10
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3384
    "return the truncation of log10 of the receiver.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3385
     The same as (self log:10) floor.
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3386
     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
  3387
     to print a number/and for conversion to a LargeInteger.
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3388
     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
  3389
     (i.e. without log)."
2
claus
parents: 1
diff changeset
  3390
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3391
    self <= 0 ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3392
	^ self class
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3393
	    raise:#domainErrorSignal
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3394
	    receiver:self
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3395
	    selector:#intlog10
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3396
	    arguments:#()
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3397
	    errorString:'logarithm of negative integer'
2
claus
parents: 1
diff changeset
  3398
    ].
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3399
    self < 10000 ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3400
	self < 10 ifTrue:[^ 0].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3401
	self < 100 ifTrue:[^ 1].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3402
	self < 1000 ifTrue:[^ 2].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3403
	^ 3
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3404
    ].
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3405
    self < 100000000 ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3406
	self < 100000 ifTrue:[^ 4].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3407
	self < 1000000 ifTrue:[^ 5].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3408
	self < 10000000 ifTrue:[^ 6].
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3409
	^ 7
14492
a1b5c788c219 changed:
Claus Gittinger <cg@exept.de>
parents: 14167
diff changeset
  3410
    ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3411
    self < 1000000000 ifTrue:[^ 8].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3412
    ^ 9
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7267
diff changeset
  3413
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3414
    "
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3415
      99 intlog10
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3416
      100 intlog10
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3417
      101 intlog10
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3418
      (101 log:10) floor
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3419
      120 intlog10
6344
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  3420
      -1 intlog10
f49b43e5b724 Raise more specific errors
Stefan Vogel <sv@exept.de>
parents: 6144
diff changeset
  3421
    "
2
claus
parents: 1
diff changeset
  3422
! !
claus
parents: 1
diff changeset
  3423
3135
8c0f47cf59e3 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 3131
diff changeset
  3424
!SmallInteger methodsFor:'modulo arithmetic'!
2
claus
parents: 1
diff changeset
  3425
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3426
plus32:aNumber
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3427
    "return the sum of the receiver and the argument, as SmallInteger.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3428
     The argument must be another SmallInteger.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3429
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3430
     This is of course not always correct, but allows for C/Java behavior to be emulated."
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3431
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3432
%{  /* NOCONTEXT */
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3433
    INT sum;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3434
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3435
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3436
#if __POINTER_SIZE__ == 8
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3437
    sum &= 0xFFFFFFFFL;
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3438
#endif
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3439
    RETURN ( __MKUINT(sum));
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3440
%}.
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3441
    self primitiveFailed
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3442
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3443
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3444
     16r7FFFFFFF + 1          2147483648
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3445
     16r7FFFFFFF plus32: 1
12876
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3446
    "
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3447
!
813dd84a5901 more 32 bit modulu arithmetic
Claus Gittinger <cg@exept.de>
parents: 12866
diff changeset
  3448
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3449
plus:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3450
    "return the sum of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3451
     The argument must be another SmallInteger.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3452
     If the result overflows the smallInteger range, the value modulo the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3453
     smallInteger range is returned (i.e. the low bits of the sum).
3135
8c0f47cf59e3 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 3131
diff changeset
  3454
     This is of course not always correct, but some code does a modulo anyway
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3455
     and can therefore speed things up by not going through LargeIntegers."
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
  3456
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3457
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3458
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3459
    if (__isSmallInteger(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3460
	INT sum;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3461
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3462
	sum =  __intVal(self) + __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3463
	if (!__ISVALIDINTEGER(sum)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3464
	    /* keep the sign */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3465
	    sum %= _MAX_INT;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3466
	}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3467
	RETURN ( __mkSmallInteger(sum));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3468
    }
2785
3d222249bd61 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2781
diff changeset
  3469
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3470
    self primitiveFailed
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3471
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3472
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3473
	5 plus:-1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3474
	5 plus:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3475
	1 plus:-5
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3476
	self maxVal plus:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3477
	self maxVal + 1
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3478
    "
2
claus
parents: 1
diff changeset
  3479
!
claus
parents: 1
diff changeset
  3480
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3481
subtract:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3482
    "return the difference of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3483
     The argument must be another SmallInteger.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3484
     If the result overflows the smallInteger range, the value modulo the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3485
     smallInteger range is returned (i.e. the low bits of the sum).
3135
8c0f47cf59e3 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 3131
diff changeset
  3486
     This is of course not always correct, but some code does a modulo anyway
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3487
     and can therefore speed things up by not going through LargeIntegers."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3488
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3489
%{  /* NOCONTEXT */
2
claus
parents: 1
diff changeset
  3490
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3491
    if (__isSmallInteger(aNumber)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3492
	INT diff;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3493
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3494
	diff = __intVal(self) - __intVal(aNumber);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3495
	if (!__ISVALIDINTEGER(diff)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3496
	    /* keep the sign */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3497
	    diff %= _MAX_INT;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3498
	}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3499
	RETURN ( __mkSmallInteger(diff));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3500
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3501
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3502
    self primitiveFailed
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3503
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3504
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3505
	-1 subtract:5
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3506
	5 subtract:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3507
	1 subtract:-5
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3508
	self minVal subtract:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3509
	self minVal - 1
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3510
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3511
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3512
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3513
times:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3514
    "return the product of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3515
     The argument must be another SmallInteger.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3516
     If the result overflows the smallInteger range, the value modulo the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3517
     smallInteger range is returned (i.e. the low bits of the product).
3135
8c0f47cf59e3 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 3131
diff changeset
  3518
     This is of course not always correct, but some code does a modulo anyway
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3519
     and can therefore speed things up by not going through LargeIntegers."
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
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3522
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3523
    INT myValue, otherValue;
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3524
    unsigned INT productLow, productHi;
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3525
    int negative;
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3526
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3527
#   define low16Bits(foo)  ((foo) & 0xFFFF)
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3528
#   define hi16Bits(foo)   ((foo) >> 16)
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3529
#   define low32Bits(foo)  ((foo) & 0xFFFFFFFFL)
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3530
#   define hi32Bits(foo)   ((foo) >> 32)
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3531
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3532
    /*
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3533
     * can we use long long arithmetic ?
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3534
     *
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3535
     * long-long arithmetic seems to be buggy with some systems
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3536
     * (took me a while to find this out :-(
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3537
     * (try 10000 * 10000)
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3538
     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3539
#if defined(__sparc__) && defined(__GNUC__) && (__GNUC__ >= 2)
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3540
# define USE_LONGLONG_FOR_MUL
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3541
#endif
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3542
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3543
#if defined(__i386__) && defined(__GNUC__) && (__GNUC__ >= 2)
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3544
# define USE_LONGLONG_FOR_MUL
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3545
#endif
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3546
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3547
    if (__isSmallInteger(aNumber)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3548
	myValue = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3549
	otherValue = __intVal(aNumber);
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3550
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3551
#if defined(USE_LONGLONG_FOR_MUL)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3552
	{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3553
# if defined(__alpha__) && !defined(__alpha64__)
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3554
#  define LONGLONG      INT64
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3555
# else
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3556
#  define LONGLONG      long long
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3557
# endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3558
	    LONGLONG product;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3559
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3560
	    product = (LONGLONG)myValue * (LONGLONG)otherValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3561
	    if (product < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3562
		RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT)));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3563
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3564
	    RETURN ( __mkSmallInteger((INT)(product & _MAX_INT)));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3565
	}
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3566
#else /* no long-long */
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3567
	negative = 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3568
	if (myValue < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3569
	    negative = -1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3570
	    myValue = -myValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3571
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3572
	if (otherValue < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3573
	    negative = -negative;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3574
	    otherValue = -otherValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3575
	}
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3576
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3577
# if defined(__GNUC__) && defined(__mc68k__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3578
	asm ("mulu%.l %3,%1:%0"
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3579
		: "=d"  ((unsigned long)(productLow)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3580
		  "=d"  ((unsigned long)(productHi))
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3581
		: "%0"  ((unsigned long)(myValue)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3582
		  "dmi" ((unsigned long)(otherValue)));
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3583
# else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3584
#  if defined (__GNUC__) && defined(__i386__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3585
	asm ("mull %3"
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3586
		: "=a"  ((unsigned long)(productLow)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3587
		  "=d"  ((unsigned long)(productHi))
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3588
		: "%0"  ((unsigned long)(myValue)),
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3589
		  "rm"  ((unsigned long)(otherValue)));
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3590
#  else
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8937
diff changeset
  3591
#   if defined(WIN32) && defined(__BORLANDC__)
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3592
	asm {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3593
	    mov   eax, myValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3594
	    mov   edx, otherValue
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3595
	    mul   edx
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3596
	    mov   productLow, eax
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3597
	    mov   productHi, edx
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3598
	}
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3599
#   else /* generic */
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3600
	{
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3601
	    unsigned INT pHH, pHL, pLH, pLL;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3602
	    unsigned INT low1, low2, hi1, hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3603
	    unsigned INT t;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3604
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3605
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3606
	     *
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3607
	     * this is too slow:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3608
	     * since most machines can do 32*32 to 64 bit multiply,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3609
	     * (or at least 32*32 with Overflow check)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3610
	     * - need more assembler (inline) functions here
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3611
	     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3612
#    if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3613
	    low1 = low32Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3614
	    hi1 = hi32Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3615
	    low2 = low32Bits((unsigned INT)otherValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3616
	    hi2 = hi32Bits((unsigned INT)otherValue);
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3617
#     define LLMASK 0xC000000000000000L
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3618
#    else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3619
	    low1 = low16Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3620
	    hi1 = hi16Bits((unsigned INT)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3621
	    low2 = low16Bits((unsigned INT)otherValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3622
	    hi2 = hi16Bits((unsigned INT)otherValue);
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3623
#     define LLMASK 0xC0000000
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3624
#    endif
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3625
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3626
	    pLH = low1 * hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3627
	    pHL = hi1 * low2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3628
	    pLL = low1 * low2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3629
	    pHH = hi1 * hi2;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3630
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3631
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3632
	     * the common case ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3633
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3634
	    if ((pHL == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3635
	     && (pLH == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3636
	     && (pHH == 0)
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3637
	     && ((pLL & LLMASK) == 0)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3638
		if (negative < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3639
		    RETURN ( __mkSmallInteger(- ((INT)pLL)) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3640
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3641
		RETURN ( __mkSmallInteger((INT)pLL) );
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3642
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3643
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3644
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3645
	     *   pHH |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3646
	     *   pLH          |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3647
	     *   pHL          |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3648
	     *   pLL                   |--------|--------|
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3649
	     */
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3650
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3651
#    if __POINTER_SIZE__ == 8
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3652
	    t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3653
	    productLow = (t << 32) + low32Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3654
	    productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH);
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3655
#    else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3656
	    t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3657
	    productLow = (t << 16) + low16Bits(pLL);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3658
	    productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3659
#    endif
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3660
	}
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3661
#   endif /* ! WIN32 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3662
#  endif /* ! (__GNUC__ && __i386__) */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8506
diff changeset
  3663
# endif /* ! (__GNUC__ && __mc68k__) */
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3664
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3665
	if (negative < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3666
	    RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT)));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3667
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3668
	RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT)));
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3669
#endif /* ! USE_LONGLONG */
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3670
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3671
%}.
8506
ddd41df3dc0f Fix #times: for WIN32
Stefan Vogel <sv@exept.de>
parents: 8498
diff changeset
  3672
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3673
    self primitiveFailed
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3674
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3675
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3676
	5 times:-1
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3677
	5 times:1
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3678
	self maxVal-1 times:2
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3679
	self maxVal-1 times:-2
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3680
	self maxVal-1 * 2  bitAnd:16r3fffffff
8498
854b2c98379e keep the sign when doing modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 8417
diff changeset
  3681
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3682
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3683
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3684
!SmallInteger methodsFor:'printing & storing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3685
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3686
printOn:aStream
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  3687
    "append my printstring (base 10) to aStream."
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3688
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3689
    aStream nextPutAll:(self printString)
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3690
!
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3691
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  3692
printOn:aStream base:base showRadix:showRadix
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  3693
    "append a string representation of the receiver in the specified numberBase to aStream
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  3694
     (if showRadix is true, with initial XXr)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  3695
     The base argument should be between 2 and 36."
6144
35b772717356 check for bad radix
james
parents: 6092
diff changeset
  3696
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  3697
    showRadix ifTrue:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3698
	base printOn:aStream.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3699
	aStream nextPut:$r.
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  3700
    ].
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  3701
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3702
    (base isInteger and:[ base between:2 and:36 ]) ifTrue:[
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3703
	aStream nextPutAll:(self printStringRadix:base)
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  3704
    ] ifFalse:[
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3705
	super printOn:aStream base:base showRadix:false.
11792
6782c723834a changed #printOn:based:showRadix:
Stefan Vogel <sv@exept.de>
parents: 11728
diff changeset
  3706
    ].
5988
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  3707
12977
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  3708
    "Created: / 07-09-2001 / 13:54:40 / cg"
fbf5437b15fb changed: #printOn:base:showRadix:
Claus Gittinger <cg@exept.de>
parents: 12876
diff changeset
  3709
    "Modified: / 02-08-2010 / 12:25:20 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3710
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3711
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3712
printString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3713
    "return my printstring (base 10)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3714
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3715
    "since this was heavily used in some applications,
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  3716
     here is an exception to the rule of basing printString
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  3717
     upon the printOn: method."
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  3718
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3719
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3720
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3721
    char buffer[30];
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3722
    char *cp;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3723
    OBJ newString = nil;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3724
    INT myValue;
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3725
    int negative = 0;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3726
    int len;
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3727
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3728
    myValue = __intVal(self);
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3729
    if (myValue == 0) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3730
	RETURN (__MKSTRING_L("0", 1));
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3731
    }
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3732
#ifdef SLOW_CODE
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3733
    /*
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3734
     * this takes twice as long as the code below ...
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3735
     * (printf is soooo slow)
369
claus
parents: 357
diff changeset
  3736
     */
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3737
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3738
    /*
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3739
     * actually only needed on sparc: since thisContext is
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3740
     * in a global register, which gets destroyed by printf,
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3741
     * manually save it here - very stupid ...
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3742
     */
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3743
    __BEGIN_PROTECT_REGISTERS__
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3744
    len = snprintf(buffer, sizeof(buffer), "%"_ld_"", (long)myValue);
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3745
    __END_PROTECT_REGISTERS__
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3746
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3747
    if (len >= 0 && len <= sizeof(buffer)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3748
	newString = __MKSTRING_L(buffer, len);
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3749
    }
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3750
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3751
#else
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3752
    if (myValue < 0) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3753
	negative = 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3754
	myValue = -myValue;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3755
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3756
    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
  3757
    *cp-- = '\0';
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3758
    while (myValue != 0) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3759
	*cp = '0' + (myValue % 10);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3760
	myValue = myValue / 10;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3761
	cp--;
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3762
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3763
    if (negative) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3764
	*cp-- = '-';
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3765
    }
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3766
    newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3767
#endif
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  3768
    if (newString != nil) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3769
	RETURN (newString);
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  3770
    }
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  3771
%}.
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3772
    "/ only arrive here,
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3773
    "/  when having memory problems (i.e. no space for string) ...
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  3774
    ^ super printString
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3775
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3776
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3777
     1234 printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3778
     0    printString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3779
     -100 printString
3704
4dd3cb7ae956 SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents: 3684
diff changeset
  3780
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3781
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3782
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3783
printStringRadix:base
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3784
    "return my printstring (optimized for bases 16, 10 and 8)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3785
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3786
    |s|
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3787
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3788
%{
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3789
    char buffer[64+3];  /* for alpha, base 2 plus sign */
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3790
    char *cp;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3791
    OBJ newString;
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3792
    INT myValue;
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3793
    int negative = 0;
3706
6cd714580176 avoid name conflict.
Claus Gittinger <cg@exept.de>
parents: 3705
diff changeset
  3794
    INT __base;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3795
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3796
    if (__isSmallInteger(base)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3797
	myValue = __intVal(self);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3798
	if (myValue == 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3799
	    RETURN (__MKSTRING_L("0", 1));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3800
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3801
	__base = __intVal(base);
3706
6cd714580176 avoid name conflict.
Claus Gittinger <cg@exept.de>
parents: 3705
diff changeset
  3802
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3803
#ifdef SLOW_CODE
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3804
	switch (__base) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3805
	    case 10:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3806
		format = "%"_ld_"";
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3807
		break;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3808
	    case 16:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3809
		format = "%"_lx_"";
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3810
		break;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3811
	    case 8:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3812
		format = "%"_lo_"";
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3813
		break;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3814
	}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3815
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3816
	if (format) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3817
	    /*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3818
	     * actually only needed on sparc: since thisContext is
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3819
	     * in a global register, which gets destroyed by printf,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3820
	     * manually save it here - very stupid ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3821
	     */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3822
	    __BEGIN_PROTECT_REGISTERS__
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3823
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3824
	    len = snprintf(buffer, sizeof(buffer), format, (long)myValue);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3825
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3826
	    __END_PROTECT_REGISTERS__
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3827
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3828
	    if (len > 0 && len <= sizeof(buffer)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3829
		newString = __MKSTRING_L(buffer, len);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3830
		if (newString != nil) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3831
		    RETURN (newString);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3832
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3833
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3834
	}
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3835
#else
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3836
	if ((__base <= 36) && (__base > 1)) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3837
	    if (myValue < 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3838
		negative = 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3839
		myValue = -myValue;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3840
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3841
	    cp = buffer + sizeof(buffer) - 1;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3842
	    *cp-- = '\0';
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3843
	    while (myValue != 0) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3844
		int digit;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3845
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3846
		digit = myValue % __base;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3847
		if (digit <= 9) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3848
		    *cp = '0' + digit;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3849
		} else {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3850
		    *cp = 'A' + digit - 10;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3851
		}
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3852
		myValue = myValue / __base;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3853
		cp--;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3854
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3855
	    if (negative) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3856
		*cp-- = '-';
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3857
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3858
	    newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3859
	    if (newString != nil) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3860
		RETURN (newString);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3861
	    }
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3862
	}
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3863
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3864
    }
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  3865
%}.
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3866
    "/ arrive here, for bad base,
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3867
    "/ or when having memory problems (i.e. no space for string) ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3868
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3869
    "/
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3870
    "/ fall back for seldom used bases
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3871
    "/ Notice: cannt use super>>printStringRadix: here,
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3872
    "/ since that would lead to endless recursion ...
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3873
    "/ (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
  3874
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3875
    s := WriteStream on:(String new:10).
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3876
    super printOn:s base:base.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3877
    ^ s contents.
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3878
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3879
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3880
      127 printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3881
      123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3882
      123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3883
      123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3884
      123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3885
      123 printStringRadix:2
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3886
      123 printStringRadix:1
3705
f4e7b2db4d4b new printStringRadix:
Claus Gittinger <cg@exept.de>
parents: 3704
diff changeset
  3887
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3888
      -127 printStringRadix:16
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3889
      -123 printStringRadix:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3890
      -123 printStringRadix:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3891
      -123 printStringRadix:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3892
      -123 printStringRadix:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3893
      -123 printStringRadix:2
3189
f07145cc8ef7 Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents: 3156
diff changeset
  3894
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3895
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3896
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3897
printfPrintString:formatString
7746
4a4208ef7699 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  3898
    "non-standard, but sometimes useful.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3899
     return a printed representation of the receiver
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3900
     as specified by formatString, which is defined by the C-
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3901
     function 'printf'.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3902
     No checking for string overrun - the resulting string
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  3903
     must be shorter than 256 chars or else ...
2781
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3904
     This method is NONSTANDARD and may be removed without notice;
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3905
     it is provided to allow special conversions in very special
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3906
     situaltions.
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3907
     Notice that a conversion may not be portable; for example,
eca37ca06b66 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
  3908
     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
  3909
     on 64bit mingw or visualc, %lld is required,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3910
     while other systems may be happy with a %d.
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3911
     (We cannot use lld unconditionally, because some (old) c compilers do not support it!!)
11923
bf02cbdab69f changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11792
diff changeset
  3912
     Use at your own risk (if at all).
bf02cbdab69f changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11792
diff changeset
  3913
     WARNNG: this goes directly to the C-printf function and may therefore me inherently unsafe.
bf02cbdab69f changed #printfPrintString:
Claus Gittinger <cg@exept.de>
parents: 11792
diff changeset
  3914
     Please use the printf: method, which is safe as it is completely implemented in Smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3915
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  3916
%{  /* STACK: 400 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3917
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  3918
    OBJ s;
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3919
    int len;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3920
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  3921
    if (__isStringLike(formatString)) {
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3922
	/*
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3923
	 * actually only needed on sparc: since thisContext is
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3924
	 * in a global register, which gets destroyed by printf,
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3925
	 * manually save it here - very stupid ...
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3926
	 */
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3927
	__BEGIN_PROTECT_REGISTERS__
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3928
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3929
	len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self));
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3930
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3931
	__END_PROTECT_REGISTERS__
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3932
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3933
	if (len < 0) goto fail;
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3934
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3935
	s = __MKSTRING_L(buffer, len);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3936
	if (s != nil) {
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3937
	    RETURN (s);
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3938
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3939
    }
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3940
fail: ;
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  3941
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3942
    self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3943
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3944
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3945
	123 printfPrintString:'%%d -> %d'
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3946
	123 printfPrintString:'%%6d -> %6d'
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3947
	123 printfPrintString:'%%x -> %x'
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3948
	123 printfPrintString:'%%4x -> %4x'
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  3949
	123 printfPrintString:'%%04x -> %04x'
8417
dcba76518224 Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents: 8408
diff changeset
  3950
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3951
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3952
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3953
!SmallInteger methodsFor:'private'!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3954
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3955
sign:aNumber
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3956
    "private: for protocol completeness with LargeIntegers"
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3957
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3958
    |absVal|
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3959
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3960
    absVal := self abs.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3961
    aNumber < 0 ifTrue:[
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3962
	^ absVal negated
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3963
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3964
    aNumber == 0 ifTrue:[^ 0].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3965
    ^ absVal
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3966
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3967
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3968
     -4 sign:-1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3969
     -4 sign:0
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3970
     -4 sign:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3971
     -4 sign:-1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3972
     -4 sign:0
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3973
     -4 sign:1
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3974
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3975
! !
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
  3976
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3977
!SmallInteger methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3978
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3979
between:min and:max
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3980
    "return true if the receiver is less than or equal to the argument max
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3981
     and greater than or equal to the argument min.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3982
     - reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3983
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3984
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3985
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3986
    if (__bothSmallInteger(min, max)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3987
	REGISTER INT selfVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3988
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  3989
	selfVal = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  3990
	if (selfVal < __intVal(min)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3991
	     RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3992
	}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  3993
	if (selfVal > __intVal(max)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3994
	     RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3995
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3996
	RETURN ( true );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3997
    }
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  3998
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  3999
    (self < min) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4000
    (self > max) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4001
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4002
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4003
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4004
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4005
    "return true, if the receiver is even"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4006
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4007
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4008
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4009
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4010
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4011
    ^ super even
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4012
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4013
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4014
isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4015
    "return true, if the receiver is a power of 2"
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4016
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4017
"/ mhmh: how about the following
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4018
"/    self == 0 ifTrue:[^ false].
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4019
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4020
    ^ (self bitAnd:(self - 1)) == 0
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4021
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4022
    "
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4023
     0 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4024
     1 isPowerOfTwo
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4025
     2 isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4026
     3 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4027
     4 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4028
     16r8000000000000000 isPowerOfTwo
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4029
     16r8000000000000001 isPowerOfTwo
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4030
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4031
     10000 factorial isPowerOfTwo
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4032
     |n| n := 10000 factorial. Time millisecondsToRun:[1000 timesRepeat:[ n isPowerOfTwo]]
13386
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4033
    "
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4034
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4035
    "Modified: / 20-06-2011 / 12:41:18 / cg"
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4036
!
6986799e2da1 moved: #isPowerOfTwo
Claus Gittinger <cg@exept.de>
parents: 13006
diff changeset
  4037
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4038
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4039
    "return true, if the receiver is less than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4040
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4041
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4042
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4043
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4044
#if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4045
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4046
    RETURN ( ((INT)(self) < 0) ? true : false );
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4047
#else
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4048
    RETURN ( (__intVal(self) < 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4049
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4050
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4051
    ^ self < 0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4052
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4053
14693
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4054
nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4055
    "return the power of 2 at or above the receiver.
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4056
     Useful for padding."
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4057
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4058
%{  /* NOCONTEXT */
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4059
    INT x;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4060
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4061
    x = __intVal(self) - 1;
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4062
    x |= (x >> 1);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4063
    x |= (x >> 2);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4064
    x |= (x >> 4);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4065
    x |= (x >> 8);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4066
    x |= (x >> 16);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4067
#if __POINTER_SIZE__ == 8
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4068
    x |= (x >> 32);
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4069
#endif
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4070
    RETURN (__MKINT(x + 1));
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4071
%}
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4072
    "
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4073
     1 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4074
     2 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4075
     3 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4076
     4 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4077
     5 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4078
     6 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4079
     7 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4080
     8 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4081
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4082
     22 nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4083
     10 factorial nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4084
     20 factorial nextPowerOf2
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4085
    "
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4086
!
d65d6d900457 added nextPowerOf2
Claus Gittinger <cg@exept.de>
parents: 14632
diff changeset
  4087
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4088
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4089
    "return true, if the receiver is odd"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4090
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4091
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4092
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4093
    RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4094
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4095
    ^ super odd
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4096
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4097
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4098
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4099
parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4100
    "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
  4101
     (i.e. true for odd parity)
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4102
     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
  4103
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4104
%{  /* NOCONTEXT */
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4105
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4106
    // tricky, but very fast (google for it, to understand)
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4107
#if __POINTER_SIZE__ == 4
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4108
    unsigned int v = __intVal(self);
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4109
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4110
    v ^= v >> 16;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4111
    v ^= v >> 8;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4112
    v ^= v >> 4;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4113
    v &= 0xf;
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4114
    RETURN ( ( (0x6996 >> v) & 1 ) ? true : false );
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4115
#endif
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4116
%}.
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4117
    ^ super parityOdd
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4118
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4119
    "
14632
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4120
	self assert:
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4121
	 (((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0])
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4122
	    asByteArray collect:[:c | c + $0 asciiValue]) asString
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4123
	 =
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4124
	    '0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110'
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4125
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4126
	self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd).
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4127
	self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd).
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4128
	self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd).
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4129
	self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd).
6fe0dc1d5377 64bit mingw changes
Claus Gittinger <cg@exept.de>
parents: 14540
diff changeset
  4130
	self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd).
13913
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4131
    "
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4132
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4133
    "Modified (comment): / 09-01-2012 / 19:55:37 / cg"
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4134
!
64aaf4304364 added: #parityOdd
Claus Gittinger <cg@exept.de>
parents: 13912
diff changeset
  4135
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4136
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4137
    "return true, if the receiver is not negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4138
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4139
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4140
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4141
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4142
#if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4143
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4144
    RETURN ( ((INT)(self) >= 0) ? true : false );
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4145
#else
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4146
    RETURN ( (__intVal(self) >= 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4147
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4148
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4149
    ^ super positive
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4150
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4151
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4152
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4153
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7438
diff changeset
  4154
    "return the sign of the receiver (-1, 0 or 1).
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4155
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4156
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4157
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4158
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  4159
    INT val = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4160
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4161
    if (val < 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4162
	RETURN ( __mkSmallInteger(-1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4163
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4164
    if (val > 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4165
	RETURN ( __mkSmallInteger(1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4166
    }
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4167
    RETURN ( __mkSmallInteger(0) );
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4168
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4169
    ^ super sign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4170
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4171
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4172
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4173
    "return true, if the receiver is greater than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4174
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4175
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4176
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4177
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4178
#if TAG_INT == 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4179
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4180
    RETURN ( ((INT)(self) > 0) ? true : false );
2216
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4181
#else
e4fed6c622de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2187
diff changeset
  4182
    RETURN ( (__intVal(self) > 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4183
#endif
5412
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4184
%}.
323c7d7ae289 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
  4185
    ^ super strictlyPositive
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4186
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4187
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
  4188
!SmallInteger class methodsFor:'documentation'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4189
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4190
version
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  4191
    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.203 2013-04-15 13:07:21 cg Exp $'
12482
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  4192
!
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  4193
41f0acde1b79 change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 11923
diff changeset
  4194
version_CVS
15083
0b700edf1d1b class: SmallInteger
Claus Gittinger <cg@exept.de>
parents: 14795
diff changeset
  4195
    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.203 2013-04-15 13:07:21 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  4196
! !
14755
821ba902d413 class: SmallInteger
Stefan Vogel <sv@exept.de>
parents: 14693
diff changeset
  4197