www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - odd bit optimized function

reply Vitaliy Fadeev <vital.fadeev gmail.com> writes:
x86 first bit check (odd check):
```asm
AND EAX, EAX  ; update FLAG OF  // odd flag
JO  Label
```

Is there D-Lang operator of optimized library function ?
Sep 22 2023
parent reply claptrap <clap trap.com> writes:
On Friday, 22 September 2023 at 14:29:08 UTC, Vitaliy Fadeev 
wrote:
 x86 first bit check (odd check):
 ```asm
 AND EAX, EAX  ; update FLAG OF  // odd flag
 JO  Label
 ```

 Is there D-Lang operator of optimized library function ?
There's no "odd" flag, theres the overflow flag "O", and "JO" is jump on overflow. Or there's the parity flag "P", which signals an odd or even number of bits in the lowest byte of the result (on x86 anyway). If you just want to test if an int is odd or even, just do if (x & 1) writeln("is odd"); else writeln("is even"); that'll compile to an AND and a jmp, or conditional move maybe. If you want to access the parity flag I think you're out of luck aside from using inline asm.
Sep 22 2023
parent Vitaliy Fadeev <vital.fadeev gmail.com> writes:
On Friday, 22 September 2023 at 22:48:34 UTC, claptrap wrote:
 On Friday, 22 September 2023 at 14:29:08 UTC, Vitaliy Fadeev 
 wrote:
 x86 first bit check (odd check):
 ```asm
 AND EAX, EAX  ; update FLAG OF  // odd flag
 JO  Label
 ```

 Is there D-Lang operator of optimized library function ?
There's no "odd" flag, theres the overflow flag "O", and "JO" is jump on overflow. Or there's the parity flag "P", which signals an odd or even number of bits in the lowest byte of the result (on x86 anyway). If you just want to test if an int is odd or even, just do if (x & 1) writeln("is odd"); else writeln("is even"); that'll compile to an AND and a jmp, or conditional move maybe. If you want to access the parity flag I think you're out of luck aside from using inline asm.
Thank, claptrap! Yes, P FLAG, of course! JP instruction. ```asm if (x & 1) ``` I am using the code above.
 using inline asm
OK, may be.
Sep 22 2023