Liang He
2006-Nov-15 18:49 UTC
[dtrace-discuss] How to print out float/double arguments from arg0, arg1, ...?
I want to print out arguments of float and double type, such as from sin(),
cos(), etc. By trial and error, I came up following macros.
union {
double d64;
float f32[2];
int64_t s64;
int32_t s32[2];
} VALUE;
#define PRINT_F32_sparc(val) \
VALUE.s64 = val; \
printf("\n%s = %f\n", \
"val", VALUE.f32[1]);
#define PRINT_F32_i386(val) \
VALUE.s64 = val; \
printf("\n%s = %f\n", \
"val", VALUE.f32[0]);
#define PRINT_D64_sparc(val) \
VALUE.s64 = val; \
this->temp = VALUE.s32[0]; \
VALUE.s32[0] = VALUE.s32[1]; \
VALUE.s32[1] = this->temp; \
printf("\n%s = %f\n", \
"val", VALUE.d64);
But I found they only work for 32-bit code, not 64-bit; and PRINT_F32_sparc
and PRINT_D64_sparc only work on SPARC and PRINT_F32_i386 only works on x86.
What is the right way to do this? Is there a way can be used cross platform?
See attachments for the test code, test D script, and test output.
Thanks,
-Liang
This message posted from opensolaris.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: print_sin.c
Type: application/octet-stream
Size: 162 bytes
Desc: not available
URL:
<http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20061115/8a7442c4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trace_sin.d
Type: application/octet-stream
Size: 717 bytes
Desc: not available
URL:
<http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20061115/8a7442c4/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trace_sin.out
Type: application/octet-stream
Size: 2176 bytes
Desc: not available
URL:
<http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20061115/8a7442c4/attachment-0002.obj>
