Advertisement
ArBa

dll

Oct 20th, 2019
2,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;A 64-bit function that posterize values in 2^8 valuse
  2. ;
  3. ; The function has prototype:
  4. ;   void posterize(unsigned short[] array, uint64_t length, char levelNo)
  5. ; -----------------------------------------------------------------------------
  6.  
  7. ; Gnu/Linux
  8. ; rdi – 1 argument - array
  9. ; rsi – 2 argument - length
  10. ; rdx – 3 argument - levelNo
  11.  
  12. ; Windows (?)
  13. ; rcx - 1 argument
  14. ; rdx - 2 argument
  15. ; r8  - 3 argument
  16.  
  17. ; r8b - vector capacity counter
  18. ; r9b - progVal
  19. ; r10b - half progVal
  20. ; r12  - table offset
  21.  
  22.     global  posterize
  23.     section .text
  24.  
  25.  
  26. calculate_progVal:
  27.    ;calculate progging value step
  28.     mv      rax, rdx
  29.     div     maxByteVal
  30.     mv      r9b, rax
  31.     mv      r10b, r9b
  32.     dec     r9b
  33.     shrw    $1, %r10b
  34.  
  35. setUpStartValues:
  36.     mov     r11b, 0;
  37.     mov     r12,  0;
  38.     mov     r8b, wordCounter;
  39.  
  40.  
  41. posterize:
  42.     cmp     rsi, 0  ; check if lenght <= 0
  43.     jle     done
  44.  
  45.  
  46. fill_vector:
  47.     VMOVDQU16   zmm0, zmmword ptr [rdi+r12w]     ;fill vector
  48.     sub     rsi, wordCounter    ;decrese vector lenght
  49.  
  50.  
  51. transform:
  52.    ; vaddsw -- add halfProgVal to vector
  53.     mv      zmm1, zmm0
  54.    ; vandpw -- modulo with progVal - 1
  55.     vpsubw  zzm2, zmm1, zmm0 ;substract zzm0 zzm1, save in zzm2
  56.  
  57.  
  58. save_values:
  59.     vmovdqu16   zmmword ptr [rdi+r12],zmm2 ;save values to array
  60.     add         r12, wordCounter
  61.     jmp         posterize;
  62.  
  63.  
  64. done:
  65.     ret
  66.  
  67.  
  68.  
  69.     section .data
  70. wordCounter:    db  32
  71. maxByteVal:     db  255
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement