English
Source / code snippets

Datentypen understand and process + float() and long() as inline Assembler

 

Sven
Bader
the to juggle with Datentypen can in the working day nerves. to that better understanding for me self have I something with Rückgabewerten of OpenGL herumgespielt. Dankenswerterweise can there always between Float, double and Integer dial. with 32-bit Floats can ältere XProfan versions first once nothing begin but too the get one there!

in the example question I The maximum Size for a drew point ex. back comes The address one Arrays with two Values, me interested each the 2. worth. with of my Grafikkarte incidentally 189.875

I have Procs and Assembler functions written, around the interne Float() and Long() To supplant. Letztendlich do I m entrapment of Float 7x the same on unterschiedlichen because of.

its my first trip To Assembler, and so The comments on the code yet something clumsy are. Letztendlich is it very for such memory-Schubsereien ideal. faster as your Vorbilder long() and float() are The functions NOT become.

Fazit:
About whom Lerneffekt out are following ways The simplest and not slower as the ASM code:

processing one 32-bit Floats a external appeal mithilfe of long and double:
float! = double(integer&) or. as area float! = double(long(area#,0))
alternatively ex XProfan X2, with the Datentyp Single works.

processing one 64-bit Floats (double) a external appeal:
directly, without converting or. as area float! = float(area#,0)

processing one 32-bit Integers a external appeal:
directly, without converting or. as area integer& = long(area#,0)

Each Variable and Arrays can like a area uses go with Addr():
long(Addr(integer&[0],4) is the same How integer&[1], So one Integer with address the first aray-Elements + 4 byte.

with Speicheradressen (Memory-Variables # and addr()) can calculated go:
long(area#,4) is the same How long(area# + 4,0)

at that monkey about with Speicheradressen must one self-evident pay attention, there one einerseits quick over declared reaches hinausschießt or even values with Speicheradressen verwechelt and somewhere in memory alights.
Cls
Declare sizeRangeFloat#, sizeRangeInteger#, float!,sizeRangeArray![2],integerArray&[2]
Declare single singleArray[2]' the goes first since X2
Dim sizeRangeFloat#, 16'2 values apiece 8 byte
Dim sizeRangeInteger#, 8'2 values apiece 4 byte
oGL("Init", %hWnd, 1,1,1,1)
oGL("glGetDoublev",  ~GL_POINT_SIZE_RANGE, Addr(sizeRangeArray![0]))
oGL("glGetDoublev",  ~GL_POINT_SIZE_RANGE, sizeRangeFloat#)
oGL("glGetFloatv",   ~GL_POINT_SIZE_RANGE, Addr(singleArray[0]))'the goes first since X2
oGL("glGetFloatv",   ~GL_POINT_SIZE_RANGE, Addr(integerArray&[0]))'ploy for ältere Profan-versions, it follows double()
oGL("glGetIntegerv", ~GL_POINT_SIZE_RANGE, sizeRangeInteger#)
oGL("Done")

Proc procLong

    Parameters a#, shift&
    'in Tests not always correctly
    Return ( (byte(a #+shift&,3) << 24) | (byte(a #+shift&,2) << 16) | (byte(a #+shift&,1) << 8) | (byte(a #+shift&,0)) )

ENDPROC

ASM "asmFloat2", 3
mov ecx, par1'par1 to ecx
mov ebx, par2'par2 to ebx
mov eax, [ebx]'par2 to eax
mov [ecx], eax' eax to par1
add ecx, 4' par1 address + 4
mov edx, par3' par2 to edx
mov eax, [edx]' par3 to eax
mov [ecx], eax' eax to par1
ENDASM
ASM "asmFloat", 2
mov eax, par2'par2 to eax
mov edx, [eax]'4-byte par2 (offset 0) to edx schieben
mov eax, par1'par1 to eax (Speicheradresse the target Float-Variable)
mov [eax], edx
mov eax, par2'par2 to eax
add eax, 4'address + 4
mov edx, [eax]
mov eax, par1
add eax, 4'address + 4
mov [eax], edx' eax (now+4) in par1 Save
ENDASM
'These function does really nothing:
'them give the out, what hineingeworfen has
ASM "asmLong", 1
mov ecx, par1'par 1 to ecx
mov eax, [ecx]'and unchanged spend
ENDASM
'These function does really nothing:
'them give the out, what hineingeworfen has
ASM "asmLong2", 2
mov ecx, par1'par 1 to ecx
mov ebx, par2'par 2 to ebx
add ecx, par2'par 1 (ecx) and par2 add
mov eax, [ecx]'spend
ENDASM
Def MoveMemory(3) !"kernel32.dll","RtlMoveMemory"

Proc procFloatMoveMemory

    Parameters dest!, source#
    MoveMemory(addr(dest!),source#,8)
    Return dest!

ENDPROC

Proc procFloatLongLong

    Parameters dest!, source#
    Long addr(dest!),0 = long(source#,8),long(source#,12)

ENDPROC

Print "\nFloats:"
'Offset each with byte 8, this is the second aray-worth
'Float() Assembler-Variante
asmFloat(addr(float!), sizeRangeFloat# + 8)'direct Zuweisung goes unfortunately because of of 32-bit Paremetern not
Print float!
'Float() as interne XProfan-function
Print Float(sizeRangeFloat#,8)
'Float() as Proc with two long()
procFloatLongLong(float!,sizeRangeFloat#+8)'direct Return you don't say so, except with float() and the ought to Yes even supplant go ;-)
print st$(float!)
'Float() as Proc with MoveMemory
Print procFloatMoveMemory(float!, sizeRangeFloat#+8)'Zuweisung possible but the Variable in the 1. Paremeter becomes in each drop too described
'worth from array (1 = zweiter worth, there it of 0 launch)
Print sizeRangeArray![1]'Zuweisung possible but the Variable in the 1. Paremeter becomes in each drop too described
'worth from Single-aray (32-bit), Datentyp ex X2 available
Print singleArray[1]
'worth from Integer-aray (32-bit) as double intepretiert. the goes too with older Profan versions
Print double(integerArray&[1])
Print "\nIntegers:"
'Long() as Proc
Print procLong(sizeRangeInteger#,4)'not always correctly...
'Long() as interne XProfan-function
Print Long(sizeRangeInteger#,4)
'Long() Assembler-Variante in a Parameter (Adress-Offset must self add go)
Print asmLong(sizeRangeInteger# + 4)
'Long() Assembler-Variante with 2 Parameters, Offset can How in the originalen function transfer go
Print asmLong2(sizeRangeInteger#, 4)
Dispose sizeRangeFloat#
Dispose sizeRangeInteger#
WaitKey
End
 
03/01/23  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.112 Views

Untitledvor 0 min.
Sven Bader08/31/23
ecki07/28/23
Thomas Zielinski06/28/23
E.T.06/12/23
More...

Themeninformationen

this Topic has 1 subscriber:

Sven Bader (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie