Windows NT 4.0 source code leak
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.

122 lines
4.1 KiB

4 years ago
  1. #++
  2. #
  3. # Copyright (c) 1993 by
  4. # Digital Equipment Corporation, Maynard, MA
  5. #
  6. # This software is furnished under a license and may be used and copied
  7. # only in accordance with the terms of such license and with the
  8. # inclusion of the above copyright notice. This software or any other
  9. # copies thereof may not be provided or otherwise made available to any
  10. # other person. No title to and ownership of the software is hereby
  11. # transferred.
  12. #
  13. # The information in this software is subject to change without notice
  14. # and should not be construed as a commitment by Digital Equipment
  15. # Corporation.
  16. #
  17. # Digital assumes no responsibility for the use or reliability of its
  18. # software on equipment which is not supplied by Digital.
  19. #
  20. # Facility:
  21. #
  22. # GEM/OTS - GEM compiler system support library
  23. #
  24. # Abstract:
  25. #
  26. # OTS character string support, Alpha version
  27. #
  28. # Authors:
  29. #
  30. # Kent Glossop
  31. #
  32. # void ots_translate(char *dst, long dstlen, char *src, char table[256]);
  33. #
  34. # Translates a string using a translation table. Handles overlap.
  35. #
  36. # Special conventions: No stack space, r16-r21 and r26-r28 ONLY,
  37. # no linkage pointer required.
  38. # (Warning: The auto-loader potentially takes some regs across
  39. # the call if this is being used in a shared lib. environment.)
  40. #
  41. # Modification history:
  42. #
  43. # 006 13 Nov 1992 KDG Initial non-tailored assembly version,
  44. # replacing BLISS -005
  45. #
  46. # 007 26 Jan 1993 KDG Add underscore
  47. #--
  48. #include "ots_defs.hs"
  49. # r16 destination address
  50. # r17 length
  51. # r18 source address
  52. # r19 table address
  53. # r20,r21,r27,r28 scratch
  54. # r26 return address
  55. #
  56. .globl _OtsStringTranslate
  57. .ent _OtsStringTranslate
  58. _OtsStringTranslate:
  59. .set noat
  60. .set noreorder
  61. .frame sp,0,r26
  62. # sort out which case to use
  63. addq r18, r17, r27 # get end address of source + 1 for overlap check
  64. cmpult r18, r16, r28 # true if src at lower addr than dest (note trans to self is not a "slow" case)
  65. cmpult r16, r27, r27 # true if dst starts before end of src
  66. beq r17, done # don't touch memory if length=0
  67. and r27, r28, r28 # does dst have bad overlap with src?
  68. blbs r28, overlap # go handle poorly overlapping src/dst
  69. # simple forward loop case (~16 cycles/byte EV4)
  70. # (length is presumed to be at least 1)
  71. subq r18, 1, r18 # one before the beginning of the source
  72. subq r16, 1, r16 # one before the beginning of the destination
  73. forward_loop:
  74. ldq_u r20, 1(r18) # load the qw containing the source
  75. lda r18, 1(r18) # bump the source pointer
  76. ldq_u r21, 1(r16) # load the qw containing the destination
  77. lda r16, 1(r16) # bump the destination pointer
  78. extbl r20 ,r18, r20 # get the byte to translate
  79. addq r19, r20, r20 # get the address of the translation
  80. ldq_u r27, (r20) # load the translation
  81. subq r17, 1, r17 # decrement length
  82. mskbl r21, r16, r21 # clear the bits in the destination
  83. extbl r27, r20, r27 # extract the translation
  84. insbl r27, r16, r27 # position for insertion
  85. bis r27, r21, r21 # merge into the destination
  86. stq_u r21, (r16) # store back
  87. bgt r17, forward_loop # do another if there
  88. done: ret r31, (r26)
  89. nop #.align 3
  90. # bad overlap case (~16 cycles/byte EV4, 11c/byte EV5)
  91. # (length is presumed to be at least 1)
  92. overlap:
  93. addq r17, r18, r18 # one past the end of the source
  94. addq r17, r16, r16 # one past the end of the destination
  95. backward_loop:
  96. ldq_u r20, -1(r18) # load the qw containing the source
  97. lda r18, -1(r18) # bump the source pointer
  98. ldq_u r21, -1(r16) # load the qw containing the destination
  99. lda r16, -1(r16) # bump the destination pointer
  100. extbl r20 ,r18, r20 # get the byte to translate
  101. addq r19, r20, r20 # get the address of the translation
  102. ldq_u r27, (r20) # load the translation
  103. subq r17, 1, r17 # decrement length
  104. mskbl r21, r16, r21 # clear the bits in the destination
  105. extbl r27, r20, r27 # extract the translation
  106. insbl r27, r16, r27 # position for insertion
  107. bis r27, r21, r21 # merge into the destination
  108. stq_u r21, (r16) # store back
  109. bgt r17, backward_loop # do another if there
  110. ret r31, (r26)
  111. .set at
  112. .set reorder
  113. .end _OtsStringTranslate