vga_copy.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* VGA framebuffer row copy: rep movsl optimized for P5 USWC write-combining.
  2. *
  3. * void vga_fb_copy_row(void *dst, void *src, unsigned int dwords);
  4. *
  5. * On Pentium (P5), rep movsl to UC memory (PCI framebuffer) uses the
  6. * 64-byte USWC write-combining buffer. Writes are batched and flushed
  7. * as burst transfers to VRAM, avoiding per-dword PCI bus stalls.
  8. */
  9. .code32
  10. .text
  11. .globl vga_fb_copy_row
  12. vga_fb_copy_row:
  13. pushl %esi
  14. pushl %edi
  15. movl 12(%esp), %edi /* dst */
  16. movl 16(%esp), %esi /* src */
  17. movl 20(%esp), %ecx /* dword count */
  18. cld
  19. rep movsl
  20. popl %edi
  21. popl %esi
  22. ret
  23. /* void vga_fb_fill_row_sse2(void *dst, unsigned int value, unsigned int dwords);
  24. *
  25. * 16 bytes of the (broadcast) dword per iteration, then the remaining dwords.
  26. * Only called when cpuid reported SSE2; unaligned-safe (movdqu). */
  27. .globl vga_fb_fill_row_sse2
  28. vga_fb_fill_row_sse2:
  29. pushl %edi
  30. movl 8(%esp), %edi /* dst */
  31. movl 12(%esp), %eax /* value */
  32. movl 16(%esp), %ecx /* dword count */
  33. movd %eax, %xmm0
  34. pshufd $0, %xmm0, %xmm0
  35. movl %ecx, %edx
  36. shrl $2, %edx
  37. jz 2f
  38. 1: movdqu %xmm0, (%edi)
  39. addl $16, %edi
  40. decl %edx
  41. jnz 1b
  42. 2: andl $3, %ecx
  43. jz 4f
  44. 3: movl %eax, (%edi)
  45. addl $4, %edi
  46. decl %ecx
  47. jnz 3b
  48. 4: popl %edi
  49. ret
  50. /* void vga_fb_fill_row_nt(void *dst, unsigned int value, unsigned int dwords);
  51. *
  52. * Streaming (non-temporal) store version for long rows: avoids the
  53. * read-for-ownership traffic of a cached fill, which is what makes large
  54. * fills DRAM-bound on the Atom. Aligns to 16 bytes with normal stores, then
  55. * movntdq. The caller must sfence before the data is read back. */
  56. .globl vga_fb_fill_row_nt
  57. vga_fb_fill_row_nt:
  58. pushl %edi
  59. movl 8(%esp), %edi /* dst */
  60. movl 12(%esp), %eax /* value */
  61. movl 16(%esp), %ecx /* dword count */
  62. movd %eax, %xmm0
  63. pshufd $0, %xmm0, %xmm0
  64. 1: testl $15, %edi
  65. jz 2f
  66. testl %ecx, %ecx
  67. jz 9f
  68. movl %eax, (%edi)
  69. addl $4, %edi
  70. decl %ecx
  71. jmp 1b
  72. 2: movl %ecx, %edx
  73. shrl $2, %edx
  74. jz 4f
  75. 3: movntdq %xmm0, (%edi)
  76. addl $16, %edi
  77. decl %edx
  78. jnz 3b
  79. 4: andl $3, %ecx
  80. jz 9f
  81. 5: movl %eax, (%edi)
  82. addl $4, %edi
  83. decl %ecx
  84. jnz 5b
  85. 9: popl %edi
  86. ret
  87. /* void vga_fb_copy_row_nt(void *dst, const void *src, unsigned int dwords);
  88. *
  89. * Same as vga_fb_copy_row, but with streaming (non-temporal) stores: WC
  90. * destinations combine them into bursts, which rep movsl does not do here.
  91. * The destination is aligned with normal stores first; the caller sfences. */
  92. .globl vga_fb_copy_row_nt
  93. vga_fb_copy_row_nt:
  94. pushl %esi
  95. pushl %edi
  96. movl 12(%esp), %edi /* dst */
  97. movl 16(%esp), %esi /* src */
  98. movl 20(%esp), %ecx /* dword count */
  99. 1: testl $15, %edi
  100. jz 2f
  101. testl %ecx, %ecx
  102. jz 9f
  103. movl (%esi), %eax
  104. movl %eax, (%edi)
  105. addl $4, %esi
  106. addl $4, %edi
  107. decl %ecx
  108. jmp 1b
  109. 2: movl %ecx, %edx
  110. shrl $2, %edx
  111. jz 4f
  112. 3: movdqu (%esi), %xmm0
  113. movntdq %xmm0, (%edi)
  114. addl $16, %esi
  115. addl $16, %edi
  116. decl %edx
  117. jnz 3b
  118. 4: andl $3, %ecx
  119. jz 9f
  120. 5: movl (%esi), %eax
  121. movl %eax, (%edi)
  122. addl $4, %esi
  123. addl $4, %edi
  124. decl %ecx
  125. jnz 5b
  126. 9: popl %edi
  127. popl %esi
  128. ret