Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Substracting value in a xmm register

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
TwinShards
How do I cheat?
Reputation: 0

Joined: 23 Jan 2023
Posts: 6

PostPosted: Sun Jan 29, 2023 12:40 pm    Post subject: Substracting value in a xmm register Reply with quote

I was wondering how can i selectively substract a value of (float)2.5 from the second row in a xmm register.

Just so i do not ask in the future, how can you do it for each row as well.

Example xmm register is X9001 Y69 Z420 Facing Value:180

How do i substract 2.5 from Y to get 67.5 ?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sun Jan 29, 2023 3:18 pm    Post subject: Reply with quote

Something simple: store the xmm register into memory and change each float individually.
Code:
newmem:
  sub rsp,10
  movups [rsp],xmm0
  movss xmm0,[rsp+4]
  subss xmm0,[val_to_sub]
  movss [rsp+4],xmm0
  movups xmm0,[rsp]
  add rsp,10
  jmp return


More complicated: write code using vector intrinsics and let a compiler tell you an "optimal" answer. e.g. C code:
Code:
typedef float v4sf __attribute__ ((vector_size (16)));

v4sf foo(v4sf vec) {
    vec[1] -= 2.5f;
    return vec;
}

gcc 12.2:
Code:
foo:
  movaps  xmm1, xmm0
  shufps  xmm1, xmm0, 85
  movaps  xmm2, xmm1
  subss   xmm2, DWORD PTR .LC0[rip]
  movaps  xmm1, xmm0
  unpcklps  xmm1, xmm0
  movss   xmm1, xmm2
  shufps  xmm1, xmm0, 225
  movaps  xmm0, xmm1
  ret
.LC0:
  .long 1075838976  # float 2.5

clang 15.0:
Code:
.LCPI0_0:
  .long   0xc0200000         # float -2.5
foo:                         # @foo
  movaps  xmm1, xmm0
  shufps  xmm1, xmm0, 85     # xmm1 = xmm1[1,1],xmm0[1,1]
  addss   xmm1, dword ptr [rip + .LCPI0_0]
  movlhps xmm1, xmm0         # xmm1 = xmm1[0],xmm0[0]
  shufps  xmm1, xmm0, 226    # xmm1 = xmm1[2,0],xmm0[2,3]
  movaps  xmm0, xmm1
  ret

You might need to look up documentation for these instructions to better incorporate them into an AA script.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Sun Jan 29, 2023 4:09 pm    Post subject: Reply with quote

[code]
{$CCODE y=XMM1.1f}
y-=2.5f
{$asm}
[code]

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
TwinShards
How do I cheat?
Reputation: 0

Joined: 23 Jan 2023
Posts: 6

PostPosted: Sat Feb 04, 2023 2:21 pm    Post subject: Reply with quote

Dark Byte wrote:
[code]
{$CCODE y=XMM1.1f}
y-=2.5f
{$asm}
[code]


Ty!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites