diff --git a/plugins/ets/runtime/intrinsics/std_math.cpp b/plugins/ets/runtime/intrinsics/std_math.cpp index 9fcb6540e2be6cc0497776653f73adf54a14668a..a817c33ab5ef0fad33e857d6b7980a74497aa28f 100644 --- a/plugins/ets/runtime/intrinsics/std_math.cpp +++ b/plugins/ets/runtime/intrinsics/std_math.cpp @@ -20,9 +20,6 @@ namespace panda::ets::intrinsics { -constexpr const uint32_t BIT_32 = 0x80000000; -constexpr const uint64_t BIT_64 = 0x8000000000000000; - extern "C" double StdMathRandom() { std::random_device rd; @@ -98,32 +95,12 @@ extern "C" double StdMathCeil(double val) extern "C" int32_t StdMathClz64(int64_t val) { - uint64_t bit = BIT_64; - int32_t count = 0; - while (bit >= 1) { - if ((static_cast(val) & bit) == 0) { - bit /= 2; - count++; - } else { - break; - } - } - return count; + return std::__countl_zero(static_cast(val)); } extern "C" int32_t StdMathClz32(int32_t val) { - uint32_t bit = BIT_32; - int32_t count = 0; - while (bit >= 1) { - if ((static_cast(val) & bit) == 0) { - bit /= 2; - count++; - } else { - break; - } - } - return count; + return std::__countl_zero(static_cast(val)); } extern "C" double StdMathLog(double val) diff --git a/plugins/ets/tests/ets-templates/06.conversions_and_contexts/Test.ets b/plugins/ets/tests/ets-templates/06.conversions_and_contexts/Test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a7941e62333e979ffa967faaf45f813ec6eca9e --- /dev/null +++ b/plugins/ets/tests/ets-templates/06.conversions_and_contexts/Test.ets @@ -0,0 +1,14 @@ +// function main(): void { +// console.println("--------"); +// let i: long = 0x00000000ffffffff; +// let j: int = 0xffffffff; +// if (clz64(i) == clz32(j)) { +// console.println("NOT HEHE") +// } +// console.println(clz32(j)) +// console.print(clz64(i)) +// console.println(" ----- instead of 32..."); +// } +function main(): void { + console.println(clz64(0x00000000ffffffffL)) +} \ No newline at end of file