I've never submitted a patch before, but here goes...
Here are the transcendental math functions.
A couple of notes:
1.) I had to change the real type of n to a 'd' for it to output
the correct type in the pack in the assembler. It was already
a 'd' in the disassembler. I also changed all of the i's to l's to
match the disassembler.
2.) I'm using the standard C math functions. I don't know if we want
to always do this, but it is a start. However, I don't include
-lm in the Makefile. Mainly because it didn't work in cygwin.
Does this need to be added to the configure system?
3.) I changed the regex for interp_guts.h in assemble.pl and
disassemble.pl to find 0-9 in the opcode names as well
(for atan2 and log10).
4.) Certain math functions aren't in the std C library (i.e. log2 and
asec). Someone might want to check my math.
5.) Attached is a .pasm file that will execute each one of these
op codes, I plan to have a perl test soon.
Thanks!
Index: assemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/assemble.pl,v
retrieving revision 1.8
diff -u -r1.8 assemble.pl
--- assemble.pl 2001/09/12 09:54:46 1.8
+++ assemble.pl 2001/09/13 06:45:11
@@ -16,20 +16,20 @@
n => 'd',
);
-my %real_type=('i'=>'i',
- 'n'=>'n',
- 'N'=>'i',
- 'I'=>'i',
- 'S'=>'i',
- 's'=>'i',
- 'D'=>'i');
+my %real_type=('i'=>'l',
+ 'n'=>'d',
+ 'N'=>'l',
+ 'I'=>'l',
+ 'S'=>'l',
+ 's'=>'l',
+ 'D'=>'l');
my $sizeof_packi = length(pack($pack_type{i},1024));
open GUTS, "interp_guts.h";
my $opcode;
while (<GUTS>) {
- next unless /\tx\[(\d+)\] = ([a-z_]+);/;
+ next unless /\tx\[(\d+)\] = ([a-z0-9_]+);/;
$opcodes{$2}{CODE} = $1;
}
Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.8
diff -u -r1.8 basic_opcodes.ops
--- basic_opcodes.ops 2001/09/12 18:39:12 1.8
+++ basic_opcodes.ops 2001/09/13 06:45:12
@@ -5,6 +5,7 @@
*/
#include "parrot.h"
+#include "math.h"
// SET Ix, CONSTANT
AUTO_OP set_i_ic {
@@ -329,3 +330,205 @@
// NOOP
AUTO_OP noop {
}
+
+// TRANSCENDENTAL MATH FUNCTIONS
+
+// sin_n_n
+AUTO_OP sin_n_n {
+ NUM_REG(P1) = sin(NUM_REG(P2));
+}
+
+// cos_n_n
+AUTO_OP cos_n_n {
+ NUM_REG(P1) = cos(NUM_REG(P2));
+}
+
+// tan_n_n
+AUTO_OP tan_n_n {
+ NUM_REG(P1) = tan(NUM_REG(P2));
+}
+
+// sec_n_n
+AUTO_OP sec_n_n {
+ NUM_REG(P1) = ((NV)1) / cos(NUM_REG(P2));
+}
+
+// atan_n_n
+AUTO_OP atan_n_n {
+ NUM_REG(P1) = atan(NUM_REG(P2));
+}
+
+// atan2_n_n_n
+AUTO_OP atan2_n_n_n {
+ NUM_REG(P1) = atan2(NUM_REG(P2), NUM_REG(P3));
+}
+
+// asin_n_n
+AUTO_OP asin_n_n {
+ NUM_REG(P1) = asin(NUM_REG(P2));
+}
+
+// acos_n_n
+AUTO_OP acos_n_n {
+ NUM_REG(P1) = acos(NUM_REG(P2));
+}
+
+// asec_n_n
+AUTO_OP asec_n_n {
+ NUM_REG(P1) = acos(((NV)1) / NUM_REG(P2));
+}
+
+// cosh_n_n
+AUTO_OP cosh_n_n {
+ NUM_REG(P1) = cosh(NUM_REG(P2));
+}
+
+// sinh_n_n
+AUTO_OP sinh_n_n {
+ NUM_REG(P1) = sinh(NUM_REG(P2));
+}
+
+// tanh_n_n
+AUTO_OP tanh_n_n {
+ NUM_REG(P1) = tanh(NUM_REG(P2));
+}
+
+// sech_n_n
+AUTO_OP sech_n_n {
+ NUM_REG(P1) = ((NV)1) / cosh(NUM_REG(P2));
+}
+
+// log2_n_n
+AUTO_OP log2_n_n {
+ NUM_REG(P1) = log(NUM_REG(P2)) / log((NV)2);
+}
+
+// log10_n_n
+AUTO_OP log10_n_n {
+ NUM_REG(P1) = log10(NUM_REG(P2));
+}
+
+// ln_n_n
+AUTO_OP ln_n_n {
+ NUM_REG(P1) = log(NUM_REG(P2));
+}
+
+// exp_n_n
+AUTO_OP exp_n_n {
+ NUM_REG(P1) = exp(NUM_REG(P2));
+}
+
+// pow_n_n_n
+AUTO_OP pow_n_n_n {
+ NUM_REG(P1) = pow(NUM_REG(P2), NUM_REG(P3));
+}
+
+// sin_n_i
+AUTO_OP sin_n_i {
+ NUM_REG(P1) = sin(INT_REG(P2));
+}
+
+// cos_n_i
+AUTO_OP cos_n_i {
+ NUM_REG(P1) = cos(INT_REG(P2));
+}
+
+// tan_n_i
+AUTO_OP tan_n_i {
+ NUM_REG(P1) = tan(INT_REG(P2));
+}
+
+// sec_n_i
+AUTO_OP sec_n_i {
+ NUM_REG(P1) = ((NV)1) / cos(INT_REG(P2));
+}
+
+// atan_n_i
+AUTO_OP atan_n_i {
+ NUM_REG(P1) = atan(INT_REG(P2));
+}
+
+// atan2_n_n_i
+AUTO_OP atan2_n_n_i {
+ NUM_REG(P1) = atan2(NUM_REG(P2), INT_REG(P3));
+}
+
+// atan2_n_i_n
+AUTO_OP atan2_n_i_n {
+ NUM_REG(P1) = atan2(INT_REG(P2), NUM_REG(P3));
+}
+
+// atan2_n_i_i
+AUTO_OP atan2_n_i_i {
+ NUM_REG(P1) = atan2(INT_REG(P2), INT_REG(P3));
+}
+
+// asin_n_i
+AUTO_OP asin_n_i {
+ NUM_REG(P1) = asin(INT_REG(P2));
+}
+
+// acos_n_i
+AUTO_OP acos_n_i {
+ NUM_REG(P1) = acos(INT_REG(P2));
+}
+
+// asec_n_i
+AUTO_OP asec_n_i {
+ NUM_REG(P1) = acos(((NV)1) / ((NV)INT_REG(P2)));
+}
+
+// cosh_n_i
+AUTO_OP cosh_n_i {
+ NUM_REG(P1) = cosh(INT_REG(P2));
+}
+
+// sinh_n_i
+AUTO_OP sinh_n_i {
+ NUM_REG(P1) = sinh(INT_REG(P2));
+}
+
+// tanh_n_i
+AUTO_OP tanh_n_i {
+ NUM_REG(P1) = tanh(INT_REG(P2));
+}
+
+// sech_n_i
+AUTO_OP sech_n_i {
+ NUM_REG(P1) = ((NV)1) / cosh(INT_REG(P2));
+}
+
+// log2_n_i
+AUTO_OP log2_n_i {
+ NUM_REG(P1) = log(INT_REG(P2)) / log((NV)2);
+}
+
+// log10_n_i
+AUTO_OP log10_n_i {
+ NUM_REG(P1) = log10(INT_REG(P2));
+}
+
+// ln_n_i
+AUTO_OP ln_n_i {
+ NUM_REG(P1) = log(INT_REG(P2));
+}
+
+// exp_n_i
+AUTO_OP exp_n_i {
+ NUM_REG(P1) = exp(INT_REG(P2));
+}
+
+// pow_n_n_i
+AUTO_OP pow_n_n_i {
+ NUM_REG(P1) = pow(NUM_REG(P2), INT_REG(P3));
+}
+
+// pow_n_i_i
+AUTO_OP pow_n_i_i {
+ NUM_REG(P1) = pow(INT_REG(P2), INT_REG(P3));
+}
+
+// pow_n_n_i
+AUTO_OP pow_n_i_n {
+ NUM_REG(P1) = pow(INT_REG(P2), NUM_REG(P3));
+}
\ No newline at end of file
Index: disassemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/disassemble.pl,v
retrieving revision 1.4
diff -u -r1.4 disassemble.pl
--- disassemble.pl 2001/09/12 09:54:46 1.4
+++ disassemble.pl 2001/09/13 06:45:12
@@ -28,7 +28,7 @@
open GUTS, "interp_guts.h";
my $opcode;
while (<GUTS>) {
- next unless /\tx\[(\d+)\] = ([a-z_]+);/;
+ next unless /\tx\[(\d+)\] = ([a-z0-9_]+);/;
$opcodes{$2}{CODE} = $1;
}
Index: opcode_table
===================================================================
RCS file: /home/perlcvs/parrot/opcode_table,v
retrieving revision 1.9
diff -u -r1.9 opcode_table
--- opcode_table 2001/09/12 18:39:12 1.9
+++ opcode_table 2001/09/13 06:45:12
@@ -102,3 +102,45 @@
clear_n 0
clear_p 0
+# Transcendental Math Ops
+
+sin_n_n 2 N N
+cos_n_n 2 N N
+tan_n_n 2 N N
+sec_n_n 2 N N
+atan_n_n 2 N N
+atan2_n_n_n 3 N N N
+asin_n_n 2 N N
+acos_n_n 2 N N
+asec_n_n 2 N N
+cosh_n_n 2 N N
+sinh_n_n 2 N N
+tanh_n_n 2 N N
+sech_n_n 2 N N
+log2_n_n 2 N N
+log10_n_n 2 N N
+ln_n_n 2 N N
+exp_n_n 2 N N
+pow_n_n_n 3 N N N
+sin_n_i 2 N I
+cos_n_i 2 N I
+tan_n_i 2 N I
+sec_n_i 2 N I
+atan_n_i 2 N I
+atan2_n_n_i 3 N N I
+atan2_n_i_n 3 N I N
+atan2_n_i_i 3 N I I
+asin_n_i 2 N I
+acos_n_i 2 N I
+asec_n_i 2 N I
+cosh_n_i 2 N I
+sinh_n_i 2 N I
+tanh_n_i 2 N I
+sech_n_i 2 N I
+log2_n_i 2 N I
+log10_n_i 2 N I
+ln_n_i 2 N I
+exp_n_i 2 N I
+pow_n_n_i 3 N N I
+pow_n_i_i 3 N I I
+pow_n_i_n 3 N I N
test4.pasm