lbnalpha.s
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:6k
源码类别:

CA认证

开发平台:

C/C++

  1. /*
  2.  * DEC Alpha 64-bit math primitives.  These use 64-bit words
  3.  * unless otherwise noted.
  4.  *
  5.  * Copyright (c) 1995, Colin Plumb.
  6.  * For licensing and other legal details, see the file legal.c.
  7.  *
  8.  * The DEC assembler apparently does some instruction scheduling,
  9.  * but I tried to do some of my own, and tries to spread things
  10.  * out over the register file to give the assembler more room
  11.  * to schedule things.
  12.  *
  13.  * Alpha OSF/1 register usage conventions:
  14.  * r0       - v0      - Temp, holds integer return value
  15.  * r1..r8   - t0..t7  - Temp, trashed by procedure call
  16.  * r9..r14  - s0..s5  - Saved across procedure calls
  17.  * r15      - s6/FP   - Frame pointer, saved across procedure calls
  18.  * r16..r21 - a0..a5  - Argument registers, all trashed by procedure call
  19.  * r22..r25 - t8..t11 - Temp, trashed by procedure call
  20.  * r26      - ra      - Return address
  21.  * r27      - t12/pv  - Procedure value, trashed by procedure call
  22.  * r28      - at      - Assembler temp, trashed by procedure call
  23.  * r29      - gp      - Global pointer
  24.  * r30      - sp      - Stack pointer
  25.  * r31      - zero    - hardwired to zero
  26.  */
  27. .text
  28. .align 4
  29. .globl lbnMulN1_64
  30. /* I have no idea what the '2' at the end of the .ent line means. */
  31. .ent lbnMulN1_64 2
  32. /*
  33.  * Arguments: $16 = out, $17 = in, $18 = len<32>, $19 = k
  34.  * Other registers: $0 = carry word, $1 = product low,
  35.  * $2 = product high, $3 = input word
  36.  */
  37. lbnMulN1_64:
  38. ldq $3,0($17) /* Load first word of input */
  39. subl $18,1,$18
  40. mulq $3,$19,$1 /* Do low half of first multiply */
  41. umulh $3,$19,$0 /* Do second half of first multiply */
  42. stq $1,0($16)
  43. beq $18,m64_done
  44. m64_loop:
  45. ldq $3,8($17)
  46. addq $17,8,$17
  47. mulq $3,$19,$1 /* Do bottom half of multiply */
  48. subl $18,1,$18
  49. umulh $3,$19,$2 /* Do top half of multiply */
  50. addq $0,$1,$1 /* Add carry word from previous multiply */
  51. stq $1,8($16)
  52. cmpult $1,$0,$0 /* Compute carry bit from add */
  53. addq $16,8,$16
  54. addq $2,$0,$0 /* Add carry bit to carry word */
  55.  
  56. beq $18,m64_done
  57. ldq $3,8($17)
  58. addq $17,8,$17
  59. mulq $3,$19,$1 /* Do bottom half of multiply */
  60. subl $18,1,$18
  61. umulh $3,$19,$2 /* Do top half of multiply */
  62. addq $0,$1,$1 /* Add carry word from previous multiply */
  63. stq $1,8($16)
  64. cmpult $1,$0,$0 /* Compute carry bit from add */
  65. addq $16,8,$16
  66. addq $2,$0,$0 /* Add carry bit to carry word */
  67.  
  68. bne $18,m64_loop
  69. m64_done:
  70. stq $0,8($16) /* Store last word of result */
  71. ret $31,($26),1
  72. /* The '1' in the hint field means procedure return - software convention */
  73. .end lbnMulN1_64
  74.  
  75.  
  76. .text
  77. .align 4
  78. .globl lbnMulAdd1_64
  79. .ent lbnMulAdd1_64 2
  80. /*
  81.  * Arguments: $16 = out, $17 = in, $18 = len<32>, $19 = k
  82.  * Other registers: $0 = product high, $1 = product low,
  83.  * $2 = product high temp, $3 = input word, $4 = output word
  84.  * $5 = carry bit from add to out
  85.  */
  86. lbnMulAdd1_64:
  87. ldq $3,0($17) /* Load first word of input */
  88. subl $18,1,$18
  89. mulq $3,$19,$1 /* Do low half of first multiply */
  90. ldq $4,0($16) /* Load first word of output */
  91. umulh $3,$19,$2 /* Do second half of first multiply */
  92. addq $4,$1,$4
  93. cmpult $4,$1,$5 /* Compute borrow bit from subtract */
  94. stq $4,0($16)
  95. addq $5,$2,$0 /* Add carry bit to high word */
  96. beq $18,ma64_done
  97. ma64_loop:
  98. ldq $3,8($17) /* Load next word of input */
  99. addq $17,8,$17
  100. ldq $4,8($16) /* Load next word of output */
  101. mulq $3,$19,$1 /* Do bottom half of multiply */
  102. subl $18,1,$18
  103. addq $0,$1,$1 /* Add carry word from previous multiply */
  104. umulh $3,$19,$2 /* Do top half of multiply */
  105. cmpult $1,$0,$0 /* Compute carry bit from add */
  106. addq $4,$1,$4 /* Add product to loaded word */
  107. cmpult $4,$1,$5 /* Compute carry bit from add */
  108. stq $4,8($16)
  109. addq $5,$0,$5 /* Add carry bits together */
  110. addq $16,8,$16
  111. addq $5,$2,$0 /* Add carry bits to carry word */
  112.  
  113. beq $18,ma64_done
  114. ldq $3,8($17) /* Load next word of input */
  115. addq $17,8,$17
  116. ldq $4,8($16) /* Load next word of output */
  117. mulq $3,$19,$1 /* Do bottom half of multiply */
  118. subl $18,1,$18
  119. addq $0,$1,$1 /* Add carry word from previous multiply */
  120. umulh $3,$19,$2 /* Do top half of multiply */
  121. cmpult $1,$0,$0 /* Compute carry bit from add */
  122. addq $4,$1,$4 /* Add product to loaded word */
  123. cmpult $4,$1,$5 /* Compute carry bit from add */
  124. stq $4,8($16)
  125. addq $5,$0,$5 /* Add carry bits together */
  126. addq $16,8,$16
  127. addq $5,$2,$0 /* Add carry bits to carry word */
  128.  
  129. bne $18,ma64_loop
  130. ma64_done:
  131. ret $31,($26),1
  132. .end lbnMulAdd1_64
  133.  
  134.  
  135. .text
  136. .align 4
  137. .globl lbnMulSub1_64
  138. .ent lbnMulSub1_64 2
  139. /*
  140.  * Arguments: $16 = out, $17 = in, $18 = len<32>, $19 = k
  141.  * Other registers: $0 = carry word, $1 = product low,
  142.  * $2 = product high temp, $3 = input word, $4 = output word
  143.  * $5 = borrow bit from subtract
  144.  */
  145. lbnMulSub1_64:
  146. ldq $3,0($17) /* Load first word of input */
  147. subl $18,1,$18
  148. mulq $3,$19,$1 /* Do low half of first multiply */
  149. ldq $4,0($16) /* Load first word of output */
  150. umulh $3,$19,$2 /* Do second half of first multiply */
  151. cmpult $4,$1,$5 /* Compute borrow bit from subtract */
  152. subq $4,$1,$4
  153. addq $5,$2,$0 /* Add carry bit to high word */
  154. stq $4,0($16)
  155. beq $18,ms64_done
  156. ms64_loop:
  157. ldq $3,8($17) /* Load next word of input */
  158. addq $17,8,$17
  159. ldq $4,8($16) /* Load next word of output */
  160. mulq $3,$19,$1 /* Do bottom half of multiply */
  161. subl $18,1,$18
  162. addq $0,$1,$1 /* Add carry word from previous multiply */
  163. umulh $3,$19,$2 /* Do top half of multiply */
  164. cmpult $1,$0,$0 /* Compute carry bit from add */
  165. cmpult $4,$1,$5 /* Compute borrow bit from subtract */
  166. subq $4,$1,$4
  167. addq $5,$0,$5 /* Add carry bits together */
  168. stq $4,8($16)
  169. addq $5,$2,$0 /* Add carry bits to carry word */
  170. addq $16,8,$16
  171.  
  172. beq $18,ms64_done
  173. ldq $3,8($17) /* Load next word of input */
  174. addq $17,8,$17
  175. ldq $4,8($16) /* Load next word of output */
  176. mulq $3,$19,$1 /* Do bottom half of multiply */
  177. subl $18,1,$18
  178. addq $0,$1,$1 /* Add carry word from previous multiply */
  179. umulh $3,$19,$2 /* Do top half of multiply */
  180. cmpult $1,$0,$0 /* Compute carry bit from add */
  181. cmpult $4,$1,$5 /* Compute borrow bit from subtract */
  182. subq $4,$1,$4
  183. addq $5,$0,$5 /* Add carry bits together */
  184. stq $4,8($16)
  185. addq $5,$2,$0 /* Add carry bits to carry word */
  186. addq $16,8,$16
  187.  
  188. bne $18,ms64_loop
  189. ms64_done:
  190. ret $31,($26),1
  191. .end lbnMulSub1_64