Code: Select all
size = ((size and &hff) shl 24) or ((size and &hff00) shl 8) or ((size and &hff0000) shr 8) or ((size and &hff000000) shr 24)
Code: Select all
size = ((size and &hff) shl 24) or ((size and &hff00) shl 8) or ((size and &hff0000) shr 8) or ((size and &hff000000) shr 24)
Code: Select all
ASM
mov eax, dword ptr [size]
bswap eax
mov dword ptr [size], eax
End ASM
Code: Select all
Dim size as uinteger
Dim x as integer
dim t as double
size = 24
t = timer
for x = 0 to 100000
ASM
mov eax, dword ptr [size]
bswap eax
mov dword ptr [size], eax
End ASM
next
Print "ASM Time: " & timer - t
t = timer
for x = 0 to 100000
size = ((size and &hff) shl 24) or ((size and &hff00) shl 8) or ((size and &hff0000) shr 8) or ((size and &hff000000) shr 24)
next
Print "Other: " & timer - t
sleep
Code: Select all
#Define fb_BSwap(size) _
size = ( ( size And &hff ) Shl 24 ) Or ( ( size And &hff00 ) Shl 8 ) Or ( ( size And &hff0000 ) Shr 8 ) Or ( ( size And &hff000000 ) Shr 24 )
Code: Select all
fb_BSwap( myNumber )
Code: Select all
'' Converts a msb dword to a lsb dword
#Define bo_conv_4(ID) ( ( ( ID And &HFF000000 ) Shr 24 ) Or _
( ( ID And &H00FF0000 ) Shr 8 ) Or _
( ( ID And &H0000FF00 ) Shl 8 ) Or _
( ( ID And &H000000FF ) Shl 24 ) )
'' Converts a msb word to a lsb word
#Define bo_conv_2(ID) ( ( ( ID And &HFF00 ) Shr 8 ) Or _
( ( ID And &H00FF ) Shl 8 ) )
'' Converts a 4-byte string to a uinteger
#Define FourCC(ID) ( ( Asc( ID, 1 ) ) Or _
( Asc( ID, 2 ) Shl 8 ) Or _
( Asc( ID, 3 ) Shl 16 ) Or _
( Asc( ID, 4 ) Shl 24 ) )
Actually, the whole big-endian - little-endian thing presents a portability problem for any intended cross-platform software or files.1000101 wrote:The asm version does lock you into x86 processors which limits your targets after the gcc port.
Well no kidding, which is the point of endian swapping. ie: convert it to the proper format for the machine you're running on. If you're on a 68k CPU you're not going to convers 68k data, however, if you're on a 68k CPU you need to convert x86 data to the proper endianness.jevans4949 wrote:Actually, the whole big-endian - little-endian thing presents a portability problem for any intended cross-platform software or files.
erm, The last thing I want is to use 68k dwords on an x86 machine. It would be horribly slow. I'll stick to converting the endianness of the data to working with the CPU native endianness.jevans4949 wrote:Ultimately, I suppose the solution would have to be to have specific big-endian and little-endian integer types built into the compiler, which could then generate processor-specific code to deal with each type.
Most variables internal to the program would continue to be "don't care" format.
Ok, but how does this affect old code and programs which will never be ported? You still need to be able to read old data if that's your goal.jevans4949 wrote:On the other hand, if Apple are swithcing to x86 processors, are the little-endians going to win sooner or later anyway?
Code: Select all
function FB_BSWAP(byval sourceInt as integer) as integer
dim tempInt as integer = sourceInt
dim tempPTR as byte ptr = cptr(byte ptr, @tempInt)
swap tempPTR[0], tempPTR[3]
swap tempPTR[1], tempPTR[2]
return tempInt
end function
dim size as integer = 24
size = fb_BSWAP(size)
print size
sleep
I think you miss my point. If you can specify to the compiler the endianness of a field on an external file, e.g., png or bmp, and the target machine for the compile, then the compiler can generate the bswap, or whatever the 68k equivalent might be, when needed.1000101 wrote:erm, The last thing I want is to use 68k dwords on an x86 machine. It would be horribly slow. I'll stick to converting the endianness of the data to working with the CPU native endianness.jevans4949 wrote:Ultimately, I suppose the solution would have to be to have specific big-endian and little-endian integer types built into the compiler, which could then generate processor-specific code to deal with each type.
Most variables internal to the program would continue to be "don't care" format.
Code: Select all
function FB_BSWAP(byval sourceInt as integer) as integer
dim tempInt as integer
dim tempPTR as byte ptr = cptr(byte ptr, @tempInt)
tempPTR[0] = (@sourceInt)[3]
tempPTR[3] = (@sourceInt)[0]
tempPTR[1] = (@sourceInt)[2]
tempPTR[2] = (@sourceInt)[1]
return tempInt
end function
dim size as integer = 24
size = fb_BSWAP(size)
print size
sleep
No, I got your point. Your idea would just results in incredibly slow executables or programming which would require a hack to get around the data format of the structs. Also, it's only a couple structs, generally, which would need this and would be simpler to just use a macro conversion after loading and before saving.jevans4949 wrote:I think you miss my point.