Eliot Miranda uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-eem.801.mcz ==================== Summary ==================== Name: System-eem.801 Author: eem Time: 20 February 2016, 11:40:02.089874 pm UUID: cb00963a-1c90-40c0-9539-04c88c0afa5f Ancestors: System-mt.800 In Spur calcEndianness can be a lot simpler. =============== Diff against System-mt.800 =============== Item was changed: ----- Method: SmalltalkImage>>calcEndianness (in category 'system attributes') ----- calcEndianness - | bytes word blt | "What endian-ness is the current hardware? The String '1234' will be stored into a machine word. On BigEndian machines (the Mac), $1 will be the high byte if the word. On LittleEndian machines (the PC), $4 will be the high byte." "Smalltalk endianness" + | wordThenBytes | + wordThenBytes := WordArray with: 16r01020304. + ByteArray adoptInstance: wordThenBytes. + wordThenBytes first = 1 ifTrue: [^#big]. + wordThenBytes first = 4 ifTrue: [^#little]. + self error: 'The author is confused'! - - bytes := ByteArray withAll: #(0 0 0 0). "(1 2 3 4) or (4 3 2 1)" - word := WordArray with: 16r01020304. - blt := (BitBlt toForm: (Form new hackBits: bytes)) - sourceForm: (Form new hackBits: word). - blt combinationRule: Form over. "store" - blt sourceY: 0; destY: 0; height: 1; width: 4. - blt sourceX: 0; destX: 0. - blt copyBits. "paste the word into the bytes" - bytes first = 1 ifTrue: [^ #big]. - bytes first = 4 ifTrue: [^ #little]. - self error: 'Ted is confused'.! |
On 21.02.2016, at 07:40, [hidden email] wrote: > Eliot Miranda uploaded a new version of System to project The Trunk: > http://source.squeak.org/trunk/System-eem.801.mcz > > ==================== Summary ==================== > > Name: System-eem.801 > Author: eem > Time: 20 February 2016, 11:40:02.089874 pm > UUID: cb00963a-1c90-40c0-9539-04c88c0afa5f > Ancestors: System-mt.800 > > In Spur calcEndianness can be a lot simpler. > > =============== Diff against System-mt.800 =============== > > Item was changed: > ----- Method: SmalltalkImage>>calcEndianness (in category 'system attributes') ----- > calcEndianness > - | bytes word blt | > "What endian-ness is the current hardware? The String '1234' will be stored into a machine word. On BigEndian machines (the Mac), $1 will be the high byte if the word. On LittleEndian machines (the PC), $4 will be the high byte." > "Smalltalk endianness" > + | wordThenBytes | > + wordThenBytes := WordArray with: 16r01020304. > + ByteArray adoptInstance: wordThenBytes. > + wordThenBytes first = 1 ifTrue: [^#big]. > + wordThenBytes first = 4 ifTrue: [^#little]. > + self error: 'The author is confused'! Well, If we had Squeak on a PDP-11, we would have also middle endian: https://en.wikipedia.org/wiki/Endianness#Middle-endian ;) Best regards -Tobias > - > - bytes := ByteArray withAll: #(0 0 0 0). "(1 2 3 4) or (4 3 2 1)" > - word := WordArray with: 16r01020304. > - blt := (BitBlt toForm: (Form new hackBits: bytes)) > - sourceForm: (Form new hackBits: word). > - blt combinationRule: Form over. "store" > - blt sourceY: 0; destY: 0; height: 1; width: 4. > - blt sourceX: 0; destX: 0. > - blt copyBits. "paste the word into the bytes" > - bytes first = 1 ifTrue: [^ #big]. > - bytes first = 4 ifTrue: [^ #little]. > - self error: 'Ted is confused'.! > > |
On Sun, Feb 21, 2016 at 12:26:01PM +0100, Tobias Pape wrote:
> > Well, If we had Squeak on a PDP-11, we would have also middle endian: > https://en.wikipedia.org/wiki/Endianness#Middle-endian ;) > Thanks for that reference. I always wondered if byte orderings like that were ever used, and was not aware of the PDP-11 convention. Dave |
In reply to this post by commits-2
On Sun, Feb 21, 2016 at 07:40:22AM +0000, [hidden email] wrote:
> Eliot Miranda uploaded a new version of System to project The Trunk: > http://source.squeak.org/trunk/System-eem.801.mcz > > ==================== Summary ==================== > > Name: System-eem.801 > Author: eem > Time: 20 February 2016, 11:40:02.089874 pm > UUID: cb00963a-1c90-40c0-9539-04c88c0afa5f > Ancestors: System-mt.800 > > In Spur calcEndianness can be a lot simpler. > This works in Spur because ByteArray can now adopt an instance of WordArray, is that right? Does the test work on big endian 64-bit? I think that it will, but if there is any doubt it might be safer to use a two element WordArray: WordArray with: 16r01020304 with: 16r01020304 The method comment describes the old String implementation, so it would be good to update that. Dave > =============== Diff against System-mt.800 =============== > > Item was changed: > ----- Method: SmalltalkImage>>calcEndianness (in category 'system attributes') ----- > calcEndianness > - | bytes word blt | > "What endian-ness is the current hardware? The String '1234' will be stored into a machine word. On BigEndian machines (the Mac), $1 will be the high byte if the word. On LittleEndian machines (the PC), $4 will be the high byte." > "Smalltalk endianness" > + | wordThenBytes | > + wordThenBytes := WordArray with: 16r01020304. > + ByteArray adoptInstance: wordThenBytes. > + wordThenBytes first = 1 ifTrue: [^#big]. > + wordThenBytes first = 4 ifTrue: [^#little]. > + self error: 'The author is confused'! > - > - bytes := ByteArray withAll: #(0 0 0 0). "(1 2 3 4) or (4 3 2 1)" > - word := WordArray with: 16r01020304. > - blt := (BitBlt toForm: (Form new hackBits: bytes)) > - sourceForm: (Form new hackBits: word). > - blt combinationRule: Form over. "store" > - blt sourceY: 0; destY: 0; height: 1; width: 4. > - blt sourceX: 0; destX: 0. > - blt copyBits. "paste the word into the bytes" > - bytes first = 1 ifTrue: [^ #big]. > - bytes first = 4 ifTrue: [^ #little]. > - self error: 'Ted is confused'.! > |
Hi David,
since WordArray is defined as a sequence of 32-bit integer slots, a one element WordArray has its first element in the first four bytes on both big and little endianness 64-bit and 32-bit platforms and so two elements are not necessary. I could add this to the comment. And yes, this is possible because there are no compact classes to prevent a more general adoptInstance:. _,,,^..^,,,_ (phone) > On Feb 21, 2016, at 8:50 AM, David T. Lewis <[hidden email]> wrote: > >> On Sun, Feb 21, 2016 at 07:40:22AM +0000, [hidden email] wrote: >> Eliot Miranda uploaded a new version of System to project The Trunk: >> http://source.squeak.org/trunk/System-eem.801.mcz >> >> ==================== Summary ==================== >> >> Name: System-eem.801 >> Author: eem >> Time: 20 February 2016, 11:40:02.089874 pm >> UUID: cb00963a-1c90-40c0-9539-04c88c0afa5f >> Ancestors: System-mt.800 >> >> In Spur calcEndianness can be a lot simpler. > > This works in Spur because ByteArray can now adopt an instance of WordArray, > is that right? > > Does the test work on big endian 64-bit? I think that it will, but if there > is any doubt it might be safer to use a two element WordArray: > > WordArray with: 16r01020304 with: 16r01020304 > > The method comment describes the old String implementation, so it would be > good to update that. > > Dave > > > >> =============== Diff against System-mt.800 =============== >> >> Item was changed: >> ----- Method: SmalltalkImage>>calcEndianness (in category 'system attributes') ----- >> calcEndianness >> - | bytes word blt | >> "What endian-ness is the current hardware? The String '1234' will be stored into a machine word. On BigEndian machines (the Mac), $1 will be the high byte if the word. On LittleEndian machines (the PC), $4 will be the high byte." >> "Smalltalk endianness" >> + | wordThenBytes | >> + wordThenBytes := WordArray with: 16r01020304. >> + ByteArray adoptInstance: wordThenBytes. >> + wordThenBytes first = 1 ifTrue: [^#big]. >> + wordThenBytes first = 4 ifTrue: [^#little]. >> + self error: 'The author is confused'! >> - >> - bytes := ByteArray withAll: #(0 0 0 0). "(1 2 3 4) or (4 3 2 1)" >> - word := WordArray with: 16r01020304. >> - blt := (BitBlt toForm: (Form new hackBits: bytes)) >> - sourceForm: (Form new hackBits: word). >> - blt combinationRule: Form over. "store" >> - blt sourceY: 0; destY: 0; height: 1; width: 4. >> - blt sourceX: 0; destX: 0. >> - blt copyBits. "paste the word into the bytes" >> - bytes first = 1 ifTrue: [^ #big]. >> - bytes first = 4 ifTrue: [^ #little]. >> - self error: 'Ted is confused'.! > |
On Sun, Feb 21, 2016 at 10:06:24AM -0800, Eliot Miranda wrote:
> Hi David, > > since WordArray is defined as a sequence of 32-bit integer slots, a one element WordArray has its first element in the first four bytes on both big and little endianness 64-bit and 32-bit platforms and so two elements are not necessary. I could add this to the comment. And yes, this is possible because there are no compact classes to prevent a more general adoptInstance:. > Thanks Eliot, Yes that makes sense and I suppose it would be a bug if the resulting ByteArray was anything /other/ than 4 bytes in size, so my suggestion does not make sense. r.e. the comment, I only meant that it should not refer to "String" any more. Maybe you (or anyone) can make that minor update the next time something gets committed to System. Thanks, Dave > _,,,^..^,,,_ (phone) > > > On Feb 21, 2016, at 8:50 AM, David T. Lewis <[hidden email]> wrote: > > > >> On Sun, Feb 21, 2016 at 07:40:22AM +0000, [hidden email] wrote: > >> Eliot Miranda uploaded a new version of System to project The Trunk: > >> http://source.squeak.org/trunk/System-eem.801.mcz > >> > >> ==================== Summary ==================== > >> > >> Name: System-eem.801 > >> Author: eem > >> Time: 20 February 2016, 11:40:02.089874 pm > >> UUID: cb00963a-1c90-40c0-9539-04c88c0afa5f > >> Ancestors: System-mt.800 > >> > >> In Spur calcEndianness can be a lot simpler. > > > > This works in Spur because ByteArray can now adopt an instance of WordArray, > > is that right? > > > > Does the test work on big endian 64-bit? I think that it will, but if there > > is any doubt it might be safer to use a two element WordArray: > > > > WordArray with: 16r01020304 with: 16r01020304 > > > > The method comment describes the old String implementation, so it would be > > good to update that. > > > > Dave > > > > > > > >> =============== Diff against System-mt.800 =============== > >> > >> Item was changed: > >> ----- Method: SmalltalkImage>>calcEndianness (in category 'system attributes') ----- > >> calcEndianness > >> - | bytes word blt | > >> "What endian-ness is the current hardware? The String '1234' will be stored into a machine word. On BigEndian machines (the Mac), $1 will be the high byte if the word. On LittleEndian machines (the PC), $4 will be the high byte." > >> "Smalltalk endianness" > >> + | wordThenBytes | > >> + wordThenBytes := WordArray with: 16r01020304. > >> + ByteArray adoptInstance: wordThenBytes. > >> + wordThenBytes first = 1 ifTrue: [^#big]. > >> + wordThenBytes first = 4 ifTrue: [^#little]. > >> + self error: 'The author is confused'! > >> - > >> - bytes := ByteArray withAll: #(0 0 0 0). "(1 2 3 4) or (4 3 2 1)" > >> - word := WordArray with: 16r01020304. > >> - blt := (BitBlt toForm: (Form new hackBits: bytes)) > >> - sourceForm: (Form new hackBits: word). > >> - blt combinationRule: Form over. "store" > >> - blt sourceY: 0; destY: 0; height: 1; width: 4. > >> - blt sourceX: 0; destX: 0. > >> - blt copyBits. "paste the word into the bytes" > >> - bytes first = 1 ifTrue: [^ #big]. > >> - bytes first = 4 ifTrue: [^ #little]. > >> - self error: 'Ted is confused'.! > > |
In reply to this post by David T. Lewis
On 21.02.2016, at 08:14, David T. Lewis <[hidden email]> wrote:
> > On Sun, Feb 21, 2016 at 12:26:01PM +0100, Tobias Pape wrote: >> >> Well, If we had Squeak on a PDP-11, we would have also middle endian: >> https://en.wikipedia.org/wiki/Endianness#Middle-endian ;) >> > > Thanks for that reference. I always wondered if byte orderings like that > were ever used, and was not aware of the PDP-11 convention. > > Dave - Bert - smime.p7s (5K) Download Attachment |
Free forum by Nabble | Edit this page |