* [9fans] what does #pragma fpround do?
@ 2009-07-12 17:37 erik quanstrom
2009-07-12 19:47 ` Russ Cox
0 siblings, 1 reply; 3+ messages in thread
From: erik quanstrom @ 2009-07-12 17:37 UTC (permalink / raw)
To: 9fans
reading 8c (the only compiler that appears to
implement this pragma), the difference appears
to be in the conversion of (double, float) ->
any type of integer. however,
#include <u.h>
#include <libc.h>
void
main(void)
{
double d;
d = 1.99999999999;
#pragma fpround on
print("%d\n", (int)d);
#pragma fpround 0
print("%d\n", (int)d);
}
generates the same output and same assembly
for both casts. can anyone explain what this pragma
is supposed to do?
- erik
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] what does #pragma fpround do?
2009-07-12 17:37 [9fans] what does #pragma fpround do? erik quanstrom
@ 2009-07-12 19:47 ` Russ Cox
2009-07-12 20:19 ` erik quanstrom
0 siblings, 1 reply; 3+ messages in thread
From: Russ Cox @ 2009-07-12 19:47 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
> generates the same output and same assembly
> for both casts. can anyone explain what this pragma
> is supposed to do?
it changes the rounding mode from the standard
truncate to integer (expensive on a 387) to
round to nearest (incorrect but cheap).
#pragma fpround on
print("%d\n", (int)d);
#pragma fpround 0
print("%d\n", (int)d);
your examples compiles to the same code in both
cases because the rounding mode is only consulted
during code generation, which happens at the
function's final }. you'd need to write two different
functions to demonstrate the difference.
russ
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] what does #pragma fpround do?
2009-07-12 19:47 ` Russ Cox
@ 2009-07-12 20:19 ` erik quanstrom
0 siblings, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2009-07-12 20:19 UTC (permalink / raw)
To: 9fans
> > generates the same output and same assembly
> > for both casts. can anyone explain what this pragma
> > is supposed to do?
>
> it changes the rounding mode from the standard
> truncate to integer (expensive on a 387) to
> round to nearest (incorrect but cheap).
sure enough. here's timings in µsec for 1<<20 cycles
slow fast factor
amd64 (2.0ghz) 82717 2873 29
xeon 5000 (1.6ghz) 17595 1963 9
core i7 (2.6ghz) 4734 1185 4
> #pragma fpround on
> print("%d\n", (int)d);
> #pragma fpround 0
> print("%d\n", (int)d);
>
> your examples compiles to the same code in both
> cases because the rounding mode is only consulted
> during code generation, which happens at the
> function's final }. you'd need to write two different
> functions to demonstrate the difference.
ah. that escaped me. thanks. it would be good to
document somwhere. would updating /sys/doc/compiler.ms
be a really bad idea?
- erik
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-07-12 20:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-12 17:37 [9fans] what does #pragma fpround do? erik quanstrom
2009-07-12 19:47 ` Russ Cox
2009-07-12 20:19 ` erik quanstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).