strnlen_user.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * User string length functions for kernel
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #define isrc r0
  21. #define max r1 /* Do not change! */
  22. #define end r2
  23. #define tmp1 r3
  24. #define obo r6 /* off-by-one */
  25. #define start r7
  26. #define mod8 r8
  27. #define dbuf r15:14
  28. #define dcmp r13:12
  29. /*
  30. * The vector mask version of this turned out *really* badly.
  31. * The hardware loop version also turned out *really* badly.
  32. * Seems straight pointer arithmetic basically wins here.
  33. */
  34. #define fname __strnlen_user
  35. .text
  36. .global fname
  37. .type fname, @function
  38. .p2align 5 /* why? */
  39. fname:
  40. {
  41. mod8 = and(isrc,#7);
  42. end = add(isrc,max);
  43. start = isrc;
  44. }
  45. {
  46. P0 = cmp.eq(mod8,#0);
  47. mod8 = and(end,#7);
  48. dcmp = #0;
  49. if (P0.new) jump:t dw_loop; /* fire up the oven */
  50. }
  51. alignment_loop:
  52. fail_1: {
  53. tmp1 = memb(start++#1);
  54. }
  55. {
  56. P0 = cmp.eq(tmp1,#0);
  57. if (P0.new) jump:nt exit_found;
  58. P1 = cmp.gtu(end,start);
  59. mod8 = and(start,#7);
  60. }
  61. {
  62. if (!P1) jump exit_error; /* hit the end */
  63. P0 = cmp.eq(mod8,#0);
  64. }
  65. {
  66. if (!P0) jump alignment_loop;
  67. }
  68. dw_loop:
  69. fail_2: {
  70. dbuf = memd(start);
  71. obo = add(start,#1);
  72. }
  73. {
  74. P0 = vcmpb.eq(dbuf,dcmp);
  75. }
  76. {
  77. tmp1 = P0;
  78. P0 = cmp.gtu(end,start);
  79. }
  80. {
  81. tmp1 = ct0(tmp1);
  82. mod8 = and(end,#7);
  83. if (!P0) jump end_check;
  84. }
  85. {
  86. P0 = cmp.eq(tmp1,#32);
  87. if (!P0.new) jump:nt exit_found;
  88. if (!P0.new) start = add(obo,tmp1);
  89. }
  90. {
  91. start = add(start,#8);
  92. jump dw_loop;
  93. } /* might be nice to combine these jumps... */
  94. end_check:
  95. {
  96. P0 = cmp.gt(tmp1,mod8);
  97. if (P0.new) jump:nt exit_error; /* neverfound! */
  98. start = add(obo,tmp1);
  99. }
  100. exit_found:
  101. {
  102. R0 = sub(start,isrc);
  103. jumpr R31;
  104. }
  105. exit_error:
  106. {
  107. R0 = add(max,#1);
  108. jumpr R31;
  109. }
  110. /* Uh, what does the "fixup" return here? */
  111. .falign
  112. fix_1:
  113. {
  114. R0 = #0;
  115. jumpr R31;
  116. }
  117. .size fname,.-fname
  118. .section __ex_table,"a"
  119. .long fail_1,fix_1
  120. .long fail_2,fix_1
  121. .previous