[squeak-dev] The Inbox: Kernel-nice.893.mcz

commits at source.squeak.org commits at source.squeak.org
Tue Dec 23 23:34:37 UTC 2014


Nicolas Cellier uploaded a new version of Kernel to project The Inbox:
http://source.squeak.org/inbox/Kernel-nice.893.mcz

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

Name: Kernel-nice.893
Author: nice
Time: 24 December 2014, 12:33:20.538 am
UUID: e186b972-454f-409d-8b43-163cfee7370d
Ancestors: Kernel-nice.892

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 directly.

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

=============== Diff against Kernel-nice.892 ===============

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 Squeak-dev mailing list