📄 xpl.inc
字号:
;/* ************************************************************************* *\
;** INTEL Corporation Proprietary Information
;**
;** This listing is supplied under the terms of a license
;** agreement with INTEL Corporation and may not be copied
;** nor disclosed except in accordance with the terms of
;** that agreement.
;**
;** Copyright (c) 2003 Intel Corporation.
;** All Rights Reserved.
;**
;** ************************************************************************* **
;** FILE: XPL.inc
;** DESCRIPTION:
;**
;** CREATED: November 30, 2004
;**
;\* ************************************************************************* */
;** ************************************************************************ **
;** ************************************************************************ **
;** CONSTANTS
;** ************************************************************************ **
;** ************************************************************************ **
; FIXED POINT CONSTANTS
HFX_ONE EQU 0x00010000
HFX_MIN EQU 0x80000000
HFX_MAX EQU 0x7FFFFFFF
HXF_ONE_F EQU 0x3F800000 ; floating point one
HXF_INV_2PI_FX EQU 0x00002763
;* ************************************************************************* *
;* ************************************************************************* **
; HXFPACKEDMATRIX - ASM INTERFACE
;* ************************************************************************* **
;* ************************************************************************* *
;** ************************************************************************ **
;** MACROS - Macros needed in a number of different assembly files.
;** ************************************************************************ **
;** ************************************************************************ **
;** Count the trailing zeros of a 32-bit unsigned number.
;** Note!! This macro can be called with $res == $num
MACRO
HXF_CTZ $res, $num, $tmp
sub $tmp, $num, #1
mvn $res, $num ; TZcount = 32 - CLZ( (~num) & (num - 1) )
and $res, $res, $tmp
clz $res, $res
rsb $res, $res, #32
MEND
;** ************************************************************************ **
;** Divider macro, 3 cycles, generates 1 bit result.
;** Expects numerator and denominator to have there first bits
;** aligned in the 31 bit offset(the leftmost bit).
;** generate results to the 31st
MACRO
HXF_ONEBITDIVIDE $bit, $num, $den, $res
subs $num, $num, $den, lsr #(31-$bit)
orrhs $res, $res, #(1 << ($bit))
addlo $num, $num, $den, lsr #(31-$bit)
MEND
;** ************************************************************************ **
;** Macro to perform a Signed CLZ.
MACRO
HXF_SIGNED_CLZ $res, $src
movs $res, $src
rsblt $res, $res, #0
clz $res, $res
MEND
;** ************************************************************************ **
;** 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
;** ************************************************************************ **
;** 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
;** ************************************************************************ **
;** 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
;** ************************************************************************ **
;** 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
;** ************************************************************************* **
END
;/* ************************************************************************* *\
;** EOF
;\* ************************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -