No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s1:apl:lab:lab4
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s1:apl:lab:lab4 [2024/12/05 12:14] – [The example code] ktokarz | en:edu:zmitac:s1:apl:lab:lab4 [2024/12/05 12:39] (current) – [Tasks to be done during laboratory] ktokarz | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== The aim of the exercise ===== | ===== The aim of the exercise ===== | ||
| The aim of the exercise is to learn about vector instructions called SIMD (Single Instruction Multiple Data) and passing parameters to functions as references to common memory. | The aim of the exercise is to learn about vector instructions called SIMD (Single Instruction Multiple Data) and passing parameters to functions as references to common memory. | ||
| - | As in previous | + | As in previous |
| - | Functions will calculate the sum, difference, multiplication and division of four single precision floating point values. | + | Functions will calculate the sum, difference, multiplication, and division of four single precision floating point values. |
| < | < | ||
| ===== First example code ===== | ===== First example code ===== | ||
| In the first example, we'll write the function in assembler with an internal definition of variables to show how to define floating point vectors in the assembly program. | In the first example, we'll write the function in assembler with an internal definition of variables to show how to define floating point vectors in the assembly program. | ||
| - | The following code is divided into three parts. The C++ part calls the function in a dynamically linked library. The function, called Sum_of_vectors(), | + | The following code is divided into three parts. The C++ part calls the function in a dynamically linked library. The function, called Sum_of_vectors(), |
| C++ file | C++ file | ||
| Line 24: | Line 24: | ||
| std::cout << "Hello World!\n"; | std::cout << "Hello World!\n"; | ||
| dllHandle = LoadLibrary(TEXT(" | dllHandle = LoadLibrary(TEXT(" | ||
| - | std::cout << procedura(); | ||
| - | |||
| MyProc Sum_of_vectors = (MyProc)GetProcAddress(dllHandle, | MyProc Sum_of_vectors = (MyProc)GetProcAddress(dllHandle, | ||
| + | | ||
| + | Sum_of_vectors(); | ||
| } | } | ||
| </ | </ | ||
| Line 45: | Line 45: | ||
| ; No input parameters, no result returned | ; No input parameters, no result returned | ||
| ; | ; | ||
| - | FindChar_1 PROC | ||
| - | PUSH RSI | ||
| - | LEA RSI, DataString | ||
| - | MOV AL, ' | ||
| - | Check_End: | ||
| - | CMP BYTE PTR [RSI], 0FFH ; is it the end of a string (special character FF)? | ||
| - | JE Not_Find | ||
| - | CMP AL, [RSI] ; compare a character with chosen char of string ' | ||
| - | JE Got_Equal | ||
| - | ADD RSI, 1 ; increment an offset | ||
| - | JMP Check_End | ||
| - | Got_Equal: | ||
| - | MOV DL, [RSI] ; load found char into DL | ||
| - | JMP Done | ||
| - | Not_Find: | ||
| - | MOV RAX,0 ; character not found | ||
| - | POP RSI | ||
| - | RET ; return from procedure | ||
| - | Done: | ||
| - | MOV RAX,1 ; character found | ||
| - | POP RSI | ||
| - | RET ; return form procedure | ||
| - | FindChar_1 ENDP ; end of FindChar_1 | ||
| - | ;**************************************************************************** | + | Sum_of_vectors PROC |
| - | ; Procedure | + | PUSH RSI |
| - | ; No input parameters, result is the time (number | + | LEA RSI, first_vector |
| - | ; | + | |
| - | ReadTime_1 PROC | + | MOVUPS XMM0, OWORD PTR first_vector |
| - | | + | |
| - | | + | ADDPS XMM0, XMM1 |
| + | | ||
| - | | + | |
| - | + | RET | |
| - | RDTSC | + | Sum_of_vectors |
| - | SUB RAX,RCX | + | |
| - | + | ||
| - | RET ; return form procedure | + | |
| - | ReadTime_1 | + | |
| END | END | ||
| Line 130: | Line 104: | ||
| std::cout << " | std::cout << " | ||
| std::cout << " | std::cout << " | ||
| - | |||
| } | } | ||
| </ | </ | ||
| Line 138: | Line 111: | ||
| .code | .code | ||
| - | ; | + | ; |
| - | ; This function | + | ; Function to calculate the sum of two vectors |
| + | ; | ||
| ; | ; | ||
| Sum_of_vectors PROC | Sum_of_vectors PROC | ||
| - | |||
| MOVUPS XMM0, OWORD PTR [RCX] ; load content of memory pointed by the first parameter | MOVUPS XMM0, OWORD PTR [RCX] ; load content of memory pointed by the first parameter | ||
| MOVUPS XMM1, OWORD PTR [RDX] ; load content of memory pointed by the second parameter | MOVUPS XMM1, OWORD PTR [RDX] ; load content of memory pointed by the second parameter | ||
| Line 156: | Line 129: | ||
| </ | </ | ||
| - | Def file is the same as in previous | + | Def file is the same as in a previous |
| ===== Tasks to be done during laboratory ===== | ===== Tasks to be done during laboratory ===== | ||
| - | - Compile the example code and observe | + | - Compile the examples |
| - | - Make the function more universal: define | + | - Write additional functions to calculate subtraction, |
| - | | + | - Write the program which calculates |
| - | - Compare execution time for scalar | + | * Table contains 64 float values and is defined |
| + | * And address | ||
| + | * A size of the table is passed | ||
| + | | ||
| + | * Function returns the value as the scalar, traditionally by XMM0. | ||
| + | |||
| + | =====For | ||
| + | - Include the code of additional functions. | ||
| + | - Include the code of the average program | ||
| + | - The above programs must contain comments. | ||
en/edu/zmitac/s1/apl/lab/lab4.1733397295.txt.gz · Last modified: by ktokarz
