T
T
tj572017-11-03 17:30:44
assembler
tj57, 2017-11-03 17:30:44

Assembler: How to find the maximum in an array using mmx?

There is an array of 16-bit signed numbers. The number is a multiple of 4. The main idea is to process every 4 elements and find 4 possible maximums, after processing all the data, find the maximum itself. . You need to use comparison and logical operations.
Short smax (const short int *p, unsigned int n ) - function prototype

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mirn, 2017-11-04
@Mirn

1. implement the algorithm in C
2. compile with GCC or another modern compiler with vectorization enabled and all optimizations.
3. disassemble or enable the option to show the intermediate result.
4. look at the result and make sure that there are MMX or SSE instructions
5. pay attention to the processing of edges that may not be aligned or fall into exactly the block, arrays of small sizes less than 16-4 elements and other trifles.
6. pay attention to the call of this function of yours and how the stack is organized, temporary variables, how parameters are passed, which registers the function of finding the maximum changes and which it saves and how.
7. try unsuccessfully to understand why this is so.
8. try to repeat the result on asma yourself without looking at the compiler result and get at best 2-3 times worse performance if you can debug at all
9. conclude that you are suffering from garbage and use assembler to optimize such a trivial thing a complete madhouse and understand why asm is still needed
10. to understand that asm is needed for system things, and understanding why the compiler slows down the code and not trying to write bicycles without being able to optimize for modern processors.
for point 2-4 there is https://godbolt.org/#

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question