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.

82 lines
1.6 KiB

  1. <% function isTrue(resReg, srcPtrReg) { %>
  2. <% const longIsZero = global.tmpLabel() %>
  3. <% const retOne = global.tmpLabel("retOne") %>
  4. <% const retZero = global.tmpLabel("retZero") %>
  5. <% const done = global.tmpLabel("done") %>
  6. mov rax, [<%=srcPtrReg%>]
  7. bt rax, 63
  8. jc <%= longIsZero %>
  9. test eax, eax
  10. jz <%= retZero %>
  11. jmp <%= retOne %>
  12. <%= longIsZero %>:
  13. <% for (let i=0; i<n64; i++) { %>
  14. mov rax, [<%= srcPtrReg + " + " +(i*8+8) %>]
  15. test rax, rax
  16. jnz <%= retOne %>
  17. <% } %>
  18. <%= retZero %>:
  19. mov qword <%=resReg%>, 0
  20. jmp <%= done %>
  21. <%= retOne %>:
  22. mov qword <%=resReg%>, 1
  23. <%= done %>:
  24. <% } %>
  25. <% function logicalOp(op) { %>
  26. ;;;;;;;;;;;;;;;;;;;;;;
  27. ; l<%= op %>
  28. ;;;;;;;;;;;;;;;;;;;;;;
  29. ; Logical <%= op %> between two elements
  30. ; Params:
  31. ; rsi <= Pointer to element 1
  32. ; rdx <= Pointer to element 2
  33. ; rdi <= Pointer to result zero or one
  34. ; Modified Registers:
  35. ; rax, rcx, r8
  36. ;;;;;;;;;;;;;;;;;;;;;;
  37. <%=name%>_l<%=op%>:
  38. <%= isTrue("r8", "rsi") %>
  39. <%= isTrue("rcx", "rdx") %>
  40. <%=op%> rcx, r8
  41. mov [rdi], rcx
  42. ret
  43. <% } %>
  44. <% logicalOp("and"); %>
  45. <% logicalOp("or"); %>
  46. ;;;;;;;;;;;;;;;;;;;;;;
  47. ; lnot
  48. ;;;;;;;;;;;;;;;;;;;;;;
  49. ; Do the logical not of an element
  50. ; Params:
  51. ; rsi <= Pointer to element to be tested
  52. ; rdi <= Pointer to result one if element1 is zero and zero otherwise
  53. ; Modified Registers:
  54. ; rax, rax, r8
  55. ;;;;;;;;;;;;;;;;;;;;;;
  56. <%=name%>_lnot:
  57. <%= isTrue("rcx", "rsi") %>
  58. test rcx, rcx
  59. jz lnot_retOne
  60. lnot_retZero:
  61. mov qword [rdi], 0
  62. ret
  63. lnot_retOne:
  64. mov qword [rdi], 1
  65. ret