Coder Social home page Coder Social logo

Comments (7)

tthsqe12 avatar tthsqe12 commented on July 29, 2024

If you want to learn the instructions, you can see my latest changes.
Keep in mind that some variables like PiecesThem, PiecesPawn, ect. are in registers already. The full list is in the beginning of the EvalThreats macro. I will give you the operations of some of the instructions here.

xor a, b ; same as a = a^b;
and a, b ; same as a = a&b;
 or a, b ; same as a = a|b;
andn a, b, c ; same as a = (~b) & c, uses a macro for cpu without this instruction, see BasicMacros.asm

from asmfish.

lantonov avatar lantonov commented on July 29, 2024
	mov   r8, PiecesThem
	mov   r9, PiecesPawn
	and   r9, r8         ;r9 = pos.pieces(Them, PAWN)
	xor   r8, r9          ;r8 = (pos.pieces(Them) ^ pos.pieces(Them, PAWN))
        mov   r9, qword[.ei.attackedBy+8*(8*Them+Pawn)]
       andn  r10,  qword[.ei.attackedBy2+8*Us], qword[.ei.attackedBy2+8*Them]
         or  r9, r10          ; r9 = stronglyProtected  		
        and   r8, r9
; r8 = defended
       andn   r9, r9, PiecesThem           ; r9 = ~stronglyProtected & pos.pieces(Them)
	and   r9, AttackedByUs              ; r9 = ~stronglyProtected & pos.pieces(Them) & ei.attackedBy[Us][ALL_PIECES]
; r9 = weak
	 or   r8, r9
; r8 = defended | weak

I tried per your explanations which are clear enough and without looking at your code. Afraid to test it though, not to blow my computer.

from asmfish.

tthsqe12 avatar tthsqe12 commented on July 29, 2024

Ah, don't be afraid of blowing up your computer. Your computer runs the program like it runs any other program. The worst you can get here is probably a segfault, which will be unhandled and thus passed to the os. There are several ways you can lock up your system:

  • set the program to real time priority and start a lot of threads that get stuck in an infinite loop
  • allocate a ton of memory and then start to fill it up

I think you will see there is no danger of that in this section of code.

from asmfish.

lantonov avatar lantonov commented on July 29, 2024

Ok, I'll "try this at home" and then try to find my errors.

from asmfish.

tthsqe12 avatar tthsqe12 commented on July 29, 2024

So your code will assemble on popcnt and base versions (and be correct!) but it will not assemble on bmi2 version. This is due to the andn macro.

line:
 andn  r10,  qword[.ei.attackedBy2+8*Us], qword[.ei.attackedBy2+8*Them]

andn is defined as a macro in line 295 of Basic macros.asm
This means that the preprocessor is going to either of these things

when CPU_HAS_BMI1=0
 mov r10, qword[.ei.attackedBy2+8*Us]
 not r10
 and r10, qword[.ei.attackedBy2+8*Them]


when CPU_HAS_BMI1=1
 andn  r10,  qword[.ei.attackedBy2+8*Us], qword[.ei.attackedBy2+8*Them]

This last instruction is not encodable because only the last argument is allowed to be a memory reference.
http://www.felixcloutier.com/x86/ANDN.html

Before you start wishing that that it were possible to encode two memory references into a single instruction, keep in mind that the cpu actually has to decode all these instructions. That is, if you believe the power consumption myth.
https://www.usenix.org/system/files/conference/cooldc16/cooldc16-paper-hirki.pdf

from asmfish.

lantonov avatar lantonov commented on July 29, 2024

Thanks for the detailed explanation and reference. Wow, I almost did it !

from asmfish.

lantonov avatar lantonov commented on July 29, 2024
	mov   r8, PiecesThem
	mov   r9, PiecesPawn
	and   r9, r8         ;r9 = pos.pieces(Them, PAWN)
	xor   r8, r9          ;r8 = (pos.pieces(Them) ^ pos.pieces(Them, PAWN))
        mov   r9, qword[.ei.attackedBy+8*(8*Them+Pawn)]
        mov r10, qword[.ei.attackedBy2+8*Us] 
       andn  r10,  r10, qword[.ei.attackedBy2+8*Them]
         or  r9, r10          ; r9 = stronglyProtected  		
        and   r8, r9
        ; r8 = defended
       andn   r9, r9, PiecesThem           ; r9 = ~stronglyProtected & pos.pieces(Them)
         and   r9, AttackedByUs              ; r9 = ~stronglyProtected & pos.pieces(Them) & ei.attackedBy[Us][ALL_PIECES]
       ; r9 = weak
	 or   r8, r9
       ; r8 = defended | weak

This should work then (I am away from my 64 bit to try it)

from asmfish.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.