The Trunk: Collections-ul.655.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-ul.655.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.655.mcz

==================== Summary ====================

Name: Collections-ul.655
Author: ul
Time: 9 September 2015, 8:30:27.564 pm
UUID: 179eb75e-eb8d-4c16-8934-158921d1ff81
Ancestors: Collections-ul.654

- 64-bit compatible and faster ByteArray>>unsignedLong64At:put:bigEndian:
- faster ByteArray>>unsignedLong64At:bigEndian:

=============== Diff against Collections-ul.654 ===============

Item was changed:
  ----- Method: ByteArray>>longAt:bigEndian: (in category 'platform independent access') -----
  longAt: index bigEndian: bigEndian
  "Return a 32-bit integer quantity starting from the given byte index. Use #normalize where necessary to ensure compatibility with non-30-bit SmallIntegers."
 
  | byte result |
  bigEndian ifFalse: [
  (byte := self at: index + 3) <= 16r7F ifTrue: [ "Is the result non-negative?"
  byte <= 16r3F ifTrue: [
  ^(((byte bitShift: 8) + (self at: index + 2) bitShift: 8) + (self at: index + 1) bitShift: 8) + (self at: index) ].
  ^(LargePositiveInteger new: 4)
  replaceFrom: 1
+ to: 4
+ with: self
+ startingAt: index;
- to: 4
- with: self
- startingAt: index;
  normalize ].
  "Negative"
  byte >= 16rC0 ifTrue: [
  ^-1 - (((((byte bitShift: 8) + (self at: index + 2) bitShift: 8) + (self at: index + 1) bitXor: 16rFFFFFF) bitShift: 8) + ((self at: index) bitXor: 16rFF)) ].
  (result := LargeNegativeInteger new: 4)
  digitAt: 4 put: ((self at: index + 3) bitXor: 16rFF);
  digitAt: 3 put: ((self at: index + 2) bitXor: 16rFF);
  digitAt: 2 put: ((self at: index + 1) bitXor: 16rFF).
  (byte := ((self at: index) bitXor: 16rFF) + 1) <= 16rFF ifTrue: [
  ^result
  digitAt: 1 put: byte;
  normalize ].
  ^result
  digitAt: 1 put: 16rFF;
+ - 1 "It's tempting to do the subtraction in a loop to avoid the LargeInteger creation, but it's actually slower than this." ].
- - 1 "It's tempting to do the subtraction in a loop, to avoid the LargeInteger creation, but it's actually slower than this." ].
  (byte := self at: index) <= 16r7F ifTrue: [ "Is the result non-negative?"
  byte <= 16r3F ifTrue: [
  ^(((byte bitShift: 8) + (self at: index + 1) bitShift: 8) + (self at: index + 2) bitShift: 8) + (self at: index + 3) ].
  ^(LargePositiveInteger new: 4)
  digitAt: 1 put: (self at: index + 3);
  digitAt: 2 put: (self at: index + 2);
  digitAt: 3 put: (self at: index + 1);
  digitAt: 4 put: byte;
  normalize ].
  "Negative"
  16rC0 <= byte ifTrue: [
  ^-1 - (((((byte bitShift: 8) + (self at: index + 1) bitShift: 8) + (self at: index + 2) bitXor: 16rFFFFFF) bitShift: 8) + ((self at: index + 3) bitXor: 16rFF)) ].
  (result := LargeNegativeInteger new: 4)
  digitAt: 4 put: (byte bitXor: 16rFF);
  digitAt: 3 put: ((self at: index + 1) bitXor: 16rFF);
  digitAt: 2 put: ((self at: index + 2) bitXor: 16rFF).
  (byte := ((self at: index + 3) bitXor: 16rFF) + 1) <= 16rFF ifTrue: [
  ^result
  digitAt: 1 put: byte;
  normalize ].
  ^result
  digitAt: 1 put: 16rFF;
+ - 1 "It's tempting to do the subtraction in a loop to avoid the LargeInteger creation, but it's actually slower than this."!
- - 1 "It's tempting to do the subtraction in a loop, to avoid the LargeInteger creation, but it's actually slower than this."!

Item was changed:
  ----- Method: ByteArray>>unsignedLong64At:bigEndian: (in category 'platform independent access') -----
  unsignedLong64At: index bigEndian: bigEndian
  "Return a 64-bit unsigned integer quantity starting from the given byte index. Use #normalize where necessary to ensure compatibility with non-30-bit SmallIntegers."
 
  | v |
  bigEndian ifFalse: [
  (v := self at: index + 7) = 0 ifFalse: [
  ^(LargePositiveInteger new: 8)
+ replaceFrom: 1
+ to: 8
+ with: self
+ startingAt: index;
- digitAt: 1 put: (self at: index);
- digitAt: 2 put: (self at: index + 1);
- digitAt: 3 put: (self at: index + 2);
- digitAt: 4 put: (self at: index + 3);
- digitAt: 5 put: (self at: index + 4);
- digitAt: 6 put: (self at: index + 5);
- digitAt: 7 put: (self at: index + 6);
- digitAt: 8 put: v;
  normalize ].
  (v := self at: index + 6) = 0 ifFalse: [
  ^(LargePositiveInteger new: 7)
+ replaceFrom: 1
+ to: 7
+ with: self
+ startingAt: index;
- digitAt: 1 put: (self at: index);
- digitAt: 2 put: (self at: index + 1);
- digitAt: 3 put: (self at: index + 2);
- digitAt: 4 put: (self at: index + 3);
- digitAt: 5 put: (self at: index + 4);
- digitAt: 6 put: (self at: index + 5);
- digitAt: 7 put: v;
  normalize ].
  (v := self at: index + 5) = 0 ifFalse: [
  ^(LargePositiveInteger new: 6)
+ replaceFrom: 1
+ to: 6
+ with: self
+ startingAt: index;
- digitAt: 1 put: (self at: index);
- digitAt: 2 put: (self at: index + 1);
- digitAt: 3 put: (self at: index + 2);
- digitAt: 4 put: (self at: index + 3);
- digitAt: 5 put: (self at: index + 4);
- digitAt: 6 put: v;
  normalize ].
  (v := self at: index + 4) = 0 ifFalse: [
  ^(LargePositiveInteger new: 5)
+ replaceFrom: 1
+ to: 5
+ with: self
+ startingAt: index;
- digitAt: 1 put: (self at: index);
- digitAt: 2 put: (self at: index + 1);
- digitAt: 3 put: (self at: index + 2);
- digitAt: 4 put: (self at: index + 3);
- digitAt: 5 put: v;
  normalize ].
  (v := self at: index + 3) <= 16r3F ifFalse: [
  ^(LargePositiveInteger new: 4)
+ replaceFrom: 1
+ to: 4
+ with: self
+ startingAt: index;
- digitAt: 1 put: (self at: index);
- digitAt: 2 put: (self at: index + 1);
- digitAt: 3 put: (self at: index + 2);
- digitAt: 4 put: v;
  normalize ].
  ^(((v bitShift: 8) + (self at: index + 2) bitShift: 8) + (self at: index + 1) bitShift: 8) + (self at: index) ].
  (v := self at: index) = 0 ifFalse: [
  ^(LargePositiveInteger new: 8)
  digitAt: 1 put: (self at: index + 7);
  digitAt: 2 put: (self at: index + 6);
  digitAt: 3 put: (self at: index + 5);
  digitAt: 4 put: (self at: index + 4);
  digitAt: 5 put: (self at: index + 3);
  digitAt: 6 put: (self at: index + 2);
  digitAt: 7 put: (self at: index + 1);
  digitAt: 8 put: v;
  normalize ].
  (v := self at: index + 1) = 0 ifFalse: [
  ^(LargePositiveInteger new: 7)
  digitAt: 1 put: (self at: index + 7);
  digitAt: 2 put: (self at: index + 6);
  digitAt: 3 put: (self at: index + 5);
  digitAt: 4 put: (self at: index + 4);
  digitAt: 5 put: (self at: index + 3);
  digitAt: 6 put: (self at: index + 2);
  digitAt: 7 put: v;
  normalize ].
  (v := self at: index + 2) = 0 ifFalse: [
  ^(LargePositiveInteger new: 6)
  digitAt: 1 put: (self at: index + 7);
  digitAt: 2 put: (self at: index + 6);
  digitAt: 3 put: (self at: index + 5);
  digitAt: 4 put: (self at: index + 4);
  digitAt: 5 put: (self at: index + 3);
  digitAt: 6 put: v;
  normalize ].
  (v := self at: index + 3) = 0 ifFalse: [
  ^(LargePositiveInteger new: 5)
  digitAt: 1 put: (self at: index + 7);
  digitAt: 2 put: (self at: index + 6);
  digitAt: 3 put: (self at: index + 5);
  digitAt: 4 put: (self at: index + 4);
  digitAt: 5 put: v;
  normalize ].
  (v := self at: index + 4) <= 16r3F ifFalse: [
  ^(LargePositiveInteger new: 4)
  digitAt: 1 put: (self at: index + 7);
  digitAt: 2 put: (self at: index + 6);
  digitAt: 3 put: (self at: index + 5);
  digitAt: 4 put: v;
  normalize ].
  ^(((v bitShift: 8) + (self at: index + 5) bitShift: 8) + (self at: index + 6) bitShift: 8) + (self at: index + 7)!

Item was changed:
  ----- Method: ByteArray>>unsignedLong64At:put:bigEndian: (in category 'platform independent access') -----
  unsignedLong64At: index put: value bigEndian: bigEndian
  "Store a 64-bit unsigned integer quantity starting from the given byte index"
 
+ | i j |
+ value isLarge ifTrue: [
+ i := value digitLength.
+ bigEndian ifFalse: [
- value isLarge
- ifTrue: [
- | i size |
- size := value digitLength.
- bigEndian ifFalse: [
- self
- replaceFrom: index
- to: index + size - 1
- with: value
- startingAt: 1;
- replaceFrom: index + size
- to: index + 7
- with: #[0 0 0 0]
- startingAt: 1.
- ^value ].
- i := 1.
- [ i <= size ] whileTrue: [
- self at: index + 8 - i put: (value digitAt: i).
- i := i + 1 ].
- [ i <= 8 ] whileTrue: [
- self at: index + 8 - i put: 0.
- i := i + 1 ] ]
- ifFalse: [
- bigEndian ifFalse: [
- self
- at: index put: (value bitAnd: 16rFF);
- at: index + 1 put: ((value bitShift: -8) bitAnd: 16rFF);
- at: index + 2 put: ((value bitShift: -16) bitAnd: 16rFF);
- at: index + 3 put: (value bitShift: -24);
- replaceFrom: index + 4
- to: index + 7
- with: #[0 0 0 0]
- startingAt: 1.
- ^value ].
  self
  replaceFrom: index
+ to: index + i - 1
+ with: value
- to: index + 3
- with: #[0 0 0 0]
  startingAt: 1;
+ replaceFrom: index + i
+ to: index + 7
+ with: #[0 0 0 0 0 0 0 0]
+ startingAt: 1.
+ ^value ].
+ j := index + 8.
+ i <= 7 ifTrue: [
+ self
+ replaceFrom: index
+ to: j - i - 1
+ with: #[0 0 0 0 0 0 0 0]
+ startingAt: 1 ].
+ [ 1 <= i ] whileTrue: [
+ self at: j - i put: (value digitAt: i).
+ i := i - 1 ].
+ ^value ].
+ bigEndian ifFalse: [
+ j := index - 1.
+ i := value.
+ [ 1 <= i ] whileTrue: [
+ self at: (j := j + 1) put: (i bitAnd: 16rFF).
+ i := i bitShift: -8 ].
+ self replaceFrom: j + 1
+ to: index + 7
+ with: #[0 0 0 0 0 0 0 0]
+ startingAt: 1.
+ ^value ].
+ j := index + 8.
+ i := value.
+ [ 1 <= i ] whileTrue: [
+ self at: (j := j - 1) put: (i bitAnd: 16rFF).
+ i := i bitShift: -8 ].
+ self replaceFrom: index
+ to: j - 1
+ with: #[0 0 0 0 0 0 0 0]
+ startingAt: 1.
- at: index + 4 put: (value bitShift: -24);
- at: index + 5 put: ((value bitShift: -16) bitAnd: 16rFF);
- at: index + 6 put: ((value bitShift: -8) bitAnd: 16rFF);
- at: index + 7 put: (value bitAnd: 16rFF) ].
  ^value!