Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions lib_xcore_math/src/arch/vx4b/vect_f32/vect_f32_max_exponent.S

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that xm.entsp is gone, I would remove NSTACKWORDS altogether, so it's not modifiable anymore

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

*/

#define NSTACKWORDS 4
#define NSTACKWORDS 0
#define FUNC_NAME vect_f32_max_exponent

.globl FUNC_NAME
Expand All @@ -25,39 +25,27 @@

.p2align 4
FUNC_NAME:
xm.entsp (NSTACKWORDS)*4
xm.stdsp s3,s2,0

{ mv t3, len ; xm.mkmski a2, 32 }
{ slli a2, a2, 16 ; xm.zexti t3, 1 }
{ srli len, len, 1 ; xm.brff t3, .L_even_elms }

// Handle the tail first
xm.ldd s3,s2, len(b)
xm.fsexp t3, s3, s3
{ mv a2, s3 ; nop }
xm.ldd a3,t3, len(b)
xm.fsexp t2, a2, a3

.L_even_elms:
{ addi len, len, -1 ; xm.brff len, .loop_end }

.loop:
xm.ldd s3,s2, len (b)
xm.fsexp t3, s2, s2
xm.fsexp a3, s3, s3
{ xm.slt t3, s2, a2 ; nop }
{ xm.slt t3, s3, a2 ; xm.bt t3, .not }
{ xm.slt t3, s3, s2 ; mv a2, s2 }
.not:
bnez t3, .not2
mv a2, s3
.not2:
.loop:
xm.ldd a3,t3, len (b)
xm.fsexp t2, t3, t3
xm.fsexp t2, a3, a3
xm.max3 a2, a2, t3, a3
{ addi len, len, -1 ; xm.bt len, .loop }
.loop_end:
.loop_end:

xm.lddsp s3,s2,0
li a0, 30
sub a0, a2, a0
xm.retsp (NSTACKWORDS)*4
{ xm.retsp (NSTACKWORDS)*4 ; sub a0, a2, a0 }

// RETURN_REG_HOLDER
.resource_const FUNC_NAME, "stack_frame_bytes", (NSTACKWORDS)*4
Expand Down
43 changes: 17 additions & 26 deletions lib_xcore_math/src/arch/vx4b/vect_f32/vect_f32_to_s32.S

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you removed s4, but s5 is still used, and both of them are saved to stack. Could you use s4 instead of s5 and only save s4 to stack? This is not gonna give us any cycles but will be a bit cleaner

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#define mant1 s2
#define mant0 s3
#define tmp s4


.p2align 4
Expand All @@ -39,38 +38,30 @@ FUNC_NAME:
xm.stdsp s5,s4,8

//handle tail first
{ srli t3, len, 1 ; li tmp, 23 }
{ xm.zexti len, 1 ; add exp, exp, tmp }
{ mv len, t3 ; xm.brff len, .L_pre_loop }
{ srli mant1, len, 1 ; li t3, 23 }
{ xm.zexti len, 1 ; add exp, exp, t3 }
{ mv len, mant1 ; xm.brff len, .L_pre_loop }
xm.ldd mant0,mant1, len(b)
xm.fsexp t3, tmp, mant0
xm.fmant mant0, mant0
{ sub tmp, tmp, exp ; xm.brff t3, .L_tail_pos }
{ xm.neg mant0, mant0 ; nop }
.L_tail_pos:
{ xm.shl mant0, mant0, tmp ; xm.shl t3, len, 1 }
xm.stw mant0, t3(a)
xm.fsexp t2, t3, mant0
xm.fmants mant0, mant0
sub t3, t3, exp
{ xm.shl mant0, mant0, t3 ; xm.shl mant1, len, 1 }
xm.stw mant0, mant1(a)

.L_pre_loop:
{ addi len, len, -1 ; xm.brff len, .L_loop_end }

.L_loop:
.L_loop:
xm.ldd mant0,mant1, len(b)
xm.fsexp t3, tmp, mant1
xm.fmant mant1, mant1
{ sub tmp, tmp, exp ; xm.brff t3, .L_not3 }
xm.neg mant1, mant1
.L_not3:
xm.shl mant1, mant1, tmp
xm.fsexp t3, tmp, mant0
xm.fmant mant0, mant0
{ sub tmp, tmp, exp ; xm.brff t3, .L_not4 }
xm.neg mant0, mant0
.L_not4:
xm.shl mant0, mant0, tmp
xm.std mant0,mant1, len(a)
xm.fsexp t2, t3, mant1
xm.fmants mant1, mant1
xm.fsexp t2, s5, mant0
xm.fmants mant0, mant0
{ sub t3, t3, exp ; sub s5, s5, exp }
{ xm.shl mant1, mant1, t3 ; xm.shl mant0, mant0, s5 }
xm.std mant0,mant1, len(a)
{ addi len, len, -1 ; xm.bt len, .L_loop }
.L_loop_end:
.L_loop_end:


xm.lddsp s3,s2,0
Expand Down
39 changes: 13 additions & 26 deletions lib_xcore_math/src/arch/vx4b/vect_s32/vect_s32_to_f32.S
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,39 @@
#define len a2
#define b_exp a3

#define _0 s2
#define tmp1 s3
#define tmp0 s4
#define tmp1 s2
#define tmp0 s3

#define _0 x28

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change it to t3 as it's more idiomatic, please?


.p2align 4
FUNC_NAME:
xm.entsp (NSTACKWORDS)*4
{ xm.entsp (NSTACKWORDS)*4 ; li _0, 0 }
xm.stdsp s3,s2,0
{ li _0, 0 ; li s3, 23 }
{ add b_exp, b_exp, s3 ; nop }
sw s4, 8(sp)
xm.subi b_exp, b_exp, 9

// handle tail first
{ srli t3, len, 1 ; xm.zexti len, 1 }
{ mv len, t3 ; xm.brff len, .L_pre_loop }
{ srli tmp0, len, 1 ; xm.zexti len, 1 }
{ mv len, tmp0 ; xm.brff len, .L_pre_loop }

xm.ldd tmp0,tmp1, len(b)
{ xm.slt t3, tmp0, _0 ; slli tmp1, len, 1 }
beqz t3, .L_posT
xm.neg tmp0, tmp0
.L_posT:
xm.fmake tmp0, t3, b_exp, _0, tmp0
slli tmp1, len, 1
xm.fmakes tmp0, b_exp, tmp0, _0
xm.stw tmp0,tmp1( a)

.L_pre_loop:

{ addi len, len, -1 ; xm.brff len, .L_loop_end }

.L_loop:
xm.ldd tmp0,tmp1, len(b)
{ xm.slt t3, tmp1, _0 ; nop }
beqz t3, .L_pos1
xm.neg tmp1, tmp1
.L_pos1:
xm.fmake tmp1, t3, b_exp, _0, tmp1
slt t3, tmp0, _0
beqz t3, .L_pos0
xm.neg tmp0, tmp0
.L_pos0:
xm.fmake tmp0, t3, b_exp, _0, tmp0
xm.ldd tmp0,tmp1, len(b)
xm.fmakes tmp1, b_exp, tmp1, _0
xm.fmakes tmp0, b_exp, tmp0, _0
xm.std tmp0,tmp1, len(a)
{ addi len, len, -1 ; xm.bt len, .L_loop }
.L_loop_end:

xm.lddsp s3,s2,0
lw s4, 8(sp)
xm.retsp (NSTACKWORDS)*4


Expand Down