@ -96,77 +96,145 @@
.endm
.endm
# endif
# endif
/* Convenience macro to load a Vector type (vtype) as immediate */
# if d e f i n e d ( _ _ r i s c v _ v _ e l e n )
.macro lvtypei rd, e , m =m1 , t p =tu , m p =mu
# define R V _ V _ E L E N _ _ r i s c v _ v _ e l e n
# else
/* Run-time detection of the V extension implies ELEN >= 64. */
# define R V _ V _ E L E N 6 4
# endif
# if R V _ V _ E L E N = = 3 2
# define V S E W _ M A X 2
# else
# define V S E W _ M A X 3
# endif
.ifc \ e,e 8
.macro parse_vtype ew, t p , m p
.equ ei, 0
.ifc \ ew,e 8
.equ vsew, 0
.else
.else
.ifc \ e,e 1 6
.ifc \ ew ,e 1 6
.equ ei, 8
.equ vsew, 1
.else
.else
.ifc \ e,e 3 2
.ifc \ ew ,e 3 2
.equ ei, 1 6
.equ vsew, 2
.else
.else
.ifc \ e,e 6 4
.ifc \ ew ,e 6 4
.equ ei, 2 4
.equ vsew, 3
.else
.else
.error " Unknown e l e m e n t t y p e "
.error " Unknown e l e m e n t w i d t h \ e w "
.endif
.endif
.endif
.endif
.endif
.endif
.endif
.endif
.ifc \ m,m 1
.ifc \ tp,t u
.equ mi, 0
.equ tp, 0
.else
.ifc \ m,m 2
.equ mi, 1
.else
.ifc \ m,m 4
.equ mi, 2
.else
.else
.ifc \ m,m 8
.ifc \ tp,t a
.equ mi, 3
.equ tp, 1
.else
.else
.ifc \ m,m f8
.error " Unknown t a i l p o l i c y \ t p "
.equ mi, 5
.else
.ifc \ m,m f4
.equ mi, 6
.else
.ifc \ m,m f2
.equ mi, 7
.else
.error " Unknown m u l t i p l i e r "
.equ mi, 3
.endif
.endif
.endif
.endif
.endif
.endif
.endif
.endif
.endif
.ifc \ tp,t u
.ifc \ mp,m u
.equ tpi , 0
.equ mp, 0
.else
.else
.ifc \ tp,t a
.ifc \ mp,m a
.equ tpi, 6 4
.equ mp, 1
.else
.else
.error " Unknown t a i l p o l i c y "
.error " Unknown m a s k p o l i c y \ m p "
.endif
.endif
.endif
.endif
.endm
.ifc \ mp,m u
/ * *
.equ mpi, 0
* Gets t h e v e c t o r t y p e w i t h t h e s m a l l e s t s u i t a b l e L M U L v a l u e .
.else
* @param[out] rd vector type destination register
.ifc \ mp,m a
* @param vl vector length constant
.equ mpi, 1 2 8
* @param ew element width: e8, e16, e32 or e64
* @param tp tail policy: tu or ta
* @param mp mask policty: mu or ma
* /
.macro vtype_ivli rd, a v l , e w , t p =tu , m p =mu
.if \ avl < = 1
.equ log2 v l , 0
.elseif \ avl < = 2
.equ log2 v l , 1
.elseif \ avl < = 4
.equ log2 v l , 2
.elseif \ avl < = 8
.equ log2 v l , 3
.elseif \ avl < = 1 6
.equ log2 v l , 4
.elseif \ avl < = 3 2
.equ log2 v l , 5
.elseif \ avl < = 6 4
.equ log2 v l , 6
.elseif \ avl < = 1 2 8
.equ log2 v l , 7
.else
.else
.error " Unknown m a s k p o l i c y "
.error " Vector l e n g t h \ a v l o u t o f r a n g e "
.endif
.endif
parse_ v t y p e \ e w , \ t p , \ m p
csrr \ r d , v l e n b
clz \ r d , \ r d
addi \ r d , \ r d , l o g 2 v l + 1 + V S E W _ M A X - _ _ r i s c v _ x l e n
max \ r d , \ r d , z e r o / / V L M U L m u s t b e > = V S E W - V S E W _ M A X
.if vsew < VSEW_ M A X
addi \ r d , \ r d , v s e w - V S E W _ M A X
andi \ r d , \ r d , 7
.endif
.endif
ori \ r d , \ r d , ( v s e w < < 3 ) | ( t p < < 6 ) | ( m p < < 7 )
.endm
/ * *
* Gets t h e v e c t o r t y p e w i t h t h e s m a l l e s t s u i t a b l e L M U L v a l u e .
* @param[out] rd vector type destination register
* @param rs vector length source register
* @param[out] tmp temporary register to be clobbered
* @param ew element width: e8, e16, e32 or e64
* @param tp tail policy: tu or ta
* @param mp mask policty: mu or ma
* /
.macro vtype_vli rd, r s , t m p , e w , t p =tu , m p =mu
parse_ v t y p e \ e w , \ t p , \ m p
/ *
* The d i f f e r e n c e b e t w e e n t h e C L Z ' s n o t i o n a l l y e q u a l s t h e V L M U L v a l u e
* for 4 - b i t e l e m e n t s . B u t w e w a n t t h e v a l u e f o r S E W _ M A X - b i t e l e m e n t s .
* /
slli \ t m p , \ r s , 1 + V S E W _ M A X
csrr \ r d , v l e n b
addi \ t m p , \ t m p , - 1
clz \ r d , \ r d
clz \ t m p , \ t m p
sub \ r d , \ r d , \ t m p
max \ r d , \ r d , z e r o / / V L M U L m u s t b e > = V S E W - V S E W _ M A X
.if vsew < VSEW_ M A X
addi \ r d , \ r d , v s e w - V S E W _ M A X
andi \ r d , \ r d , 7
.endif
ori \ r d , \ r d , ( v s e w < < 3 ) | ( t p < < 6 ) | ( m p < < 7 )
.endm
/ * *
* Widens a v e c t o r t y p e .
* @param[out] rd widened vector type destination register
* @param rs vector type source register
* @param n number of times to widen (once by default)
* /
.macro vwtypei rd, r s , n =1
xori \ r d , \ r s , 4
addi \ r d , \ r d , ( \ n ) * 0 1 1
xori \ r d , \ r d , 4
.endm
li \ r d , ( e i | m i | t p i | m p i )
/ * *
* Narrows a v e c t o r t y p e .
* @param[out] rd narrowed vector type destination register
* @param rs vector type source register
* @param n number of times to narrow (once by default)
* /
.macro vntypei rd, r s , n =1
vwtypei \ r d , \ r s , - ( \ n )
.endm
.endm