Anonymous | Login | 01-24-2021 22:34 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ View Advanced ] [ Issue History ] [ Print ] | |||||||||||
ID | Category | Severity | Reproducibility | Date Submitted | Last Update | |||||||
0007109 | [Squeak] VM | minor | always | 07-03-08 23:56 | 05-16-11 12:06 | |||||||
Reporter | nicolas cellier | View Status | public | |||||||||
Assigned To | lewis | |||||||||||
Priority | normal | Resolution | open | |||||||||
Status | testing | Product Version | 3.10 | |||||||||
Summary | 0007109: [ENH] Speed-up LargeInteger bitShift: | |||||||||||
Description |
Positive (left) shift are optimized when byte-aligned Negative (right) shifts are not! You can see this with a code like this: | x | x := SmallInteger maxVal raisedTo: 1000. x digitLength. x highBit. {Time millisecondsToRun: [10000 timesRepeat: [x bitShift: -12000]]. Time millisecondsToRun: [10000 timesRepeat: [x bitShift: -11997]]. } => #(324 376) Not much difference whether byte aligned or not While: | x | x := SmallInteger maxVal raisedTo: 100. {Time millisecondsToRun: [10000 timesRepeat: [x bitShift: 12000]]. Time millisecondsToRun: [10000 timesRepeat: [x bitShift: 11997]]. } => #(90 180) a big difference whether byte aligned or not |
|||||||||||
Additional Information |
bitShifts should be fast, because often used in tight loops (I need them for fast divide and conquer algorithms). I can as well write a byteShift: more efficient than bitShift: (see below) But it would be preferable to improve LargeIntegersPlugin The byteShift: code is here if you wanna try: LargePositiveInteger>>byteShift: n "shift by bytes, which is faster than bits when n < 0" | shifted | n = 0 ifTrue: [^ self]. n > 0 ifTrue: [ shifted := self class new: self digitLength + n. shifted replaceFrom: n+1 to: self digitLength + n with: self startingAt: 1. ^ shifted]. self digitLength + n <= 0 ifTrue: [^0]. shifted := self class new: self digitLength + n. shifted replaceFrom: 1 to: self digitLength + n with: self startingAt: 1 - n. ^ shifted normalize Which could also be written: LargePositiveInteger>>byteShift: n "shift by bytes, which is faster than bits when n < 0" | shifted | n = 0 ifTrue: [^ self]. self digitLength + n <= 0 ifTrue: [^0]. shifted := self class new: self digitLength + n. shifted replaceFrom: (1 max: 1 + n) to: self digitLength + n with: self startingAt: (1 max: 1 - n). ^ shifted normalize |
|||||||||||
Attached Files |
![]() ![]() |
|||||||||||
|
Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
56 total queries executed. 36 unique queries executed. |