Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

va_list and unusual floatval types #828

Open
rurban opened this Issue · 3 comments

1 participant

Reini Urban
Reini Urban
Collaborator

print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with 3 va_start/va_end
scenarios and a custom format string parser , and through char* -> STRING->char*
conversion until the fixed FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This is

  1. horrible unoptimized. We can shortcut through via
    inline op print(in NUM) :base_io {
        char buf[128];
    #ifdef PARROT_HAS_SNPRINTF
        snprintf(buf, 128, FLOATVAL_FMT, $1);
    #else
        sprintf(buf, FLOATVAL_FMT, $1);
    #endif
    #ifdef PARROT_HAS_NEGATIVE_ZERO
        Parrot_io_write_b(interp, _PIO_STDOUT(interp), buf, strlen(buf));
    #else
        if (!Parrot_is_nzero(NREG(1)))
            Parrot_io_write_b(interp, _PIO_STDOUT(interp), buf, strlen(buf));
        else
            /* Workaround for older msvcrt and openbsd. GH #366 */
            Parrot_io_write_b(interp, _PIO_STDOUT(interp), "-0", 2));
    #endif
        return cur_opcode + 2;
    }

I can see no number exceed 128.
We use %g which switches to -e format, and with long long integers ditto.

  1. varargs is broken with non-supported floatval's.

va_start does not support this, and consequently prints only 0.

http://www.eskimo.com/~scs/cclass/int/sx11c.html
"Therefore, varargs functions will never receive arguments of type char, short int, or float. Furthermore, it's an error to ``pass'' the type names char, short int, or float as the second argument to the va_arg() macro. Finally, for vaguely related reasons, the last fixed argument (the one whose name is passed as the second argument to the va_start() macro) should not be of type char, short int, or float, either."

It is even not tested in the configure probe.
In my case the error happens sometimes with float and long_double, not with __float128.
It may depend on the alignment generated by the compiler.

In the other remaining va_list functions we need to promote a non-double to double.
And we need to probe for it. Some compilers do support float, long double or quad via varargs.

I'm working on this in a rurban/va_arg_print_n branch.

Reini Urban rurban was assigned
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Use t/pmc/testlib/annotations.pbc for binary comparisons of packfiles since
  stringifying non-double numbers is not stable enough.

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
6f0e533
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
2958219
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Probe if double is needed for va_arg or if native floatval …
…does fine

Set new feature.h PARROT_VA_PTR_FLOATVAL to double or the given floatval,
and use it in src/call/args.c

Print "stack|register (double)" in Configure va_arg result if a cast is
required and precision is lost.

Still some va_arg casts missing, multidispatch.t and nci.t fail.
b04ce3f
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban warnings: Improve clang support
clang requires warnings overrides for -Wno-parentheses-equality
and adds -Wno-unused-result to src/ops/core_ops.c.
(used in 2958219 [GH #828] Optimize print_n/i and say_n/i)
6afb068
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Use t/pmc/testlib/annotations.pbc for binary comparisons of packfiles since
  stringifying non-double numbers is not stable enough.

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
a96c72b
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
ef15cff
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #843] warnings: Improve clang support
clang requires warnings overrides for -Wno-parentheses-equality
and adds -Wno-unused-result to src/ops/core_ops.c.
(used in 2958219 [GH #828] Optimize print_n/i and say_n/i)
740b218
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
db2f627
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
31a0740
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
e012664
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
2183265
Reini Urban rurban added the Optimization label
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Use t/pmc/testlib/annotations.pbc for binary comparisons of packfiles since
  stringifying non-double numbers is not stable enough.

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
afaf0c4
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
a993b2e
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Probe if double is needed for va_arg or if native floatval …
…does fine

Set new feature.h PARROT_VA_PTR_FLOATVAL to double or the given floatval,
and use it in src/call/args.c

Print "stack|register (double)" in Configure va_arg result if a cast is
required and precision is lost.

Still some va_arg casts missing, multidispatch.t and nci.t fail.
1ef8728
Reini Urban
Collaborator

Latest smoke with intel long double:
http://smolder.parrot.org/app/projects/report_details/46228
23 failed tests:

t/pmc/float.t   99%
t/pmc/integer.t 99%
t/pmc/packfile.t    97%
t/src/extend_vtable.t   88%
t/src/embed/pmc.t   88%
t/dynoplibs/sysinfo.t   88%
t/dynpmc/rational.t 98%
t/library/test_more.t
Reini Urban
Collaborator

One of the remaining issues at b941590 is PARROT_FLOATVAL_NAN_QUIET NAN <=> nanl
isnan for long double really needs nanl.

Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Use t/pmc/testlib/annotations.pbc for binary comparisons of packfiles since
  stringifying non-double numbers is not stable enough.

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
31b2b40
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
76e949c
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Probe if double is needed for va_arg or if native floatval …
…does fine

Set new feature.h PARROT_VA_PTR_FLOATVAL to double or the given floatval,
and use it in src/call/args.c

Print "stack|register (double)" in Configure va_arg result if a cast is
required and precision is lost.

Still some va_arg casts missing, multidispatch.t and nci.t fail.
6896cff
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Optimize print_n/i and say_n/i
print_n/nc/i/ic and the say variants go through a full Parrot_io_printf with
3 va_start/va_end scenarios and a custom format string parser,
and through char* -> STRING->char* conversion until the fixed
FLOATVAL_FMT or INTVAL_FMT printf is done.
Just to print a single int or number.

This also lost precision for non-double floatval's - if cast to (double).
Now avoided.
d4cc5c2
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Fix most tests for non-double floatval
Add more needed precisions to numeric tests, tested with intel long double.

Change a magic number in t/library/test_more.t 888.81<=>888.82 1e-2
  was not stable enough for intel long double

Use t/pmc/testlib/annotations.pbc for binary comparisons of packfiles since
  stringifying non-double numbers is not stable enough.

Fix src/dynoplibs/sys.ops doublesize to numvalsize. This only works for double.
944f977
Reini Urban rurban referenced this issue from a commit
Reini Urban rurban [GH #828] Probe if double is needed for va_arg or if native floatval …
…does fine

Set new feature.h PARROT_VA_PTR_FLOATVAL to double or the given floatval,
and use it in src/call/args.c

Print "stack|register (double)" in Configure va_arg result if a cast is
required and precision is lost.

Still some va_arg casts missing, multidispatch.t and nci.t fail.
e53dc70
Reini Urban
Collaborator

remaining errors with --floatval='long double' with e451d80, release 6.11.0:

t/src/embed/pmc.t                         (Wstat: 256 Tests: 9 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
t/src/extend_vtable.t                     (Wstat: 3840 Tests: 134 Failed: 15)
  Failed tests:  7, 22, 46-47, 59, 72, 80-81, 89-90, 96-97
                103-104, 128
  Non-zero exit status: 15

See http://smolder.parrot.org/app/projects/report_details/46634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.