Coder Social home page Coder Social logo

Comments (9)

jserv avatar jserv commented on May 28, 2024 1

Cause I had found that the unexpected output only occur when the size of the previous array is not equal to multiples of four byte, so I suspected that maybe their have some bug in lw or la.

The concept of alignment is dependent upon the size of data. For word data the address is either multiple of 4 (aligned), or it is misaligned. @maromaSamsa, you can now prepare a revised MRE which reflects the above findings.

from rv32emu.

qwe661234 avatar qwe661234 commented on May 28, 2024 1

Thanks for your reply, I think this explanation convince me why the unexpected output doesn't print any character when misaligned occur in rv32emu, and I am curious about the source code.

You can check the op_load function in file emulate.c.

from rv32emu.

jserv avatar jserv commented on May 28, 2024

@maromaSamsa, you shall provide a minimal reproducible example (MRE) instead of hyperlinks. Edit the description of this issue to inline MRE.

from rv32emu.

Risheng1128 avatar Risheng1128 commented on May 28, 2024

@maromaSamsa I want to check your problem. Does your problem is that the emulator executes wrong when instruction la is changed to instruction lw ?

Example:

la     s1, arr1    ->    lw    s1, arr1

from rv32emu.

maromaSamsa avatar maromaSamsa commented on May 28, 2024

@maromaSamsa I want to check your problem. Does your problem is that the emulator executes wrong when instruction la is changed to instruction lw ?

Example:

la     s1, arr1    ->    lw    s1, arr1

Actually I am not sure, in this RISC-V source code I just use la to get address of the byte array, and use lw to load 4 byte value from the array.

Cause I had found that the unexpected output only occur when the size of the previous array is not equal to multiples of four byte, so I suspected that maybe their have some bug in lw or la.

from rv32emu.

maromaSamsa avatar maromaSamsa commented on May 28, 2024

Cause I had found that the unexpected output only occur when the size of the previous array is not equal to multiples of four byte, so I suspected that maybe their have some bug in lw or la.

The concept of alignment is dependent upon the size of data. For word data the address is either multiple of 4 (aligned), or it is misaligned. @maromaSamsa, you can now prepare a revised MRE which reflects the above findings.

Please check this commit

the output is normal when you change the test case

.data
arr1:
	.byte 48, 49, 50 # this will cause unexpected output
	#.byte 48, 49, 50, 51 # check this

PS: sorry for the wrong term in this commit, is MRE(minimal reproducible example) not MSE(Mean squared error).

from rv32emu.

qwe661234 avatar qwe661234 commented on May 28, 2024

@maromaSamsa, I already checked this commit. The reason why test case .byte 48, 49, 50 cause unexpected output is misalignment.

In the rv32emu, arr1 and arr2 are stored in contiguous memory address. First lw instruction checks whether the address of arr1 + 4 is misaligned. Because the start address of arr1 is aligned, the address of arr1 + 4 is also aligned. Therefore, first lw instruction loads 3 bytes of data of arr1 and 1 byte of data of arr2. However, the start address of arr2 is the start address of arr1 + 3, so second lw instruction finds out arr2 + 4 is misaligned and calls exeception handler without printing any data.

As alternative, you can use lb instruction to load a byte of data.

from rv32emu.

maromaSamsa avatar maromaSamsa commented on May 28, 2024

However, the start address of arr2 is the start address of arr1 + 3, so second lw instruction finds out arr2 + 4 is misaligned and calls exeception handler without printing any data.

Thanks for your reply, I think this explanation convince me why the unexpected output doesn't print any character when misaligned occur in rv32emu, and I am curious about the source code.

As alternative, you can use lb instruction to load a byte of data.

Since I hope I can save the memory by constrain the test data into byte, and also lw is more efficiency than lb cause I can spent only one instruction time to load 4 byte, I choose to use lw if it is possible.

from rv32emu.

jserv avatar jserv commented on May 28, 2024

I probably close this as the issue is not one of emulator flaws.

from rv32emu.

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.