what is the mechanism of SRA/SLA when using Fixed Point

18 views
Skip to first unread message

saber cheng

unread,
Jun 19, 2019, 11:38:56 PM6/19/19
to Spatial Users
Hi all,

Recently, i received a strange problem.
when using spatial and in the Accel{} region, for example, i define "val x = Reg[FixPt[TRUE, _16, _16]]" and i want to do SRA.
so i define another parameter "val shift = x.to[FixPt[TRUE, _16, _0]]", i use "result" to receive the return value of "x >> shift".
But here is a strange problem, if i set x to 0, then the result will be 0 rather tnan x. And if the x doesnt equal to 0, for example 1 or 2, the the result will be what it should be like x/2 or x/4.

So can anyone help me with this

Matt F

unread,
Jun 20, 2019, 2:26:17 PM6/20/19
to Spatial Users
Hi Saber,

Looks like you found a bug.  I'll fix this shortly.

Just to clarify, you said that doing  x >> x.to[FixPt[TRUE,_16,_0]]  gives 0, but I assume you meant anything shifted by 0 gives 0.

When you shift by a non-constant value, it replaces that shift with a loop structure whose counter is set by the shift amount.  In general, if you can get away with creating a list of results each shifted by a different amount and then using a mux to select the correct result based on shift, this would probably give you better performance.

saber cheng

unread,
Jun 22, 2019, 3:35:15 AM6/22/19
to Spatial Users
sorry , what i expressed was a little confusing
let me re-explain it
in the Accel{} region
i have a register "val x = Reg[FixPt[TRUE,_16,_16]]"
then i have const or input value "val shift = ArgIn[FixPt[TRUE, _16, _0]]"
so when the shift is set to zero, then the return value of "x >> shift" will always be 0

hope this time i can make it clear, 
here i will attach my code 

Untitled.png


Matt F

unread,
Jun 22, 2019, 12:30:45 PM6/22/19
to Spatial Users
Thanks.  This should be fixed now (pull if you are using spatial repo, or just recompile if you are using spatial-quickstart).  Let me know if you still have any problems.
Reply all
Reply to author
Forward
0 new messages