Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns » Sound/s/subrouts1
Sound/s/subrouts1
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns |
Filename: | Sound/s/subrouts1 |
Read OK: | ✔ |
File size: | 4BB8 bytes |
Load address: | 0000 |
Exec address: | 0000 |
Duplicates
There is 1 duplicate copy of this file in the archive:
- Archimedes archive » Archimedes World » AW-1996-07.adf » !AcornAns_AcornAns » Sound/s/subrouts1
- Archimedes archive » Archimedes World » AW-1996-06-Disc 1.adf » !AcornAns_AcornAns » !Scape2/s/subrouts1
File contents
max16 * &7fffffff ;max positive number in 16 bit fixed point format (2^31-1)/65536 min16 * &80000000 ;min negative number -2^31 /65536 one * 65536 ; rbbcinc ; a leaf APCS function ; ; C prototype: ; int rbbcinc(int r, int k) ; ; given limits 0 <= r < 2^k, return (r � 1) where � denotes a reversed bit ordering increment, ; subject to the stated limits. ; NB in this case, for the function f: n -> {for (k=c=0; c<n; c++, k=rbbcinc(k, l); return k;}, ; we have f(f(n))=n. ; NB2 algo requires 2 <= k <= 32, but doesn't check for this - BEWARE! ; (for k=1 get no action taken, while for any other bad k get code executed at unintended address, ; hence unpredictable & likely system fatal). ; EXPORT rbbcinc rbnsta DCB "rbbcinc", 0 ALIGN rbnend DCD &ff000000 + rbnend - rbnsta rbbcinc rbbc a1, a2, a3 MOVS pc, lr ; pow16 ; a leaf APCS function ; ; C prototype: ; int pow16(int a, int b) ; ; returns 65536 * (a/65536)^(b/65536) ; ; is about 5 to 40 times faster than FPEmulator working with double floats ; ; nb if a<0 require b an integer ; ; nb2 unexpected return values: ; a=b=0 returns 1 actual value ill defined ; a<0, b non integer returns 0 actual value complex ; abs(bln(a)) > max16 unknown errors likely (to avoid, restrict b to �(2^11)one, roughly) ; a=0, b<0 returns max16 actual value +infinity ; a & b st result out of range unknown result ; ; nb precise nature of errors for other values not yet confirmed acceptable, though should be okay except ; perhaps in extreme cases (as of 22/11/95) ; ; Few subsequent notes on error: ; ; For result much bigger than one: ; since exp16 only yields 16 significant bits, pow16 gives no more than this, hence for result much bigger ; than one get increasing error, eg for a around 64one & b=1.03125one get errors st answer (around 73one) ; is only correct to top 15 or 16 bits (ie error upto around one/1024 to one/256) ; ; For 0<=a<=one, & b eg 2one, 3one, 13.125one etc get error typically no more than in low 1 or 2 bits ; ; For a large (say a>one) & b<0 get error typically in only lowest bit or no error ; ; **** Strongly recommend this fn is only used where accuracy not crucial or with limited range **** ; **** of arguments where you can confirm yourself accuracy in that range is adequate. **** ; EXPORT pow16 pwnsta DCB "pow16", 0 ALIGN pwnend DCD &ff000000 + pwnend - pwnsta pow16 CMP a2, #0 MOVEQ a1, #&10000 ;if b=0 return one directly MOVEQS pc, lr CMP a2, #&10000 MOVEQS pc, lr ;handle trival case b=one directly, by returning a CMP a1, #0 MOVGT ip, #0 BGT pow16_apos BNE pow16_aneg CMP a2, #0 MOV a1, #0 ;if a=0 and b>0 return 0 MOVLT a1, #max16+1 ;if a=0 and b<0 return max16 SUBLT a1, a1, #1 MOVS pc, lr pow16_aneg MOVS ip, a2, LSL #16 MOVNE a1, #0 ;if a<0 and b not an integer return 0 MOVNES pc, lr AND ip, a2, #&10000 ;if a<0 then go on to evaluate (65536 * (-a/65536)^(b/65536)) RSB a1, a1, #0 ;with sign subsequently forced to + or - according to whether b/one pow16_apos ;is even or odd ( eg (-2.5)^3 is just (-1)^3 * 2.5^3 ) STMFD sp!, {v1, v2, lr} MOV v1, ip ;now evaluate (65536 * (a/65536)^(b/65536)), for a>0 MOV v2, a2 ;via exp16( ln16(a) * b / 65536 ) BL ln16 ;nb this uses property that exp(b.log(a)) = exp(log(a^b)) = a^b mul16 a1, v2, a1, a2, a3, a4 BL exp16 CMP v1, #0 RSBNE a1, a1, #0 ;finally switch sign on answer if originally a<0 and b/one was odd LDMFD sp!, {v1, v2, pc}^ ; ln16 ; a leaf APCS function ; ; C prototype: ; int ln16(int a) ; ; returns 65536 * ln (a/65536) ; ; is about 30 times faster than FPEmulator working with double floats ; EXPORT ln16 lnnsta DCB "ln16", 0 ALIGN lnnend DCD &ff000000 + lnnend - lnnsta ln16 CMP a1, #0 ;if a<=0 return min16 MOVLE a1, #min16 MOVLES pc, lr ;else most significant bit is between b30 & b0 GBLA counter counter SETA 30 ;find msb & store (msb_index - 15) in a4 WHILE counter > 1 TST a1, #1<<counter MOVNE a4, #counter-15 BNE ln16_gotmsb counter SETA counter-1 WEND TST a1, #1<<1 MOVNE a4, #1-15 MOVEQ a4, #0-15 ln16_gotmsb ;if we set z = a1/(2^a4), will have ln(a/one) = ln(z/one * 2^a4) CMP a4, #2 ; = ln(z/one) + a4*ln2 SUBGT a2, a4, #2 ;with z in range [0.5,1) MOVGT a1, a1, LSR a2 ;so calc a1 = 4*( a1/(2^a4) ) - 3*one RSBLE a2, a4, #2 ;which puts a1 in range �one suitable for approximation by poly MOVLE a1, a1, LSL a2 ;leaving us to calculate a4*one*ln2 + one*ln((a1+3one)/4one) SUB a1, a1, #&30000 ADD a2, a1, a1, LSL #2 ;start polynomial approximation calculation on a1 RSB a2, a2, a1, LSL #10 MOV a2, a2, ASR #16 ;for details of how this works see comments against similar code SUB a2, a2, #&000e00 ;in exp16 function, directly below this function SUB a2, a2, #&000034 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&003200 ADD a2, a2, #&000031 MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&00e200 SUB a2, a2, #&0000f2 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&050000 ADD a2, a2, #&005500 ADD a2, a2, #&000065 MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&040000 SUB a2, a2, #&009a00 ;end of polynomial approximation calculation SUB a1, a2, #&000059 ;a1 now holds (2^20)*(approximated value) ADD ip, a4, a4, LSL #1 ADD a2, ip, a4, LSL #3 ;now add in the a4*one*ln2 term using an explicit binary expansion ADD a2, a4, a2, LSL #4 ;of approximately one*ln2 RSB a3, a4, a4, LSL #3 ADD a2, a3, a2, LSL #4 ;nb we actually add approx (2^20)*ln2, & then divide by 16 ADD a2, a4, a2, LSL #3 ;to reduce truncation error ADD a1, a1, a2, LSL #5 ADD a1, a1, ip, ASR #1 MOV a1, a1, ASR #4 MOVS pc, lr ; exp16 ; a leaf APCS function ; ; C prototype: ; int exp16(int a) ; ; returns 65536 * exp (a/65536) ; ; is about 45 times faster than FPEmulator working with double floats ; EXPORT exp16 epnsta DCB "exp16", 0 ALIGN epnend DCD &ff000000 + epnend - epnsta exp16 ;this fn returns a value with only about 17 significant binary ;digits - eg for 'a' small or negative, get near maximal accuracy ;but for 'a' large (upto around 10one) where exp has value CMP a1, #12*65536 ;~20000one can get error upto roughly 0.1one MOVGT a1, #max16+1 SUBGT a1, a1, #1 MOVGTS pc, lr CMP a1, #-12*65536 MOVLT a1, #0 MOVLTS pc, lr ;otherwise know |a| <= 12one RSB a2, a1, a1, LSL #3 ;now set a = a/ln2 using explicit mul by 2_1.01110001010101000111 ADD a3, a1, a1, LSL #2 ;nb only need 1st 20 digits given range on a ADD a3, a3, a3, LSL #4 ;nb2 this calc is approximate only, though will usually yield an ADD a1, a2, a1, LSL #4 ;answer correct to the stored 16 binary places (else error one/65536) ADD a1, a1, a3, ASR #10 ADD a1, a1, a2, ASR #16 ;thus exp(original a) = exp(new a * ln2) = 2^(new a), eval'd below: ADD a1, a1, #8 MOV a1, a1, ASR #4 ;calc a = a/ln2 complete MOV a4, a1, ASR #16 ;a4 now holds integer component of a BIC a1, a1, a4, LSL #16 ;a1 now holds fractional component in range [0,1)*one CMP a4, #15 ;do another check on a to ensure exp(a) is in range MOVGE a1, #max16+1 ;& if not return maximal or minimal value as appropriate SUBGE a1, a1, #1 MOVGE pc, lr CMP a4, #-16 MOVLT a1, #0 MOVLTS pc, lr ;else need to return value (one * 2^(a4 + a1/one)) MOV a1, a1, LSL #1 ; = (one * 2^(a1/one) * 2^a4) SUB a1, a1, #&10000 ;convert a1 to lie in [-1,-1), then apply poly approximation: RSB a2, a1, a1, LSL #3 ADD a2, a1, a2, LSL #6 MOV a2, a2, ASR #15 ;a2 = 0.0008561*(2^20)*(a1/one) ADD a2, a2, #&002800 ADD a2, a2, #&00007e ;a2 = 0.0008561*(2^20)*(a1/one) + 0.0098857*(2^20) MOV ip, a1 mul16c a2, ip, a2, a3 ;a2 = 0.0008561*(2^20)*(a1/one)^2 + 0.0098857*(2^20)*(a1/one) ADD a2, a2, #&015000 ADD a2, a2, #&000be0 ; etc MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&070000 ADD a2, a2, #&00d700 ADD a2, a2, #&00007e MOV ip, a1 mul16c a2, ip, a2, a3 ;until we have ADD a2, a2, #&160000 ;a2 = (2^20) ( 0.0008561(a1/one)^4 + 0.0098857(a1/one)^3 + ADD a2, a2, #&00a000 ; 0.0849301(a1/one)^2 + 0.4901106(a1/one) + ADD a2, a2, #&0000a7 ; 1.14142138(a1/one) ) MOV a1, a2, ASR #4 ;now divide by 16 removing most truncation error from above calcs, CMP a4, #0 ;leaving a2 = (2^16)*(approximated value) RSBLT a4, a4, #0 MOVLT a1, a1, ASR a4 ;finally carry out the (a2 = a2 * 2^a4) step MOVLTS pc, lr MOVS a1, a1, LSL a4 MOVMI a1, #max16+1 SUBMI a1, a1, #1 MOVS pc, lr ; cos16 ; a leaf APCS function ; ; C prototype: ; int cos16(int a) ; ; returns 65536 * cos ((a/65536)(pi/2)) ; ; is about 44 times faster than FPEmulator working with double floats ; EXPORT cos16 csnsta DCB "cos16", 0 ALIGN csnend DCD &ff000000 + csnend - csnsta cos16 EOR a4, a1, a1, LSL #1 ;since cos is periodic and cos((a/65536)(pi/2)) has period 4*one TST a4, #&20000 ;eval is simpler than for ln or exp: MOV a4, #0 ;we need only to truncate a to [0,4one) and then approx the function MOVNE a4, #1 ;via a poly TST a1, #&10000 MOV a1, a1, LSL #16 ;in fact further symmetries in cos over this range allow us to MOV a1, a1, LSR #16 ;actually only approximate function over range [0,one) RSBEQ a1, a1, #&10000 ;and reconstruct it over remainder of range [one,4one) from that part MOV a1, a1, LSL #1 ;eg cos( (a/65536)(pi/2) ) for a in [2one, 3one) SUB a1, a1, #&10000 ; = -cos( ((a-2one)/65536)(pi/2) ) RSB a2, a1, a1, LSL #3 ADD a2, a1, a2, LSL #8 MOV a2, a2, ASR #16 ADD a2, a2, #&002c00 ADD a2, a2, #&000086 MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&00e900 SUB a2, a2, #&0000bd MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&030000 SUB a2, a2, #&007c00 SUB a2, a2, #&0000c6 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&080000 ADD a2, a2, #&00E200 ADD a2, a2, #&0000BD MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&0b0000 ADD a2, a2, #&005000 ADD a2, a2, #&000050 MOV a1, a2, ASR #4 TST a4, #1 RSBNE a1, a1, #0 MOVS pc, lr ; sin16 ; a leaf APCS function ; ; C prototype: ; int sin16(int a) ; ; returns 65536 * sin ((a/65536)(pi/2)) ; ; is about 44 times faster than FPEmulator working with double floats ; EXPORT sin16 snnsta DCB "sin16", 0 ALIGN snnend DCD &ff000000 + snnend - snnsta sin16 TST a1, #&20000 ;eval of sin is almost identical to that of cos MOV a4, #0 MOVNE a4, #1 TST a1, #&10000 MOV a1, a1, LSL #16 MOV a1, a1, LSR #16 RSBNE a1, a1, #&10000 MOV a1, a1, LSL #1 SUB a1, a1, #&10000 RSB a2, a1, a1, LSL #3 ADD a2, a1, a2, LSL #8 MOV a2, a2, ASR #16 ADD a2, a2, #&002c00 ADD a2, a2, #&000086 MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&00e900 SUB a2, a2, #&0000bd MOV ip, a1 mul16c a2, ip, a2, a3 SUB a2, a2, #&030000 SUB a2, a2, #&007c00 SUB a2, a2, #&0000c6 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&080000 ADD a2, a2, #&00E200 ADD a2, a2, #&0000BD MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&0b0000 ADD a2, a2, #&005000 ADD a2, a2, #&000050 MOV a1, a2, ASR #4 TST a4, #1 RSBNE a1, a1, #0 MOVS pc, lr ; acs16 ; a leaf APCS function ; ; C prototype: ; int acs16(int a) ; ; returns 65536 * 2/pi * arccos (a/65536) ; ; for a out of range (ie abs a > 65536), reset a to �65536 as appropriate before eval ; ; is about 24 times faster than FPEmulator working with double floats ; EXPORT acs16 acnsta DCB "acs16", 0 ALIGN acnend DCD &ff000000 + acnend - acnsta acs16 CMP a1, #65536 MOVGE a1, #0 MOVGES pc, lr CMP a1, #-65536 MOVLE a1, #2*65536 MOVLES pc, lr STMFD sp!, {lr} ;now have arg in range (-one,one) CMP a1, #0 RSBMI a1, a1, #0 MOVMI a4, #1 ;b0 in a4 set iff final result r needs replacing by 2*one-r MOVPL a4, #0 ;now have arg in range [0,one) SUB a2, a1, #&b500 SUBS a2, a2, #&0005 BLT acs16_arglow ;if arg < one/sqrt2 go and apply poly else first transmute into here ORR a4, a4, #2 ;b1 in a4 clear iff penultimate result r need be replaced by one-r MUL a2, a1, a1 MOV a1, a2, LSR #16 RSB a1, a1, #65536 sqrt16 a1, a1, a2, a3, ip, lr ;arg transmuted (ie replaced by one-sqrt(arg^2)) acs16_arglow ADD a3, a1, a1, ASL #2 ADD a2, a3, a1, ASL #4 ADD a2, a2, a3, ASL #5 ADD a2, a2, a3, ASR #8 ADD a2, a2, #32 MOV a1, a2, ASR #6 ;range transform applied (ie replaced by arg*2sqrt2-one) SUB a1, a1, #&10000 ;so arg lies in range [-1,1] ADD a2, a1, a1, LSL #2 ;now apply poly ADD a2, a2, a2, LSL #5 MOV a2, a2, ASR #14 ADD a2, a2, #&000500 ADD a2, a2, #&0000ae MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&000800 ADD a2, a2, #&000088 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&002000 ADD a2, a2, #&00009a MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&004600 ADD a2, a2, #&00009a MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&030000 ADD a2, a2, #&00d900 ADD a2, a2, #&0000b4 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&030000 ADD a2, a2, #&00ae00 ADD a2, a2, #&000052 MOV a1, a2, ASR #4 TST a4, #2 RSBEQ a1, a1, #65536 TST a4, #1 RSBNE a1, a1, #2*65536 LDMFD sp!, {pc}^ ; asn16 ; a leaf APCS function ; ; C prototype: ; int asn16(int a) ; ; returns 65536 * 2/pi * arcsin (a/65536) ; ; for a out of range (ie abs a > 65536), reset a to �65536 as appropriate before eval ; ; is about 24 times faster than FPEmulator working with double floats ; EXPORT asn16 asnsta DCB "asn16", 0 ALIGN asnend DCD &ff000000 + asnend - asnsta asn16 CMP a1, #65536 MOVGE a1, #65536 MOVGES pc, lr ADDS a2, a1, #65536 ;equiv to CMP a1,#-65536 SUBLE a1, a1, a2 ;equiv to MOVLE a1,#-65536 (which wouldn't work due to bad constant) MOVLES pc, lr STMFD sp!, {lr} ;now have arg in range (-one,one) CMP a1, #0 RSBMI a1, a1, #0 MOVMI a4, #1 ;b0 in a4 set iff final result needs negating MOVPL a4, #0 ;now have arg in range [0,one) SUB a2, a1, #&b500 SUBS a2, a2, #&0005 BLT asn16_arglow ;if arg < one/sqrt2 go and apply poly else first transmute into here ORR a4, a4, #2 ;b1 in a4 set iff penultimate result r needs to be replaced by one-r MUL a2, a1, a1 MOV a1, a2, LSR #16 RSB a1, a1, #65536 sqrt16 a1, a1, a2, a3, ip, lr ;arg transmuted (ie replaced by one-sqrt(arg^2)) asn16_arglow ADD a3, a1, a1, ASL #2 ADD a2, a3, a1, ASL #4 ADD a2, a2, a3, ASL #5 ADD a2, a2, a3, ASR #8 ADD a2, a2, #32 MOV a1, a2, ASR #6 ;range transform applied (ie replaced by arg*2sqrt2-one) SUB a1, a1, #&10000 ;so arg lies in range [-1,1] ADD a2, a1, a1, LSL #2 ;now apply poly ADD a2, a2, a2, LSL #5 MOV a2, a2, ASR #14 ADD a2, a2, #&000500 ADD a2, a2, #&0000ae MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&000800 ADD a2, a2, #&000088 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&002000 ADD a2, a2, #&00009a MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&004600 ADD a2, a2, #&00009a MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&030000 ADD a2, a2, #&00d900 ADD a2, a2, #&0000b4 MOV ip, a1 mul16c a2, ip, a2, a3 ADD a2, a2, #&030000 ADD a2, a2, #&00ae00 ADD a2, a2, #&000052 MOV a1, a2, ASR #4 TST a4, #2 RSBNE a1, a1, #65536 TST a4, #1 RSBNE a1, a1, #0 LDMFD sp!, {pc}^ ; gauss16 ; a leaf APCS function ; ; C prototype: ; int gauss16(void) ; ; returns 65536 * ( pseudo randon variable with approximate distribution N(0,1) ) ; note, the approximate gaussian distribution is achieved via the sum of n pseudo U[0,65535] ; random variables & application of the central limit theorem ; here we use n=8, giving an actual range of �(sqrt24) (*65536). ; ; for general n, recall we need to return: ; (sum n U[0,65535] random variables) * 2sqrt(3n)*65536/(65535n) - sqrt(3n)*65536 ; EXPORT gauss16 gansta DCB "gauss16", 0 ALIGN ganend DCD &ff000000 + ganend - gansta gauss16 ADR a1, gaussseed1 LDMIA a1, {a2, a3} MOVS a3, a3, LSR #1 MOVS a4, a2, RRX ADC a3, a3, a3 EOR a4, a4, a2, LSL #12 EOR a2, a4, a4, LSR #20 MOV ip, a2, LSR #16 MOV a4, a2, LSL #16 ADD ip, ip, a4, LSR #16 MOVS a3, a3, LSR #1 MOVS a4, a2, RRX ADC a3, a3, a3 EOR a4, a4, a2, LSL #12 EOR a2, a4, a4, LSR #20 ADD ip, ip, a2, LSR #16 MOV a4, a2, LSL #16 ADD ip, ip, a4, LSR #16 MOVS a3, a3, LSR #1 MOVS a4, a2, RRX ADC a3, a3, a3 EOR a4, a4, a2, LSL #12 EOR a2, a4, a4, LSR #20 ADD ip, ip, a2, LSR #16 MOV a4, a2, LSL #16 ADD ip, ip, a4, LSR #16 MOVS a3, a3, LSR #1 MOVS a4, a2, RRX ADC a3, a3, a3 EOR a4, a4, a2, LSL #12 EOR a2, a4, a4, LSR #20 ADD ip, ip, a2, LSR #16 MOV a4, a2, LSL #16 ADD ip, ip, a4, LSR #16 ;sum now in ip STMIA a1, {a2, a3} RSB a1, ip, ip, ASL #3 RSB a2, ip, ip, ASL #2 ADD a1, a2, a1, ASL #4 ADD a1, a1, ip, ASL #9 ADD a2, ip, ip, ASL #4 ADD a2, a2, ip, ASL #6 ADD a1, a1, a2, LSR #10 MOV a1, a1, LSR #9 SUB a1, a1, #&4E000 SUB a1, a1, #&00620 SUB a1, a1, #&00004 MOVS pc, lr gaussseed1 DCD -1 ;bits b0-b31 of seed DCD -1 ;bit b32 of seed (in lsb of word) ; sgauss16 ; a leaf APCS function ; ; C prototype: ; void sgauss16(int seed) ; ; sets the seed for gauss16 ; EXPORT sgauss16 sgnsta DCB "sgauss16", 0 ALIGN sgnend DCD &ff000000 + sgnend - sgnsta sgauss16 ADR a2, gaussseed1 MOV a3, #1 STMIA a2, {a1, a3} MOVS pc, lr ; div_frac16 ; a leaf APCS function ; ; C prototype: ; int div_frac16(int number, int divisor) ; ; returns integer part of 65536*number/divisor ; assumes abs number < 65536 * abs divisor ; if this needs checking, must be done by caller ; EXPORT div_frac16 dfnsta DCB "div_frac16", 0 ALIGN dfnend DCD &ff000000 + dfnend - dfnsta div_frac16 div16 a1, a2, a1, a3, a4 MOVS pc, lr ; mul_frac16 ; a leaf APCS function ; ; C prototype: ; int mul_frac16(int x, int a) ; ; returns 32-bit signed integer x*a/65536 ; assumes result fits into 32-bit signed representation ; note, no other restrictions on a - if can guarantee abs a < 65536, use mul_frac16c instead as is quicker ; EXPORT mul_frac16 mfnsta DCB "mul_frac16", 0 ALIGN mfnend DCD &ff000000 + mfnend - mfnsta mul_frac16 mul16 a1, a2, a1, a3, a4, ip MOVS pc, lr ; mul_frac16c ; a leaf APCS function ; ; C prototype: ; int mul_frac16c(int x, int a) ; ; returns 32-bit signed integer x*a/65536 ; assumes abs a <=65536 ; if it is possible that abs a > 65536, caller must check range & either not call fn or round down to 65536 ; EXPORT mul_frac16c mfcnsta DCB "mul_frac16c", 0 ALIGN mfcnend DCD &ff000000 + mfcnend - mfcnsta mul_frac16c mul16c a1, a2, a1, a3 MOVS pc, lr ; sqrt_frac16 ; a leaf APCS function ; ; C prototype: ; int sqrt_frac16(unsigned int x) ; ; returns 32-bit integer sqrt(x<<16) ; EXPORT sqrt_frac16 sqfnsta DCB "sqrt_frac16", 0 ALIGN sqfnend DCD &ff000000 + sqfnend - sqfnsta sqrt_frac16 sqrt16 a1, a1, a2, a3, a4, ip MOVS pc, lr END
00000000 0a 6d 61 78 31 36 09 2a 09 26 37 66 66 66 66 66 |.max16.*.&7fffff| 00000010 66 66 09 3b 6d 61 78 20 70 6f 73 69 74 69 76 65 |ff.;max positive| 00000020 20 6e 75 6d 62 65 72 20 69 6e 20 31 36 20 62 69 | number in 16 bi| 00000030 74 20 66 69 78 65 64 20 70 6f 69 6e 74 20 66 6f |t fixed point fo| 00000040 72 6d 61 74 20 28 32 5e 33 31 2d 31 29 2f 36 35 |rmat (2^31-1)/65| 00000050 35 33 36 0a 6d 69 6e 31 36 09 2a 09 26 38 30 30 |536.min16.*.&800| 00000060 30 30 30 30 30 09 3b 6d 69 6e 20 6e 65 67 61 74 |00000.;min negat| 00000070 69 76 65 20 6e 75 6d 62 65 72 09 09 09 09 20 20 |ive number.... | 00000080 2d 32 5e 33 31 20 20 20 2f 36 35 35 33 36 0a 6f |-2^31 /65536.o| 00000090 6e 65 09 2a 09 36 35 35 33 36 0a 0a 0a 0a 3b 20 |ne.*.65536....; | 000000a0 72 62 62 63 69 6e 63 0a 3b 20 61 20 6c 65 61 66 |rbbcinc.; a leaf| 000000b0 20 41 50 43 53 20 66 75 6e 63 74 69 6f 6e 0a 3b | APCS function.;| 000000c0 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a |.; C prototype:.| 000000d0 3b 20 69 6e 74 20 72 62 62 63 69 6e 63 28 69 6e |; int rbbcinc(in| 000000e0 74 20 72 2c 20 69 6e 74 20 6b 29 0a 3b 0a 3b 20 |t r, int k).;.; | 000000f0 67 69 76 65 6e 20 6c 69 6d 69 74 73 20 30 20 3c |given limits 0 <| 00000100 3d 20 72 20 3c 20 32 5e 6b 2c 20 72 65 74 75 72 |= r < 2^k, retur| 00000110 6e 20 28 72 20 a4 20 31 29 20 77 68 65 72 65 20 |n (r . 1) where | 00000120 a4 20 64 65 6e 6f 74 65 73 20 61 20 72 65 76 65 |. denotes a reve| 00000130 72 73 65 64 20 62 69 74 20 6f 72 64 65 72 69 6e |rsed bit orderin| 00000140 67 20 69 6e 63 72 65 6d 65 6e 74 2c 0a 3b 20 73 |g increment,.; s| 00000150 75 62 6a 65 63 74 20 74 6f 20 74 68 65 20 73 74 |ubject to the st| 00000160 61 74 65 64 20 6c 69 6d 69 74 73 2e 0a 3b 20 4e |ated limits..; N| 00000170 42 20 69 6e 20 74 68 69 73 20 63 61 73 65 2c 20 |B in this case, | 00000180 66 6f 72 20 74 68 65 20 66 75 6e 63 74 69 6f 6e |for the function| 00000190 20 66 3a 20 6e 20 2d 3e 20 7b 66 6f 72 20 28 6b | f: n -> {for (k| 000001a0 3d 63 3d 30 3b 20 63 3c 6e 3b 20 63 2b 2b 2c 20 |=c=0; c<n; c++, | 000001b0 6b 3d 72 62 62 63 69 6e 63 28 6b 2c 20 6c 29 3b |k=rbbcinc(k, l);| 000001c0 20 72 65 74 75 72 6e 20 6b 3b 7d 2c 0a 3b 20 77 | return k;},.; w| 000001d0 65 20 68 61 76 65 20 66 28 66 28 6e 29 29 3d 6e |e have f(f(n))=n| 000001e0 2e 0a 3b 20 4e 42 32 20 61 6c 67 6f 20 72 65 71 |..; NB2 algo req| 000001f0 75 69 72 65 73 20 32 20 3c 3d 20 6b 20 3c 3d 20 |uires 2 <= k <= | 00000200 33 32 2c 20 62 75 74 20 64 6f 65 73 6e 27 74 20 |32, but doesn't | 00000210 63 68 65 63 6b 20 66 6f 72 20 74 68 69 73 20 2d |check for this -| 00000220 20 42 45 57 41 52 45 21 0a 3b 20 28 66 6f 72 20 | BEWARE!.; (for | 00000230 6b 3d 31 20 67 65 74 20 6e 6f 20 61 63 74 69 6f |k=1 get no actio| 00000240 6e 20 74 61 6b 65 6e 2c 20 77 68 69 6c 65 20 66 |n taken, while f| 00000250 6f 72 20 61 6e 79 20 6f 74 68 65 72 20 62 61 64 |or any other bad| 00000260 20 6b 20 67 65 74 20 63 6f 64 65 20 65 78 65 63 | k get code exec| 00000270 75 74 65 64 20 61 74 20 75 6e 69 6e 74 65 6e 64 |uted at unintend| 00000280 65 64 20 61 64 64 72 65 73 73 2c 0a 3b 20 20 68 |ed address,.; h| 00000290 65 6e 63 65 20 75 6e 70 72 65 64 69 63 74 61 62 |ence unpredictab| 000002a0 6c 65 20 26 20 6c 69 6b 65 6c 79 20 73 79 73 74 |le & likely syst| 000002b0 65 6d 20 66 61 74 61 6c 29 2e 0a 3b 0a 0a 20 20 |em fatal)..;.. | 000002c0 20 20 20 20 20 20 45 58 50 4f 52 54 20 20 72 62 | EXPORT rb| 000002d0 62 63 69 6e 63 0a 0a 72 62 6e 73 74 61 20 20 44 |bcinc..rbnsta D| 000002e0 43 42 20 20 20 20 20 22 72 62 62 63 69 6e 63 22 |CB "rbbcinc"| 000002f0 2c 20 30 0a 20 20 20 20 20 20 20 20 41 4c 49 47 |, 0. ALIG| 00000300 4e 0a 72 62 6e 65 6e 64 20 20 44 43 44 20 20 20 |N.rbnend DCD | 00000310 20 20 26 66 66 30 30 30 30 30 30 20 2b 20 72 62 | &ff000000 + rb| 00000320 6e 65 6e 64 20 2d 20 72 62 6e 73 74 61 0a 0a 72 |nend - rbnsta..r| 00000330 62 62 63 69 6e 63 0a 0a 20 20 20 20 20 20 20 20 |bbcinc.. | 00000340 72 62 62 63 20 20 20 20 61 31 2c 20 61 32 2c 20 |rbbc a1, a2, | 00000350 61 33 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 20 |a3. MOVS | 00000360 20 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 3b 20 70 | pc, lr....; p| 00000370 6f 77 31 36 0a 3b 20 61 20 6c 65 61 66 20 41 50 |ow16.; a leaf AP| 00000380 43 53 20 66 75 6e 63 74 69 6f 6e 0a 3b 0a 3b 20 |CS function.;.; | 00000390 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a 3b 20 69 |C prototype:.; i| 000003a0 6e 74 20 70 6f 77 31 36 28 69 6e 74 20 61 2c 20 |nt pow16(int a, | 000003b0 69 6e 74 20 62 29 0a 3b 0a 3b 20 72 65 74 75 72 |int b).;.; retur| 000003c0 6e 73 20 36 35 35 33 36 20 2a 20 28 61 2f 36 35 |ns 65536 * (a/65| 000003d0 35 33 36 29 5e 28 62 2f 36 35 35 33 36 29 0a 3b |536)^(b/65536).;| 000003e0 0a 3b 20 69 73 20 61 62 6f 75 74 20 35 20 74 6f |.; is about 5 to| 000003f0 20 34 30 20 74 69 6d 65 73 20 66 61 73 74 65 72 | 40 times faster| 00000400 20 74 68 61 6e 20 46 50 45 6d 75 6c 61 74 6f 72 | than FPEmulator| 00000410 20 77 6f 72 6b 69 6e 67 20 77 69 74 68 20 64 6f | working with do| 00000420 75 62 6c 65 20 66 6c 6f 61 74 73 0a 3b 0a 3b 20 |uble floats.;.; | 00000430 6e 62 20 69 66 20 61 3c 30 20 72 65 71 75 69 72 |nb if a<0 requir| 00000440 65 20 62 20 61 6e 20 69 6e 74 65 67 65 72 0a 3b |e b an integer.;| 00000450 0a 3b 20 6e 62 32 20 75 6e 65 78 70 65 63 74 65 |.; nb2 unexpecte| 00000460 64 20 72 65 74 75 72 6e 20 76 61 6c 75 65 73 3a |d return values:| 00000470 0a 3b 20 61 3d 62 3d 30 09 09 09 09 72 65 74 75 |.; a=b=0....retu| 00000480 72 6e 73 20 31 09 61 63 74 75 61 6c 20 76 61 6c |rns 1.actual val| 00000490 75 65 20 69 6c 6c 20 64 65 66 69 6e 65 64 0a 3b |ue ill defined.;| 000004a0 20 61 3c 30 2c 20 62 20 6e 6f 6e 20 69 6e 74 65 | a<0, b non inte| 000004b0 67 65 72 09 09 72 65 74 75 72 6e 73 20 30 09 61 |ger..returns 0.a| 000004c0 63 74 75 61 6c 20 76 61 6c 75 65 20 63 6f 6d 70 |ctual value comp| 000004d0 6c 65 78 0a 3b 20 61 62 73 28 62 6c 6e 28 61 29 |lex.; abs(bln(a)| 000004e0 29 20 3e 20 6d 61 78 31 36 09 09 75 6e 6b 6e 6f |) > max16..unkno| 000004f0 77 6e 20 65 72 72 6f 72 73 20 6c 69 6b 65 6c 79 |wn errors likely| 00000500 20 28 74 6f 20 61 76 6f 69 64 2c 20 72 65 73 74 | (to avoid, rest| 00000510 72 69 63 74 20 62 20 74 6f 20 b1 28 32 5e 31 31 |rict b to .(2^11| 00000520 29 6f 6e 65 2c 20 72 6f 75 67 68 6c 79 29 0a 3b |)one, roughly).;| 00000530 20 61 3d 30 2c 20 62 3c 30 09 09 09 72 65 74 75 | a=0, b<0...retu| 00000540 72 6e 73 20 6d 61 78 31 36 09 61 63 74 75 61 6c |rns max16.actual| 00000550 20 76 61 6c 75 65 20 2b 69 6e 66 69 6e 69 74 79 | value +infinity| 00000560 0a 3b 20 61 20 26 20 62 20 73 74 20 72 65 73 75 |.; a & b st resu| 00000570 6c 74 20 6f 75 74 20 6f 66 20 72 61 6e 67 65 09 |lt out of range.| 00000580 75 6e 6b 6e 6f 77 6e 20 72 65 73 75 6c 74 0a 3b |unknown result.;| 00000590 0a 3b 20 6e 62 20 70 72 65 63 69 73 65 20 6e 61 |.; nb precise na| 000005a0 74 75 72 65 20 6f 66 20 65 72 72 6f 72 73 20 66 |ture of errors f| 000005b0 6f 72 20 6f 74 68 65 72 20 76 61 6c 75 65 73 20 |or other values | 000005c0 6e 6f 74 20 79 65 74 20 63 6f 6e 66 69 72 6d 65 |not yet confirme| 000005d0 64 20 61 63 63 65 70 74 61 62 6c 65 2c 20 74 68 |d acceptable, th| 000005e0 6f 75 67 68 20 73 68 6f 75 6c 64 20 62 65 20 6f |ough should be o| 000005f0 6b 61 79 20 65 78 63 65 70 74 0a 3b 20 70 65 72 |kay except.; per| 00000600 68 61 70 73 20 69 6e 20 65 78 74 72 65 6d 65 20 |haps in extreme | 00000610 63 61 73 65 73 20 28 61 73 20 6f 66 20 32 32 2f |cases (as of 22/| 00000620 31 31 2f 39 35 29 0a 3b 0a 3b 20 46 65 77 20 73 |11/95).;.; Few s| 00000630 75 62 73 65 71 75 65 6e 74 20 6e 6f 74 65 73 20 |ubsequent notes | 00000640 6f 6e 20 65 72 72 6f 72 3a 0a 3b 0a 3b 20 46 6f |on error:.;.; Fo| 00000650 72 20 72 65 73 75 6c 74 20 6d 75 63 68 20 62 69 |r result much bi| 00000660 67 67 65 72 20 74 68 61 6e 20 6f 6e 65 3a 0a 3b |gger than one:.;| 00000670 20 73 69 6e 63 65 20 65 78 70 31 36 20 6f 6e 6c | since exp16 onl| 00000680 79 20 79 69 65 6c 64 73 20 31 36 20 73 69 67 6e |y yields 16 sign| 00000690 69 66 69 63 61 6e 74 20 62 69 74 73 2c 20 70 6f |ificant bits, po| 000006a0 77 31 36 20 67 69 76 65 73 20 6e 6f 20 6d 6f 72 |w16 gives no mor| 000006b0 65 20 74 68 61 6e 20 74 68 69 73 2c 20 68 65 6e |e than this, hen| 000006c0 63 65 20 66 6f 72 20 72 65 73 75 6c 74 20 6d 75 |ce for result mu| 000006d0 63 68 20 62 69 67 67 65 72 0a 3b 20 74 68 61 6e |ch bigger.; than| 000006e0 20 6f 6e 65 20 67 65 74 20 69 6e 63 72 65 61 73 | one get increas| 000006f0 69 6e 67 20 65 72 72 6f 72 2c 20 65 67 20 66 6f |ing error, eg fo| 00000700 72 20 61 20 61 72 6f 75 6e 64 20 36 34 6f 6e 65 |r a around 64one| 00000710 20 26 20 62 3d 31 2e 30 33 31 32 35 6f 6e 65 20 | & b=1.03125one | 00000720 67 65 74 20 65 72 72 6f 72 73 20 73 74 20 61 6e |get errors st an| 00000730 73 77 65 72 20 28 61 72 6f 75 6e 64 20 37 33 6f |swer (around 73o| 00000740 6e 65 29 0a 3b 20 69 73 20 6f 6e 6c 79 20 63 6f |ne).; is only co| 00000750 72 72 65 63 74 20 74 6f 20 74 6f 70 20 31 35 20 |rrect to top 15 | 00000760 6f 72 20 31 36 20 62 69 74 73 20 28 69 65 20 65 |or 16 bits (ie e| 00000770 72 72 6f 72 20 75 70 74 6f 20 61 72 6f 75 6e 64 |rror upto around| 00000780 20 6f 6e 65 2f 31 30 32 34 20 74 6f 20 6f 6e 65 | one/1024 to one| 00000790 2f 32 35 36 29 0a 3b 0a 3b 20 46 6f 72 20 30 3c |/256).;.; For 0<| 000007a0 3d 61 3c 3d 6f 6e 65 2c 20 26 20 62 20 65 67 20 |=a<=one, & b eg | 000007b0 32 6f 6e 65 2c 20 33 6f 6e 65 2c 20 31 33 2e 31 |2one, 3one, 13.1| 000007c0 32 35 6f 6e 65 20 65 74 63 20 67 65 74 20 65 72 |25one etc get er| 000007d0 72 6f 72 20 74 79 70 69 63 61 6c 6c 79 20 6e 6f |ror typically no| 000007e0 20 6d 6f 72 65 20 74 68 61 6e 20 69 6e 20 6c 6f | more than in lo| 000007f0 77 20 31 20 6f 72 20 32 20 62 69 74 73 0a 3b 0a |w 1 or 2 bits.;.| 00000800 3b 20 46 6f 72 20 61 20 6c 61 72 67 65 20 28 73 |; For a large (s| 00000810 61 79 20 61 3e 6f 6e 65 29 20 26 20 62 3c 30 20 |ay a>one) & b<0 | 00000820 67 65 74 20 65 72 72 6f 72 20 74 79 70 69 63 61 |get error typica| 00000830 6c 6c 79 20 69 6e 20 6f 6e 6c 79 20 6c 6f 77 65 |lly in only lowe| 00000840 73 74 20 62 69 74 20 6f 72 20 6e 6f 20 65 72 72 |st bit or no err| 00000850 6f 72 0a 3b 0a 3b 20 20 20 2a 2a 2a 2a 20 20 53 |or.;.; **** S| 00000860 74 72 6f 6e 67 6c 79 20 72 65 63 6f 6d 6d 65 6e |trongly recommen| 00000870 64 20 74 68 69 73 20 66 6e 20 69 73 20 6f 6e 6c |d this fn is onl| 00000880 79 20 75 73 65 64 20 77 68 65 72 65 20 61 63 63 |y used where acc| 00000890 75 72 61 63 79 20 6e 6f 74 20 63 72 75 63 69 61 |uracy not crucia| 000008a0 6c 20 6f 72 20 77 69 74 68 20 6c 69 6d 69 74 65 |l or with limite| 000008b0 64 20 72 61 6e 67 65 20 2a 2a 2a 2a 0a 3b 20 20 |d range ****.; | 000008c0 20 2a 2a 2a 2a 20 20 6f 66 20 61 72 67 75 6d 65 | **** of argume| 000008d0 6e 74 73 20 77 68 65 72 65 20 79 6f 75 20 63 61 |nts where you ca| 000008e0 6e 20 63 6f 6e 66 69 72 6d 20 79 6f 75 72 73 65 |n confirm yourse| 000008f0 6c 66 20 61 63 63 75 72 61 63 79 20 69 6e 20 74 |lf accuracy in t| 00000900 68 61 74 20 72 61 6e 67 65 20 69 73 20 61 64 65 |hat range is ade| 00000910 71 75 61 74 65 2e 20 20 20 20 20 20 20 20 20 20 |quate. | 00000920 2a 2a 2a 2a 0a 3b 0a 0a 20 20 20 20 20 20 20 20 |****.;.. | 00000930 45 58 50 4f 52 54 20 20 70 6f 77 31 36 0a 0a 70 |EXPORT pow16..p| 00000940 77 6e 73 74 61 20 20 44 43 42 20 20 20 20 20 22 |wnsta DCB "| 00000950 70 6f 77 31 36 22 2c 20 30 0a 20 20 20 20 20 20 |pow16", 0. | 00000960 20 20 41 4c 49 47 4e 0a 70 77 6e 65 6e 64 20 20 | ALIGN.pwnend | 00000970 44 43 44 20 20 20 20 20 26 66 66 30 30 30 30 30 |DCD &ff00000| 00000980 30 20 2b 20 70 77 6e 65 6e 64 20 2d 20 70 77 6e |0 + pwnend - pwn| 00000990 73 74 61 0a 0a 70 6f 77 31 36 0a 0a 09 43 4d 50 |sta..pow16...CMP| 000009a0 09 61 32 2c 20 23 30 0a 09 4d 4f 56 45 51 09 61 |.a2, #0..MOVEQ.a| 000009b0 31 2c 20 23 26 31 30 30 30 30 09 09 3b 69 66 20 |1, #&10000..;if | 000009c0 62 3d 30 20 72 65 74 75 72 6e 20 6f 6e 65 20 64 |b=0 return one d| 000009d0 69 72 65 63 74 6c 79 0a 09 4d 4f 56 45 51 53 09 |irectly..MOVEQS.| 000009e0 70 63 2c 20 6c 72 0a 09 43 4d 50 09 61 32 2c 20 |pc, lr..CMP.a2, | 000009f0 23 26 31 30 30 30 30 0a 09 4d 4f 56 45 51 53 09 |#&10000..MOVEQS.| 00000a00 70 63 2c 20 6c 72 09 09 09 3b 68 61 6e 64 6c 65 |pc, lr...;handle| 00000a10 20 74 72 69 76 61 6c 20 63 61 73 65 20 62 3d 6f | trival case b=o| 00000a20 6e 65 20 64 69 72 65 63 74 6c 79 2c 20 62 79 20 |ne directly, by | 00000a30 72 65 74 75 72 6e 69 6e 67 20 61 0a 09 43 4d 50 |returning a..CMP| 00000a40 09 61 31 2c 20 23 30 0a 09 4d 4f 56 47 54 09 69 |.a1, #0..MOVGT.i| 00000a50 70 2c 20 23 30 0a 09 42 47 54 09 70 6f 77 31 36 |p, #0..BGT.pow16| 00000a60 5f 61 70 6f 73 0a 09 42 4e 45 09 70 6f 77 31 36 |_apos..BNE.pow16| 00000a70 5f 61 6e 65 67 0a 09 43 4d 50 09 61 32 2c 20 23 |_aneg..CMP.a2, #| 00000a80 30 0a 09 4d 4f 56 09 61 31 2c 20 23 30 09 09 09 |0..MOV.a1, #0...| 00000a90 3b 69 66 20 61 3d 30 20 61 6e 64 20 62 3e 30 20 |;if a=0 and b>0 | 00000aa0 72 65 74 75 72 6e 20 30 0a 09 4d 4f 56 4c 54 09 |return 0..MOVLT.| 00000ab0 61 31 2c 20 23 6d 61 78 31 36 2b 31 09 09 3b 69 |a1, #max16+1..;i| 00000ac0 66 20 61 3d 30 20 61 6e 64 20 62 3c 30 20 72 65 |f a=0 and b<0 re| 00000ad0 74 75 72 6e 20 6d 61 78 31 36 0a 09 53 55 42 4c |turn max16..SUBL| 00000ae0 54 09 61 31 2c 20 61 31 2c 20 23 31 0a 09 4d 4f |T.a1, a1, #1..MO| 00000af0 56 53 09 70 63 2c 20 6c 72 0a 70 6f 77 31 36 5f |VS.pc, lr.pow16_| 00000b00 61 6e 65 67 0a 09 4d 4f 56 53 09 69 70 2c 20 61 |aneg..MOVS.ip, a| 00000b10 32 2c 20 4c 53 4c 20 23 31 36 0a 09 4d 4f 56 4e |2, LSL #16..MOVN| 00000b20 45 09 61 31 2c 20 23 30 09 09 09 3b 69 66 20 61 |E.a1, #0...;if a| 00000b30 3c 30 20 61 6e 64 20 62 20 6e 6f 74 20 61 6e 20 |<0 and b not an | 00000b40 69 6e 74 65 67 65 72 20 72 65 74 75 72 6e 20 30 |integer return 0| 00000b50 0a 09 4d 4f 56 4e 45 53 09 70 63 2c 20 6c 72 0a |..MOVNES.pc, lr.| 00000b60 09 41 4e 44 09 69 70 2c 20 61 32 2c 20 23 26 31 |.AND.ip, a2, #&1| 00000b70 30 30 30 30 09 09 3b 69 66 20 61 3c 30 20 74 68 |0000..;if a<0 th| 00000b80 65 6e 20 67 6f 20 6f 6e 20 74 6f 20 65 76 61 6c |en go on to eval| 00000b90 75 61 74 65 20 28 36 35 35 33 36 20 2a 20 28 2d |uate (65536 * (-| 00000ba0 61 2f 36 35 35 33 36 29 5e 28 62 2f 36 35 35 33 |a/65536)^(b/6553| 00000bb0 36 29 29 0a 09 52 53 42 09 61 31 2c 20 61 31 2c |6))..RSB.a1, a1,| 00000bc0 20 23 30 09 09 3b 77 69 74 68 20 73 69 67 6e 20 | #0..;with sign | 00000bd0 73 75 62 73 65 71 75 65 6e 74 6c 79 20 66 6f 72 |subsequently for| 00000be0 63 65 64 20 74 6f 20 2b 20 6f 72 20 2d 20 61 63 |ced to + or - ac| 00000bf0 63 6f 72 64 69 6e 67 20 74 6f 20 77 68 65 74 68 |cording to wheth| 00000c00 65 72 20 62 2f 6f 6e 65 0a 70 6f 77 31 36 5f 61 |er b/one.pow16_a| 00000c10 70 6f 73 09 09 09 09 3b 69 73 20 65 76 65 6e 20 |pos....;is even | 00000c20 6f 72 20 6f 64 64 20 28 20 65 67 20 28 2d 32 2e |or odd ( eg (-2.| 00000c30 35 29 5e 33 20 69 73 20 6a 75 73 74 20 28 2d 31 |5)^3 is just (-1| 00000c40 29 5e 33 20 2a 20 32 2e 35 5e 33 20 29 0a 09 53 |)^3 * 2.5^3 )..S| 00000c50 54 4d 46 44 09 73 70 21 2c 20 7b 76 31 2c 20 76 |TMFD.sp!, {v1, v| 00000c60 32 2c 20 6c 72 7d 0a 09 4d 4f 56 09 76 31 2c 20 |2, lr}..MOV.v1, | 00000c70 69 70 09 09 09 3b 6e 6f 77 20 65 76 61 6c 75 61 |ip...;now evalua| 00000c80 74 65 20 28 36 35 35 33 36 20 2a 20 28 61 2f 36 |te (65536 * (a/6| 00000c90 35 35 33 36 29 5e 28 62 2f 36 35 35 33 36 29 29 |5536)^(b/65536))| 00000ca0 2c 20 66 6f 72 20 61 3e 30 0a 09 4d 4f 56 09 76 |, for a>0..MOV.v| 00000cb0 32 2c 20 61 32 09 09 09 3b 76 69 61 20 65 78 70 |2, a2...;via exp| 00000cc0 31 36 28 20 6c 6e 31 36 28 61 29 20 2a 20 62 20 |16( ln16(a) * b | 00000cd0 2f 20 36 35 35 33 36 20 29 0a 09 42 4c 09 6c 6e |/ 65536 )..BL.ln| 00000ce0 31 36 09 09 09 3b 6e 62 20 74 68 69 73 20 75 73 |16...;nb this us| 00000cf0 65 73 20 70 72 6f 70 65 72 74 79 20 74 68 61 74 |es property that| 00000d00 20 65 78 70 28 62 2e 6c 6f 67 28 61 29 29 20 3d | exp(b.log(a)) =| 00000d10 20 65 78 70 28 6c 6f 67 28 61 5e 62 29 29 20 3d | exp(log(a^b)) =| 00000d20 20 61 5e 62 0a 20 20 20 20 20 20 20 20 6d 75 6c | a^b. mul| 00000d30 31 36 09 61 31 2c 20 76 32 2c 20 61 31 2c 20 61 |16.a1, v2, a1, a| 00000d40 32 2c 20 61 33 2c 20 61 34 0a 09 42 4c 09 65 78 |2, a3, a4..BL.ex| 00000d50 70 31 36 0a 09 43 4d 50 09 76 31 2c 20 23 30 0a |p16..CMP.v1, #0.| 00000d60 09 52 53 42 4e 45 09 61 31 2c 20 61 31 2c 20 23 |.RSBNE.a1, a1, #| 00000d70 30 09 09 3b 66 69 6e 61 6c 6c 79 20 73 77 69 74 |0..;finally swit| 00000d80 63 68 20 73 69 67 6e 20 6f 6e 20 61 6e 73 77 65 |ch sign on answe| 00000d90 72 20 69 66 20 6f 72 69 67 69 6e 61 6c 6c 79 20 |r if originally | 00000da0 61 3c 30 20 61 6e 64 20 62 2f 6f 6e 65 20 77 61 |a<0 and b/one wa| 00000db0 73 20 6f 64 64 0a 09 4c 44 4d 46 44 09 73 70 21 |s odd..LDMFD.sp!| 00000dc0 2c 20 7b 76 31 2c 20 76 32 2c 20 70 63 7d 5e 0a |, {v1, v2, pc}^.| 00000dd0 0a 0a 0a 3b 20 6c 6e 31 36 0a 3b 20 61 20 6c 65 |...; ln16.; a le| 00000de0 61 66 20 41 50 43 53 20 66 75 6e 63 74 69 6f 6e |af APCS function| 00000df0 0a 3b 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 65 |.;.; C prototype| 00000e00 3a 0a 3b 20 69 6e 74 20 6c 6e 31 36 28 69 6e 74 |:.; int ln16(int| 00000e10 20 61 29 0a 3b 0a 3b 20 72 65 74 75 72 6e 73 20 | a).;.; returns | 00000e20 36 35 35 33 36 20 2a 20 6c 6e 20 28 61 2f 36 35 |65536 * ln (a/65| 00000e30 35 33 36 29 0a 3b 0a 3b 20 69 73 20 61 62 6f 75 |536).;.; is abou| 00000e40 74 20 33 30 20 74 69 6d 65 73 20 66 61 73 74 65 |t 30 times faste| 00000e50 72 20 74 68 61 6e 20 46 50 45 6d 75 6c 61 74 6f |r than FPEmulato| 00000e60 72 20 77 6f 72 6b 69 6e 67 20 77 69 74 68 20 64 |r working with d| 00000e70 6f 75 62 6c 65 20 66 6c 6f 61 74 73 0a 3b 0a 0a |ouble floats.;..| 00000e80 20 20 20 20 20 20 20 20 45 58 50 4f 52 54 20 20 | EXPORT | 00000e90 6c 6e 31 36 0a 0a 6c 6e 6e 73 74 61 20 20 44 43 |ln16..lnnsta DC| 00000ea0 42 20 20 20 20 20 22 6c 6e 31 36 22 2c 20 30 0a |B "ln16", 0.| 00000eb0 20 20 20 20 20 20 20 20 41 4c 49 47 4e 0a 6c 6e | ALIGN.ln| 00000ec0 6e 65 6e 64 20 20 44 43 44 20 20 20 20 20 26 66 |nend DCD &f| 00000ed0 66 30 30 30 30 30 30 20 2b 20 6c 6e 6e 65 6e 64 |f000000 + lnnend| 00000ee0 20 2d 20 6c 6e 6e 73 74 61 0a 0a 6c 6e 31 36 0a | - lnnsta..ln16.| 00000ef0 0a 09 43 4d 50 09 61 31 2c 20 23 30 09 09 09 3b |..CMP.a1, #0...;| 00000f00 69 66 20 61 3c 3d 30 20 72 65 74 75 72 6e 20 6d |if a<=0 return m| 00000f10 69 6e 31 36 0a 09 4d 4f 56 4c 45 09 61 31 2c 20 |in16..MOVLE.a1, | 00000f20 23 6d 69 6e 31 36 0a 09 4d 4f 56 4c 45 53 09 70 |#min16..MOVLES.p| 00000f30 63 2c 20 6c 72 09 09 09 3b 65 6c 73 65 20 6d 6f |c, lr...;else mo| 00000f40 73 74 20 73 69 67 6e 69 66 69 63 61 6e 74 20 62 |st significant b| 00000f50 69 74 20 69 73 20 62 65 74 77 65 65 6e 20 62 33 |it is between b3| 00000f60 30 20 26 20 62 30 0a 09 47 42 4c 41 09 63 6f 75 |0 & b0..GBLA.cou| 00000f70 6e 74 65 72 0a 63 6f 75 6e 74 65 72 09 53 45 54 |nter.counter.SET| 00000f80 41 09 33 30 09 09 09 3b 66 69 6e 64 20 6d 73 62 |A.30...;find msb| 00000f90 20 26 20 73 74 6f 72 65 20 28 6d 73 62 5f 69 6e | & store (msb_in| 00000fa0 64 65 78 20 2d 20 31 35 29 20 69 6e 20 61 34 0a |dex - 15) in a4.| 00000fb0 09 57 48 49 4c 45 09 63 6f 75 6e 74 65 72 20 3e |.WHILE.counter >| 00000fc0 20 31 0a 09 54 53 54 09 61 31 2c 20 23 31 3c 3c | 1..TST.a1, #1<<| 00000fd0 63 6f 75 6e 74 65 72 0a 09 4d 4f 56 4e 45 09 61 |counter..MOVNE.a| 00000fe0 34 2c 20 23 63 6f 75 6e 74 65 72 2d 31 35 0a 09 |4, #counter-15..| 00000ff0 42 4e 45 09 6c 6e 31 36 5f 67 6f 74 6d 73 62 0a |BNE.ln16_gotmsb.| 00001000 63 6f 75 6e 74 65 72 09 53 45 54 41 09 63 6f 75 |counter.SETA.cou| 00001010 6e 74 65 72 2d 31 0a 09 57 45 4e 44 0a 09 54 53 |nter-1..WEND..TS| 00001020 54 09 61 31 2c 20 23 31 3c 3c 31 0a 09 4d 4f 56 |T.a1, #1<<1..MOV| 00001030 4e 45 09 61 34 2c 20 23 31 2d 31 35 0a 09 4d 4f |NE.a4, #1-15..MO| 00001040 56 45 51 09 61 34 2c 20 23 30 2d 31 35 0a 6c 6e |VEQ.a4, #0-15.ln| 00001050 31 36 5f 67 6f 74 6d 73 62 09 09 09 09 3b 69 66 |16_gotmsb....;if| 00001060 20 77 65 20 73 65 74 20 7a 20 3d 20 61 31 2f 28 | we set z = a1/(| 00001070 32 5e 61 34 29 2c 20 77 69 6c 6c 20 68 61 76 65 |2^a4), will have| 00001080 20 6c 6e 28 61 2f 6f 6e 65 29 20 3d 20 6c 6e 28 | ln(a/one) = ln(| 00001090 7a 2f 6f 6e 65 20 2a 20 32 5e 61 34 29 0a 09 43 |z/one * 2^a4)..C| 000010a0 4d 50 09 61 34 2c 20 23 32 09 09 09 3b 09 09 09 |MP.a4, #2...;...| 000010b0 09 09 20 20 20 20 20 20 3d 20 6c 6e 28 7a 2f 6f |.. = ln(z/o| 000010c0 6e 65 29 20 2b 20 61 34 2a 6c 6e 32 0a 09 53 55 |ne) + a4*ln2..SU| 000010d0 42 47 54 09 61 32 2c 20 61 34 2c 20 23 32 09 09 |BGT.a2, a4, #2..| 000010e0 3b 77 69 74 68 20 7a 20 69 6e 20 72 61 6e 67 65 |;with z in range| 000010f0 20 5b 30 2e 35 2c 31 29 0a 09 4d 4f 56 47 54 09 | [0.5,1)..MOVGT.| 00001100 61 31 2c 20 61 31 2c 20 4c 53 52 20 61 32 09 09 |a1, a1, LSR a2..| 00001110 3b 73 6f 20 63 61 6c 63 20 61 31 20 3d 20 34 2a |;so calc a1 = 4*| 00001120 28 20 61 31 2f 28 32 5e 61 34 29 20 29 20 2d 20 |( a1/(2^a4) ) - | 00001130 33 2a 6f 6e 65 0a 09 52 53 42 4c 45 09 61 32 2c |3*one..RSBLE.a2,| 00001140 20 61 34 2c 20 23 32 09 09 3b 77 68 69 63 68 20 | a4, #2..;which | 00001150 70 75 74 73 20 61 31 20 69 6e 20 72 61 6e 67 65 |puts a1 in range| 00001160 20 b1 6f 6e 65 20 73 75 69 74 61 62 6c 65 20 66 | .one suitable f| 00001170 6f 72 20 61 70 70 72 6f 78 69 6d 61 74 69 6f 6e |or approximation| 00001180 20 62 79 20 70 6f 6c 79 0a 09 4d 4f 56 4c 45 09 | by poly..MOVLE.| 00001190 61 31 2c 20 61 31 2c 20 4c 53 4c 20 61 32 09 09 |a1, a1, LSL a2..| 000011a0 3b 6c 65 61 76 69 6e 67 20 75 73 20 74 6f 20 63 |;leaving us to c| 000011b0 61 6c 63 75 6c 61 74 65 20 61 34 2a 6f 6e 65 2a |alculate a4*one*| 000011c0 6c 6e 32 20 2b 20 6f 6e 65 2a 6c 6e 28 28 61 31 |ln2 + one*ln((a1| 000011d0 2b 33 6f 6e 65 29 2f 34 6f 6e 65 29 0a 09 53 55 |+3one)/4one)..SU| 000011e0 42 09 61 31 2c 20 61 31 2c 20 23 26 33 30 30 30 |B.a1, a1, #&3000| 000011f0 30 0a 09 41 44 44 09 61 32 2c 20 61 31 2c 20 61 |0..ADD.a2, a1, a| 00001200 31 2c 20 4c 53 4c 20 23 32 09 3b 73 74 61 72 74 |1, LSL #2.;start| 00001210 20 70 6f 6c 79 6e 6f 6d 69 61 6c 20 61 70 70 72 | polynomial appr| 00001220 6f 78 69 6d 61 74 69 6f 6e 20 63 61 6c 63 75 6c |oximation calcul| 00001230 61 74 69 6f 6e 20 6f 6e 20 61 31 0a 09 52 53 42 |ation on a1..RSB| 00001240 09 61 32 2c 20 61 32 2c 20 61 31 2c 20 4c 53 4c |.a2, a2, a1, LSL| 00001250 20 23 31 30 0a 09 4d 4f 56 09 61 32 2c 20 61 32 | #10..MOV.a2, a2| 00001260 2c 20 41 53 52 20 23 31 36 09 09 3b 66 6f 72 20 |, ASR #16..;for | 00001270 64 65 74 61 69 6c 73 20 6f 66 20 68 6f 77 20 74 |details of how t| 00001280 68 69 73 20 77 6f 72 6b 73 20 73 65 65 20 63 6f |his works see co| 00001290 6d 6d 65 6e 74 73 20 61 67 61 69 6e 73 74 20 73 |mments against s| 000012a0 69 6d 69 6c 61 72 20 63 6f 64 65 0a 09 53 55 42 |imilar code..SUB| 000012b0 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 65 30 |.a2, a2, #&000e0| 000012c0 30 09 3b 69 6e 20 65 78 70 31 36 20 66 75 6e 63 |0.;in exp16 func| 000012d0 74 69 6f 6e 2c 20 64 69 72 65 63 74 6c 79 20 62 |tion, directly b| 000012e0 65 6c 6f 77 20 74 68 69 73 20 66 75 6e 63 74 69 |elow this functi| 000012f0 6f 6e 0a 09 53 55 42 09 61 32 2c 20 61 32 2c 20 |on..SUB.a2, a2, | 00001300 23 26 30 30 30 30 33 34 0a 20 20 20 20 20 20 20 |#&000034. | 00001310 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c | MOV.ip, a1..mul| 00001320 31 36 63 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 |16c.a2, ip, a2, | 00001330 61 33 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 |a3..ADD.a2, a2, | 00001340 23 26 30 30 33 32 30 30 0a 09 41 44 44 09 61 32 |#&003200..ADD.a2| 00001350 2c 20 61 32 2c 20 23 26 30 30 30 30 33 31 0a 20 |, a2, #&000031. | 00001360 20 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 | MOV.ip, a| 00001370 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 |1..mul16c.a2, ip| 00001380 2c 20 61 32 2c 20 61 33 0a 09 53 55 42 09 61 32 |, a2, a3..SUB.a2| 00001390 2c 20 61 32 2c 20 23 26 30 30 65 32 30 30 0a 09 |, a2, #&00e200..| 000013a0 53 55 42 09 61 32 2c 20 61 32 2c 20 23 26 30 30 |SUB.a2, a2, #&00| 000013b0 30 30 66 32 0a 20 20 20 20 20 20 20 20 4d 4f 56 |00f2. MOV| 000013c0 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 |.ip, a1..mul16c.| 000013d0 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 |a2, ip, a2, a3..| 000013e0 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 35 |ADD.a2, a2, #&05| 000013f0 30 30 30 30 0a 09 41 44 44 09 61 32 2c 20 61 32 |0000..ADD.a2, a2| 00001400 2c 20 23 26 30 30 35 35 30 30 0a 09 41 44 44 09 |, #&005500..ADD.| 00001410 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 36 35 |a2, a2, #&000065| 00001420 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 2c |. MOV.ip,| 00001430 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 | a1..mul16c.a2, | 00001440 69 70 2c 20 61 32 2c 20 61 33 0a 09 53 55 42 09 |ip, a2, a3..SUB.| 00001450 61 32 2c 20 61 32 2c 20 23 26 30 34 30 30 30 30 |a2, a2, #&040000| 00001460 0a 09 53 55 42 09 61 32 2c 20 61 32 2c 20 23 26 |..SUB.a2, a2, #&| 00001470 30 30 39 61 30 30 09 3b 65 6e 64 20 6f 66 20 70 |009a00.;end of p| 00001480 6f 6c 79 6e 6f 6d 69 61 6c 20 61 70 70 72 6f 78 |olynomial approx| 00001490 69 6d 61 74 69 6f 6e 20 63 61 6c 63 75 6c 61 74 |imation calculat| 000014a0 69 6f 6e 0a 09 53 55 42 09 61 31 2c 20 61 32 2c |ion..SUB.a1, a2,| 000014b0 20 23 26 30 30 30 30 35 39 09 3b 61 31 20 6e 6f | #&000059.;a1 no| 000014c0 77 20 68 6f 6c 64 73 20 28 32 5e 32 30 29 2a 28 |w holds (2^20)*(| 000014d0 61 70 70 72 6f 78 69 6d 61 74 65 64 20 76 61 6c |approximated val| 000014e0 75 65 29 0a 09 41 44 44 09 69 70 2c 20 61 34 2c |ue)..ADD.ip, a4,| 000014f0 20 61 34 2c 20 4c 53 4c 20 23 31 0a 09 41 44 44 | a4, LSL #1..ADD| 00001500 09 61 32 2c 20 69 70 2c 20 61 34 2c 20 4c 53 4c |.a2, ip, a4, LSL| 00001510 20 23 33 09 3b 6e 6f 77 20 61 64 64 20 69 6e 20 | #3.;now add in | 00001520 74 68 65 20 61 34 2a 6f 6e 65 2a 6c 6e 32 20 74 |the a4*one*ln2 t| 00001530 65 72 6d 20 75 73 69 6e 67 20 61 6e 20 65 78 70 |erm using an exp| 00001540 6c 69 63 69 74 20 62 69 6e 61 72 79 20 65 78 70 |licit binary exp| 00001550 61 6e 73 69 6f 6e 0a 09 41 44 44 09 61 32 2c 20 |ansion..ADD.a2, | 00001560 61 34 2c 20 61 32 2c 20 4c 53 4c 20 23 34 09 3b |a4, a2, LSL #4.;| 00001570 6f 66 20 61 70 70 72 6f 78 69 6d 61 74 65 6c 79 |of approximately| 00001580 20 6f 6e 65 2a 6c 6e 32 0a 09 52 53 42 09 61 33 | one*ln2..RSB.a3| 00001590 2c 20 61 34 2c 20 61 34 2c 20 4c 53 4c 20 23 33 |, a4, a4, LSL #3| 000015a0 0a 09 41 44 44 09 61 32 2c 20 61 33 2c 20 61 32 |..ADD.a2, a3, a2| 000015b0 2c 20 4c 53 4c 20 23 34 09 3b 6e 62 20 77 65 20 |, LSL #4.;nb we | 000015c0 61 63 74 75 61 6c 6c 79 20 61 64 64 20 61 70 70 |actually add app| 000015d0 72 6f 78 20 28 32 5e 32 30 29 2a 6c 6e 32 2c 20 |rox (2^20)*ln2, | 000015e0 26 20 74 68 65 6e 20 64 69 76 69 64 65 20 62 79 |& then divide by| 000015f0 20 31 36 0a 09 41 44 44 09 61 32 2c 20 61 34 2c | 16..ADD.a2, a4,| 00001600 20 61 32 2c 20 4c 53 4c 20 23 33 09 3b 74 6f 20 | a2, LSL #3.;to | 00001610 72 65 64 75 63 65 20 74 72 75 6e 63 61 74 69 6f |reduce truncatio| 00001620 6e 20 65 72 72 6f 72 0a 09 41 44 44 09 61 31 2c |n error..ADD.a1,| 00001630 20 61 31 2c 20 61 32 2c 20 4c 53 4c 20 23 35 0a | a1, a2, LSL #5.| 00001640 09 41 44 44 09 61 31 2c 20 61 31 2c 20 69 70 2c |.ADD.a1, a1, ip,| 00001650 20 41 53 52 20 23 31 0a 09 4d 4f 56 09 61 31 2c | ASR #1..MOV.a1,| 00001660 20 61 31 2c 20 41 53 52 20 23 34 0a 20 20 20 20 | a1, ASR #4. | 00001670 20 20 20 20 4d 4f 56 53 20 20 20 20 70 63 2c 20 | MOVS pc, | 00001680 6c 72 0a 0a 0a 0a 3b 20 65 78 70 31 36 0a 3b 20 |lr....; exp16.; | 00001690 61 20 6c 65 61 66 20 41 50 43 53 20 66 75 6e 63 |a leaf APCS func| 000016a0 74 69 6f 6e 0a 3b 0a 3b 20 43 20 70 72 6f 74 6f |tion.;.; C proto| 000016b0 74 79 70 65 3a 0a 3b 20 69 6e 74 20 65 78 70 31 |type:.; int exp1| 000016c0 36 28 69 6e 74 20 61 29 0a 3b 0a 3b 20 72 65 74 |6(int a).;.; ret| 000016d0 75 72 6e 73 20 36 35 35 33 36 20 2a 20 65 78 70 |urns 65536 * exp| 000016e0 20 28 61 2f 36 35 35 33 36 29 0a 3b 0a 3b 20 69 | (a/65536).;.; i| 000016f0 73 20 61 62 6f 75 74 20 34 35 20 74 69 6d 65 73 |s about 45 times| 00001700 20 66 61 73 74 65 72 20 74 68 61 6e 20 46 50 45 | faster than FPE| 00001710 6d 75 6c 61 74 6f 72 20 77 6f 72 6b 69 6e 67 20 |mulator working | 00001720 77 69 74 68 20 64 6f 75 62 6c 65 20 66 6c 6f 61 |with double floa| 00001730 74 73 0a 3b 0a 0a 20 20 20 20 20 20 20 20 45 58 |ts.;.. EX| 00001740 50 4f 52 54 20 20 65 78 70 31 36 0a 0a 65 70 6e |PORT exp16..epn| 00001750 73 74 61 20 20 44 43 42 20 20 20 20 20 22 65 78 |sta DCB "ex| 00001760 70 31 36 22 2c 20 30 0a 20 20 20 20 20 20 20 20 |p16", 0. | 00001770 41 4c 49 47 4e 0a 65 70 6e 65 6e 64 20 20 44 43 |ALIGN.epnend DC| 00001780 44 20 20 20 20 20 26 66 66 30 30 30 30 30 30 20 |D &ff000000 | 00001790 2b 20 65 70 6e 65 6e 64 20 2d 20 65 70 6e 73 74 |+ epnend - epnst| 000017a0 61 0a 0a 65 78 70 31 36 09 09 09 09 09 3b 74 68 |a..exp16.....;th| 000017b0 69 73 20 66 6e 20 72 65 74 75 72 6e 73 20 61 20 |is fn returns a | 000017c0 76 61 6c 75 65 20 77 69 74 68 20 6f 6e 6c 79 20 |value with only | 000017d0 61 62 6f 75 74 20 31 37 20 73 69 67 6e 69 66 69 |about 17 signifi| 000017e0 63 61 6e 74 20 62 69 6e 61 72 79 0a 09 09 09 09 |cant binary.....| 000017f0 09 3b 64 69 67 69 74 73 20 2d 20 65 67 20 66 6f |.;digits - eg fo| 00001800 72 20 27 61 27 20 73 6d 61 6c 6c 20 6f 72 20 6e |r 'a' small or n| 00001810 65 67 61 74 69 76 65 2c 20 67 65 74 20 6e 65 61 |egative, get nea| 00001820 72 20 6d 61 78 69 6d 61 6c 20 61 63 63 75 72 61 |r maximal accura| 00001830 63 79 0a 09 09 09 09 09 3b 62 75 74 20 66 6f 72 |cy......;but for| 00001840 20 27 61 27 20 6c 61 72 67 65 20 28 75 70 74 6f | 'a' large (upto| 00001850 20 61 72 6f 75 6e 64 20 31 30 6f 6e 65 29 20 77 | around 10one) w| 00001860 68 65 72 65 20 65 78 70 20 68 61 73 20 76 61 6c |here exp has val| 00001870 75 65 0a 09 43 4d 50 09 61 31 2c 20 23 31 32 2a |ue..CMP.a1, #12*| 00001880 36 35 35 33 36 09 09 3b 7e 32 30 30 30 30 6f 6e |65536..;~20000on| 00001890 65 20 63 61 6e 20 67 65 74 20 65 72 72 6f 72 20 |e can get error | 000018a0 75 70 74 6f 20 72 6f 75 67 68 6c 79 20 30 2e 31 |upto roughly 0.1| 000018b0 6f 6e 65 0a 09 4d 4f 56 47 54 09 61 31 2c 20 23 |one..MOVGT.a1, #| 000018c0 6d 61 78 31 36 2b 31 0a 09 53 55 42 47 54 09 61 |max16+1..SUBGT.a| 000018d0 31 2c 20 61 31 2c 20 23 31 0a 09 4d 4f 56 47 54 |1, a1, #1..MOVGT| 000018e0 53 09 70 63 2c 20 6c 72 0a 09 43 4d 50 09 61 31 |S.pc, lr..CMP.a1| 000018f0 2c 20 23 2d 31 32 2a 36 35 35 33 36 0a 09 4d 4f |, #-12*65536..MO| 00001900 56 4c 54 09 61 31 2c 20 23 30 0a 09 4d 4f 56 4c |VLT.a1, #0..MOVL| 00001910 54 53 09 70 63 2c 20 6c 72 09 09 09 3b 6f 74 68 |TS.pc, lr...;oth| 00001920 65 72 77 69 73 65 20 6b 6e 6f 77 20 7c 61 7c 20 |erwise know |a| | 00001930 3c 3d 20 31 32 6f 6e 65 0a 09 52 53 42 09 61 32 |<= 12one..RSB.a2| 00001940 2c 20 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 33 |, a1, a1, LSL #3| 00001950 09 3b 6e 6f 77 20 73 65 74 20 61 20 3d 20 61 2f |.;now set a = a/| 00001960 6c 6e 32 20 75 73 69 6e 67 20 65 78 70 6c 69 63 |ln2 using explic| 00001970 69 74 20 6d 75 6c 20 62 79 20 32 5f 31 2e 30 31 |it mul by 2_1.01| 00001980 31 31 30 30 30 31 30 31 30 31 30 31 30 30 30 31 |1100010101010001| 00001990 31 31 0a 09 41 44 44 09 61 33 2c 20 61 31 2c 20 |11..ADD.a3, a1, | 000019a0 61 31 2c 20 4c 53 4c 20 23 32 09 3b 6e 62 20 6f |a1, LSL #2.;nb o| 000019b0 6e 6c 79 20 6e 65 65 64 20 31 73 74 20 32 30 20 |nly need 1st 20 | 000019c0 64 69 67 69 74 73 20 67 69 76 65 6e 20 72 61 6e |digits given ran| 000019d0 67 65 20 6f 6e 20 61 0a 09 41 44 44 09 61 33 2c |ge on a..ADD.a3,| 000019e0 20 61 33 2c 20 61 33 2c 20 4c 53 4c 20 23 34 09 | a3, a3, LSL #4.| 000019f0 3b 6e 62 32 20 74 68 69 73 20 63 61 6c 63 20 69 |;nb2 this calc i| 00001a00 73 20 61 70 70 72 6f 78 69 6d 61 74 65 20 6f 6e |s approximate on| 00001a10 6c 79 2c 20 74 68 6f 75 67 68 20 77 69 6c 6c 20 |ly, though will | 00001a20 75 73 75 61 6c 6c 79 20 79 69 65 6c 64 20 61 6e |usually yield an| 00001a30 0a 09 41 44 44 09 61 31 2c 20 61 32 2c 20 61 31 |..ADD.a1, a2, a1| 00001a40 2c 20 4c 53 4c 20 23 34 09 3b 61 6e 73 77 65 72 |, LSL #4.;answer| 00001a50 20 63 6f 72 72 65 63 74 20 74 6f 20 74 68 65 20 | correct to the | 00001a60 73 74 6f 72 65 64 20 31 36 20 62 69 6e 61 72 79 |stored 16 binary| 00001a70 20 70 6c 61 63 65 73 20 28 65 6c 73 65 20 65 72 | places (else er| 00001a80 72 6f 72 20 6f 6e 65 2f 36 35 35 33 36 29 0a 09 |ror one/65536)..| 00001a90 41 44 44 09 61 31 2c 20 61 31 2c 20 61 33 2c 20 |ADD.a1, a1, a3, | 00001aa0 41 53 52 20 23 31 30 0a 09 41 44 44 09 61 31 2c |ASR #10..ADD.a1,| 00001ab0 20 61 31 2c 20 61 32 2c 20 41 53 52 20 23 31 36 | a1, a2, ASR #16| 00001ac0 09 3b 74 68 75 73 20 65 78 70 28 6f 72 69 67 69 |.;thus exp(origi| 00001ad0 6e 61 6c 20 61 29 20 20 3d 20 65 78 70 28 6e 65 |nal a) = exp(ne| 00001ae0 77 20 61 20 2a 20 6c 6e 32 29 20 3d 20 32 5e 28 |w a * ln2) = 2^(| 00001af0 6e 65 77 20 61 29 2c 20 65 76 61 6c 27 64 20 62 |new a), eval'd b| 00001b00 65 6c 6f 77 3a 0a 09 41 44 44 09 61 31 2c 20 61 |elow:..ADD.a1, a| 00001b10 31 2c 20 23 38 0a 09 4d 4f 56 09 61 31 2c 20 61 |1, #8..MOV.a1, a| 00001b20 31 2c 20 41 53 52 20 23 34 09 09 3b 63 61 6c 63 |1, ASR #4..;calc| 00001b30 20 61 20 3d 20 61 2f 6c 6e 32 20 63 6f 6d 70 6c | a = a/ln2 compl| 00001b40 65 74 65 0a 09 4d 4f 56 09 61 34 2c 20 61 31 2c |ete..MOV.a4, a1,| 00001b50 20 41 53 52 20 23 31 36 09 09 3b 61 34 20 6e 6f | ASR #16..;a4 no| 00001b60 77 20 68 6f 6c 64 73 20 69 6e 74 65 67 65 72 20 |w holds integer | 00001b70 63 6f 6d 70 6f 6e 65 6e 74 20 6f 66 20 61 0a 09 |component of a..| 00001b80 42 49 43 09 61 31 2c 20 61 31 2c 20 61 34 2c 20 |BIC.a1, a1, a4, | 00001b90 4c 53 4c 20 23 31 36 09 3b 61 31 20 6e 6f 77 20 |LSL #16.;a1 now | 00001ba0 68 6f 6c 64 73 20 66 72 61 63 74 69 6f 6e 61 6c |holds fractional| 00001bb0 20 63 6f 6d 70 6f 6e 65 6e 74 20 69 6e 20 72 61 | component in ra| 00001bc0 6e 67 65 20 5b 30 2c 31 29 2a 6f 6e 65 0a 09 43 |nge [0,1)*one..C| 00001bd0 4d 50 09 61 34 2c 20 23 31 35 09 09 09 3b 64 6f |MP.a4, #15...;do| 00001be0 20 61 6e 6f 74 68 65 72 20 63 68 65 63 6b 20 6f | another check o| 00001bf0 6e 20 61 20 74 6f 20 65 6e 73 75 72 65 20 65 78 |n a to ensure ex| 00001c00 70 28 61 29 20 69 73 20 69 6e 20 72 61 6e 67 65 |p(a) is in range| 00001c10 0a 09 4d 4f 56 47 45 09 61 31 2c 20 23 6d 61 78 |..MOVGE.a1, #max| 00001c20 31 36 2b 31 09 09 3b 26 20 69 66 20 6e 6f 74 20 |16+1..;& if not | 00001c30 72 65 74 75 72 6e 20 6d 61 78 69 6d 61 6c 20 6f |return maximal o| 00001c40 72 20 6d 69 6e 69 6d 61 6c 20 76 61 6c 75 65 20 |r minimal value | 00001c50 61 73 20 61 70 70 72 6f 70 72 69 61 74 65 0a 09 |as appropriate..| 00001c60 53 55 42 47 45 09 61 31 2c 20 61 31 2c 20 23 31 |SUBGE.a1, a1, #1| 00001c70 0a 09 4d 4f 56 47 45 09 70 63 2c 20 6c 72 0a 09 |..MOVGE.pc, lr..| 00001c80 43 4d 50 09 61 34 2c 20 23 2d 31 36 0a 09 4d 4f |CMP.a4, #-16..MO| 00001c90 56 4c 54 09 61 31 2c 20 23 30 0a 09 4d 4f 56 4c |VLT.a1, #0..MOVL| 00001ca0 54 53 09 70 63 2c 20 6c 72 09 09 09 3b 65 6c 73 |TS.pc, lr...;els| 00001cb0 65 20 6e 65 65 64 20 74 6f 20 72 65 74 75 72 6e |e need to return| 00001cc0 20 76 61 6c 75 65 20 28 6f 6e 65 20 2a 20 32 5e | value (one * 2^| 00001cd0 28 61 34 20 2b 20 61 31 2f 6f 6e 65 29 29 0a 09 |(a4 + a1/one))..| 00001ce0 4d 4f 56 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 |MOV.a1, a1, LSL | 00001cf0 23 31 09 09 3b 09 09 09 20 3d 20 28 6f 6e 65 20 |#1..;... = (one | 00001d00 2a 20 32 5e 28 61 31 2f 6f 6e 65 29 20 2a 20 32 |* 2^(a1/one) * 2| 00001d10 5e 61 34 29 0a 09 53 55 42 09 61 31 2c 20 61 31 |^a4)..SUB.a1, a1| 00001d20 2c 20 23 26 31 30 30 30 30 09 09 3b 63 6f 6e 76 |, #&10000..;conv| 00001d30 65 72 74 20 61 31 20 74 6f 20 6c 69 65 20 69 6e |ert a1 to lie in| 00001d40 20 5b 2d 31 2c 2d 31 29 2c 20 74 68 65 6e 20 61 | [-1,-1), then a| 00001d50 70 70 6c 79 20 70 6f 6c 79 20 61 70 70 72 6f 78 |pply poly approx| 00001d60 69 6d 61 74 69 6f 6e 3a 0a 09 52 53 42 09 61 32 |imation:..RSB.a2| 00001d70 2c 20 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 33 |, a1, a1, LSL #3| 00001d80 0a 09 41 44 44 09 61 32 2c 20 61 31 2c 20 61 32 |..ADD.a2, a1, a2| 00001d90 2c 20 4c 53 4c 20 23 36 0a 09 4d 4f 56 09 61 32 |, LSL #6..MOV.a2| 00001da0 2c 20 61 32 2c 20 41 53 52 20 23 31 35 09 09 3b |, a2, ASR #15..;| 00001db0 61 32 20 3d 20 30 2e 30 30 30 38 35 36 31 2a 28 |a2 = 0.0008561*(| 00001dc0 32 5e 32 30 29 2a 28 61 31 2f 6f 6e 65 29 0a 09 |2^20)*(a1/one)..| 00001dd0 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 |ADD.a2, a2, #&00| 00001de0 32 38 30 30 0a 09 41 44 44 09 61 32 2c 20 61 32 |2800..ADD.a2, a2| 00001df0 2c 20 23 26 30 30 30 30 37 65 09 3b 61 32 20 3d |, #&00007e.;a2 =| 00001e00 20 30 2e 30 30 30 38 35 36 31 2a 28 32 5e 32 30 | 0.0008561*(2^20| 00001e10 29 2a 28 61 31 2f 6f 6e 65 29 20 2b 20 30 2e 30 |)*(a1/one) + 0.0| 00001e20 30 39 38 38 35 37 2a 28 32 5e 32 30 29 0a 20 20 |098857*(2^20). | 00001e30 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 | MOV.ip, a1| 00001e40 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c |..mul16c.a2, ip,| 00001e50 20 61 32 2c 20 61 33 09 09 3b 61 32 20 3d 20 30 | a2, a3..;a2 = 0| 00001e60 2e 30 30 30 38 35 36 31 2a 28 32 5e 32 30 29 2a |.0008561*(2^20)*| 00001e70 28 61 31 2f 6f 6e 65 29 5e 32 20 2b 20 30 2e 30 |(a1/one)^2 + 0.0| 00001e80 30 39 38 38 35 37 2a 28 32 5e 32 30 29 2a 28 61 |098857*(2^20)*(a| 00001e90 31 2f 6f 6e 65 29 0a 09 41 44 44 09 61 32 2c 20 |1/one)..ADD.a2, | 00001ea0 61 32 2c 20 23 26 30 31 35 30 30 30 0a 09 41 44 |a2, #&015000..AD| 00001eb0 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 62 |D.a2, a2, #&000b| 00001ec0 65 30 09 3b 20 65 74 63 0a 20 20 20 20 20 20 20 |e0.; etc. | 00001ed0 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c | MOV.ip, a1..mul| 00001ee0 31 36 63 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 |16c.a2, ip, a2, | 00001ef0 61 33 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 |a3..ADD.a2, a2, | 00001f00 23 26 30 37 30 30 30 30 0a 09 41 44 44 09 61 32 |#&070000..ADD.a2| 00001f10 2c 20 61 32 2c 20 23 26 30 30 64 37 30 30 0a 09 |, a2, #&00d700..| 00001f20 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 |ADD.a2, a2, #&00| 00001f30 30 30 37 65 0a 20 20 20 20 20 20 20 20 4d 4f 56 |007e. MOV| 00001f40 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 |.ip, a1..mul16c.| 00001f50 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 09 09 |a2, ip, a2, a3..| 00001f60 3b 75 6e 74 69 6c 20 77 65 20 68 61 76 65 0a 09 |;until we have..| 00001f70 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 31 36 |ADD.a2, a2, #&16| 00001f80 30 30 30 30 09 3b 61 32 20 3d 20 28 32 5e 32 30 |0000.;a2 = (2^20| 00001f90 29 20 28 20 30 2e 30 30 30 38 35 36 31 28 61 31 |) ( 0.0008561(a1| 00001fa0 2f 6f 6e 65 29 5e 34 20 2b 20 30 2e 30 30 39 38 |/one)^4 + 0.0098| 00001fb0 38 35 37 28 61 31 2f 6f 6e 65 29 5e 33 20 2b 0a |857(a1/one)^3 +.| 00001fc0 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00001fd0 30 61 30 30 30 09 3b 09 20 20 20 20 20 20 20 30 |0a000.;. 0| 00001fe0 2e 30 38 34 39 33 30 31 28 61 31 2f 6f 6e 65 29 |.0849301(a1/one)| 00001ff0 5e 32 20 2b 20 30 2e 34 39 30 31 31 30 36 28 61 |^2 + 0.4901106(a| 00002000 31 2f 6f 6e 65 29 20 2b 0a 09 41 44 44 09 61 32 |1/one) +..ADD.a2| 00002010 2c 20 61 32 2c 20 23 26 30 30 30 30 61 37 09 3b |, a2, #&0000a7.;| 00002020 09 20 20 20 20 20 20 20 31 2e 31 34 31 34 32 31 |. 1.141421| 00002030 33 38 28 61 31 2f 6f 6e 65 29 20 20 20 20 20 20 |38(a1/one) | 00002040 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00002050 20 20 20 20 20 29 0a 09 4d 4f 56 09 61 31 2c 20 | )..MOV.a1, | 00002060 61 32 2c 20 41 53 52 20 23 34 09 09 3b 6e 6f 77 |a2, ASR #4..;now| 00002070 20 64 69 76 69 64 65 20 62 79 20 31 36 20 72 65 | divide by 16 re| 00002080 6d 6f 76 69 6e 67 20 6d 6f 73 74 20 74 72 75 6e |moving most trun| 00002090 63 61 74 69 6f 6e 20 65 72 72 6f 72 20 66 72 6f |cation error fro| 000020a0 6d 20 61 62 6f 76 65 20 63 61 6c 63 73 2c 0a 09 |m above calcs,..| 000020b0 43 4d 50 09 61 34 2c 20 23 30 09 09 09 3b 6c 65 |CMP.a4, #0...;le| 000020c0 61 76 69 6e 67 20 61 32 20 3d 20 28 32 5e 31 36 |aving a2 = (2^16| 000020d0 29 2a 28 61 70 70 72 6f 78 69 6d 61 74 65 64 20 |)*(approximated | 000020e0 76 61 6c 75 65 29 0a 09 52 53 42 4c 54 09 61 34 |value)..RSBLT.a4| 000020f0 2c 20 61 34 2c 20 23 30 0a 09 4d 4f 56 4c 54 09 |, a4, #0..MOVLT.| 00002100 61 31 2c 20 61 31 2c 20 41 53 52 20 61 34 09 09 |a1, a1, ASR a4..| 00002110 3b 66 69 6e 61 6c 6c 79 20 63 61 72 72 79 20 6f |;finally carry o| 00002120 75 74 20 74 68 65 20 28 61 32 20 3d 20 61 32 20 |ut the (a2 = a2 | 00002130 2a 20 32 5e 61 34 29 20 73 74 65 70 0a 09 4d 4f |* 2^a4) step..MO| 00002140 56 4c 54 53 09 70 63 2c 20 6c 72 0a 09 4d 4f 56 |VLTS.pc, lr..MOV| 00002150 53 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 61 34 |S.a1, a1, LSL a4| 00002160 0a 09 4d 4f 56 4d 49 09 61 31 2c 20 23 6d 61 78 |..MOVMI.a1, #max| 00002170 31 36 2b 31 0a 09 53 55 42 4d 49 09 61 31 2c 20 |16+1..SUBMI.a1, | 00002180 61 31 2c 20 23 31 0a 20 20 20 20 20 20 20 20 4d |a1, #1. M| 00002190 4f 56 53 20 20 20 20 70 63 2c 20 6c 72 0a 0a 0a |OVS pc, lr...| 000021a0 0a 3b 20 63 6f 73 31 36 0a 3b 20 61 20 6c 65 61 |.; cos16.; a lea| 000021b0 66 20 41 50 43 53 20 66 75 6e 63 74 69 6f 6e 0a |f APCS function.| 000021c0 3b 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 65 3a |;.; C prototype:| 000021d0 0a 3b 20 69 6e 74 20 63 6f 73 31 36 28 69 6e 74 |.; int cos16(int| 000021e0 20 61 29 0a 3b 0a 3b 20 72 65 74 75 72 6e 73 20 | a).;.; returns | 000021f0 36 35 35 33 36 20 2a 20 63 6f 73 20 28 28 61 2f |65536 * cos ((a/| 00002200 36 35 35 33 36 29 28 70 69 2f 32 29 29 0a 3b 0a |65536)(pi/2)).;.| 00002210 3b 20 69 73 20 61 62 6f 75 74 20 34 34 20 74 69 |; is about 44 ti| 00002220 6d 65 73 20 66 61 73 74 65 72 20 74 68 61 6e 20 |mes faster than | 00002230 46 50 45 6d 75 6c 61 74 6f 72 20 77 6f 72 6b 69 |FPEmulator worki| 00002240 6e 67 20 77 69 74 68 20 64 6f 75 62 6c 65 20 66 |ng with double f| 00002250 6c 6f 61 74 73 0a 3b 0a 0a 20 20 20 20 20 20 20 |loats.;.. | 00002260 20 45 58 50 4f 52 54 20 20 63 6f 73 31 36 0a 0a | EXPORT cos16..| 00002270 63 73 6e 73 74 61 20 20 44 43 42 20 20 20 20 20 |csnsta DCB | 00002280 22 63 6f 73 31 36 22 2c 20 30 0a 20 20 20 20 20 |"cos16", 0. | 00002290 20 20 20 41 4c 49 47 4e 0a 63 73 6e 65 6e 64 20 | ALIGN.csnend | 000022a0 20 44 43 44 20 20 20 20 20 26 66 66 30 30 30 30 | DCD &ff0000| 000022b0 30 30 20 2b 20 63 73 6e 65 6e 64 20 2d 20 63 73 |00 + csnend - cs| 000022c0 6e 73 74 61 0a 0a 63 6f 73 31 36 0a 0a 09 45 4f |nsta..cos16...EO| 000022d0 52 09 61 34 2c 20 61 31 2c 20 61 31 2c 20 4c 53 |R.a4, a1, a1, LS| 000022e0 4c 20 23 31 09 3b 73 69 6e 63 65 20 63 6f 73 20 |L #1.;since cos | 000022f0 69 73 20 70 65 72 69 6f 64 69 63 20 61 6e 64 20 |is periodic and | 00002300 63 6f 73 28 28 61 2f 36 35 35 33 36 29 28 70 69 |cos((a/65536)(pi| 00002310 2f 32 29 29 20 68 61 73 20 70 65 72 69 6f 64 20 |/2)) has period | 00002320 34 2a 6f 6e 65 0a 09 54 53 54 09 61 34 2c 20 23 |4*one..TST.a4, #| 00002330 26 32 30 30 30 30 09 09 3b 65 76 61 6c 20 69 73 |&20000..;eval is| 00002340 20 73 69 6d 70 6c 65 72 20 74 68 61 6e 20 66 6f | simpler than fo| 00002350 72 20 6c 6e 20 6f 72 20 65 78 70 3a 0a 09 4d 4f |r ln or exp:..MO| 00002360 56 09 61 34 2c 20 23 30 09 09 09 3b 77 65 20 6e |V.a4, #0...;we n| 00002370 65 65 64 20 6f 6e 6c 79 20 74 6f 20 74 72 75 6e |eed only to trun| 00002380 63 61 74 65 20 61 20 74 6f 20 5b 30 2c 34 6f 6e |cate a to [0,4on| 00002390 65 29 20 61 6e 64 20 74 68 65 6e 20 61 70 70 72 |e) and then appr| 000023a0 6f 78 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 0a |ox the function.| 000023b0 09 4d 4f 56 4e 45 09 61 34 2c 20 23 31 09 09 09 |.MOVNE.a4, #1...| 000023c0 3b 76 69 61 20 61 20 70 6f 6c 79 0a 09 54 53 54 |;via a poly..TST| 000023d0 09 61 31 2c 20 23 26 31 30 30 30 30 0a 09 4d 4f |.a1, #&10000..MO| 000023e0 56 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 31 |V.a1, a1, LSL #1| 000023f0 36 09 09 3b 69 6e 20 66 61 63 74 20 66 75 72 74 |6..;in fact furt| 00002400 68 65 72 20 73 79 6d 6d 65 74 72 69 65 73 20 69 |her symmetries i| 00002410 6e 20 63 6f 73 20 6f 76 65 72 20 74 68 69 73 20 |n cos over this | 00002420 72 61 6e 67 65 20 61 6c 6c 6f 77 20 75 73 20 74 |range allow us t| 00002430 6f 0a 09 4d 4f 56 09 61 31 2c 20 61 31 2c 20 4c |o..MOV.a1, a1, L| 00002440 53 52 20 23 31 36 09 09 3b 61 63 74 75 61 6c 6c |SR #16..;actuall| 00002450 79 20 6f 6e 6c 79 20 61 70 70 72 6f 78 69 6d 61 |y only approxima| 00002460 74 65 20 66 75 6e 63 74 69 6f 6e 20 6f 76 65 72 |te function over| 00002470 20 72 61 6e 67 65 20 5b 30 2c 6f 6e 65 29 0a 09 | range [0,one)..| 00002480 52 53 42 45 51 09 61 31 2c 20 61 31 2c 20 23 26 |RSBEQ.a1, a1, #&| 00002490 31 30 30 30 30 09 09 3b 61 6e 64 20 72 65 63 6f |10000..;and reco| 000024a0 6e 73 74 72 75 63 74 20 69 74 20 6f 76 65 72 20 |nstruct it over | 000024b0 72 65 6d 61 69 6e 64 65 72 20 6f 66 20 72 61 6e |remainder of ran| 000024c0 67 65 20 5b 6f 6e 65 2c 34 6f 6e 65 29 20 66 72 |ge [one,4one) fr| 000024d0 6f 6d 20 74 68 61 74 20 70 61 72 74 0a 09 4d 4f |om that part..MO| 000024e0 56 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 31 |V.a1, a1, LSL #1| 000024f0 09 09 3b 65 67 20 20 63 6f 73 28 20 28 61 2f 36 |..;eg cos( (a/6| 00002500 35 35 33 36 29 28 70 69 2f 32 29 20 29 20 66 6f |5536)(pi/2) ) fo| 00002510 72 20 61 20 69 6e 20 5b 32 6f 6e 65 2c 20 33 6f |r a in [2one, 3o| 00002520 6e 65 29 0a 09 53 55 42 09 61 31 2c 20 61 31 2c |ne)..SUB.a1, a1,| 00002530 20 23 26 31 30 30 30 30 09 09 3b 20 3d 20 2d 63 | #&10000..; = -c| 00002540 6f 73 28 20 28 28 61 2d 32 6f 6e 65 29 2f 36 35 |os( ((a-2one)/65| 00002550 35 33 36 29 28 70 69 2f 32 29 20 29 0a 09 52 53 |536)(pi/2) )..RS| 00002560 42 09 61 32 2c 20 61 31 2c 20 61 31 2c 20 4c 53 |B.a2, a1, a1, LS| 00002570 4c 20 23 33 0a 09 41 44 44 09 61 32 2c 20 61 31 |L #3..ADD.a2, a1| 00002580 2c 20 61 32 2c 20 4c 53 4c 20 23 38 0a 09 4d 4f |, a2, LSL #8..MO| 00002590 56 09 61 32 2c 20 61 32 2c 20 41 53 52 20 23 31 |V.a2, a2, ASR #1| 000025a0 36 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |6..ADD.a2, a2, #| 000025b0 26 30 30 32 63 30 30 0a 09 41 44 44 09 61 32 2c |&002c00..ADD.a2,| 000025c0 20 61 32 2c 20 23 26 30 30 30 30 38 36 0a 20 20 | a2, #&000086. | 000025d0 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 | MOV.ip, a1| 000025e0 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c |..mul16c.a2, ip,| 000025f0 20 61 32 2c 20 61 33 0a 09 53 55 42 09 61 32 2c | a2, a3..SUB.a2,| 00002600 20 61 32 2c 20 23 26 30 30 65 39 30 30 0a 09 53 | a2, #&00e900..S| 00002610 55 42 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 |UB.a2, a2, #&000| 00002620 30 62 64 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 |0bd. MOV.| 00002630 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 |ip, a1..mul16c.a| 00002640 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 53 |2, ip, a2, a3..S| 00002650 55 42 09 61 32 2c 20 61 32 2c 20 23 26 30 33 30 |UB.a2, a2, #&030| 00002660 30 30 30 0a 09 53 55 42 09 61 32 2c 20 61 32 2c |000..SUB.a2, a2,| 00002670 20 23 26 30 30 37 63 30 30 0a 09 53 55 42 09 61 | #&007c00..SUB.a| 00002680 32 2c 20 61 32 2c 20 23 26 30 30 30 30 63 36 0a |2, a2, #&0000c6.| 00002690 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 | MOV.ip, | 000026a0 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 |a1..mul16c.a2, i| 000026b0 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 44 09 61 |p, a2, a3..ADD.a| 000026c0 32 2c 20 61 32 2c 20 23 26 30 38 30 30 30 30 0a |2, a2, #&080000.| 000026d0 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 000026e0 30 45 32 30 30 0a 09 41 44 44 09 61 32 2c 20 61 |0E200..ADD.a2, a| 000026f0 32 2c 20 23 26 30 30 30 30 42 44 0a 20 20 20 20 |2, #&0000BD. | 00002700 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 | MOV.ip, a1..| 00002710 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c 20 61 |mul16c.a2, ip, a| 00002720 32 2c 20 61 33 0a 09 41 44 44 09 61 32 2c 20 61 |2, a3..ADD.a2, a| 00002730 32 2c 20 23 26 30 62 30 30 30 30 0a 09 41 44 44 |2, #&0b0000..ADD| 00002740 09 61 32 2c 20 61 32 2c 20 23 26 30 30 35 30 30 |.a2, a2, #&00500| 00002750 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |0..ADD.a2, a2, #| 00002760 26 30 30 30 30 35 30 0a 09 4d 4f 56 09 61 31 2c |&000050..MOV.a1,| 00002770 20 61 32 2c 20 41 53 52 20 23 34 0a 09 54 53 54 | a2, ASR #4..TST| 00002780 09 61 34 2c 20 23 31 0a 09 52 53 42 4e 45 09 61 |.a4, #1..RSBNE.a| 00002790 31 2c 20 61 31 2c 20 23 30 0a 20 20 20 20 20 20 |1, a1, #0. | 000027a0 20 20 4d 4f 56 53 20 20 20 20 70 63 2c 20 6c 72 | MOVS pc, lr| 000027b0 0a 0a 0a 0a 3b 20 73 69 6e 31 36 0a 3b 20 61 20 |....; sin16.; a | 000027c0 6c 65 61 66 20 41 50 43 53 20 66 75 6e 63 74 69 |leaf APCS functi| 000027d0 6f 6e 0a 3b 0a 3b 20 43 20 70 72 6f 74 6f 74 79 |on.;.; C prototy| 000027e0 70 65 3a 0a 3b 20 69 6e 74 20 73 69 6e 31 36 28 |pe:.; int sin16(| 000027f0 69 6e 74 20 61 29 0a 3b 0a 3b 20 72 65 74 75 72 |int a).;.; retur| 00002800 6e 73 20 36 35 35 33 36 20 2a 20 73 69 6e 20 28 |ns 65536 * sin (| 00002810 28 61 2f 36 35 35 33 36 29 28 70 69 2f 32 29 29 |(a/65536)(pi/2))| 00002820 0a 3b 0a 3b 20 69 73 20 61 62 6f 75 74 20 34 34 |.;.; is about 44| 00002830 20 74 69 6d 65 73 20 66 61 73 74 65 72 20 74 68 | times faster th| 00002840 61 6e 20 46 50 45 6d 75 6c 61 74 6f 72 20 77 6f |an FPEmulator wo| 00002850 72 6b 69 6e 67 20 77 69 74 68 20 64 6f 75 62 6c |rking with doubl| 00002860 65 20 66 6c 6f 61 74 73 0a 3b 0a 0a 20 20 20 20 |e floats.;.. | 00002870 20 20 20 20 45 58 50 4f 52 54 20 20 73 69 6e 31 | EXPORT sin1| 00002880 36 0a 0a 73 6e 6e 73 74 61 20 20 44 43 42 20 20 |6..snnsta DCB | 00002890 20 20 20 22 73 69 6e 31 36 22 2c 20 30 0a 20 20 | "sin16", 0. | 000028a0 20 20 20 20 20 20 41 4c 49 47 4e 0a 73 6e 6e 65 | ALIGN.snne| 000028b0 6e 64 20 20 44 43 44 20 20 20 20 20 26 66 66 30 |nd DCD &ff0| 000028c0 30 30 30 30 30 20 2b 20 73 6e 6e 65 6e 64 20 2d |00000 + snnend -| 000028d0 20 73 6e 6e 73 74 61 0a 0a 73 69 6e 31 36 0a 0a | snnsta..sin16..| 000028e0 09 54 53 54 09 61 31 2c 20 23 26 32 30 30 30 30 |.TST.a1, #&20000| 000028f0 09 09 3b 65 76 61 6c 20 6f 66 20 73 69 6e 20 69 |..;eval of sin i| 00002900 73 20 61 6c 6d 6f 73 74 20 69 64 65 6e 74 69 63 |s almost identic| 00002910 61 6c 20 74 6f 20 74 68 61 74 20 6f 66 20 63 6f |al to that of co| 00002920 73 0a 09 4d 4f 56 09 61 34 2c 20 23 30 0a 09 4d |s..MOV.a4, #0..M| 00002930 4f 56 4e 45 09 61 34 2c 20 23 31 0a 09 54 53 54 |OVNE.a4, #1..TST| 00002940 09 61 31 2c 20 23 26 31 30 30 30 30 0a 09 4d 4f |.a1, #&10000..MO| 00002950 56 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 31 |V.a1, a1, LSL #1| 00002960 36 0a 09 4d 4f 56 09 61 31 2c 20 61 31 2c 20 4c |6..MOV.a1, a1, L| 00002970 53 52 20 23 31 36 0a 09 52 53 42 4e 45 09 61 31 |SR #16..RSBNE.a1| 00002980 2c 20 61 31 2c 20 23 26 31 30 30 30 30 0a 09 4d |, a1, #&10000..M| 00002990 4f 56 09 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 |OV.a1, a1, LSL #| 000029a0 31 0a 09 53 55 42 09 61 31 2c 20 61 31 2c 20 23 |1..SUB.a1, a1, #| 000029b0 26 31 30 30 30 30 0a 09 52 53 42 09 61 32 2c 20 |&10000..RSB.a2, | 000029c0 61 31 2c 20 61 31 2c 20 4c 53 4c 20 23 33 0a 09 |a1, a1, LSL #3..| 000029d0 41 44 44 09 61 32 2c 20 61 31 2c 20 61 32 2c 20 |ADD.a2, a1, a2, | 000029e0 4c 53 4c 20 23 38 0a 09 4d 4f 56 09 61 32 2c 20 |LSL #8..MOV.a2, | 000029f0 61 32 2c 20 41 53 52 20 23 31 36 0a 09 41 44 44 |a2, ASR #16..ADD| 00002a00 09 61 32 2c 20 61 32 2c 20 23 26 30 30 32 63 30 |.a2, a2, #&002c0| 00002a10 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |0..ADD.a2, a2, #| 00002a20 26 30 30 30 30 38 36 0a 20 20 20 20 20 20 20 20 |&000086. | 00002a30 4d 4f 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 |MOV.ip, a1..mul1| 00002a40 36 63 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 |6c.a2, ip, a2, a| 00002a50 33 0a 09 53 55 42 09 61 32 2c 20 61 32 2c 20 23 |3..SUB.a2, a2, #| 00002a60 26 30 30 65 39 30 30 0a 09 53 55 42 09 61 32 2c |&00e900..SUB.a2,| 00002a70 20 61 32 2c 20 23 26 30 30 30 30 62 64 0a 20 20 | a2, #&0000bd. | 00002a80 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 | MOV.ip, a1| 00002a90 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c |..mul16c.a2, ip,| 00002aa0 20 61 32 2c 20 61 33 0a 09 53 55 42 09 61 32 2c | a2, a3..SUB.a2,| 00002ab0 20 61 32 2c 20 23 26 30 33 30 30 30 30 0a 09 53 | a2, #&030000..S| 00002ac0 55 42 09 61 32 2c 20 61 32 2c 20 23 26 30 30 37 |UB.a2, a2, #&007| 00002ad0 63 30 30 0a 09 53 55 42 09 61 32 2c 20 61 32 2c |c00..SUB.a2, a2,| 00002ae0 20 23 26 30 30 30 30 63 36 0a 20 20 20 20 20 20 | #&0000c6. | 00002af0 20 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 6d 75 | MOV.ip, a1..mu| 00002b00 6c 31 36 63 09 61 32 2c 20 69 70 2c 20 61 32 2c |l16c.a2, ip, a2,| 00002b10 20 61 33 0a 09 41 44 44 09 61 32 2c 20 61 32 2c | a3..ADD.a2, a2,| 00002b20 20 23 26 30 38 30 30 30 30 0a 09 41 44 44 09 61 | #&080000..ADD.a| 00002b30 32 2c 20 61 32 2c 20 23 26 30 30 45 32 30 30 0a |2, a2, #&00E200.| 00002b40 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00002b50 30 30 30 42 44 0a 20 20 20 20 20 20 20 20 4d 4f |000BD. MO| 00002b60 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 |V.ip, a1..mul16c| 00002b70 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a |.a2, ip, a2, a3.| 00002b80 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00002b90 62 30 30 30 30 0a 09 41 44 44 09 61 32 2c 20 61 |b0000..ADD.a2, a| 00002ba0 32 2c 20 23 26 30 30 35 30 30 30 0a 09 41 44 44 |2, #&005000..ADD| 00002bb0 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 35 |.a2, a2, #&00005| 00002bc0 30 0a 09 4d 4f 56 09 61 31 2c 20 61 32 2c 20 41 |0..MOV.a1, a2, A| 00002bd0 53 52 20 23 34 0a 09 54 53 54 09 61 34 2c 20 23 |SR #4..TST.a4, #| 00002be0 31 0a 09 52 53 42 4e 45 09 61 31 2c 20 61 31 2c |1..RSBNE.a1, a1,| 00002bf0 20 23 30 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 | #0. MOVS| 00002c00 20 20 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 3b 20 | pc, lr....; | 00002c10 61 63 73 31 36 0a 3b 20 61 20 6c 65 61 66 20 41 |acs16.; a leaf A| 00002c20 50 43 53 20 66 75 6e 63 74 69 6f 6e 0a 3b 0a 3b |PCS function.;.;| 00002c30 20 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a 3b 20 | C prototype:.; | 00002c40 69 6e 74 20 61 63 73 31 36 28 69 6e 74 20 61 29 |int acs16(int a)| 00002c50 0a 3b 0a 3b 20 72 65 74 75 72 6e 73 20 36 35 35 |.;.; returns 655| 00002c60 33 36 20 2a 20 32 2f 70 69 20 2a 20 61 72 63 63 |36 * 2/pi * arcc| 00002c70 6f 73 20 28 61 2f 36 35 35 33 36 29 0a 3b 0a 3b |os (a/65536).;.;| 00002c80 20 66 6f 72 20 61 20 6f 75 74 20 6f 66 20 72 61 | for a out of ra| 00002c90 6e 67 65 20 28 69 65 20 61 62 73 20 61 20 3e 20 |nge (ie abs a > | 00002ca0 36 35 35 33 36 29 2c 20 72 65 73 65 74 20 61 20 |65536), reset a | 00002cb0 74 6f 20 b1 36 35 35 33 36 20 61 73 20 61 70 70 |to .65536 as app| 00002cc0 72 6f 70 72 69 61 74 65 20 62 65 66 6f 72 65 20 |ropriate before | 00002cd0 65 76 61 6c 0a 3b 0a 3b 20 69 73 20 61 62 6f 75 |eval.;.; is abou| 00002ce0 74 20 32 34 20 74 69 6d 65 73 20 66 61 73 74 65 |t 24 times faste| 00002cf0 72 20 74 68 61 6e 20 46 50 45 6d 75 6c 61 74 6f |r than FPEmulato| 00002d00 72 20 77 6f 72 6b 69 6e 67 20 77 69 74 68 20 64 |r working with d| 00002d10 6f 75 62 6c 65 20 66 6c 6f 61 74 73 0a 3b 0a 0a |ouble floats.;..| 00002d20 20 20 20 20 20 20 20 20 45 58 50 4f 52 54 20 20 | EXPORT | 00002d30 61 63 73 31 36 0a 0a 61 63 6e 73 74 61 20 20 44 |acs16..acnsta D| 00002d40 43 42 20 20 20 20 20 22 61 63 73 31 36 22 2c 20 |CB "acs16", | 00002d50 30 0a 20 20 20 20 20 20 20 20 41 4c 49 47 4e 0a |0. ALIGN.| 00002d60 61 63 6e 65 6e 64 20 20 44 43 44 20 20 20 20 20 |acnend DCD | 00002d70 26 66 66 30 30 30 30 30 30 20 2b 20 61 63 6e 65 |&ff000000 + acne| 00002d80 6e 64 20 2d 20 61 63 6e 73 74 61 0a 0a 61 63 73 |nd - acnsta..acs| 00002d90 31 36 0a 0a 09 43 4d 50 09 61 31 2c 20 23 36 35 |16...CMP.a1, #65| 00002da0 35 33 36 0a 09 4d 4f 56 47 45 09 61 31 2c 20 23 |536..MOVGE.a1, #| 00002db0 30 0a 09 4d 4f 56 47 45 53 09 70 63 2c 20 6c 72 |0..MOVGES.pc, lr| 00002dc0 0a 09 43 4d 50 09 61 31 2c 20 23 2d 36 35 35 33 |..CMP.a1, #-6553| 00002dd0 36 0a 09 4d 4f 56 4c 45 09 61 31 2c 20 23 32 2a |6..MOVLE.a1, #2*| 00002de0 36 35 35 33 36 0a 09 4d 4f 56 4c 45 53 09 70 63 |65536..MOVLES.pc| 00002df0 2c 20 6c 72 0a 09 53 54 4d 46 44 09 73 70 21 2c |, lr..STMFD.sp!,| 00002e00 20 7b 6c 72 7d 09 09 3b 6e 6f 77 20 68 61 76 65 | {lr}..;now have| 00002e10 20 61 72 67 20 69 6e 20 72 61 6e 67 65 20 28 2d | arg in range (-| 00002e20 6f 6e 65 2c 6f 6e 65 29 0a 09 43 4d 50 09 61 31 |one,one)..CMP.a1| 00002e30 2c 20 23 30 0a 09 52 53 42 4d 49 09 61 31 2c 20 |, #0..RSBMI.a1, | 00002e40 61 31 2c 20 23 30 0a 09 4d 4f 56 4d 49 09 61 34 |a1, #0..MOVMI.a4| 00002e50 2c 20 23 31 09 09 09 3b 62 30 20 69 6e 20 61 34 |, #1...;b0 in a4| 00002e60 20 73 65 74 20 69 66 66 20 66 69 6e 61 6c 20 72 | set iff final r| 00002e70 65 73 75 6c 74 20 72 20 6e 65 65 64 73 20 72 65 |esult r needs re| 00002e80 70 6c 61 63 69 6e 67 20 62 79 20 32 2a 6f 6e 65 |placing by 2*one| 00002e90 2d 72 0a 09 4d 4f 56 50 4c 09 61 34 2c 20 23 30 |-r..MOVPL.a4, #0| 00002ea0 09 09 09 3b 6e 6f 77 20 68 61 76 65 20 61 72 67 |...;now have arg| 00002eb0 20 69 6e 20 72 61 6e 67 65 20 5b 30 2c 6f 6e 65 | in range [0,one| 00002ec0 29 0a 09 53 55 42 09 61 32 2c 20 61 31 2c 20 23 |)..SUB.a2, a1, #| 00002ed0 26 62 35 30 30 0a 09 53 55 42 53 09 61 32 2c 20 |&b500..SUBS.a2, | 00002ee0 61 32 2c 20 23 26 30 30 30 35 0a 09 42 4c 54 09 |a2, #&0005..BLT.| 00002ef0 61 63 73 31 36 5f 61 72 67 6c 6f 77 09 09 3b 69 |acs16_arglow..;i| 00002f00 66 20 61 72 67 20 3c 20 6f 6e 65 2f 73 71 72 74 |f arg < one/sqrt| 00002f10 32 20 67 6f 20 61 6e 64 20 61 70 70 6c 79 20 70 |2 go and apply p| 00002f20 6f 6c 79 20 65 6c 73 65 20 66 69 72 73 74 20 74 |oly else first t| 00002f30 72 61 6e 73 6d 75 74 65 20 69 6e 74 6f 20 68 65 |ransmute into he| 00002f40 72 65 0a 09 4f 52 52 09 61 34 2c 20 61 34 2c 20 |re..ORR.a4, a4, | 00002f50 23 32 09 09 3b 62 31 20 69 6e 20 61 34 20 63 6c |#2..;b1 in a4 cl| 00002f60 65 61 72 20 69 66 66 20 70 65 6e 75 6c 74 69 6d |ear iff penultim| 00002f70 61 74 65 20 72 65 73 75 6c 74 20 72 20 6e 65 65 |ate result r nee| 00002f80 64 20 62 65 20 72 65 70 6c 61 63 65 64 20 62 79 |d be replaced by| 00002f90 20 6f 6e 65 2d 72 0a 09 4d 55 4c 09 61 32 2c 20 | one-r..MUL.a2, | 00002fa0 61 31 2c 20 61 31 0a 09 4d 4f 56 09 61 31 2c 20 |a1, a1..MOV.a1, | 00002fb0 61 32 2c 20 4c 53 52 20 23 31 36 0a 09 52 53 42 |a2, LSR #16..RSB| 00002fc0 09 61 31 2c 20 61 31 2c 20 23 36 35 35 33 36 0a |.a1, a1, #65536.| 00002fd0 09 73 71 72 74 31 36 09 61 31 2c 20 61 31 2c 20 |.sqrt16.a1, a1, | 00002fe0 61 32 2c 20 61 33 2c 20 69 70 2c 20 6c 72 09 3b |a2, a3, ip, lr.;| 00002ff0 61 72 67 20 74 72 61 6e 73 6d 75 74 65 64 20 28 |arg transmuted (| 00003000 69 65 20 72 65 70 6c 61 63 65 64 20 62 79 20 6f |ie replaced by o| 00003010 6e 65 2d 73 71 72 74 28 61 72 67 5e 32 29 29 0a |ne-sqrt(arg^2)).| 00003020 61 63 73 31 36 5f 61 72 67 6c 6f 77 0a 09 41 44 |acs16_arglow..AD| 00003030 44 09 61 33 2c 20 61 31 2c 20 61 31 2c 20 41 53 |D.a3, a1, a1, AS| 00003040 4c 20 23 32 0a 09 41 44 44 09 61 32 2c 20 61 33 |L #2..ADD.a2, a3| 00003050 2c 20 61 31 2c 20 41 53 4c 20 23 34 0a 09 41 44 |, a1, ASL #4..AD| 00003060 44 09 61 32 2c 20 61 32 2c 20 61 33 2c 20 41 53 |D.a2, a2, a3, AS| 00003070 4c 20 23 35 0a 09 41 44 44 09 61 32 2c 20 61 32 |L #5..ADD.a2, a2| 00003080 2c 20 61 33 2c 20 41 53 52 09 23 38 0a 09 41 44 |, a3, ASR.#8..AD| 00003090 44 09 61 32 2c 20 61 32 2c 20 23 33 32 0a 09 4d |D.a2, a2, #32..M| 000030a0 4f 56 09 61 31 2c 20 61 32 2c 20 41 53 52 20 23 |OV.a1, a2, ASR #| 000030b0 36 09 09 3b 72 61 6e 67 65 20 74 72 61 6e 73 66 |6..;range transf| 000030c0 6f 72 6d 20 61 70 70 6c 69 65 64 20 28 69 65 20 |orm applied (ie | 000030d0 72 65 70 6c 61 63 65 64 20 62 79 20 61 72 67 2a |replaced by arg*| 000030e0 32 73 71 72 74 32 2d 6f 6e 65 29 0a 09 53 55 42 |2sqrt2-one)..SUB| 000030f0 09 61 31 2c 20 61 31 2c 20 23 26 31 30 30 30 30 |.a1, a1, #&10000| 00003100 09 09 3b 73 6f 20 61 72 67 20 6c 69 65 73 20 69 |..;so arg lies i| 00003110 6e 20 72 61 6e 67 65 20 5b 2d 31 2c 31 5d 0a 09 |n range [-1,1]..| 00003120 41 44 44 09 61 32 2c 20 61 31 2c 20 61 31 2c 20 |ADD.a2, a1, a1, | 00003130 4c 53 4c 20 23 32 09 3b 6e 6f 77 20 61 70 70 6c |LSL #2.;now appl| 00003140 79 20 70 6f 6c 79 0a 09 41 44 44 09 61 32 2c 20 |y poly..ADD.a2, | 00003150 61 32 2c 20 61 32 2c 20 4c 53 4c 20 23 35 0a 09 |a2, a2, LSL #5..| 00003160 4d 4f 56 09 61 32 2c 20 61 32 2c 20 41 53 52 20 |MOV.a2, a2, ASR | 00003170 23 31 34 0a 09 41 44 44 09 61 32 2c 20 61 32 2c |#14..ADD.a2, a2,| 00003180 20 23 26 30 30 30 35 30 30 0a 09 41 44 44 09 61 | #&000500..ADD.a| 00003190 32 2c 20 61 32 2c 20 23 26 30 30 30 30 61 65 0a |2, a2, #&0000ae.| 000031a0 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 | MOV.ip, | 000031b0 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 |a1..mul16c.a2, i| 000031c0 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 44 09 61 |p, a2, a3..ADD.a| 000031d0 32 2c 20 61 32 2c 20 23 26 30 30 30 38 30 30 0a |2, a2, #&000800.| 000031e0 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 000031f0 30 30 30 38 38 0a 20 20 20 20 20 20 20 20 4d 4f |00088. MO| 00003200 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 |V.ip, a1..mul16c| 00003210 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a |.a2, ip, a2, a3.| 00003220 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 |.ADD.a2, a2, #&0| 00003230 30 32 30 30 30 0a 09 41 44 44 09 61 32 2c 20 61 |02000..ADD.a2, a| 00003240 32 2c 20 23 26 30 30 30 30 39 61 0a 20 20 20 20 |2, #&00009a. | 00003250 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 | MOV.ip, a1..| 00003260 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c 20 61 |mul16c.a2, ip, a| 00003270 32 2c 20 61 33 0a 09 41 44 44 09 61 32 2c 20 61 |2, a3..ADD.a2, a| 00003280 32 2c 20 23 26 30 30 34 36 30 30 0a 09 41 44 44 |2, #&004600..ADD| 00003290 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 39 |.a2, a2, #&00009| 000032a0 61 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 |a. MOV.ip| 000032b0 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c |, a1..mul16c.a2,| 000032c0 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 44 | ip, a2, a3..ADD| 000032d0 09 61 32 2c 20 61 32 2c 20 23 26 30 33 30 30 30 |.a2, a2, #&03000| 000032e0 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |0..ADD.a2, a2, #| 000032f0 26 30 30 64 39 30 30 0a 09 41 44 44 09 61 32 2c |&00d900..ADD.a2,| 00003300 20 61 32 2c 20 23 26 30 30 30 30 62 34 0a 20 20 | a2, #&0000b4. | 00003310 20 20 20 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 | MOV.ip, a1| 00003320 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 69 70 2c |..mul16c.a2, ip,| 00003330 20 61 32 2c 20 61 33 0a 09 41 44 44 09 61 32 2c | a2, a3..ADD.a2,| 00003340 20 61 32 2c 20 23 26 30 33 30 30 30 30 0a 09 41 | a2, #&030000..A| 00003350 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 61 |DD.a2, a2, #&00a| 00003360 65 30 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c |e00..ADD.a2, a2,| 00003370 20 23 26 30 30 30 30 35 32 0a 09 4d 4f 56 09 61 | #&000052..MOV.a| 00003380 31 2c 20 61 32 2c 20 41 53 52 20 23 34 0a 09 54 |1, a2, ASR #4..T| 00003390 53 54 09 61 34 2c 20 23 32 0a 09 52 53 42 45 51 |ST.a4, #2..RSBEQ| 000033a0 09 61 31 2c 20 61 31 2c 20 23 36 35 35 33 36 0a |.a1, a1, #65536.| 000033b0 09 54 53 54 09 61 34 2c 20 23 31 0a 09 52 53 42 |.TST.a4, #1..RSB| 000033c0 4e 45 09 61 31 2c 20 61 31 2c 20 23 32 2a 36 35 |NE.a1, a1, #2*65| 000033d0 35 33 36 0a 09 4c 44 4d 46 44 09 73 70 21 2c 20 |536..LDMFD.sp!, | 000033e0 7b 70 63 7d 5e 0a 0a 0a 0a 3b 20 61 73 6e 31 36 |{pc}^....; asn16| 000033f0 0a 3b 20 61 20 6c 65 61 66 20 41 50 43 53 20 66 |.; a leaf APCS f| 00003400 75 6e 63 74 69 6f 6e 0a 3b 0a 3b 20 43 20 70 72 |unction.;.; C pr| 00003410 6f 74 6f 74 79 70 65 3a 0a 3b 20 69 6e 74 20 61 |ototype:.; int a| 00003420 73 6e 31 36 28 69 6e 74 20 61 29 0a 3b 0a 3b 20 |sn16(int a).;.; | 00003430 72 65 74 75 72 6e 73 20 36 35 35 33 36 20 2a 20 |returns 65536 * | 00003440 32 2f 70 69 20 2a 20 61 72 63 73 69 6e 20 28 61 |2/pi * arcsin (a| 00003450 2f 36 35 35 33 36 29 0a 3b 0a 3b 20 66 6f 72 20 |/65536).;.; for | 00003460 61 20 6f 75 74 20 6f 66 20 72 61 6e 67 65 20 28 |a out of range (| 00003470 69 65 20 61 62 73 20 61 20 3e 20 36 35 35 33 36 |ie abs a > 65536| 00003480 29 2c 20 72 65 73 65 74 20 61 20 74 6f 20 b1 36 |), reset a to .6| 00003490 35 35 33 36 20 61 73 20 61 70 70 72 6f 70 72 69 |5536 as appropri| 000034a0 61 74 65 20 62 65 66 6f 72 65 20 65 76 61 6c 0a |ate before eval.| 000034b0 3b 0a 3b 20 69 73 20 61 62 6f 75 74 20 32 34 20 |;.; is about 24 | 000034c0 74 69 6d 65 73 20 66 61 73 74 65 72 20 74 68 61 |times faster tha| 000034d0 6e 20 46 50 45 6d 75 6c 61 74 6f 72 20 77 6f 72 |n FPEmulator wor| 000034e0 6b 69 6e 67 20 77 69 74 68 20 64 6f 75 62 6c 65 |king with double| 000034f0 20 66 6c 6f 61 74 73 0a 3b 0a 0a 20 20 20 20 20 | floats.;.. | 00003500 20 20 20 45 58 50 4f 52 54 20 20 61 73 6e 31 36 | EXPORT asn16| 00003510 0a 0a 61 73 6e 73 74 61 20 20 44 43 42 20 20 20 |..asnsta DCB | 00003520 20 20 22 61 73 6e 31 36 22 2c 20 30 0a 20 20 20 | "asn16", 0. | 00003530 20 20 20 20 20 41 4c 49 47 4e 0a 61 73 6e 65 6e | ALIGN.asnen| 00003540 64 20 20 44 43 44 20 20 20 20 20 26 66 66 30 30 |d DCD &ff00| 00003550 30 30 30 30 20 2b 20 61 73 6e 65 6e 64 20 2d 20 |0000 + asnend - | 00003560 61 73 6e 73 74 61 0a 0a 61 73 6e 31 36 0a 0a 09 |asnsta..asn16...| 00003570 43 4d 50 09 61 31 2c 20 23 36 35 35 33 36 0a 09 |CMP.a1, #65536..| 00003580 4d 4f 56 47 45 09 61 31 2c 20 23 36 35 35 33 36 |MOVGE.a1, #65536| 00003590 0a 09 4d 4f 56 47 45 53 09 70 63 2c 20 6c 72 0a |..MOVGES.pc, lr.| 000035a0 09 41 44 44 53 09 61 32 2c 20 61 31 2c 20 23 36 |.ADDS.a2, a1, #6| 000035b0 35 35 33 36 09 09 3b 65 71 75 69 76 20 74 6f 20 |5536..;equiv to | 000035c0 43 4d 50 20 61 31 2c 23 2d 36 35 35 33 36 0a 09 |CMP a1,#-65536..| 000035d0 53 55 42 4c 45 09 61 31 2c 20 61 31 2c 20 61 32 |SUBLE.a1, a1, a2| 000035e0 09 09 3b 65 71 75 69 76 20 74 6f 20 4d 4f 56 4c |..;equiv to MOVL| 000035f0 45 20 61 31 2c 23 2d 36 35 35 33 36 20 28 77 68 |E a1,#-65536 (wh| 00003600 69 63 68 20 77 6f 75 6c 64 6e 27 74 20 77 6f 72 |ich wouldn't wor| 00003610 6b 20 64 75 65 20 74 6f 20 62 61 64 20 63 6f 6e |k due to bad con| 00003620 73 74 61 6e 74 29 0a 09 4d 4f 56 4c 45 53 09 70 |stant)..MOVLES.p| 00003630 63 2c 20 6c 72 0a 09 53 54 4d 46 44 09 73 70 21 |c, lr..STMFD.sp!| 00003640 2c 20 7b 6c 72 7d 09 09 3b 6e 6f 77 20 68 61 76 |, {lr}..;now hav| 00003650 65 20 61 72 67 20 69 6e 20 72 61 6e 67 65 20 28 |e arg in range (| 00003660 2d 6f 6e 65 2c 6f 6e 65 29 0a 09 43 4d 50 09 61 |-one,one)..CMP.a| 00003670 31 2c 20 23 30 0a 09 52 53 42 4d 49 09 61 31 2c |1, #0..RSBMI.a1,| 00003680 20 61 31 2c 20 23 30 0a 09 4d 4f 56 4d 49 09 61 | a1, #0..MOVMI.a| 00003690 34 2c 20 23 31 09 09 09 3b 62 30 20 69 6e 20 61 |4, #1...;b0 in a| 000036a0 34 20 73 65 74 20 69 66 66 20 66 69 6e 61 6c 20 |4 set iff final | 000036b0 72 65 73 75 6c 74 20 6e 65 65 64 73 20 6e 65 67 |result needs neg| 000036c0 61 74 69 6e 67 0a 09 4d 4f 56 50 4c 09 61 34 2c |ating..MOVPL.a4,| 000036d0 20 23 30 09 09 09 3b 6e 6f 77 20 68 61 76 65 20 | #0...;now have | 000036e0 61 72 67 20 69 6e 20 72 61 6e 67 65 20 5b 30 2c |arg in range [0,| 000036f0 6f 6e 65 29 0a 09 53 55 42 09 61 32 2c 20 61 31 |one)..SUB.a2, a1| 00003700 2c 20 23 26 62 35 30 30 0a 09 53 55 42 53 09 61 |, #&b500..SUBS.a| 00003710 32 2c 20 61 32 2c 20 23 26 30 30 30 35 0a 09 42 |2, a2, #&0005..B| 00003720 4c 54 09 61 73 6e 31 36 5f 61 72 67 6c 6f 77 09 |LT.asn16_arglow.| 00003730 09 3b 69 66 20 61 72 67 20 3c 20 6f 6e 65 2f 73 |.;if arg < one/s| 00003740 71 72 74 32 20 67 6f 20 61 6e 64 20 61 70 70 6c |qrt2 go and appl| 00003750 79 20 70 6f 6c 79 20 65 6c 73 65 20 66 69 72 73 |y poly else firs| 00003760 74 20 74 72 61 6e 73 6d 75 74 65 20 69 6e 74 6f |t transmute into| 00003770 20 68 65 72 65 0a 09 4f 52 52 09 61 34 2c 20 61 | here..ORR.a4, a| 00003780 34 2c 20 23 32 09 09 3b 62 31 20 69 6e 20 61 34 |4, #2..;b1 in a4| 00003790 20 73 65 74 20 69 66 66 20 70 65 6e 75 6c 74 69 | set iff penulti| 000037a0 6d 61 74 65 20 72 65 73 75 6c 74 20 72 20 6e 65 |mate result r ne| 000037b0 65 64 73 20 74 6f 20 62 65 20 72 65 70 6c 61 63 |eds to be replac| 000037c0 65 64 20 62 79 20 6f 6e 65 2d 72 0a 09 4d 55 4c |ed by one-r..MUL| 000037d0 09 61 32 2c 20 61 31 2c 20 61 31 0a 09 4d 4f 56 |.a2, a1, a1..MOV| 000037e0 09 61 31 2c 20 61 32 2c 20 4c 53 52 20 23 31 36 |.a1, a2, LSR #16| 000037f0 0a 09 52 53 42 09 61 31 2c 20 61 31 2c 20 23 36 |..RSB.a1, a1, #6| 00003800 35 35 33 36 0a 09 73 71 72 74 31 36 09 61 31 2c |5536..sqrt16.a1,| 00003810 20 61 31 2c 20 61 32 2c 20 61 33 2c 20 69 70 2c | a1, a2, a3, ip,| 00003820 20 6c 72 09 3b 61 72 67 20 74 72 61 6e 73 6d 75 | lr.;arg transmu| 00003830 74 65 64 20 28 69 65 20 72 65 70 6c 61 63 65 64 |ted (ie replaced| 00003840 20 62 79 20 6f 6e 65 2d 73 71 72 74 28 61 72 67 | by one-sqrt(arg| 00003850 5e 32 29 29 0a 61 73 6e 31 36 5f 61 72 67 6c 6f |^2)).asn16_arglo| 00003860 77 0a 09 41 44 44 09 61 33 2c 20 61 31 2c 20 61 |w..ADD.a3, a1, a| 00003870 31 2c 20 41 53 4c 20 23 32 0a 09 41 44 44 09 61 |1, ASL #2..ADD.a| 00003880 32 2c 20 61 33 2c 20 61 31 2c 20 41 53 4c 20 23 |2, a3, a1, ASL #| 00003890 34 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 61 |4..ADD.a2, a2, a| 000038a0 33 2c 20 41 53 4c 20 23 35 0a 09 41 44 44 09 61 |3, ASL #5..ADD.a| 000038b0 32 2c 20 61 32 2c 20 61 33 2c 20 41 53 52 09 23 |2, a2, a3, ASR.#| 000038c0 38 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 |8..ADD.a2, a2, #| 000038d0 33 32 0a 09 4d 4f 56 09 61 31 2c 20 61 32 2c 20 |32..MOV.a1, a2, | 000038e0 41 53 52 20 23 36 09 09 3b 72 61 6e 67 65 20 74 |ASR #6..;range t| 000038f0 72 61 6e 73 66 6f 72 6d 20 61 70 70 6c 69 65 64 |ransform applied| 00003900 20 28 69 65 20 72 65 70 6c 61 63 65 64 20 62 79 | (ie replaced by| 00003910 20 61 72 67 2a 32 73 71 72 74 32 2d 6f 6e 65 29 | arg*2sqrt2-one)| 00003920 0a 09 53 55 42 09 61 31 2c 20 61 31 2c 20 23 26 |..SUB.a1, a1, #&| 00003930 31 30 30 30 30 09 09 3b 73 6f 20 61 72 67 20 6c |10000..;so arg l| 00003940 69 65 73 20 69 6e 20 72 61 6e 67 65 20 5b 2d 31 |ies in range [-1| 00003950 2c 31 5d 0a 09 41 44 44 09 61 32 2c 20 61 31 2c |,1]..ADD.a2, a1,| 00003960 20 61 31 2c 20 4c 53 4c 20 23 32 09 3b 6e 6f 77 | a1, LSL #2.;now| 00003970 20 61 70 70 6c 79 20 70 6f 6c 79 0a 09 41 44 44 | apply poly..ADD| 00003980 09 61 32 2c 20 61 32 2c 20 61 32 2c 20 4c 53 4c |.a2, a2, a2, LSL| 00003990 20 23 35 0a 09 4d 4f 56 09 61 32 2c 20 61 32 2c | #5..MOV.a2, a2,| 000039a0 20 41 53 52 20 23 31 34 0a 09 41 44 44 09 61 32 | ASR #14..ADD.a2| 000039b0 2c 20 61 32 2c 20 23 26 30 30 30 35 30 30 0a 09 |, a2, #&000500..| 000039c0 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 |ADD.a2, a2, #&00| 000039d0 30 30 61 65 0a 20 20 20 20 20 20 20 20 4d 4f 56 |00ae. MOV| 000039e0 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 |.ip, a1..mul16c.| 000039f0 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 |a2, ip, a2, a3..| 00003a00 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 |ADD.a2, a2, #&00| 00003a10 30 38 30 30 0a 09 41 44 44 09 61 32 2c 20 61 32 |0800..ADD.a2, a2| 00003a20 2c 20 23 26 30 30 30 30 38 38 0a 20 20 20 20 20 |, #&000088. | 00003a30 20 20 20 4d 4f 56 09 69 70 2c 20 61 31 0a 09 6d | MOV.ip, a1..m| 00003a40 75 6c 31 36 63 09 61 32 2c 20 69 70 2c 20 61 32 |ul16c.a2, ip, a2| 00003a50 2c 20 61 33 0a 09 41 44 44 09 61 32 2c 20 61 32 |, a3..ADD.a2, a2| 00003a60 2c 20 23 26 30 30 32 30 30 30 0a 09 41 44 44 09 |, #&002000..ADD.| 00003a70 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 39 61 |a2, a2, #&00009a| 00003a80 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 69 70 2c |. MOV.ip,| 00003a90 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 2c 20 | a1..mul16c.a2, | 00003aa0 69 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 44 09 |ip, a2, a3..ADD.| 00003ab0 61 32 2c 20 61 32 2c 20 23 26 30 30 34 36 30 30 |a2, a2, #&004600| 00003ac0 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 |..ADD.a2, a2, #&| 00003ad0 30 30 30 30 39 61 0a 20 20 20 20 20 20 20 20 4d |00009a. M| 00003ae0 4f 56 09 69 70 2c 20 61 31 0a 09 6d 75 6c 31 36 |OV.ip, a1..mul16| 00003af0 63 09 61 32 2c 20 69 70 2c 20 61 32 2c 20 61 33 |c.a2, ip, a2, a3| 00003b00 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 23 26 |..ADD.a2, a2, #&| 00003b10 30 33 30 30 30 30 0a 09 41 44 44 09 61 32 2c 20 |030000..ADD.a2, | 00003b20 61 32 2c 20 23 26 30 30 64 39 30 30 0a 09 41 44 |a2, #&00d900..AD| 00003b30 44 09 61 32 2c 20 61 32 2c 20 23 26 30 30 30 30 |D.a2, a2, #&0000| 00003b40 62 34 0a 20 20 20 20 20 20 20 20 4d 4f 56 09 69 |b4. MOV.i| 00003b50 70 2c 20 61 31 0a 09 6d 75 6c 31 36 63 09 61 32 |p, a1..mul16c.a2| 00003b60 2c 20 69 70 2c 20 61 32 2c 20 61 33 0a 09 41 44 |, ip, a2, a3..AD| 00003b70 44 09 61 32 2c 20 61 32 2c 20 23 26 30 33 30 30 |D.a2, a2, #&0300| 00003b80 30 30 0a 09 41 44 44 09 61 32 2c 20 61 32 2c 20 |00..ADD.a2, a2, | 00003b90 23 26 30 30 61 65 30 30 0a 09 41 44 44 09 61 32 |#&00ae00..ADD.a2| 00003ba0 2c 20 61 32 2c 20 23 26 30 30 30 30 35 32 0a 09 |, a2, #&000052..| 00003bb0 4d 4f 56 09 61 31 2c 20 61 32 2c 20 41 53 52 20 |MOV.a1, a2, ASR | 00003bc0 23 34 0a 09 54 53 54 09 61 34 2c 20 23 32 0a 09 |#4..TST.a4, #2..| 00003bd0 52 53 42 4e 45 09 61 31 2c 20 61 31 2c 20 23 36 |RSBNE.a1, a1, #6| 00003be0 35 35 33 36 0a 09 54 53 54 09 61 34 2c 20 23 31 |5536..TST.a4, #1| 00003bf0 0a 09 52 53 42 4e 45 09 61 31 2c 20 61 31 2c 20 |..RSBNE.a1, a1, | 00003c00 23 30 0a 09 4c 44 4d 46 44 09 73 70 21 2c 20 7b |#0..LDMFD.sp!, {| 00003c10 70 63 7d 5e 0a 0a 0a 0a 3b 20 67 61 75 73 73 31 |pc}^....; gauss1| 00003c20 36 0a 3b 20 61 20 6c 65 61 66 20 41 50 43 53 20 |6.; a leaf APCS | 00003c30 66 75 6e 63 74 69 6f 6e 0a 3b 0a 3b 20 43 20 70 |function.;.; C p| 00003c40 72 6f 74 6f 74 79 70 65 3a 0a 3b 20 69 6e 74 20 |rototype:.; int | 00003c50 67 61 75 73 73 31 36 28 76 6f 69 64 29 0a 3b 0a |gauss16(void).;.| 00003c60 3b 20 72 65 74 75 72 6e 73 20 36 35 35 33 36 20 |; returns 65536 | 00003c70 2a 20 28 20 70 73 65 75 64 6f 20 72 61 6e 64 6f |* ( pseudo rando| 00003c80 6e 20 76 61 72 69 61 62 6c 65 20 77 69 74 68 20 |n variable with | 00003c90 61 70 70 72 6f 78 69 6d 61 74 65 20 64 69 73 74 |approximate dist| 00003ca0 72 69 62 75 74 69 6f 6e 20 4e 28 30 2c 31 29 20 |ribution N(0,1) | 00003cb0 29 0a 3b 20 6e 6f 74 65 2c 20 74 68 65 20 61 70 |).; note, the ap| 00003cc0 70 72 6f 78 69 6d 61 74 65 20 67 61 75 73 73 69 |proximate gaussi| 00003cd0 61 6e 20 64 69 73 74 72 69 62 75 74 69 6f 6e 20 |an distribution | 00003ce0 69 73 20 61 63 68 69 65 76 65 64 20 76 69 61 20 |is achieved via | 00003cf0 74 68 65 20 73 75 6d 20 6f 66 20 6e 20 70 73 65 |the sum of n pse| 00003d00 75 64 6f 20 55 5b 30 2c 36 35 35 33 35 5d 0a 3b |udo U[0,65535].;| 00003d10 20 20 20 20 20 20 20 72 61 6e 64 6f 6d 20 76 61 | random va| 00003d20 72 69 61 62 6c 65 73 20 26 20 61 70 70 6c 69 63 |riables & applic| 00003d30 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 63 65 6e |ation of the cen| 00003d40 74 72 61 6c 20 6c 69 6d 69 74 20 74 68 65 6f 72 |tral limit theor| 00003d50 65 6d 0a 3b 20 20 20 20 20 20 20 68 65 72 65 20 |em.; here | 00003d60 77 65 20 75 73 65 20 6e 3d 38 2c 20 67 69 76 69 |we use n=8, givi| 00003d70 6e 67 20 61 6e 20 61 63 74 75 61 6c 20 72 61 6e |ng an actual ran| 00003d80 67 65 20 6f 66 20 b1 28 73 71 72 74 32 34 29 20 |ge of .(sqrt24) | 00003d90 28 2a 36 35 35 33 36 29 2e 0a 3b 0a 3b 20 20 20 |(*65536)..;.; | 00003da0 20 20 20 20 66 6f 72 20 67 65 6e 65 72 61 6c 20 | for general | 00003db0 6e 2c 20 72 65 63 61 6c 6c 20 77 65 20 6e 65 65 |n, recall we nee| 00003dc0 64 20 74 6f 20 72 65 74 75 72 6e 3a 0a 3b 20 20 |d to return:.; | 00003dd0 20 20 20 20 20 28 73 75 6d 20 6e 20 55 5b 30 2c | (sum n U[0,| 00003de0 36 35 35 33 35 5d 20 72 61 6e 64 6f 6d 20 76 61 |65535] random va| 00003df0 72 69 61 62 6c 65 73 29 20 2a 20 32 73 71 72 74 |riables) * 2sqrt| 00003e00 28 33 6e 29 2a 36 35 35 33 36 2f 28 36 35 35 33 |(3n)*65536/(6553| 00003e10 35 6e 29 20 20 2d 20 20 73 71 72 74 28 33 6e 29 |5n) - sqrt(3n)| 00003e20 2a 36 35 35 33 36 0a 3b 0a 0a 09 45 58 50 4f 52 |*65536.;...EXPOR| 00003e30 54 09 67 61 75 73 73 31 36 0a 0a 67 61 6e 73 74 |T.gauss16..ganst| 00003e40 61 20 20 44 43 42 20 20 20 20 20 22 67 61 75 73 |a DCB "gaus| 00003e50 73 31 36 22 2c 20 30 0a 20 20 20 20 20 20 20 20 |s16", 0. | 00003e60 41 4c 49 47 4e 0a 67 61 6e 65 6e 64 20 20 44 43 |ALIGN.ganend DC| 00003e70 44 20 20 20 20 20 26 66 66 30 30 30 30 30 30 20 |D &ff000000 | 00003e80 2b 20 67 61 6e 65 6e 64 20 2d 20 67 61 6e 73 74 |+ ganend - ganst| 00003e90 61 0a 0a 67 61 75 73 73 31 36 0a 0a 09 41 44 52 |a..gauss16...ADR| 00003ea0 09 61 31 2c 20 67 61 75 73 73 73 65 65 64 31 0a |.a1, gaussseed1.| 00003eb0 09 4c 44 4d 49 41 09 61 31 2c 20 7b 61 32 2c 20 |.LDMIA.a1, {a2, | 00003ec0 61 33 7d 0a 0a 09 4d 4f 56 53 20 20 20 20 61 33 |a3}...MOVS a3| 00003ed0 2c 20 61 33 2c 20 4c 53 52 20 23 31 0a 20 20 20 |, a3, LSR #1. | 00003ee0 20 20 20 20 20 4d 4f 56 53 20 20 20 20 61 34 2c | MOVS a4,| 00003ef0 20 61 32 2c 20 52 52 58 0a 20 20 20 20 20 20 20 | a2, RRX. | 00003f00 20 41 44 43 20 20 20 20 20 61 33 2c 20 61 33 2c | ADC a3, a3,| 00003f10 20 61 33 0a 20 20 20 20 20 20 20 20 45 4f 52 20 | a3. EOR | 00003f20 20 20 20 20 61 34 2c 20 61 34 2c 20 61 32 2c 20 | a4, a4, a2, | 00003f30 4c 53 4c 20 23 31 32 0a 20 20 20 20 20 20 20 20 |LSL #12. | 00003f40 45 4f 52 20 20 20 20 20 61 32 2c 20 61 34 2c 20 |EOR a2, a4, | 00003f50 61 34 2c 20 4c 53 52 20 23 32 30 0a 09 4d 4f 56 |a4, LSR #20..MOV| 00003f60 09 69 70 2c 20 61 32 2c 20 4c 53 52 20 23 31 36 |.ip, a2, LSR #16| 00003f70 0a 09 4d 4f 56 09 61 34 2c 20 61 32 2c 20 4c 53 |..MOV.a4, a2, LS| 00003f80 4c 20 23 31 36 0a 09 41 44 44 09 69 70 2c 20 69 |L #16..ADD.ip, i| 00003f90 70 2c 20 61 34 2c 20 4c 53 52 20 23 31 36 0a 0a |p, a4, LSR #16..| 00003fa0 09 4d 4f 56 53 20 20 20 20 61 33 2c 20 61 33 2c |.MOVS a3, a3,| 00003fb0 20 4c 53 52 20 23 31 0a 20 20 20 20 20 20 20 20 | LSR #1. | 00003fc0 4d 4f 56 53 20 20 20 20 61 34 2c 20 61 32 2c 20 |MOVS a4, a2, | 00003fd0 52 52 58 0a 20 20 20 20 20 20 20 20 41 44 43 20 |RRX. ADC | 00003fe0 20 20 20 20 61 33 2c 20 61 33 2c 20 61 33 0a 20 | a3, a3, a3. | 00003ff0 20 20 20 20 20 20 20 45 4f 52 20 20 20 20 20 61 | EOR a| 00004000 34 2c 20 61 34 2c 20 61 32 2c 20 4c 53 4c 20 23 |4, a4, a2, LSL #| 00004010 31 32 0a 20 20 20 20 20 20 20 20 45 4f 52 20 20 |12. EOR | 00004020 20 20 20 61 32 2c 20 61 34 2c 20 61 34 2c 20 4c | a2, a4, a4, L| 00004030 53 52 20 23 32 30 0a 09 41 44 44 09 69 70 2c 20 |SR #20..ADD.ip, | 00004040 69 70 2c 20 61 32 2c 20 4c 53 52 20 23 31 36 0a |ip, a2, LSR #16.| 00004050 09 4d 4f 56 09 61 34 2c 20 61 32 2c 20 4c 53 4c |.MOV.a4, a2, LSL| 00004060 20 23 31 36 0a 09 41 44 44 09 69 70 2c 20 69 70 | #16..ADD.ip, ip| 00004070 2c 20 61 34 2c 20 4c 53 52 20 23 31 36 0a 0a 09 |, a4, LSR #16...| 00004080 4d 4f 56 53 20 20 20 20 61 33 2c 20 61 33 2c 20 |MOVS a3, a3, | 00004090 4c 53 52 20 23 31 0a 20 20 20 20 20 20 20 20 4d |LSR #1. M| 000040a0 4f 56 53 20 20 20 20 61 34 2c 20 61 32 2c 20 52 |OVS a4, a2, R| 000040b0 52 58 0a 20 20 20 20 20 20 20 20 41 44 43 20 20 |RX. ADC | 000040c0 20 20 20 61 33 2c 20 61 33 2c 20 61 33 0a 20 20 | a3, a3, a3. | 000040d0 20 20 20 20 20 20 45 4f 52 20 20 20 20 20 61 34 | EOR a4| 000040e0 2c 20 61 34 2c 20 61 32 2c 20 4c 53 4c 20 23 31 |, a4, a2, LSL #1| 000040f0 32 0a 20 20 20 20 20 20 20 20 45 4f 52 20 20 20 |2. EOR | 00004100 20 20 61 32 2c 20 61 34 2c 20 61 34 2c 20 4c 53 | a2, a4, a4, LS| 00004110 52 20 23 32 30 0a 09 41 44 44 09 69 70 2c 20 69 |R #20..ADD.ip, i| 00004120 70 2c 20 61 32 2c 20 4c 53 52 20 23 31 36 0a 09 |p, a2, LSR #16..| 00004130 4d 4f 56 09 61 34 2c 20 61 32 2c 20 4c 53 4c 20 |MOV.a4, a2, LSL | 00004140 23 31 36 0a 09 41 44 44 09 69 70 2c 20 69 70 2c |#16..ADD.ip, ip,| 00004150 20 61 34 2c 20 4c 53 52 20 23 31 36 0a 0a 09 4d | a4, LSR #16...M| 00004160 4f 56 53 20 20 20 20 61 33 2c 20 61 33 2c 20 4c |OVS a3, a3, L| 00004170 53 52 20 23 31 0a 20 20 20 20 20 20 20 20 4d 4f |SR #1. MO| 00004180 56 53 20 20 20 20 61 34 2c 20 61 32 2c 20 52 52 |VS a4, a2, RR| 00004190 58 0a 20 20 20 20 20 20 20 20 41 44 43 20 20 20 |X. ADC | 000041a0 20 20 61 33 2c 20 61 33 2c 20 61 33 0a 20 20 20 | a3, a3, a3. | 000041b0 20 20 20 20 20 45 4f 52 20 20 20 20 20 61 34 2c | EOR a4,| 000041c0 20 61 34 2c 20 61 32 2c 20 4c 53 4c 20 23 31 32 | a4, a2, LSL #12| 000041d0 0a 20 20 20 20 20 20 20 20 45 4f 52 20 20 20 20 |. EOR | 000041e0 20 61 32 2c 20 61 34 2c 20 61 34 2c 20 4c 53 52 | a2, a4, a4, LSR| 000041f0 20 23 32 30 0a 09 41 44 44 09 69 70 2c 20 69 70 | #20..ADD.ip, ip| 00004200 2c 20 61 32 2c 20 4c 53 52 20 23 31 36 0a 09 4d |, a2, LSR #16..M| 00004210 4f 56 09 61 34 2c 20 61 32 2c 20 4c 53 4c 20 23 |OV.a4, a2, LSL #| 00004220 31 36 0a 09 41 44 44 09 69 70 2c 20 69 70 2c 20 |16..ADD.ip, ip, | 00004230 61 34 2c 20 4c 53 52 20 23 31 36 09 09 3b 73 75 |a4, LSR #16..;su| 00004240 6d 20 6e 6f 77 20 69 6e 20 69 70 0a 0a 09 53 54 |m now in ip...ST| 00004250 4d 49 41 09 61 31 2c 20 7b 61 32 2c 20 61 33 7d |MIA.a1, {a2, a3}| 00004260 0a 0a 09 52 53 42 09 61 31 2c 20 69 70 2c 20 69 |...RSB.a1, ip, i| 00004270 70 2c 20 41 53 4c 20 23 33 0a 09 52 53 42 09 61 |p, ASL #3..RSB.a| 00004280 32 2c 20 69 70 2c 20 69 70 2c 20 41 53 4c 20 23 |2, ip, ip, ASL #| 00004290 32 0a 09 41 44 44 09 61 31 2c 20 61 32 2c 20 61 |2..ADD.a1, a2, a| 000042a0 31 2c 20 41 53 4c 20 23 34 0a 09 41 44 44 09 61 |1, ASL #4..ADD.a| 000042b0 31 2c 20 61 31 2c 20 69 70 2c 20 41 53 4c 20 23 |1, a1, ip, ASL #| 000042c0 39 0a 09 41 44 44 09 61 32 2c 20 69 70 2c 20 69 |9..ADD.a2, ip, i| 000042d0 70 2c 20 41 53 4c 20 23 34 0a 09 41 44 44 09 61 |p, ASL #4..ADD.a| 000042e0 32 2c 20 61 32 2c 20 69 70 2c 20 41 53 4c 20 23 |2, a2, ip, ASL #| 000042f0 36 0a 09 41 44 44 09 61 31 2c 20 61 31 2c 20 61 |6..ADD.a1, a1, a| 00004300 32 2c 20 4c 53 52 20 23 31 30 0a 09 4d 4f 56 09 |2, LSR #10..MOV.| 00004310 61 31 2c 20 61 31 2c 20 4c 53 52 20 23 39 0a 09 |a1, a1, LSR #9..| 00004320 53 55 42 09 61 31 2c 20 61 31 2c 20 23 26 34 45 |SUB.a1, a1, #&4E| 00004330 30 30 30 0a 09 53 55 42 09 61 31 2c 20 61 31 2c |000..SUB.a1, a1,| 00004340 20 23 26 30 30 36 32 30 0a 09 53 55 42 09 61 31 | #&00620..SUB.a1| 00004350 2c 20 61 31 2c 20 23 26 30 30 30 30 34 0a 0a 20 |, a1, #&00004.. | 00004360 20 20 20 20 20 20 20 4d 4f 56 53 20 20 20 20 70 | MOVS p| 00004370 63 2c 20 6c 72 0a 0a 67 61 75 73 73 73 65 65 64 |c, lr..gaussseed| 00004380 31 09 44 43 44 09 2d 31 09 09 3b 62 69 74 73 20 |1.DCD.-1..;bits | 00004390 62 30 2d 62 33 31 20 6f 66 20 73 65 65 64 0a 09 |b0-b31 of seed..| 000043a0 09 44 43 44 09 2d 31 09 09 3b 62 69 74 20 20 62 |.DCD.-1..;bit b| 000043b0 33 32 20 6f 66 20 73 65 65 64 20 28 69 6e 20 6c |32 of seed (in l| 000043c0 73 62 20 6f 66 20 77 6f 72 64 29 0a 0a 3b 20 73 |sb of word)..; s| 000043d0 67 61 75 73 73 31 36 0a 3b 20 61 20 6c 65 61 66 |gauss16.; a leaf| 000043e0 20 41 50 43 53 20 66 75 6e 63 74 69 6f 6e 0a 3b | APCS function.;| 000043f0 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a |.; C prototype:.| 00004400 3b 20 76 6f 69 64 20 73 67 61 75 73 73 31 36 28 |; void sgauss16(| 00004410 69 6e 74 20 73 65 65 64 29 0a 3b 0a 3b 20 73 65 |int seed).;.; se| 00004420 74 73 20 74 68 65 20 73 65 65 64 20 66 6f 72 20 |ts the seed for | 00004430 67 61 75 73 73 31 36 0a 3b 0a 0a 09 45 58 50 4f |gauss16.;...EXPO| 00004440 52 54 09 73 67 61 75 73 73 31 36 0a 0a 73 67 6e |RT.sgauss16..sgn| 00004450 73 74 61 20 20 44 43 42 20 20 20 20 20 22 73 67 |sta DCB "sg| 00004460 61 75 73 73 31 36 22 2c 20 30 0a 20 20 20 20 20 |auss16", 0. | 00004470 20 20 20 41 4c 49 47 4e 0a 73 67 6e 65 6e 64 20 | ALIGN.sgnend | 00004480 20 44 43 44 20 20 20 20 20 26 66 66 30 30 30 30 | DCD &ff0000| 00004490 30 30 20 2b 20 73 67 6e 65 6e 64 20 2d 20 73 67 |00 + sgnend - sg| 000044a0 6e 73 74 61 0a 0a 73 67 61 75 73 73 31 36 0a 0a |nsta..sgauss16..| 000044b0 09 41 44 52 09 61 32 2c 20 67 61 75 73 73 73 65 |.ADR.a2, gaussse| 000044c0 65 64 31 0a 09 4d 4f 56 09 61 33 2c 20 23 31 0a |ed1..MOV.a3, #1.| 000044d0 09 53 54 4d 49 41 09 61 32 2c 20 7b 61 31 2c 20 |.STMIA.a2, {a1, | 000044e0 61 33 7d 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 |a3}. MOVS| 000044f0 20 20 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 3b 20 | pc, lr....; | 00004500 64 69 76 5f 66 72 61 63 31 36 0a 3b 20 61 20 6c |div_frac16.; a l| 00004510 65 61 66 20 41 50 43 53 20 66 75 6e 63 74 69 6f |eaf APCS functio| 00004520 6e 0a 3b 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 |n.;.; C prototyp| 00004530 65 3a 0a 3b 20 69 6e 74 20 64 69 76 5f 66 72 61 |e:.; int div_fra| 00004540 63 31 36 28 69 6e 74 20 6e 75 6d 62 65 72 2c 20 |c16(int number, | 00004550 69 6e 74 20 64 69 76 69 73 6f 72 29 0a 3b 0a 3b |int divisor).;.;| 00004560 20 72 65 74 75 72 6e 73 20 69 6e 74 65 67 65 72 | returns integer| 00004570 20 70 61 72 74 20 6f 66 20 36 35 35 33 36 2a 6e | part of 65536*n| 00004580 75 6d 62 65 72 2f 64 69 76 69 73 6f 72 0a 3b 20 |umber/divisor.; | 00004590 61 73 73 75 6d 65 73 20 61 62 73 20 6e 75 6d 62 |assumes abs numb| 000045a0 65 72 20 3c 20 36 35 35 33 36 20 2a 20 61 62 73 |er < 65536 * abs| 000045b0 20 64 69 76 69 73 6f 72 0a 3b 20 69 66 20 74 68 | divisor.; if th| 000045c0 69 73 20 6e 65 65 64 73 20 63 68 65 63 6b 69 6e |is needs checkin| 000045d0 67 2c 20 6d 75 73 74 20 62 65 20 64 6f 6e 65 20 |g, must be done | 000045e0 62 79 20 63 61 6c 6c 65 72 0a 3b 0a 0a 20 20 20 |by caller.;.. | 000045f0 20 20 20 20 20 45 58 50 4f 52 54 20 20 64 69 76 | EXPORT div| 00004600 5f 66 72 61 63 31 36 0a 0a 64 66 6e 73 74 61 20 |_frac16..dfnsta | 00004610 20 44 43 42 20 20 20 20 20 22 64 69 76 5f 66 72 | DCB "div_fr| 00004620 61 63 31 36 22 2c 20 30 0a 20 20 20 20 20 20 20 |ac16", 0. | 00004630 20 41 4c 49 47 4e 0a 64 66 6e 65 6e 64 20 20 44 | ALIGN.dfnend D| 00004640 43 44 20 20 20 20 20 26 66 66 30 30 30 30 30 30 |CD &ff000000| 00004650 20 2b 20 64 66 6e 65 6e 64 20 2d 20 64 66 6e 73 | + dfnend - dfns| 00004660 74 61 0a 0a 64 69 76 5f 66 72 61 63 31 36 0a 0a |ta..div_frac16..| 00004670 20 20 20 20 20 20 20 20 64 69 76 31 36 20 20 20 | div16 | 00004680 61 31 2c 20 61 32 2c 20 61 31 2c 20 61 33 2c 20 |a1, a2, a1, a3, | 00004690 61 34 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 20 |a4. MOVS | 000046a0 20 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 3b 20 6d | pc, lr....; m| 000046b0 75 6c 5f 66 72 61 63 31 36 0a 3b 20 61 20 6c 65 |ul_frac16.; a le| 000046c0 61 66 20 41 50 43 53 20 66 75 6e 63 74 69 6f 6e |af APCS function| 000046d0 0a 3b 0a 3b 20 43 20 70 72 6f 74 6f 74 79 70 65 |.;.; C prototype| 000046e0 3a 0a 3b 20 69 6e 74 20 6d 75 6c 5f 66 72 61 63 |:.; int mul_frac| 000046f0 31 36 28 69 6e 74 20 78 2c 20 69 6e 74 20 61 29 |16(int x, int a)| 00004700 0a 3b 0a 3b 20 72 65 74 75 72 6e 73 20 33 32 2d |.;.; returns 32-| 00004710 62 69 74 20 73 69 67 6e 65 64 20 69 6e 74 65 67 |bit signed integ| 00004720 65 72 20 78 2a 61 2f 36 35 35 33 36 0a 3b 20 61 |er x*a/65536.; a| 00004730 73 73 75 6d 65 73 20 72 65 73 75 6c 74 20 66 69 |ssumes result fi| 00004740 74 73 20 69 6e 74 6f 20 33 32 2d 62 69 74 20 73 |ts into 32-bit s| 00004750 69 67 6e 65 64 20 72 65 70 72 65 73 65 6e 74 61 |igned representa| 00004760 74 69 6f 6e 0a 3b 20 6e 6f 74 65 2c 20 6e 6f 20 |tion.; note, no | 00004770 6f 74 68 65 72 20 72 65 73 74 72 69 63 74 69 6f |other restrictio| 00004780 6e 73 20 6f 6e 20 61 20 2d 20 69 66 20 63 61 6e |ns on a - if can| 00004790 20 67 75 61 72 61 6e 74 65 65 20 61 62 73 20 61 | guarantee abs a| 000047a0 20 3c 20 36 35 35 33 36 2c 20 75 73 65 20 6d 75 | < 65536, use mu| 000047b0 6c 5f 66 72 61 63 31 36 63 20 69 6e 73 74 65 61 |l_frac16c instea| 000047c0 64 20 61 73 20 69 73 20 71 75 69 63 6b 65 72 0a |d as is quicker.| 000047d0 3b 0a 0a 20 20 20 20 20 20 20 20 45 58 50 4f 52 |;.. EXPOR| 000047e0 54 20 20 6d 75 6c 5f 66 72 61 63 31 36 0a 0a 6d |T mul_frac16..m| 000047f0 66 6e 73 74 61 20 20 44 43 42 20 20 20 20 20 22 |fnsta DCB "| 00004800 6d 75 6c 5f 66 72 61 63 31 36 22 2c 20 30 0a 20 |mul_frac16", 0. | 00004810 20 20 20 20 20 20 20 41 4c 49 47 4e 0a 6d 66 6e | ALIGN.mfn| 00004820 65 6e 64 20 20 44 43 44 20 20 20 20 20 26 66 66 |end DCD &ff| 00004830 30 30 30 30 30 30 20 2b 20 6d 66 6e 65 6e 64 20 |000000 + mfnend | 00004840 2d 20 6d 66 6e 73 74 61 0a 0a 6d 75 6c 5f 66 72 |- mfnsta..mul_fr| 00004850 61 63 31 36 0a 0a 20 20 20 20 20 20 20 20 6d 75 |ac16.. mu| 00004860 6c 31 36 20 20 20 61 31 2c 20 61 32 2c 20 61 31 |l16 a1, a2, a1| 00004870 2c 20 61 33 2c 20 61 34 2c 20 69 70 0a 20 20 20 |, a3, a4, ip. | 00004880 20 20 20 20 20 4d 4f 56 53 20 20 20 20 70 63 2c | MOVS pc,| 00004890 20 6c 72 0a 0a 0a 0a 3b 20 6d 75 6c 5f 66 72 61 | lr....; mul_fra| 000048a0 63 31 36 63 0a 3b 20 61 20 6c 65 61 66 20 41 50 |c16c.; a leaf AP| 000048b0 43 53 20 66 75 6e 63 74 69 6f 6e 0a 3b 0a 3b 20 |CS function.;.; | 000048c0 43 20 70 72 6f 74 6f 74 79 70 65 3a 0a 3b 20 69 |C prototype:.; i| 000048d0 6e 74 20 6d 75 6c 5f 66 72 61 63 31 36 63 28 69 |nt mul_frac16c(i| 000048e0 6e 74 20 78 2c 20 69 6e 74 20 61 29 0a 3b 0a 3b |nt x, int a).;.;| 000048f0 20 72 65 74 75 72 6e 73 20 33 32 2d 62 69 74 20 | returns 32-bit | 00004900 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 78 |signed integer x| 00004910 2a 61 2f 36 35 35 33 36 0a 3b 20 61 73 73 75 6d |*a/65536.; assum| 00004920 65 73 20 61 62 73 20 61 20 3c 3d 36 35 35 33 36 |es abs a <=65536| 00004930 0a 3b 20 69 66 20 69 74 20 69 73 20 70 6f 73 73 |.; if it is poss| 00004940 69 62 6c 65 20 74 68 61 74 20 61 62 73 20 61 20 |ible that abs a | 00004950 3e 20 36 35 35 33 36 2c 20 63 61 6c 6c 65 72 20 |> 65536, caller | 00004960 6d 75 73 74 20 63 68 65 63 6b 20 72 61 6e 67 65 |must check range| 00004970 20 26 20 65 69 74 68 65 72 20 6e 6f 74 20 63 61 | & either not ca| 00004980 6c 6c 20 66 6e 20 6f 72 20 72 6f 75 6e 64 20 64 |ll fn or round d| 00004990 6f 77 6e 20 74 6f 20 36 35 35 33 36 0a 3b 0a 0a |own to 65536.;..| 000049a0 20 20 20 20 20 20 20 20 45 58 50 4f 52 54 20 20 | EXPORT | 000049b0 6d 75 6c 5f 66 72 61 63 31 36 63 0a 0a 6d 66 63 |mul_frac16c..mfc| 000049c0 6e 73 74 61 20 44 43 42 20 20 20 20 20 22 6d 75 |nsta DCB "mu| 000049d0 6c 5f 66 72 61 63 31 36 63 22 2c 20 30 0a 20 20 |l_frac16c", 0. | 000049e0 20 20 20 20 20 20 41 4c 49 47 4e 0a 6d 66 63 6e | ALIGN.mfcn| 000049f0 65 6e 64 20 44 43 44 20 20 20 20 20 26 66 66 30 |end DCD &ff0| 00004a00 30 30 30 30 30 20 2b 20 6d 66 63 6e 65 6e 64 20 |00000 + mfcnend | 00004a10 2d 20 6d 66 63 6e 73 74 61 0a 0a 6d 75 6c 5f 66 |- mfcnsta..mul_f| 00004a20 72 61 63 31 36 63 0a 0a 20 20 20 20 20 20 20 20 |rac16c.. | 00004a30 6d 75 6c 31 36 63 20 20 61 31 2c 20 61 32 2c 20 |mul16c a1, a2, | 00004a40 61 31 2c 20 61 33 0a 20 20 20 20 20 20 20 20 4d |a1, a3. M| 00004a50 4f 56 53 20 20 20 20 70 63 2c 20 6c 72 0a 0a 0a |OVS pc, lr...| 00004a60 0a 3b 20 73 71 72 74 5f 66 72 61 63 31 36 0a 3b |.; sqrt_frac16.;| 00004a70 20 61 20 6c 65 61 66 20 41 50 43 53 20 66 75 6e | a leaf APCS fun| 00004a80 63 74 69 6f 6e 0a 3b 0a 3b 20 43 20 70 72 6f 74 |ction.;.; C prot| 00004a90 6f 74 79 70 65 3a 0a 3b 20 69 6e 74 20 73 71 72 |otype:.; int sqr| 00004aa0 74 5f 66 72 61 63 31 36 28 75 6e 73 69 67 6e 65 |t_frac16(unsigne| 00004ab0 64 20 69 6e 74 20 78 29 0a 3b 0a 3b 20 72 65 74 |d int x).;.; ret| 00004ac0 75 72 6e 73 20 33 32 2d 62 69 74 20 69 6e 74 65 |urns 32-bit inte| 00004ad0 67 65 72 20 73 71 72 74 28 78 3c 3c 31 36 29 0a |ger sqrt(x<<16).| 00004ae0 3b 0a 0a 20 20 20 20 20 20 20 20 45 58 50 4f 52 |;.. EXPOR| 00004af0 54 20 20 73 71 72 74 5f 66 72 61 63 31 36 0a 0a |T sqrt_frac16..| 00004b00 73 71 66 6e 73 74 61 20 44 43 42 20 20 20 20 20 |sqfnsta DCB | 00004b10 22 73 71 72 74 5f 66 72 61 63 31 36 22 2c 20 30 |"sqrt_frac16", 0| 00004b20 0a 20 20 20 20 20 20 20 20 41 4c 49 47 4e 0a 73 |. ALIGN.s| 00004b30 71 66 6e 65 6e 64 20 44 43 44 20 20 20 20 20 26 |qfnend DCD &| 00004b40 66 66 30 30 30 30 30 30 20 2b 20 73 71 66 6e 65 |ff000000 + sqfne| 00004b50 6e 64 20 2d 20 73 71 66 6e 73 74 61 0a 0a 73 71 |nd - sqfnsta..sq| 00004b60 72 74 5f 66 72 61 63 31 36 0a 0a 20 20 20 20 20 |rt_frac16.. | 00004b70 20 20 20 73 71 72 74 31 36 20 20 61 31 2c 20 61 | sqrt16 a1, a| 00004b80 31 2c 20 61 32 2c 20 61 33 2c 20 61 34 2c 20 69 |1, a2, a3, a4, i| 00004b90 70 0a 20 20 20 20 20 20 20 20 4d 4f 56 53 20 20 |p. MOVS | 00004ba0 20 20 70 63 2c 20 6c 72 0a 0a 0a 0a 20 20 20 20 | pc, lr.... | 00004bb0 20 20 20 20 45 4e 44 0a | END.| 00004bb8