Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;A 64-bit function that posterize values in 2^8 valuse
- ;
- ; The function has prototype:
- ; void posterize(unsigned short[] array, uint64_t length, char levelNo)
- ; array - array of values to posterize
- ; length - length of array
- ; levelNo - number of posterize levels. Cube root of number of colors
- ; -----------------------------------------------------------------------------
- ; Gnu/Linux
- ; rdi – 1 argument - array
- ; rsi – 2 argument - length
- ; rdx – 3 argument - levelNo
- ; Windows (TODO check if correct, change when working on Windows)
- ; rcx - 1 argument
- ; rdx - 2 argument
- ; r8 - 3 argument
- ; r9 - progging step value -1. Used to modulo calculation
- ; r10 - half of the progging step value
- ; r12 - table offset, used to calculate the actual part of the table to transform
- global posterize
- section .text
- calculate_progVal:
- ;calculate progging step value
- mov r10, rdx ;save level No to r10
- mov rax, maxByteVal ;set divisor to 255
- mov rdx, 0
- div r10
- mov r9, rax ;copy value to r9 and r10
- mov r10, r9
- dec r9 ;decrese r9 to use it in modulo operation
- shr r10, 1 ;divide r10 by 2
- setUpStartValues:
- mov r12, 0 ;set table offset = 0
- posterize:
- cmp rsi, 0 ;check if lenght <= 0
- jle done ;go to done if length <= 0
- fill_vector:
- VMOVDQU16 zmm0, [rdi+r12] ;fill vector with array values
- sub rsi, wordCounter ;decrese lenght by vector size
- transform:
- ; add half progging value
- VXORPS zmm2, zmm2, zmm2 ;make zmm2 = 0
- PSHUFW zmm2, zmm2, r10 ;copy halfVal as vector to zmm2
- ;using shuffling with map
- VPADDW zmm0, zmm0, zmm2 ;add vector zmm2 and zmm0
- ; modulo with progVal - 1
- VXORPS zmm2, zmm2, zmm2 ;make zmm2 = 0
- PSHUFW zmm2, zmm2, r9 ;copy progVal-1 as vector to zmm2
- ;using shuffling with map
- VPANDQ zmm1, zmm2, zmm0 ;make modulo operation
- vpsubw zmm2, zmm0, zmm1 ;substract zmm0 from zmm1, save in zmm2
- save_values:
- vmovdqu16 [rdi+r12], zmm2 ;save values to array
- add r12, wordCounter ;move to the next elements of array
- jmp posterize ;go back to posterize
- done:
- ret ;end function
- section .data
- wordCounter: db 32
- maxByteVal: db 255
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement