I continue working on FloatArrays, and I have some implementation questions. Squeak's Floats are 64 bits C doubles in the PowerPC ordering. In some plataforms (Intel for instance) the doubles are word-swapped, i.e. the lower 32 bits are swapped with the upper. I implemented FloatArray as a variableWord subclass of ArrayedCollection. I want to see FloatArrays as 'double *' from translated primitives... so I need to keep them in the ordering of the plataform in which Squeak is running. To handle this, I do the following: 1) I keep a class variable in FloatArray (SwapWords) that says whether I need to swap words when storing and retriving Floats. 2) I added to the method SystemDictionary|processStartUpList a line doing FloatArray startUp 3) I implemented FloatArray class|startUp this way: ((self with: 1.0) * 2.0) first = 2.0 ifFalse: [SwapWords _ SwapWords not. self allInstancesDo: [ :each | each swap]]. 4) and I implemented FloatAray|swap as it's ovious.
What do you think about this scheme. Is all this right? Is there another way to do this, more close to the Squeak spirit?
Having access to 'double *' from translated primitives alows doing sound analysis, high-quality speech synthesis and speech recognition... that's way all this is too important to me.
Thanks in advance, Luciano.-
Luciano Esteban Notarfrancesco wrote:
... Having access to 'double *' from translated primitives alows doing sound analysis, high-quality speech synthesis and speech recognition... that's way all this is too important to me.
Thanks in advance, Luciano.-
I would propose to go further than that and change the format of Floats as well, to make all float-containing objects be usable from the platform without special macros. This would require the image startup code of the VM (which does the byte swapping) to be modified to swap floats as well. Alternatively, the code in the image that gets executed upon startup could do the swapping, since it should not rely on functioning Floats.
However, this opens another, more difficult, question: Since doubles on some platforms have to be 8-byte aligned, objects (at least those potentially containing doubles) should probably be aligned on 8-byte minus 4. Would it be possible to modify the object memory to ensure this alignment for variableWordSubclasses, at least?
Hans-Martin
Hans-Martin,
I would propose to go further than that and change the format of Floats as well, to make all float-containing objects be usable from the platform without special macros.
I agree. There are only a few locations where the order of Floats is important and those could be changed to use selectors like #highWord and #lowWord instead of #basicAt:
However, this opens another, more difficult, question: Since doubles on some platforms have to be 8-byte aligned, objects (at least those potentially containing doubles) should probably be aligned on 8-byte minus 4.
The alternative would be using single precision floats in the FloatArrays. Actually, I was investigating this since the storage overhead of double precision floats outweighs the improved precision in a number of applications (say in 3D graphics where you have literally millions of them).
Bye, Andreas
On Fri, 12 Jun 1998, Hans-Martin Mosner wrote:
I would propose to go further than that and change the format of Floats as well, to make all float-containing objects be usable from the platform without special macros. This would require the image startup code of the VM (which does the byte swapping) to be modified to swap floats as well. Alternatively, the code in the image that gets executed upon startup could do the swapping, since it should not rely on functioning Floats.
I like this... But I don't have the courage to do such dramatical change. ;)
However, this opens another, more difficult, question: Since doubles on some platforms have to be 8-byte aligned, objects (at least those potentially containing doubles) should probably be aligned on 8-byte minus 4. Would it be possible to modify the object memory to ensure this alignment for variableWordSubclasses, at least?
I didn't have problems with this yet... Doubles need alignment in some plataform, but floats need it too? I have no experience on the subject. May be the best way to handle this is doing what Andreas proposes, i.e. using floats instead of doubles for FloatArrays.
Andreas: Have you implemented FloatArrays? If so, could you tell me a bit more about your implementation? I'd like to take a look at your changes.
Luciano.-
Luciano,
Doubles need alignment in some plataform, but floats need it too?
Yes, on several platforms both need alignment. However, Squeak already aligns all data to 4-byte boundaries which is ok for single precision floats.
Have you implemented FloatArrays? If so, could you tell me a bit more about your implementation? I'd like to take a look at your changes.
I haven't done a whole lot. Just a floatAt: and floatAt:put: primitive. My idea was to use FloatArrays as repository for floats which are converted in the two methods from and to doubles. So, floatAt: actually returns a double precision float and floatAt:put: stores a double precision float. Any more primitives should then operate on the raw single precision data for obvious speed and bandwidth reasons.
Andreas
squeak-dev@lists.squeakfoundation.org