[Pkg] The Trunk: Kernel-nice.923.mcz

commits at source.squeak.org commits at source.squeak.org
Fri May 1 13:33:28 UTC 2015


Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.923.mcz

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

Name: Kernel-nice.923
Author: nice
Time: 1 May 2015, 3:32:43.592 pm
UUID: 875249b7-3037-4f50-9ab1-c1b2ec94b0e1
Ancestors: Kernel-nice.922

Use an intermediate abstract Float representation (sign, exponent, significand) in order to convert single precision bits to double precision bits rather than attempting the conversion by direct bit manipulations.

This lead to simpler code, because it is like a semantic bit manipulation rather than a raw bit manipulation.

And this also lead to faster code on 32 bits interpreter/COG/Spur VM thanks to avoidance of LargeInteger

(was Kernel-nice.893 / 24 December 2014)

=============== Diff against Kernel-nice.922 ===============

Item was changed:
  ----- Method: Float class>>fromIEEE32Bit: (in category 'instance creation') -----
  fromIEEE32Bit: word
  	"Convert the given 32 bit word (which is supposed to be a positive 32bit value) from a 32bit IEEE floating point representation into an actual Squeak float object (being 64bit wide). Should only be used for conversion in FloatArrays or likewise objects."
  	
+ 	| sign mantissa exponent |
- 	| sign mantissa exponent newFloat delta |
  	word negative ifTrue: [^ self error:'Cannot deal with negative numbers'].
  	word = 0 ifTrue: [^ Float zero].
+ 	word = 16r80000000 ifTrue: [^Float negativeZero].
- 	sign := word bitAnd: 16r80000000.
- 	word = sign ifTrue: [^self negativeZero].
  	
+ 	sign := word bitShift: -31.
  	exponent := ((word bitShift: -23) bitAnd: 16rFF) - 127.
  	mantissa := word bitAnd:  16r7FFFFF.
  
  	exponent = 128 ifTrue:["Either NAN or INF"
  		mantissa = 0 ifFalse:[^ Float nan].
  		sign = 0 
  			ifTrue:[^ Float infinity]
  			ifFalse:[^ Float negativeInfinity]].
  
+ 	exponent = -127
+ 		ifTrue:
+ 			["gradual underflow (denormalized number)
+ 			There is no implied one, but the exponent is -126"
+ 			exponent := -126]
+ 		ifFalse:
+ 			[mantissa := mantissa + 16r800000 "impliedOne"].
- 	exponent = -127 ifTrue: [
- 		"gradual underflow (denormalized number)
- 		Remove first bit of mantissa and adjust exponent"
- 		delta := mantissa highBit.
- 		mantissa := (mantissa bitAnd: (1 bitShift: delta - 1) - 1) bitShift: 24 - delta.
- 		exponent := exponent + delta - 23].
  	
  	"Create new float"
+ 	^(sign = 0
+ 		ifTrue: [mantissa]
+ 		ifFalse: [mantissa negated])
+ 			asFloat timesTwoPower: exponent - 23!
- 	newFloat := self new: 2.
- 	newFloat basicAt: 1 put: ((sign bitOr: (1023 + exponent bitShift: 20)) bitOr: (mantissa bitShift: -3)).
- 	newFloat basicAt: 2 put: ((mantissa bitAnd: 7) bitShift: 29).
- 	^newFloat!



More information about the Packages mailing list