You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

  1. <% function negS() { %>
  2. neg eax
  3. jo neg_manageOverflow ; Check if overflow. (0x80000000 is the only case)
  4. mov [rdi], rax ; not necessary to adjust so just save and return
  5. ret
  6. neg_manageOverflow: ; Do the operation in 64 bits
  7. push rsi
  8. movsx rsi, eax
  9. neg rsi
  10. call rawCopyS2L
  11. pop rsi
  12. ret
  13. <% } %>
  14. <% function negL() { %>
  15. add rdi, 8
  16. add rsi, 8
  17. call rawNegL
  18. sub rdi, 8
  19. sub rsi, 8
  20. ret
  21. <% } %>
  22. ;;;;;;;;;;;;;;;;;;;;;;
  23. ; neg
  24. ;;;;;;;;;;;;;;;;;;;;;;
  25. ; Adds two elements of any kind
  26. ; Params:
  27. ; rsi <= Pointer to element to be negated
  28. ; rdi <= Pointer to result
  29. ; [rdi] = -[rsi]
  30. ;;;;;;;;;;;;;;;;;;;;;;
  31. <%=name%>_neg:
  32. mov rax, [rsi]
  33. bt rax, 63 ; Check if is short first operand
  34. jc neg_l
  35. neg_s: ; Operand is short
  36. <%= negS() %>
  37. neg_l:
  38. mov [rdi], rax ; Copy the type
  39. <%= negL() %>
  40. ;;;;;;;;;;;;;;;;;;;;;;
  41. ; rawNeg
  42. ;;;;;;;;;;;;;;;;;;;;;;
  43. ; Negates a value
  44. ; Params:
  45. ; rdi <= Pointer to the long data of result
  46. ; rsi <= Pointer to the long data of element 1
  47. ;
  48. ; [rdi] = - [rsi]
  49. ;;;;;;;;;;;;;;;;;;;;;;
  50. rawNegL:
  51. ; Compare is zero
  52. xor rax, rax
  53. <% for (let i=0; i<n64; i++) { %>
  54. cmp [rsi + <%=i*8%>], rax
  55. jnz doNegate
  56. <% } %>
  57. ; it's zero so just set to zero
  58. <% for (let i=0; i<n64; i++) { %>
  59. mov [rdi + <%=i*8%>], rax
  60. <% } %>
  61. ret
  62. doNegate:
  63. <% for (let i=0; i<n64; i++) { %>
  64. mov rax, [q + <%=i*8%>]
  65. <%= i==0 ? "sub" : "sbb" %> rax, [rsi + <%=i*8%>]
  66. mov [rdi + <%=i*8%>], rax
  67. <% } %>
  68. ret