| | 4324 | } |
|---|
| | 4325 | # endif |
|---|
| | 4326 | return i32; |
|---|
| | 4327 | # endif /* !RT_ARCH_AMD64 */ |
|---|
| | 4328 | } |
|---|
| | 4329 | #endif |
|---|
| | 4330 | |
|---|
| | 4331 | |
|---|
| | 4332 | /** |
|---|
| | 4333 | * Performs 64-bit unsigned by a 32-bit unsigned division with a 32-bit unsigned result, |
|---|
| | 4334 | * returning the rest. |
|---|
| | 4335 | * |
|---|
| | 4336 | * @returns u64 % u32. |
|---|
| | 4337 | * |
|---|
| | 4338 | * @remarks It is important that the result is <= UINT32_MAX or we'll overflow and crash. |
|---|
| | 4339 | */ |
|---|
| | 4340 | #if RT_INLINE_ASM_EXTERNAL && !defined(RT_ARCH_AMD64) |
|---|
| | 4341 | DECLASM(uint32_t) ASMModU64ByU32RetU32(uint64_t u64, uint32_t u32); |
|---|
| | 4342 | #else |
|---|
| | 4343 | DECLINLINE(uint32_t) ASMModU64ByU32RetU32(uint64_t u64, uint32_t u32) |
|---|
| | 4344 | { |
|---|
| | 4345 | # ifdef RT_ARCH_AMD64 |
|---|
| | 4346 | return (uint32_t)(u64 % u32); |
|---|
| | 4347 | # else /* !RT_ARCH_AMD64 */ |
|---|
| | 4348 | # if RT_INLINE_ASM_GNU_STYLE |
|---|
| | 4349 | RTCCUINTREG uDummy; |
|---|
| | 4350 | __asm__ __volatile__("divl %3" |
|---|
| | 4351 | : "=a" (uDummy), "=d"(u32) |
|---|
| | 4352 | : "A" (u64), "r" (u32)); |
|---|
| | 4353 | # else |
|---|
| | 4354 | __asm |
|---|
| | 4355 | { |
|---|
| | 4356 | mov eax, dword ptr [u64] |
|---|
| | 4357 | mov edx, dword ptr [u64 + 4] |
|---|
| | 4358 | mov ecx, [u32] |
|---|
| | 4359 | div ecx |
|---|
| | 4360 | mov [u32], edx |
|---|
| | 4361 | } |
|---|
| | 4362 | # endif |
|---|
| | 4363 | return u32; |
|---|
| | 4364 | # endif /* !RT_ARCH_AMD64 */ |
|---|
| | 4365 | } |
|---|
| | 4366 | #endif |
|---|
| | 4367 | |
|---|
| | 4368 | |
|---|
| | 4369 | /** |
|---|
| | 4370 | * Performs 64-bit signed by a 32-bit signed division with a 32-bit signed result, |
|---|
| | 4371 | * returning the rest. |
|---|
| | 4372 | * |
|---|
| | 4373 | * @returns u64 % u32. |
|---|
| | 4374 | * |
|---|
| | 4375 | * @remarks It is important that the result is <= UINT32_MAX or we'll overflow and crash. |
|---|
| | 4376 | */ |
|---|
| | 4377 | #if RT_INLINE_ASM_EXTERNAL && !defined(RT_ARCH_AMD64) |
|---|
| | 4378 | DECLASM(int32_t) ASMModS64ByS32RetS32(int64_t i64, int32_t i32); |
|---|
| | 4379 | #else |
|---|
| | 4380 | DECLINLINE(int32_t) ASMModS64ByS32RetS32(int64_t i64, int32_t i32) |
|---|
| | 4381 | { |
|---|
| | 4382 | # ifdef RT_ARCH_AMD64 |
|---|
| | 4383 | return (int32_t)(i64 % i32); |
|---|
| | 4384 | # else /* !RT_ARCH_AMD64 */ |
|---|
| | 4385 | # if RT_INLINE_ASM_GNU_STYLE |
|---|
| | 4386 | RTCCUINTREG iDummy; |
|---|
| | 4387 | __asm__ __volatile__("idivl %3" |
|---|
| | 4388 | : "=a" (iDummy), "=d"(i32) |
|---|
| | 4389 | : "A" (i64), "r" (i32)); |
|---|
| | 4390 | # else |
|---|
| | 4391 | __asm |
|---|
| | 4392 | { |
|---|
| | 4393 | mov eax, dword ptr [i64] |
|---|
| | 4394 | mov edx, dword ptr [i64 + 4] |
|---|
| | 4395 | mov ecx, [i32] |
|---|
| | 4396 | idiv ecx |
|---|
| | 4397 | mov [i32], edx |
|---|