Skip to content

Commit

Permalink
Squashed 'deps/r128/' changes from cf2e88f..42dec2d
Browse files Browse the repository at this point in the history
42dec2d update version number
348ac18 ARM tests
def2cfc abs and nabs
a35a2fa r128FromString: correctly set endptr if input string has a decimal point

git-subtree-dir: deps/r128
git-subtree-split: 42dec2d7125e3ea630ad5c237ad2bc02c8c75c03
  • Loading branch information
kozyilmaz committed Oct 18, 2021
1 parent 3ec2c60 commit 84ef00c
Show file tree
Hide file tree
Showing 6 changed files with 577 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,12 @@
# Change Log

## 1.5.0 - 2021/9/02
### Fixed
* r128FromString: correctly set endptr in strings with a decimal point.
### Added
* r128Abs, and r128Nabs.
* ARM and ARM64 tests

## 1.4.4 - 2020/9/12
### Fixed
* Gcc/clang compile warnings
Expand Down
52 changes: 41 additions & 11 deletions r128.h
@@ -1,5 +1,5 @@
/*
r128.h: 128-bit (64.64) signed fixed-point arithmetic. Version 1.4.4
r128.h: 128-bit (64.64) signed fixed-point arithmetic. Version 1.5.0
COMPILATION
-----------
Expand Down Expand Up @@ -127,8 +127,10 @@ extern double r128ToFloat(const R128 *v);
// Copy
extern void r128Copy(R128 *dst, const R128 *src);

// Negate
extern void r128Neg(R128 *dst, const R128 *src);
// Sign manipulation
extern void r128Neg(R128 *dst, const R128 *v); // -v
extern void r128Abs(R128* dst, const R128* v); // abs(v)
extern void r128Nabs(R128* dst, const R128* v); // -abs(v)

// Bitwise operations
extern void r128Not(R128 *dst, const R128 *src); // ~a
Expand Down Expand Up @@ -1413,15 +1415,15 @@ void r128FromString(R128 *dst, const char *s, char **endptr)
}
}

for (--s; s >= exp; --s) {
for (const char *c = s - 1; c >= exp; --c) {
R128_U64 digit, unused;

if ('0' <= *s && *s <= '9') {
digit = *s - '0';
} else if ('a' <= *s && *s <= 'f') {
digit = *s - 'a' + 10;
if ('0' <= *c && *c <= '9') {
digit = *c - '0';
} else if ('a' <= *c && *c <= 'f') {
digit = *c - 'a' + 10;
} else {
digit = *s - 'A' + 10;
digit = *c - 'A' + 10;
}

lo = r128__udiv128(lo, digit, base, &unused);
Expand Down Expand Up @@ -1546,12 +1548,40 @@ void r128Copy(R128 *dst, const R128 *src)
R128_DEBUG_SET(dst);
}

void r128Neg(R128 *dst, const R128 *src)
void r128Neg(R128 *dst, const R128 *v)
{
r128__neg(dst, src);
r128__neg(dst, v);
R128_DEBUG_SET(dst);
}

void r128Abs(R128* dst, const R128* v)
{
R128 sign, inv;

R128_ASSERT(dst != NULL);
R128_ASSERT(v != NULL);

sign.lo = sign.hi = (R128_U64)(((R128_S64)v->hi) >> 63);
inv.lo = v->lo ^ sign.lo;
inv.hi = v->hi ^ sign.hi;

r128Sub(dst, &inv, &sign);
}

void r128Nabs(R128* dst, const R128* v)
{
R128 sign, inv;

R128_ASSERT(dst != NULL);
R128_ASSERT(v != NULL);

sign.lo = sign.hi = (R128_U64)(((R128_S64)v->hi) >> 63);
inv.lo = v->lo ^ sign.lo;
inv.hi = v->hi ^ sign.hi;

r128Sub(dst, &sign, &inv);
}

void r128Not(R128 *dst, const R128 *src)
{
R128_ASSERT(dst != NULL);
Expand Down

0 comments on commit 84ef00c

Please sign in to comment.