SLEIGH: How to Support Sin, Cos, and Sqrt?
See original GitHub issueI would like to close https://github.com/NationalSecurityAgency/ghidra/issues/1730. I believe I have disassembly for fsca and fsrra working. I have no clue to how to implement the pseudo code (http://www.shared-ptr.com/sh_insns.html):
fsca:
void FSCA (int n)
{
if (FPSCR_PR != 0)
undefined_operation ();
else
{
float angle;
long offset = 0x00010000;
long fraction = 0x0000FFFF;
set_I ();
fraction &= FPUL; // extract sub-rotation (fraction) part
angle = fraction; // convert to float
angle = 2 * M_PI * angle / offset; // convert to radian
FR[n] = sin (angle);
FR[n+1] = cos (angle);
PC += 2;
}
}
fsrra:
void FSRRA (int n)
{
if (FPSCR_PR != 0)
undefined_operation ();
else
{
PC += 2;
clear_cause();
switch (data_type_of (n))
{
case NORM:
if (sign_of (n) == 0)
{
set_I ();
FR[n] = 1 / sqrt (FR[n]);
}
else
invalid (n);
break;
case DENORM:
if (sign_of (n) == 0)
fpu_error ();
else
invalid (n);
break;
case PZERO:
case NZERO:
dz (n, sign_of (n));
break;
case PINF:
FR[n] = 0;
break;
case NINF:
invalid (n);
break;
case qNAN:
qnan (n);
break;
case sNAN:
invalid (n);
break;
}
}
}
Any advice on how to tackle this? I found references in ia.sinc for pcodeops for cos. I don’t quite understand it. Thanks in advance.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Unit Circle Trigonometry - Sin Cos Tan - Radians & Degrees
This trigonometry / precalculus video tutorial review explains the unit circle and the basics of how to memorize it. It provides the angles ......
Read more >Easy trick to remember sin, cos and tan values! - YouTube
Learn a quick and easy way to remember key sin, cos and tan values. I've found this super helpful in lots of exams...
Read more >Sine Cosine Tangent Explained - sin cos tan sec csc cot
This trigonometry video tutorials explains how to use the sine cosine and tangent function as it relates to right triangles and SOHCAHTOA.
Read more >Which is more efficient for sines and cosines? Sin and Cos or ...
If I want to calculate a sin and a cos, is it cheaper to calculate a sin and a cos, or calculate a...
Read more >Cosine, sine and tangent of π/6 and π/3 (video) - Khan Academy
But to help us there, I'm going to give us a little bit of a ... So sine of pi over three is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You could implement it as a
pcodeop
, which is effectively just an opaque “intrinsic” operation. It gets decompiled as simply a function call.Declare the
pcodeop
somewhere in yourslaspec
asdefine pcodeop sin;
Then in your constructor just do
r0 = sin(r0);
The “functions” thus declared by
pcodeop
can take any arguments and return anything.See section “7.7.1.8. User-Defined Operations” in the SLEIGH manual, which says the following:
You also need to take care with how you handle the
Fr[N+1]
for the cos.Your best bet here would be to add an additional token and attach statement:
FRN_1 = (8,11)
...
attach variables [FRN_1] [fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 _ ];
FRN_1t: FRN_1 is FRN_1 { export FRN_1; }
:fsca fpul_t, FRN_0t is fpul_t & FRN_0t & FRN_1t ...