//-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // This code sort a vector of 64 bits integers in ascending order. // The code uses macro HEAPSORT from the standard DaVinci assembler RISC-V module. // It can be called as a function by C code generated by the GNU compiler // or any GNU compatible compiler // // The code is divided into two sections: // // 1. The macro that carries out all integer comparisons // // 2. The SECTION that use macro HEAPSORT to actually sort the vector // //-------------------------------------------------------------------------------------------------- // // Define the comparison macro that is used by the HEAPSORT macro // This compares two 64 bits number passed in registers. // #MACRO //MACRO CompLong r1, r2, equalFlag, branchLabel, WReg[] if (equalFlag) \#Label BLE #r1, #r2, #branchLabel else \#Label BLT #r1, #r2, #branchLabel #END // // Actual code starts here // SETENV "RISCV", "RV64I:a,c,d,m,n,zicsr,zifencei", "LP64D", "linux" // Define the srchitecture BaseDef // Include standard definitions // Code TextSect // Start .text section C.SUSPEND // Do not use two byte opCode extension // dvasmsortlong /> Entry label ENTRY Stack=!"" // Leaf entry, only A* and T* registers // are used. No need to use a stack // or save/restore registers HEAPSORT a0, a1, 64, CompLong, [t0-6, a2-3] // Invoke HEAPSORT macro Exit EXIT // Return to caller // END