Giter Club home page Giter Club logo

nxdk-pdclib's Introduction

PDCLib - Public Domain C Library
================================

License
-------

PDCLib is distributed unter the Creative Commons CC0 License. You
should have received a copy of the full legal text of this license
as part of this distribution (COPYING.CC0). It is also available at

https://creativecommons.org/publicdomain/zero/1.0/legalcode

The following is a human-readable summary of that license.

                       No Copyright

The person who associated a work with this deed has dedicated the
work to the public domain by waiving all of his or her rights to
the work worldwide under copyright law, including all related and
neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for
commercial purposes, all without asking permission. See Other
Information below.

                    Other Information

In no way are the patent or trademark rights of any person affected
by CC0, nor are the rights that other persons may have in the work
or in how the work is used, such as publicity or privacy rights.

Unless expressly stated otherwise, the person who associated a work
with this deed makes no warranties about the work, and disclaims
liability for all uses of the work, to the fullest extent permitted
by applicable law.

When using or citing the work, you should not imply endorsement by
the author or the affirmer.

What is it
----------

This is a C Standard Library. Nothing more, nothing less. No POSIX
or other extensions, just what's defined in ISO/IEC 9899.

(Well, this is what it will be when the 1.0 release comes out. Check
http://pdclib.rootdirectory.de to see what is implemented so far.)

Further Documentation
---------------------

Check Quickstart.txt to get a "working" version of the library as quick
as possible.

Check Internals.txt for an overview of technical intricacies.

Check Notes.txt for a list of credits and an idea of the standards I
hold myself to in my work on PDCLib.

nxdk-pdclib's People

Contributors

ajenbo avatar devsolar avatar dracc avatar glebm avatar jayfoxrox avatar sam-itt avatar thrimbor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nxdk-pdclib's Issues

tan() and tanf() seem broken

Both tan() and tanf() seem to return 0 or garbage on any inputs I've tested them with.

Sample code:

#define DEG2RAD(x) ((x) * M_PI / 180.0)
#define DEG2RADF(x) ((x) * (float)M_PI / 180.f)
#define FAKETAN(x) (sin((x)) / cos((x)))

const double testd1 = tan(DEG2RAD(45.0));
const double testd2 = tan(DEG2RAD(90.0));
const double testd3 = tan(DEG2RAD(0.0));
const double testd4 = tan(DEG2RAD(22.5));

const float testf1 = tanf(DEG2RADF(45.0f));
const float testf2 = tanf(DEG2RADF(90.0f));
const float testf3 = tanf(DEG2RADF(0.0f));
const float testf4 = tanf(DEG2RADF(22.5f));

const double testc1 = FAKETAN(DEG2RAD(45.0));
const double testc2 = FAKETAN(DEG2RAD(90.0));
const double testc3 = FAKETAN(DEG2RAD(0.0));
const double testc4 = FAKETAN(DEG2RAD(22.5));

gdb output when running in xqemu, code compiled with DEBUG=y and inserted into the hello sample:

(gdb) p testd1
$2 = 0
(gdb) p testd2
$3 = 0
(gdb) p testd3
$4 = 0
(gdb) p testd4
$5 = 0
(gdb) p testf1
$6 = 0
(gdb) p testf2
$7 = 0
(gdb) p testf3
$8 = 0
(gdb) p testf4
$9 = 1.55740774
(gdb) p testc1
$10 = 0.99999999999999989
(gdb) p testc2
$11 = 16331778728383844
(gdb) p testc3
$12 = 0
(gdb) p testc4
$13 = 0.41421356237309509

Output from real hardware, built with my nxdk fork and added debugPrints (not sure if my float formatter is very correct):

testd1 = nan
testd2 = nan
testd3 = nan
testd4 = nan
testf1 = nan
testf2 = nan
testf3 = nan
testf4 = nan
testc1 = 1.000000
testc2 = 1.633178e+16
testc3 = 0.000000
testc4 = 0.414214

Use DbgPrint in place of internal `_PDCLIB_print`

Attempting to minimize executable size, PDClib' print function uses a fair amount of space and is frankly unneeded, also as far as I can tell these aren't actually printed anywhere to the user(?), either the screen or via serial port. So it should be replaced with a call to DbgPrint.

int main(void)
{
    for(;;) {
        DbgPrint("Hello\n");
    }
    return 0;
}
LTO = y
CFLAGS += -Oz -DNDEBUG
CXXFLAGS += -Oz -DNDEBUG
NXDK_CFLAGS += -Oz -DNDEBUG
NXDK_CXXFLAGS += -Oz -DNDEBUG

As is, this results in a 32KB binary. Nuking the while loops in vfprintf and vsnprintf we end up with 28KB.

CMakeLists.txt points at missing file

18e3b16 introduced a bug which breaks CMake (which was added later in 4246158); this prevents running tests on non-Xbox platforms.

$ mkdir build
$ cd build
$ cmake ..
++ CMAKE_BUILD_TYPE not set. Defaulting to 'Debug'.
-- Configuring done
CMake Error at CMakeLists.txt:309 (add_library):
  Cannot find source file:

    functions/_PDCLIB/assert.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

[...]

I'm not sure how to resolve this most gracefully.

Generally it feels like 18e3b16 shouldn't require changes to existing pdclib code. We have extension hooks now and there has always been the optimization overlay (which works as long as we don't use wildcards in our Makefiles).

`pow()` leads to issues in SDL2 audio conversion

See XboxDev/nxdk-sdl#20 (comment)

Additionally, I noticed that the math functions don't have any copyright header or note where they stem from / wether they were tested; this makes it hard to analyze / report such issues.

It is worth noting that the code for different precisions is exactly the same (except for type suffix on float constants). I'm not sure if this is enough / correct.

I also believe we never set up or check the control words for precision (I expected this in crt0). So it might be possible to get different results on different runs, depending on how the XBE was started?

sscanf() is broken (hangs / stores unexpected values)

This code (taken from Neverball) leads to faulty behaviour:

#ifdef NXDK
#include <hal/video.h>
#include <hal/debug.h>
#else
#define debugPrint(...) printf(__VA_ARGS__)
#endif
#include <stdio.h>

int main() {

#ifdef NXDK
  XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
#endif

  const char* line = "fullscreen                0";

  int ks, ke, vs;

  ks = -1;
  ke = -1;
  vs = -1;

  debugPrint("Starting scan\n");

  int ret = sscanf(line, " %n%*s%n %n", &ks, &ke, &vs);

  debugPrint("Result %d = %d %d %d\n", ret, ks, ke, vs);

#ifdef NXDK
  while(1);
#else
  return 0;
#endif
}

On my desktop with clang I get:

Starting scan
Result 0 = 0 10 26

On nxdk (in XQEMU) I only get:

Starting scan

(it seems to hang before the second debugPrint is reached)

On nxdk (in XQEMU) I got this with an older revision of the code which didn't retrieve / print int ret:

Starting scan
Result 1701995379 1819047270 10

Probably a bug in pdclib? CC @DevSolar

math.h is not optimized for Xbox

I was surprised to find that trunc is done using x87 by modifying the control word.

Xbox should have SSE, so we can use faster methods like these http://wurstcaptures.untergrund.net/assembler_tricks.html

This isn't necessarily much faster, but hopefully shorter code which is easier to read (and step through).

We should also review other math.h funtions like round. Also possibly affects #7 (future floor implementation).

I think we can safely ignore any precision issues beyond 32 / 64 bit IEEE float.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.