Traversing a string using arm assembly inside V8 source

97 views Asked by At

I am trying to implement a fastpath for regular expressions in arm/code-stubs-arm.cc in the RegExpExecStub::Generate function. The subject string is stored in the register 'r4'. I need to traverse character by character in the string but I can't seem to be able to do it. I have tried things like:

__ ldrb( r3, MemOperand(r4,0)); 
//to get to 0th char and store it to r3

Or:

 __ ldrb( r3, MemOperand(r4,String::kLengthOffset)); 
//to do the same thing as above in case the data begins after length field.

I am using the d8 shell to check the value of the registers by stopping at a breakpoint after the above statements and doing a print r3 to check if the character is loaded or not. However, I see random values in the register when I try the above statements. Ideally I should see the character in hex form.

1

There are 1 answers

0
doomguy On BEST ANSWER

Turns out the correct offset should be String::kSize-1 and so on.

 __ ldrb( r3, MemOperand(r4,String::kSize-1)); //to get 0th character
 __ ldrb( r3, MemOperand(r4,String::kSize)); //to get 1st character
 __ ldrb( r3, MemOperand(r4,String::kSize+1)); //to get 2nd character`