//MACRO Hash.string Anchor, String, HashAddr, WReg[3] //-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- // // // Get load/store MIs and word length // eval(DVASM.getEnv()[4]); var ld= "L" + abiWID; var st= "S" + abiWID; var wl= abiWLen; var wn= abiWID == "D" ? "double word" : "word"; var WReg0= WReg[0]; var WReg1= WReg[1]; var WReg2= WReg[2]; // // Generate code // \#Label LI #HashAddr, 0 // Set hash starting value to zero \ LB #WReg0, 0[#String] // Load first byte \ WHILE CONDITION= ( #WReg0 != 0 ) // Start hash loop one byte a time \ ADD #HashAddr, #WReg0 // Add new byte to hash \ SLLI #WReg0, 5[#HashAddr] // Multiply by 32 \ SUB #HashAddr, #WReg0, #HashAddr // Reduce multiplication to 31 \ ADDI #String, 1 // Load next byte address \ LB #WReg0, 0[#String] // Load next byte for to be hashed \ ENDWHILE // // Do the final hash on the resulted value in register HashAddr // \ #ld #WReg0, #wl+#Anchor // Load prime for final hash \ LWU #WReg1, (2*#wl)+#Anchor // Load key shift \ SRL #WReg2, #HashAddr, #WReg1 // Shift Key right \ XOR #HashAddr, #WReg2 // XOR shifted key with original key \ MUL #HashAddr, #WReg0 // Multiply shifted and XORed key by prime number \ SRL #HashAddr, #WReg1 // Shift key right \ LWU #WReg1, (2*#wl+4)+#Anchor // Load cell shift \ SLL #HashAddr, #WReg1 // Shift key left - offset in hash vector \ #ld #WReg1, #Anchor // Load hash vector addr \ ADD #HashAddr, #WReg1 // Add vector address - hash cell addr