Add private function mju_isZeroByte to check for byte-wise zero.
PiperOrigin-RevId: 810456282 Change-Id: I877d0f9225e7a783ed7ff12ce54f4ed0a7889793
This commit is contained in:
committed by
Copybara-Service
parent
bb0878417e
commit
d71d42a374
@@ -1350,7 +1350,7 @@ int mju_isBad(mjtNum x) {
|
||||
|
||||
|
||||
// return 1 if all elements are 0
|
||||
int mju_isZero(mjtNum* vec, int n) {
|
||||
int mju_isZero(const mjtNum* vec, int n) {
|
||||
for (int i=0; i < n; i++) {
|
||||
if (vec[i] != 0) {
|
||||
return 0;
|
||||
@@ -1362,6 +1362,32 @@ int mju_isZero(mjtNum* vec, int n) {
|
||||
|
||||
|
||||
|
||||
// return 1 if all elements are 0
|
||||
int mju_isZeroByte(const unsigned char* vec, int n) {
|
||||
size_t i = 0;
|
||||
|
||||
// unroll using 8-byte chunks
|
||||
const uint64_t* vec64 = (const uint64_t*)vec;
|
||||
size_t n64 = n / sizeof(uint64_t);
|
||||
for (; i < n64; ++i) {
|
||||
if (vec64[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// remaining bytes
|
||||
i *= sizeof(uint64_t);
|
||||
for (; i < n; ++i) {
|
||||
if (vec[i]) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// set integer vector to 0
|
||||
void mju_zeroInt(int* res, int n) {
|
||||
memset(res, 0, n*sizeof(int));
|
||||
|
||||
Reference in New Issue
Block a user