1 .global __sdivsi3 2 .global __sdivsi3_1 3 .global __sdivsi3_2 4 .section .text..SHmedia32,"ax" 5 .align 2 6 7 /* inputs: r4,r5 */ 8 /* clobbered: r1,r18,r19,r20,r21,r25,tr0 */ 9 /* result in r0 */ 10__sdivsi3: 11__sdivsi3_1: 12 ptb __div_table,tr0 13 gettr tr0,r20 14 15__sdivsi3_2: 16 nsb r5, r1 17 shlld r5, r1, r25 /* normalize; [-2 ..1, 1..2) in s2.62 */ 18 shari r25, 58, r21 /* extract 5(6) bit index (s2.4 with hole -1..1) */ 19 /* bubble */ 20 ldx.ub r20, r21, r19 /* u0.8 */ 21 shari r25, 32, r25 /* normalize to s2.30 */ 22 shlli r21, 1, r21 23 muls.l r25, r19, r19 /* s2.38 */ 24 ldx.w r20, r21, r21 /* s2.14 */ 25 ptabs r18, tr0 26 shari r19, 24, r19 /* truncate to s2.14 */ 27 sub r21, r19, r19 /* some 11 bit inverse in s1.14 */ 28 muls.l r19, r19, r21 /* u0.28 */ 29 sub r63, r1, r1 30 addi r1, 92, r1 31 muls.l r25, r21, r18 /* s2.58 */ 32 shlli r19, 45, r19 /* multiply by two and convert to s2.58 */ 33 /* bubble */ 34 sub r19, r18, r18 35 shari r18, 28, r18 /* some 22 bit inverse in s1.30 */ 36 muls.l r18, r25, r0 /* s2.60 */ 37 muls.l r18, r4, r25 /* s32.30 */ 38 /* bubble */ 39 shari r0, 16, r19 /* s-16.44 */ 40 muls.l r19, r18, r19 /* s-16.74 */ 41 shari r25, 63, r0 42 shari r4, 14, r18 /* s19.-14 */ 43 shari r19, 30, r19 /* s-16.44 */ 44 muls.l r19, r18, r19 /* s15.30 */ 45 xor r21, r0, r21 /* You could also use the constant 1 << 27. */ 46 add r21, r25, r21 47 sub r21, r19, r21 48 shard r21, r1, r21 49 sub r21, r0, r0 50 blink tr0, r63 51 52/* This table has been generated by divtab.c . 53Defects for bias -330: 54 Max defect: 6.081536e-07 at -1.000000e+00 55 Min defect: 2.849516e-08 at 1.030651e+00 56 Max 2nd step defect: 9.606539e-12 at -1.000000e+00 57 Min 2nd step defect: 0.000000e+00 at 0.000000e+00 58 Defect at 1: 1.238659e-07 59 Defect at -2: 1.061708e-07 */ 60 61 .balign 2 62 .type __div_table,@object 63 .size __div_table,128 64/* negative division constants */ 65 .word -16638 66 .word -17135 67 .word -17737 68 .word -18433 69 .word -19103 70 .word -19751 71 .word -20583 72 .word -21383 73 .word -22343 74 .word -23353 75 .word -24407 76 .word -25582 77 .word -26863 78 .word -28382 79 .word -29965 80 .word -31800 81/* negative division factors */ 82 .byte 66 83 .byte 70 84 .byte 75 85 .byte 81 86 .byte 87 87 .byte 93 88 .byte 101 89 .byte 109 90 .byte 119 91 .byte 130 92 .byte 142 93 .byte 156 94 .byte 172 95 .byte 192 96 .byte 214 97 .byte 241 98 .skip 16 99 .global __div_table 100__div_table: 101 .skip 16 102/* positive division factors */ 103 .byte 241 104 .byte 214 105 .byte 192 106 .byte 172 107 .byte 156 108 .byte 142 109 .byte 130 110 .byte 119 111 .byte 109 112 .byte 101 113 .byte 93 114 .byte 87 115 .byte 81 116 .byte 75 117 .byte 70 118 .byte 66 119/* positive division constants */ 120 .word 31801 121 .word 29966 122 .word 28383 123 .word 26864 124 .word 25583 125 .word 24408 126 .word 23354 127 .word 22344 128 .word 21384 129 .word 20584 130 .word 19752 131 .word 19104 132 .word 18434 133 .word 17738 134 .word 17136 135 .word 16639 136