android_memset32.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "cache.h"
  17. #ifndef MEMSET
  18. # define MEMSET android_memset32
  19. #endif
  20. #ifndef L
  21. # define L(label) .L##label
  22. #endif
  23. #ifndef ALIGN
  24. # define ALIGN(n) .p2align n
  25. #endif
  26. #ifndef cfi_startproc
  27. # define cfi_startproc .cfi_startproc
  28. #endif
  29. #ifndef cfi_endproc
  30. # define cfi_endproc .cfi_endproc
  31. #endif
  32. #ifndef cfi_rel_offset
  33. # define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off
  34. #endif
  35. #ifndef cfi_restore
  36. # define cfi_restore(reg) .cfi_restore reg
  37. #endif
  38. #ifndef cfi_adjust_cfa_offset
  39. # define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off
  40. #endif
  41. #ifndef ENTRY
  42. # define ENTRY(name) \
  43. .type name, @function; \
  44. .globl name; \
  45. .p2align 4; \
  46. name: \
  47. cfi_startproc
  48. #endif
  49. #ifndef END
  50. # define END(name) \
  51. cfi_endproc; \
  52. .size name, .-name
  53. #endif
  54. #define CFI_PUSH(REG) \
  55. cfi_adjust_cfa_offset (4); \
  56. cfi_rel_offset (REG, 0)
  57. #define CFI_POP(REG) \
  58. cfi_adjust_cfa_offset (-4); \
  59. cfi_restore (REG)
  60. #define PUSH(REG) pushl REG; CFI_PUSH (REG)
  61. #define POP(REG) popl REG; CFI_POP (REG)
  62. #ifdef USE_AS_BZERO32
  63. # define DEST PARMS
  64. # define LEN DEST+4
  65. # define SETRTNVAL
  66. #else
  67. # define DEST PARMS
  68. # define DWDS DEST+4
  69. # define LEN DWDS+4
  70. # define SETRTNVAL movl DEST(%esp), %eax
  71. #endif
  72. #if (defined SHARED || defined __PIC__)
  73. # define ENTRANCE PUSH (%ebx);
  74. # define RETURN_END POP (%ebx); ret
  75. # define RETURN RETURN_END; CFI_PUSH (%ebx)
  76. # define PARMS 8 /* Preserve EBX. */
  77. # define JMPTBL(I, B) I - B
  78. /* Load an entry in a jump table into EBX and branch to it. TABLE is a
  79. jump table with relative offsets. */
  80. # define BRANCH_TO_JMPTBL_ENTRY(TABLE) \
  81. /* We first load PC into EBX. */ \
  82. call __x86.get_pc_thunk.bx; \
  83. /* Get the address of the jump table. */ \
  84. add $(TABLE - .), %ebx; \
  85. /* Get the entry and convert the relative offset to the \
  86. absolute address. */ \
  87. add (%ebx,%ecx,4), %ebx; \
  88. /* We loaded the jump table and adjuested EDX. Go. */ \
  89. jmp *%ebx
  90. .section .gnu.linkonce.t.__x86.get_pc_thunk.bx,"ax",@progbits
  91. .globl __x86.get_pc_thunk.bx
  92. .hidden __x86.get_pc_thunk.bx
  93. ALIGN (4)
  94. .type __x86.get_pc_thunk.bx,@function
  95. __x86.get_pc_thunk.bx:
  96. movl (%esp), %ebx
  97. ret
  98. #else
  99. # define ENTRANCE
  100. # define RETURN_END ret
  101. # define RETURN RETURN_END
  102. # define PARMS 4
  103. # define JMPTBL(I, B) I
  104. /* Branch to an entry in a jump table. TABLE is a jump table with
  105. absolute offsets. */
  106. # define BRANCH_TO_JMPTBL_ENTRY(TABLE) \
  107. jmp *TABLE(,%ecx,4)
  108. #endif
  109. .section .text.sse2,"ax",@progbits
  110. ALIGN (4)
  111. ENTRY (MEMSET)
  112. ENTRANCE
  113. movl LEN(%esp), %ecx
  114. shr $2, %ecx
  115. #ifdef USE_AS_BZERO32
  116. xor %eax, %eax
  117. #else
  118. mov DWDS(%esp), %eax
  119. mov %eax, %edx
  120. #endif
  121. movl DEST(%esp), %edx
  122. cmp $16, %ecx
  123. jae L(16dbwordsormore)
  124. L(write_less16dbwords):
  125. lea (%edx, %ecx, 4), %edx
  126. BRANCH_TO_JMPTBL_ENTRY (L(table_less16dbwords))
  127. .pushsection .rodata.sse2,"a",@progbits
  128. ALIGN (2)
  129. L(table_less16dbwords):
  130. .int JMPTBL (L(write_0dbwords), L(table_less16dbwords))
  131. .int JMPTBL (L(write_1dbwords), L(table_less16dbwords))
  132. .int JMPTBL (L(write_2dbwords), L(table_less16dbwords))
  133. .int JMPTBL (L(write_3dbwords), L(table_less16dbwords))
  134. .int JMPTBL (L(write_4dbwords), L(table_less16dbwords))
  135. .int JMPTBL (L(write_5dbwords), L(table_less16dbwords))
  136. .int JMPTBL (L(write_6dbwords), L(table_less16dbwords))
  137. .int JMPTBL (L(write_7dbwords), L(table_less16dbwords))
  138. .int JMPTBL (L(write_8dbwords), L(table_less16dbwords))
  139. .int JMPTBL (L(write_9dbwords), L(table_less16dbwords))
  140. .int JMPTBL (L(write_10dbwords), L(table_less16dbwords))
  141. .int JMPTBL (L(write_11dbwords), L(table_less16dbwords))
  142. .int JMPTBL (L(write_12dbwords), L(table_less16dbwords))
  143. .int JMPTBL (L(write_13dbwords), L(table_less16dbwords))
  144. .int JMPTBL (L(write_14dbwords), L(table_less16dbwords))
  145. .int JMPTBL (L(write_15dbwords), L(table_less16dbwords))
  146. .popsection
  147. ALIGN (4)
  148. L(write_15dbwords):
  149. movl %eax, -60(%edx)
  150. L(write_14dbwords):
  151. movl %eax, -56(%edx)
  152. L(write_13dbwords):
  153. movl %eax, -52(%edx)
  154. L(write_12dbwords):
  155. movl %eax, -48(%edx)
  156. L(write_11dbwords):
  157. movl %eax, -44(%edx)
  158. L(write_10dbwords):
  159. movl %eax, -40(%edx)
  160. L(write_9dbwords):
  161. movl %eax, -36(%edx)
  162. L(write_8dbwords):
  163. movl %eax, -32(%edx)
  164. L(write_7dbwords):
  165. movl %eax, -28(%edx)
  166. L(write_6dbwords):
  167. movl %eax, -24(%edx)
  168. L(write_5dbwords):
  169. movl %eax, -20(%edx)
  170. L(write_4dbwords):
  171. movl %eax, -16(%edx)
  172. L(write_3dbwords):
  173. movl %eax, -12(%edx)
  174. L(write_2dbwords):
  175. movl %eax, -8(%edx)
  176. L(write_1dbwords):
  177. movl %eax, -4(%edx)
  178. L(write_0dbwords):
  179. SETRTNVAL
  180. RETURN
  181. ALIGN (4)
  182. L(16dbwordsormore):
  183. test $3, %edx
  184. jz L(aligned4bytes)
  185. mov %eax, (%edx)
  186. mov %eax, -4(%edx, %ecx, 4)
  187. sub $1, %ecx
  188. rol $24, %eax
  189. add $1, %edx
  190. test $3, %edx
  191. jz L(aligned4bytes)
  192. ror $8, %eax
  193. add $1, %edx
  194. test $3, %edx
  195. jz L(aligned4bytes)
  196. ror $8, %eax
  197. add $1, %edx
  198. L(aligned4bytes):
  199. shl $2, %ecx
  200. #ifdef USE_AS_BZERO32
  201. pxor %xmm0, %xmm0
  202. #else
  203. movd %eax, %xmm0
  204. pshufd $0, %xmm0, %xmm0
  205. #endif
  206. testl $0xf, %edx
  207. jz L(aligned_16)
  208. /* ECX > 32 and EDX is not 16 byte aligned. */
  209. L(not_aligned_16):
  210. movdqu %xmm0, (%edx)
  211. movl %edx, %eax
  212. and $-16, %edx
  213. add $16, %edx
  214. sub %edx, %eax
  215. add %eax, %ecx
  216. movd %xmm0, %eax
  217. ALIGN (4)
  218. L(aligned_16):
  219. cmp $128, %ecx
  220. jae L(128bytesormore)
  221. L(aligned_16_less128bytes):
  222. add %ecx, %edx
  223. shr $2, %ecx
  224. BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
  225. ALIGN (4)
  226. L(128bytesormore):
  227. #ifdef SHARED_CACHE_SIZE
  228. PUSH (%ebx)
  229. mov $SHARED_CACHE_SIZE, %ebx
  230. #else
  231. # if (defined SHARED || defined __PIC__)
  232. call __x86.get_pc_thunk.bx
  233. add $_GLOBAL_OFFSET_TABLE_, %ebx
  234. mov __x86_shared_cache_size@GOTOFF(%ebx), %ebx
  235. # else
  236. PUSH (%ebx)
  237. mov __x86_shared_cache_size, %ebx
  238. # endif
  239. #endif
  240. cmp %ebx, %ecx
  241. jae L(128bytesormore_nt_start)
  242. #ifdef DATA_CACHE_SIZE
  243. POP (%ebx)
  244. # define RESTORE_EBX_STATE CFI_PUSH (%ebx)
  245. cmp $DATA_CACHE_SIZE, %ecx
  246. #else
  247. # if (defined SHARED || defined __PIC__)
  248. # define RESTORE_EBX_STATE
  249. call __x86.get_pc_thunk.bx
  250. add $_GLOBAL_OFFSET_TABLE_, %ebx
  251. cmp __x86_data_cache_size@GOTOFF(%ebx), %ecx
  252. # else
  253. POP (%ebx)
  254. # define RESTORE_EBX_STATE CFI_PUSH (%ebx)
  255. cmp __x86_data_cache_size, %ecx
  256. # endif
  257. #endif
  258. jae L(128bytes_L2_normal)
  259. subl $128, %ecx
  260. L(128bytesormore_normal):
  261. sub $128, %ecx
  262. movdqa %xmm0, (%edx)
  263. movdqa %xmm0, 0x10(%edx)
  264. movdqa %xmm0, 0x20(%edx)
  265. movdqa %xmm0, 0x30(%edx)
  266. movdqa %xmm0, 0x40(%edx)
  267. movdqa %xmm0, 0x50(%edx)
  268. movdqa %xmm0, 0x60(%edx)
  269. movdqa %xmm0, 0x70(%edx)
  270. lea 128(%edx), %edx
  271. jb L(128bytesless_normal)
  272. sub $128, %ecx
  273. movdqa %xmm0, (%edx)
  274. movdqa %xmm0, 0x10(%edx)
  275. movdqa %xmm0, 0x20(%edx)
  276. movdqa %xmm0, 0x30(%edx)
  277. movdqa %xmm0, 0x40(%edx)
  278. movdqa %xmm0, 0x50(%edx)
  279. movdqa %xmm0, 0x60(%edx)
  280. movdqa %xmm0, 0x70(%edx)
  281. lea 128(%edx), %edx
  282. jae L(128bytesormore_normal)
  283. L(128bytesless_normal):
  284. lea 128(%ecx), %ecx
  285. add %ecx, %edx
  286. shr $2, %ecx
  287. BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
  288. ALIGN (4)
  289. L(128bytes_L2_normal):
  290. prefetcht0 0x380(%edx)
  291. prefetcht0 0x3c0(%edx)
  292. sub $128, %ecx
  293. movdqa %xmm0, (%edx)
  294. movaps %xmm0, 0x10(%edx)
  295. movaps %xmm0, 0x20(%edx)
  296. movaps %xmm0, 0x30(%edx)
  297. movaps %xmm0, 0x40(%edx)
  298. movaps %xmm0, 0x50(%edx)
  299. movaps %xmm0, 0x60(%edx)
  300. movaps %xmm0, 0x70(%edx)
  301. add $128, %edx
  302. cmp $128, %ecx
  303. jae L(128bytes_L2_normal)
  304. L(128bytesless_L2_normal):
  305. add %ecx, %edx
  306. shr $2, %ecx
  307. BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
  308. RESTORE_EBX_STATE
  309. L(128bytesormore_nt_start):
  310. sub %ebx, %ecx
  311. mov %ebx, %eax
  312. and $0x7f, %eax
  313. add %eax, %ecx
  314. movd %xmm0, %eax
  315. ALIGN (4)
  316. L(128bytesormore_shared_cache_loop):
  317. prefetcht0 0x3c0(%edx)
  318. prefetcht0 0x380(%edx)
  319. sub $0x80, %ebx
  320. movdqa %xmm0, (%edx)
  321. movdqa %xmm0, 0x10(%edx)
  322. movdqa %xmm0, 0x20(%edx)
  323. movdqa %xmm0, 0x30(%edx)
  324. movdqa %xmm0, 0x40(%edx)
  325. movdqa %xmm0, 0x50(%edx)
  326. movdqa %xmm0, 0x60(%edx)
  327. movdqa %xmm0, 0x70(%edx)
  328. add $0x80, %edx
  329. cmp $0x80, %ebx
  330. jae L(128bytesormore_shared_cache_loop)
  331. cmp $0x80, %ecx
  332. jb L(shared_cache_loop_end)
  333. ALIGN (4)
  334. L(128bytesormore_nt):
  335. sub $0x80, %ecx
  336. movntdq %xmm0, (%edx)
  337. movntdq %xmm0, 0x10(%edx)
  338. movntdq %xmm0, 0x20(%edx)
  339. movntdq %xmm0, 0x30(%edx)
  340. movntdq %xmm0, 0x40(%edx)
  341. movntdq %xmm0, 0x50(%edx)
  342. movntdq %xmm0, 0x60(%edx)
  343. movntdq %xmm0, 0x70(%edx)
  344. add $0x80, %edx
  345. cmp $0x80, %ecx
  346. jae L(128bytesormore_nt)
  347. sfence
  348. L(shared_cache_loop_end):
  349. #if defined DATA_CACHE_SIZE || !(defined SHARED || defined __PIC__)
  350. POP (%ebx)
  351. #endif
  352. add %ecx, %edx
  353. shr $2, %ecx
  354. BRANCH_TO_JMPTBL_ENTRY (L(table_16_128bytes))
  355. .pushsection .rodata.sse2,"a",@progbits
  356. ALIGN (2)
  357. L(table_16_128bytes):
  358. .int JMPTBL (L(aligned_16_0bytes), L(table_16_128bytes))
  359. .int JMPTBL (L(aligned_16_4bytes), L(table_16_128bytes))
  360. .int JMPTBL (L(aligned_16_8bytes), L(table_16_128bytes))
  361. .int JMPTBL (L(aligned_16_12bytes), L(table_16_128bytes))
  362. .int JMPTBL (L(aligned_16_16bytes), L(table_16_128bytes))
  363. .int JMPTBL (L(aligned_16_20bytes), L(table_16_128bytes))
  364. .int JMPTBL (L(aligned_16_24bytes), L(table_16_128bytes))
  365. .int JMPTBL (L(aligned_16_28bytes), L(table_16_128bytes))
  366. .int JMPTBL (L(aligned_16_32bytes), L(table_16_128bytes))
  367. .int JMPTBL (L(aligned_16_36bytes), L(table_16_128bytes))
  368. .int JMPTBL (L(aligned_16_40bytes), L(table_16_128bytes))
  369. .int JMPTBL (L(aligned_16_44bytes), L(table_16_128bytes))
  370. .int JMPTBL (L(aligned_16_48bytes), L(table_16_128bytes))
  371. .int JMPTBL (L(aligned_16_52bytes), L(table_16_128bytes))
  372. .int JMPTBL (L(aligned_16_56bytes), L(table_16_128bytes))
  373. .int JMPTBL (L(aligned_16_60bytes), L(table_16_128bytes))
  374. .int JMPTBL (L(aligned_16_64bytes), L(table_16_128bytes))
  375. .int JMPTBL (L(aligned_16_68bytes), L(table_16_128bytes))
  376. .int JMPTBL (L(aligned_16_72bytes), L(table_16_128bytes))
  377. .int JMPTBL (L(aligned_16_76bytes), L(table_16_128bytes))
  378. .int JMPTBL (L(aligned_16_80bytes), L(table_16_128bytes))
  379. .int JMPTBL (L(aligned_16_84bytes), L(table_16_128bytes))
  380. .int JMPTBL (L(aligned_16_88bytes), L(table_16_128bytes))
  381. .int JMPTBL (L(aligned_16_92bytes), L(table_16_128bytes))
  382. .int JMPTBL (L(aligned_16_96bytes), L(table_16_128bytes))
  383. .int JMPTBL (L(aligned_16_100bytes), L(table_16_128bytes))
  384. .int JMPTBL (L(aligned_16_104bytes), L(table_16_128bytes))
  385. .int JMPTBL (L(aligned_16_108bytes), L(table_16_128bytes))
  386. .int JMPTBL (L(aligned_16_112bytes), L(table_16_128bytes))
  387. .int JMPTBL (L(aligned_16_116bytes), L(table_16_128bytes))
  388. .int JMPTBL (L(aligned_16_120bytes), L(table_16_128bytes))
  389. .int JMPTBL (L(aligned_16_124bytes), L(table_16_128bytes))
  390. .popsection
  391. ALIGN (4)
  392. L(aligned_16_112bytes):
  393. movdqa %xmm0, -112(%edx)
  394. L(aligned_16_96bytes):
  395. movdqa %xmm0, -96(%edx)
  396. L(aligned_16_80bytes):
  397. movdqa %xmm0, -80(%edx)
  398. L(aligned_16_64bytes):
  399. movdqa %xmm0, -64(%edx)
  400. L(aligned_16_48bytes):
  401. movdqa %xmm0, -48(%edx)
  402. L(aligned_16_32bytes):
  403. movdqa %xmm0, -32(%edx)
  404. L(aligned_16_16bytes):
  405. movdqa %xmm0, -16(%edx)
  406. L(aligned_16_0bytes):
  407. SETRTNVAL
  408. RETURN
  409. ALIGN (4)
  410. L(aligned_16_116bytes):
  411. movdqa %xmm0, -116(%edx)
  412. L(aligned_16_100bytes):
  413. movdqa %xmm0, -100(%edx)
  414. L(aligned_16_84bytes):
  415. movdqa %xmm0, -84(%edx)
  416. L(aligned_16_68bytes):
  417. movdqa %xmm0, -68(%edx)
  418. L(aligned_16_52bytes):
  419. movdqa %xmm0, -52(%edx)
  420. L(aligned_16_36bytes):
  421. movdqa %xmm0, -36(%edx)
  422. L(aligned_16_20bytes):
  423. movdqa %xmm0, -20(%edx)
  424. L(aligned_16_4bytes):
  425. movl %eax, -4(%edx)
  426. SETRTNVAL
  427. RETURN
  428. ALIGN (4)
  429. L(aligned_16_120bytes):
  430. movdqa %xmm0, -120(%edx)
  431. L(aligned_16_104bytes):
  432. movdqa %xmm0, -104(%edx)
  433. L(aligned_16_88bytes):
  434. movdqa %xmm0, -88(%edx)
  435. L(aligned_16_72bytes):
  436. movdqa %xmm0, -72(%edx)
  437. L(aligned_16_56bytes):
  438. movdqa %xmm0, -56(%edx)
  439. L(aligned_16_40bytes):
  440. movdqa %xmm0, -40(%edx)
  441. L(aligned_16_24bytes):
  442. movdqa %xmm0, -24(%edx)
  443. L(aligned_16_8bytes):
  444. movq %xmm0, -8(%edx)
  445. SETRTNVAL
  446. RETURN
  447. ALIGN (4)
  448. L(aligned_16_124bytes):
  449. movdqa %xmm0, -124(%edx)
  450. L(aligned_16_108bytes):
  451. movdqa %xmm0, -108(%edx)
  452. L(aligned_16_92bytes):
  453. movdqa %xmm0, -92(%edx)
  454. L(aligned_16_76bytes):
  455. movdqa %xmm0, -76(%edx)
  456. L(aligned_16_60bytes):
  457. movdqa %xmm0, -60(%edx)
  458. L(aligned_16_44bytes):
  459. movdqa %xmm0, -44(%edx)
  460. L(aligned_16_28bytes):
  461. movdqa %xmm0, -28(%edx)
  462. L(aligned_16_12bytes):
  463. movq %xmm0, -12(%edx)
  464. movl %eax, -4(%edx)
  465. SETRTNVAL
  466. RETURN
  467. END (MEMSET)