strlen.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * linux/arch/m32r/strlen.S -- strlen code.
  3. *
  4. * Copyright (C) 2001 Hirokazu Takata
  5. *
  6. * size_t strlen(const char *s);
  7. *
  8. */
  9. /* $Id$ */
  10. #include <linux/config.h>
  11. #include <linux/linkage.h>
  12. #include <asm/assembler.h>
  13. #ifdef CONFIG_ISA_DUAL_ISSUE
  14. .text
  15. ENTRY(strlen)
  16. mv r6, r0 || ldi r2, #0
  17. and3 r0, r0, #3
  18. bnez r0, strlen_byte
  19. ;
  20. strlen_word:
  21. ld r0, @r6+
  22. ;
  23. seth r5, #high(0x01010101)
  24. or3 r5, r5, #low(0x01010101)
  25. sll3 r7, r5, #7
  26. strlen_word_loop:
  27. ld r1, @r6+ || not r4, r0
  28. sub r0, r5 || and r4, r7
  29. and r4, r0
  30. bnez r4, strlen_last_bytes
  31. ld r0, @r6+ || not r4, r1
  32. sub r1, r5 || and r4, r7
  33. and r4, r1 || addi r2, #4
  34. bnez r4, strlen_last_bytes
  35. addi r2, #4 || bra.s strlen_word_loop
  36. ; NOTE: If a null char. exists, return 0.
  37. ; if ((x - 0x01010101) & ~x & 0x80808080)
  38. ; return 0;
  39. ;
  40. strlen_byte:
  41. ldb r1, @r6 || addi r6, #1
  42. beqz r1, strlen_exit
  43. addi r2, #1 || bra.s strlen_byte
  44. ;
  45. strlen_last_bytes:
  46. ldi r0, #4 || addi r6, #-8
  47. ;
  48. strlen_byte_loop:
  49. ldb r1, @r6 || addi r6, #1
  50. addi r0, #-1 || cmpz r1
  51. bc.s strlen_exit || cmpz r0
  52. addi r2, #1 || bnc.s strlen_byte_loop
  53. ;
  54. strlen_exit:
  55. mv r0, r2 || jmp r14
  56. #else /* not CONFIG_ISA_DUAL_ISSUE */
  57. .text
  58. ENTRY(strlen)
  59. mv r6, r0
  60. ldi r2, #0
  61. and3 r0, r0, #3
  62. bnez r0, strlen_byte
  63. ;
  64. strlen_word:
  65. ld r0, @r6+
  66. ;
  67. seth r5, #high(0x01010101)
  68. or3 r5, r5, #low(0x01010101)
  69. sll3 r7, r5, #7
  70. strlen_word_loop:
  71. ld r1, @r6+
  72. not r4, r0 ; NOTE: If a null char. exists, return 0.
  73. sub r0, r5 ; if ((x - 0x01010101) & ~x & 0x80808080)
  74. and r4, r7 ; return 0;
  75. and r4, r0
  76. bnez r4, strlen_last_bytes
  77. addi r2, #4
  78. ;
  79. ld r0, @r6+
  80. not r4, r1 ; NOTE: If a null char. exists, return 0.
  81. sub r1, r5 ; if ((x - 0x01010101) & ~x & 0x80808080)
  82. and r4, r7 ; return 0;
  83. and r4, r1
  84. bnez r4, strlen_last_bytes
  85. addi r2, #4
  86. bra strlen_word_loop
  87. ;
  88. strlen_byte:
  89. ldb r1, @r6
  90. addi r6, #1
  91. beqz r1, strlen_exit
  92. addi r2, #1
  93. bra strlen_byte
  94. ;
  95. strlen_last_bytes:
  96. ldi r0, #4
  97. addi r6, #-8
  98. ;
  99. strlen_byte_loop:
  100. ldb r1, @r6
  101. addi r6, #1
  102. addi r0, #-1
  103. beqz r1, strlen_exit
  104. addi r2, #1
  105. bnez r0, strlen_byte_loop
  106. ;
  107. strlen_exit:
  108. mv r0, r2
  109. jmp r14
  110. #endif /* not CONFIG_ISA_DUAL_ISSUE */
  111. .end