📄 hxfstate.inc
字号:
;** Macro to convert a Fixed point value to IEEE float
;** Destroys values in fx and tmp
MACRO
HXF_FXToF $f, $fx, $tmp, $l
;$l HXF_FXToF $f, $fx, $tmp ; This syntax is broken always evals to ""
mov $f, #0 ; Zero out result
; Handle Zero
cmp $fx, #0
beq $l.HXF_FXToF_End
; sign
ands $f, $fx, #0x80000000
rsbne $fx, $fx, #0 ; convert to ones complement
; exponent
; clz will return the zero based location of the first 1 in value
; ignoring the Sign bit, it is also the Number of leading
; zeros
; we now want to shift the number so that the one is in the
; 23 bit position -- (31 - 23 - lz) will yeild the shift necessary
; to accomlish this. )
; The decimal in the source number was at the 16 bit position.
; now we have adjusted the number by e thus moving the
; decimal place by e, the new decimal place is 16 - e.
; we now need to calculate the power that the number needs to
; be raised to in order to get the decimal in the correct position.
; We need to know the the offset from 23 where the decimal needs
; to move to. 23 - 16 = 7
clz $tmp, $fx ; find the offset of the leading bit
subs $tmp, $tmp, #8 ; calculate the adjustment to the decimal. negative implies a left shift.
; mantisa
movge $fx, $fx, lsl $tmp ; shift into position
rsblt $tmp, $tmp, #0 ; make shift value positive
movlt $fx, $fx, asr $tmp
rsblt $tmp, $tmp, #0 ; restore the exponent sign
eor $fx, $fx, #0x00800000 ; Remove implied bit
orr $f, $f, $fx ; Pack mantissa
; Compute and pack the exponent
rsb $tmp, $tmp, #134 ; Calculate the exponent
orr $f, $f, $tmp, lsl #23 ; put the exp in the proper place
$l.HXF_FXToF_End
MEND
;** ************************************************************************ **
;** Macro to convert a signed byte value to IEEE float
;** Destroys values in fx and tmp
MACRO
HXF_IToF $f, $fx, $tmp, $l
; $l HXF_IToF $f, $fx, $tmp ; This syntax is broken always evals to ""
mov $f, #0 ; Zero out result
; Handle Zero
cmp $fx, #0
beq $l.HXF_IToF_End
; sign
ands $f, $fx, #0x80000000
rsbne $fx, $fx, #0 ; convert to ones complement
; exponent
clz $tmp, $fx ; find the offset of the leading bit
subs $tmp, $tmp, #8 ; calculate the adjustment to the decimal. negative implies a left shift.
; mantisa
movge $fx, $fx, lsl $tmp ; shift into position
rsblt $tmp, $tmp, #0 ; make shift value positive
movlt $fx, $fx, asr $tmp
rsblt $tmp, $tmp, #0 ; restore the exponent sign
eor $fx, $fx, #0x00800000 ; Remove implied bit
orr $f, $f, $fx ; Pack mantissa
; Compute and pack the exponent
rsb $tmp, $tmp, #150 ; Calculate the exponent (127 + 23(decimal adj))
orr $f, $f, $tmp, lsl #23 ; put the exp in the proper place
$l.HXF_IToF_End
MEND
;** ************************************************************************ **
;** Macro to convert a Fixed point value to a Fat Float
MACRO
HXF_FXToFF $fx, $m, $e
; exponent
HXF_SIGNED_CLZ $e, $fx ; find the offset of the leading bit
rsbs $e, $e, #8 ; calculate the adjustment to the decimal. negative implies a left shift.
; mantisa
movge $m, $fx, asr $e ; shift into position
rsblt $m, $e, #0 ; make shift value positive
movlt $m, $fx, lsl $m
add $e, $e, #7
MEND
;** ************************************************************************ **
;** Macro to convert a integer value to a Fat Float
MACRO
HXF_IToFF $fx, $m, $e
; exponent
HXF_SIGNED_CLZ $e, $fx ; find the offset of the leading bit
rsbs $e, $e, #8 ; calculate the adjustment to the decimal. negative implies a left shift.
; mantisa
movge $m, $fx, asr $e ; shift into position
rsblt $m, $e, #0 ; make shift value positive
movlt $m, $fx, lsl $m
add $e, $e, #23
MEND
;** ************************************************************************ **
;** Macro to convert an IEEE float to a Fat Float
MACRO
HXF_FToFF $f, $m, $e, $l
; $l HXF_FToFF $f, $m, $e ; This syntax is broken always evals to ""
and $m, $f, #0x00FFFFFF
; Handle Zero
cmp $f, #0
beq $l.HXF_FToFF_End
; extract exponent
mov $e, $f, lsr #23
and $e, $e, #0xFF
sub $e, $e, #127
; extract mantissa
orr $m, $m, #0x00800000
; set sign
tst $f, #0x80000000
rsbne $m, $m, #0 ; Set proper sign
$l.HXF_FToFF_End
MEND
;** ************************************************************************ **
;** Float to fixed conversion.
MACRO
HXF_FToFX $v, $tmp, $tmp2, $l
cmp $v, #0
beq $l.HXF_FToFX_End
; sign
movs $tmp2, $v, lsr #31
; exponent
mov $tmp, $v, lsr #23
and $tmp, $tmp, #0xff
rsbs $tmp, $tmp, #142 ; (127 + 8(Float Leading Zeros) + 7(Float to fixed exponent shift) )
; mantisa
mvnle $v, #0x80000000 ; Overflow value
movgt $v, $v, lsl #8
orrgt $v, $v, #0x80000000 ; add back the implied bit.
movgt $v, $v, lsr $tmp
cmp $tmp2, #0
rsbne $v, $v, #0
$l.HXF_FToFX_End
MEND
;** ************************************************************************ **
;** Fat Float to fixed conversion.
MACRO
HXF_FFToFX $m, $e, $l
cmp $m, #0
beq $l.HXF_FFToFX_End
; exponent
rsbs $e, $e, #15 ; 8(Float Leading Zeros) +7(Float to fixed exponent shift)
; mantisa
mvnle $m, #0x80000000 ; Overflow value
movgt $m, $m, lsl #8
orrgt $m, $m, #0x80000000 ; add back the implied bit.
movgt $m, $m, lsr $e
$l.HXF_FFToFX_End
MEND
IMPORT |g_HXFInvSqrtTable|
;** ************************************************************************ **
;**
MACRO
HXF_INVSQRT $m, $e, $t1, $t2, $t3
tst $e, #0x01
mvneq $t2, #0x3F800000 ; if even exponent
andeq $m, $m, $t2 ; remove lead bit
mov $e, $e, asr #1 ; compute new exponent
rsb $e, $e, #0
; get interpolation value
mov $t2, $m, lsr #9
and $t2, $t2, #0x7F
mov $m, $m, lsr #15
mov $m, $m, lsl #1
ldr $t1, = g_HXFInvSqrtTable
add $t1, $t1, $m
ldrh $m, [$t1]
ldrh $t1, [$t1, #2]
cmp $m, #0
orreq $m, $m, #0x00010000
; compute weighted value
mul $t3, $t1, $t2
rsb $t2, $t2, #0x080
mul $t1, $m, $t2
add $m, $t1, $t3
tst $m, #0x00800000
subeq $e, $e, #1
orr $m, $m, #0x00800000
MEND
;** ************************************************************************ **
;** Compute the Inv Sqrt of a Fixed point number.
;** Input must be >= 0
;** this was implemented as in the easiest way possible. It should be possible
;** To further optimize this macro the sub macros should be unrolled.
MACRO
HXF_INVSQRTFX $fx, $t0, $t1, $t2, $t3, $l
HXF_FXToFF $fx, $t0, $t1
HXF_INVSQRT $t0, $t1, $fx, $t2, $t3
HXF_FFToFX $t0, $t1, $l
mov $fx, $t0
MEND
;** ************************************************************************ **
;** Converts a FIXED point 16.16 into a color value for packing in to a
;** returns the byte value in the low 8 bits of the register
MACRO
HXF_FIXED_TO_COLORBYTE $val, $tmp
; 3 cases, (in range(0-1), over>1, under<0)
cmp $val, #0x00010000
movge $val, #0xFF00 ; shifted by the in range handler
cmplt $val, #0
movlt $val, #0x00
movge $val, $val, lsr #8 ; in range
MEND
;** ************************************************************************ **
;** debug utilities
; IF :DEF:DEBUG
; IMPORT |g_WMMXRegisters|
; MACRO
; HXF_UPDATE_WMMX_REGISTER $reg
; stmfd sp!, {r0}
; ldr r0, =g_WMMXRegisters
; add r0, r0, #$reg<<3 ; RegisterNum * RegisterId(8)
; wstrd $reg, [r0]
; ldmfd sp!, {r0}
; MEND
; ENDIF
; IF :DEF:DEBUG
; IMPORT |g_FloatValue|
; MACRO
; HXF_SAVE_FLOAT $m, $e, $l
; stmfd sp!, {r0-r3}
; mov r0, $m
; mov r1, $e
; HXF_FFToF r2, r0, r1, r3, $l
; ldr r0, =g_FloatValue
; str r2, [r0]
; ldmfd sp!, {r0-r3}
; MEND
; ENDIF
;** ************************************************************************* **
END
;/* ************************************************************************* *\
;** ************************************************************************* **
;** EOF
;** ************************************************************************* **
;\* ************************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -