The MASM Forum

General => The Workshop => Topic started by: UniverseIsASimulation on November 13, 2019, 04:30:41 AM

Title: Implementing QuickSort
Post by: UniverseIsASimulation on November 13, 2019, 04:30:41 AM
Hey, guys!
I am currently studying computer science and electrical engineering at the FERIT university in Osijek.
So, for a seminar in algorithms and data structures, I've decided to attempt to implement QuickSort in my own simple low-level programming language, called AEC.
You can see my work here:
https://github.com/FlatAssembler/ArithmeticExpressionCompiler/tree/master/QuickSort (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/tree/master/QuickSort)
So, the source code, written in AEC, is available here:
https://github.com/FlatAssembler/ArithmeticExpressionCompiler/blob/master/QuickSort/qsort.aec (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/blob/master/QuickSort/qsort.aec)
The assembly my compiler (available for download here (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/raw/master/ArithmeticExpressionCompiler.zip)) produced is available here:
https://github.com/FlatAssembler/ArithmeticExpressionCompiler/blob/master/QuickSort/qsort.asm (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/blob/master/QuickSort/qsort.asm)
The executable that FlatAssembler produced is available here:
https://github.com/FlatAssembler/ArithmeticExpressionCompiler/raw/master/QuickSort/qsort.exe (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/raw/master/QuickSort/qsort.exe)
So, I've noticed that program is significantly slower (https://github.com/FlatAssembler/ArithmeticExpressionCompiler/raw/master/QuickSort/TestResults/Ubuntu2.png) than the programs produced by GCC.
Any idea how I can make it better?
Title: Re: Implementing QuickSort
Post by: jj2007 on November 13, 2019, 05:21:54 AM
I had a quick look at qsort.asm - a detailed look is way beyond the time I can invest. What strikes my eye are numerous finit instructions. They are utterly slow. To give you an idea: One finit is over three times slower than measuring the length of a 100 byte string.

You should replace these finits with proper management of the fpu, i.e. ffree st(7), fstp st etc; where you consider finit essential, move it at least out of innermost loops.
Title: Re: Implementing QuickSort
Post by: UniverseIsASimulation on November 13, 2019, 05:58:06 PM
Quote from: jj2007 on November 13, 2019, 05:21:54 AM
I had a quick look at qsort.asm - a detailed look is way beyond the time I can invest. What strikes my eye are numerous finit instructions. They are utterly slow. To give you an idea: One finit is over three times slower than measuring the length of a 100 byte string.

You should replace these finits with proper management of the fpu, i.e. ffree st(7), fstp st etc; where you consider finit essential, move it at least out of innermost loops.
OK, thanks, I didn't know about that one with "finit".