28#ifndef OZZ_OZZ_BASE_MATHS_SOA_FLOAT_H_
29#define OZZ_OZZ_BASE_MATHS_SOA_FLOAT_H_
33#include "ozz/base/maths/math_constant.h"
34#include "ozz/base/maths/simd_math.h"
35#include "ozz/base/platform.h"
49 const SoaFloat2 r = {simd_float4::zero(), simd_float4::zero()};
54 const SoaFloat2 r = {simd_float4::one(), simd_float4::one()};
59 const SoaFloat2 r = {simd_float4::one(), simd_float4::zero()};
64 const SoaFloat2 r = {simd_float4::zero(), simd_float4::one()};
84 const SoaFloat3 r = {simd_float4::zero(), simd_float4::zero(),
90 const SoaFloat3 r = {simd_float4::one(), simd_float4::one(),
96 const SoaFloat3 r = {simd_float4::one(), simd_float4::zero(),
102 const SoaFloat3 r = {simd_float4::zero(), simd_float4::one(),
103 simd_float4::zero()};
108 const SoaFloat3 r = {simd_float4::zero(), simd_float4::zero(),
124 const SoaFloat4 r = {_v.x, _v.y, _v.z, _w};
130 const SoaFloat4 r = {_v.x, _v.y, _z, _w};
136 const SoaFloat4 r = {zero, zero, zero, zero};
142 const SoaFloat4 r = {one, one, one, one};
148 const SoaFloat4 r = {simd_float4::one(), zero, zero, zero};
154 const SoaFloat4 r = {zero, simd_float4::one(), zero, zero};
160 const SoaFloat4 r = {zero, zero, simd_float4::one(), zero};
166 const SoaFloat4 r = {zero, zero, zero, simd_float4::one()};
265 ozz::math::MAdd(_a.y, _b.y, _addend.y)};
272 ozz::math::MAdd(_a.y, _b.y, _addend.y),
273 ozz::math::MAdd(_a.z, _b.z, _addend.z)};
280 ozz::math::MAdd(_a.y, _b.y, _addend.y),
281 ozz::math::MAdd(_a.z, _b.z, _addend.z),
282 ozz::math::MAdd(_a.w, _b.w, _addend.w)};
328 return ozz::math::And(ozz::math::And(ozz::math::And(x, y), z), w);
335 return ozz::math::And(ozz::math::And(x, y), z);
341 return ozz::math::And(x, y);
351 return ozz::math::And(ozz::math::And(ozz::math::And(x, y), z), w);
358 return ozz::math::And(ozz::math::And(x, y), z);
364 return ozz::math::And(x, y);
374 return ozz::math::And(ozz::math::And(ozz::math::And(x, y), z), w);
381 return ozz::math::And(ozz::math::And(x, y), z);
387 return ozz::math::And(x, y);
397 return ozz::math::And(ozz::math::And(ozz::math::And(x, y), z), w);
404 return ozz::math::And(ozz::math::And(x, y), z);
410 return ozz::math::And(x, y);
421 return ozz::math::And(ozz::math::And(ozz::math::And(x, y), z), w);
428 return ozz::math::And(ozz::math::And(x, y), z);
434 return ozz::math::And(x, y);
445 return ozz::math::Or(ozz::math::Or(ozz::math::Or(x, y), z), w);
452 return ozz::math::Or(ozz::math::Or(x, y), z);
458 return ozz::math::Or(x, y);
465OZZ_INLINE SimdFloat4 HAdd(
const SoaFloat4& _v) {
466 return _v.x + _v.y + _v.z + _v.w;
468OZZ_INLINE SimdFloat4 HAdd(
const SoaFloat3& _v) {
return _v.x + _v.y + _v.z; }
469OZZ_INLINE SimdFloat4 HAdd(
const SoaFloat2& _v) {
return _v.x + _v.y; }
472OZZ_INLINE SimdFloat4 Dot(
const SoaFloat4& _a,
const SoaFloat4& _b) {
473 return _a.x * _b.x + _a.y * _b.y + _a.z * _b.z + _a.w * _b.w;
475OZZ_INLINE SimdFloat4 Dot(
const SoaFloat3& _a,
const SoaFloat3& _b) {
476 return _a.x * _b.x + _a.y * _b.y + _a.z * _b.z;
478OZZ_INLINE SimdFloat4 Dot(
const SoaFloat2& _a,
const SoaFloat2& _b) {
479 return _a.x * _b.x + _a.y * _b.y;
483OZZ_INLINE SoaFloat3 Cross(
const SoaFloat3& _a,
const SoaFloat3& _b) {
484 const SoaFloat3 r = {_a.y * _b.z - _b.y * _a.z, _a.z * _b.x - _b.z * _a.x,
485 _a.x * _b.y - _b.x * _a.y};
490OZZ_INLINE SimdFloat4 Length(
const SoaFloat4& _v) {
491 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
494OZZ_INLINE SimdFloat4 Length(
const SoaFloat3& _v) {
495 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
498OZZ_INLINE SimdFloat4 Length(
const SoaFloat2& _v) {
499 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y;
504OZZ_INLINE SimdFloat4 LengthSqr(
const SoaFloat4& _v) {
505 return _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
507OZZ_INLINE SimdFloat4 LengthSqr(
const SoaFloat3& _v) {
508 return _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
510OZZ_INLINE SimdFloat4 LengthSqr(
const SoaFloat2& _v) {
511 return _v.x * _v.x + _v.y * _v.y;
515OZZ_INLINE SoaFloat4 Normalize(
const SoaFloat4& _v) {
516 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
517 assert(AreAllTrue(CmpNe(len2, simd_float4::zero())) &&
518 "_v is not normalizable");
519 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
520 const SoaFloat4 r = {_v.x * inv_len, _v.y * inv_len, _v.z * inv_len,
524OZZ_INLINE SoaFloat3 Normalize(
const SoaFloat3& _v) {
525 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
526 assert(AreAllTrue(CmpNe(len2, simd_float4::zero())) &&
527 "_v is not normalizable");
528 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
529 const SoaFloat3 r = {_v.x * inv_len, _v.y * inv_len, _v.z * inv_len};
532OZZ_INLINE SoaFloat2 Normalize(
const SoaFloat2& _v) {
533 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y;
534 assert(AreAllTrue(CmpNe(len2, simd_float4::zero())) &&
535 "_v is not normalizable");
536 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
537 const SoaFloat2 r = {_v.x * inv_len, _v.y * inv_len};
542OZZ_INLINE math::SimdInt4 IsNormalized(
const SoaFloat4& _v) {
543 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
544 return CmpLt(Abs(len2 - math::simd_float4::one()),
545 simd_float4::Load1(kNormalizationToleranceSq));
547OZZ_INLINE math::SimdInt4 IsNormalized(
const SoaFloat3& _v) {
548 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
549 return CmpLt(Abs(len2 - math::simd_float4::one()),
550 simd_float4::Load1(kNormalizationToleranceSq));
552OZZ_INLINE math::SimdInt4 IsNormalized(
const SoaFloat2& _v) {
553 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y;
554 return CmpLt(Abs(len2 - math::simd_float4::one()),
555 simd_float4::Load1(kNormalizationToleranceSq));
559OZZ_INLINE math::SimdInt4 IsNormalizedEst(
const SoaFloat4& _v) {
560 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
561 return CmpLt(Abs(len2 - math::simd_float4::one()),
562 simd_float4::Load1(kNormalizationToleranceEstSq));
564OZZ_INLINE math::SimdInt4 IsNormalizedEst(
const SoaFloat3& _v) {
565 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
566 return CmpLt(Abs(len2 - math::simd_float4::one()),
567 simd_float4::Load1(kNormalizationToleranceEstSq));
569OZZ_INLINE math::SimdInt4 IsNormalizedEst(
const SoaFloat2& _v) {
570 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y;
571 return CmpLt(Abs(len2 - math::simd_float4::one()),
572 simd_float4::Load1(kNormalizationToleranceEstSq));
577OZZ_INLINE SoaFloat4 NormalizeSafe(
const SoaFloat4& _v,
578 const SoaFloat4& _safer) {
579 assert(AreAllTrue(IsNormalizedEst(_safer)) &&
"_safer is not normalized");
580 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _v.w * _v.w;
581 const math::SimdInt4 b = CmpNe(len2, math::simd_float4::zero());
582 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
583 const SoaFloat4 r = {
584 Select(b, _v.x * inv_len, _safer.x), Select(b, _v.y * inv_len, _safer.y),
585 Select(b, _v.z * inv_len, _safer.z), Select(b, _v.w * inv_len, _safer.w)};
588OZZ_INLINE SoaFloat3 NormalizeSafe(
const SoaFloat3& _v,
589 const SoaFloat3& _safer) {
590 assert(AreAllTrue(IsNormalizedEst(_safer)) &&
"_safer is not normalized");
591 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y + _v.z * _v.z;
592 const math::SimdInt4 b = CmpNe(len2, math::simd_float4::zero());
593 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
594 const SoaFloat3 r = {Select(b, _v.x * inv_len, _safer.x),
595 Select(b, _v.y * inv_len, _safer.y),
596 Select(b, _v.z * inv_len, _safer.z)};
599OZZ_INLINE SoaFloat2 NormalizeSafe(
const SoaFloat2& _v,
600 const SoaFloat2& _safer) {
601 assert(AreAllTrue(IsNormalizedEst(_safer)) &&
"_safer is not normalized");
602 const SimdFloat4 len2 = _v.x * _v.x + _v.y * _v.y;
603 const math::SimdInt4 b = CmpNe(len2, math::simd_float4::zero());
604 const SimdFloat4 inv_len = math::simd_float4::one() / Sqrt(len2);
605 const SoaFloat2 r = {Select(b, _v.x * inv_len, _safer.x),
606 Select(b, _v.y * inv_len, _safer.y)};
612OZZ_INLINE SoaFloat4 Lerp(
const SoaFloat4& _a,
const SoaFloat4& _b,
614 const SoaFloat4 r = {(_b.x - _a.x) * _f + _a.x, (_b.y - _a.y) * _f + _a.y,
615 (_b.z - _a.z) * _f + _a.z, (_b.w - _a.w) * _f + _a.w};
618OZZ_INLINE SoaFloat3 Lerp(
const SoaFloat3& _a,
const SoaFloat3& _b,
620 const SoaFloat3 r = {(_b.x - _a.x) * _f + _a.x, (_b.y - _a.y) * _f + _a.y,
621 (_b.z - _a.z) * _f + _a.z};
624OZZ_INLINE SoaFloat2 Lerp(
const SoaFloat2& _a,
const SoaFloat2& _b,
626 const SoaFloat2 r = {(_b.x - _a.x) * _f + _a.x, (_b.y - _a.y) * _f + _a.y};
631OZZ_INLINE SoaFloat4 Min(
const SoaFloat4& _a,
const SoaFloat4& _b) {
632 const SoaFloat4 r = {Min(_a.x, _b.x), Min(_a.y, _b.y), Min(_a.z, _b.z),
636OZZ_INLINE SoaFloat3 Min(
const SoaFloat3& _a,
const SoaFloat3& _b) {
637 const SoaFloat3 r = {Min(_a.x, _b.x), Min(_a.y, _b.y), Min(_a.z, _b.z)};
640OZZ_INLINE SoaFloat2 Min(
const SoaFloat2& _a,
const SoaFloat2& _b) {
641 const SoaFloat2 r = {Min(_a.x, _b.x), Min(_a.y, _b.y)};
646OZZ_INLINE SoaFloat4 Max(
const SoaFloat4& _a,
const SoaFloat4& _b) {
647 const SoaFloat4 r = {Max(_a.x, _b.x), Max(_a.y, _b.y), Max(_a.z, _b.z),
651OZZ_INLINE SoaFloat3 Max(
const SoaFloat3& _a,
const SoaFloat3& _b) {
652 const SoaFloat3 r = {Max(_a.x, _b.x), Max(_a.y, _b.y), Max(_a.z, _b.z)};
655OZZ_INLINE SoaFloat2 Max(
const SoaFloat2& _a,
const SoaFloat2& _b) {
656 const SoaFloat2 r = {Max(_a.x, _b.x), Max(_a.y, _b.y)};
662OZZ_INLINE SoaFloat4 Clamp(
const SoaFloat4& _a,
const SoaFloat4& _v,
663 const SoaFloat4& _b) {
664 return Max(_a, Min(_v, _b));
666OZZ_INLINE SoaFloat3 Clamp(
const SoaFloat3& _a,
const SoaFloat3& _v,
667 const SoaFloat3& _b) {
668 return Max(_a, Min(_v, _b));
670OZZ_INLINE SoaFloat2 Clamp(
const SoaFloat2& _a,
const SoaFloat2& _v,
671 const SoaFloat2& _b) {
672 return Max(_a, Min(_v, _b));
Definition simd_math_config.h:121
Definition simd_math_config.h:129
Definition soa_float.h:40
Definition soa_float.h:69
Definition soa_float.h:114