Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atomic instructions are not supported #44

Open
JIMXGtamods opened this issue Nov 26, 2024 · 8 comments
Open

atomic instructions are not supported #44

JIMXGtamods opened this issue Nov 26, 2024 · 8 comments

Comments

@JIMXGtamods
Copy link

I have this error: Unsupported instruction: I32AtomicRmwAdd { memarg: MemArg { align: 2, max_align: 2, offset: 8, memory: 0 } }
I been trying to upgrade the code to support atomic functions but i can't :(
Solution?

@Rerumu
Copy link
Owner

Rerumu commented Nov 26, 2024

Sadly, there are no plans to further extend this version of Wasynth with any of the proposals like atomics or SIMD and such. You'd likely need your compiler to not emit that code if possible or alter it to work with host workarounds.

There is a Wasynth rewrite in the works that will tackle most proposals and fix this too, but I have no real ETA for it.

@JIMXGtamods
Copy link
Author

ty

@JIMXGtamods
Copy link
Author

JIMXGtamods commented Dec 14, 2024

Sadly, there are no plans to further extend this version of Wasynth with any of the proposals like atomics or SIMD and such. You'd likely need your compiler to not emit that code if possible or alter it to work with host workarounds.

There is a Wasynth rewrite in the works that will tackle most proposals and fix this too, but I have no real ETA for it.

I found a way for atomics support, i have made the lua functions, i add the names in Wasynth but last problem wasmparser (wasm-tools)'s Operator Enum doesn't contains atomics operators. What can i do?

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::MemoryAtomicNotify
--> wasm-ast\src\node.rs:242:4
|
242 | Operator::MemoryAtomicNotify => Self::MemoryAtomicNotify,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::MemoryAtomicWait32
--> wasm-ast\src\node.rs:243:4
|
243 | Operator::MemoryAtomicWait32 => Self::MemoryAtomicWait32,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::MemoryAtomicWait64
--> wasm-ast\src\node.rs:244:4
|
244 | Operator::MemoryAtomicWait64 => Self::MemoryAtomicWait64,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::I32AtomicRmwAdd
--> wasm-ast\src\node.rs:393:4
|
393 | Operator::I32AtomicRmwAdd => Self::I32AtomicRmwAdd,
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::I64AtomicRmwAdd
--> wasm-ast\src\node.rs:394:4
|
394 | Operator::I64AtomicRmwAdd => Self::I64AtomicRmwAdd,
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

error[E0533]: expected unit struct, unit variant or constant, found struct variant Operator::I32AtomicRmw8AddU
--> wasm-ast\src\node.rs:395:4
|
395 | Operator::I32AtomicRmw8AddU => Self::I32AtomicRmw8AddU,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant

@JIMXGtamods JIMXGtamods reopened this Dec 14, 2024
@Rerumu
Copy link
Owner

Rerumu commented Dec 15, 2024

I think you may be missing a feature flag somewhere. Extensions in wasmparser are gated behind feature flags based on their proposal name.

@JIMXGtamods
Copy link
Author

JIMXGtamods commented Dec 15, 2024

I think you may be missing a feature flag somewhere. Extensions in wasmparser are gated behind feature flags based on their proposal name.

Thanks for the reply, the wasmparser wasn't enough recent to include atomic operations so i update it to the latest (i had to change some lines). Now the code seems to be working, i included the atomic operations. I built it, but when i launch wasm2luau.exe with the atomic wasm file, the stack array seems to be broken, i debug the issue and it was the atomic fault. Error: thread 'main' panicked at wasm-ast\src\stack.rs:82:29:
called Option::unwrap() on a None value
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/std\src\panicking.rs:662
1: core::panicking::panic_fmt
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\panicking.rs:74
2: core::panicking::panic
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\panicking.rs:148
3: core::option::unwrap_failed
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library/core\src\option.rs:2015
4: enum2$<core::option::Option<enum2$<wasm_ast::node::Expression> > >::unwrap
at /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\core\src\option.rs:965
5: wasm_ast::stack::Stack::pop
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\stack.rs:82
6: wasm_ast::factory::StatList::push_cmp_op
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\factory.rs:214
7: wasm_ast::factory::StatList::try_add_operation
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\factory.rs:251
8: wasm_ast::factory::Factory::add_instruction
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\factory.rs:479
9: wasm_ast::factory::Factory::build_stat_list
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\factory.rs:787
10: wasm_ast::factory::Factory::create_indexed
at D:\Downloads\Wasynth-trunk\Wasynth-trunk\wasm-ast\src\factory.rs:318
11: codegen_luau::translator::build_func_list::closure$0 The problem is here:
fn push_atomic_rmw(&mut self, atomic_type: AtomicRmwType, memarg: MemArg) {
let memory = memarg.memory.try_into().unwrap();
let offset = memarg.offset.try_into().unwrap();

	let data = Statement::AtomicRmw(AtomicRmw {
		atomic_type,
		memory,
		offset,
		value: self.stack.pop().into(),
		pointer: self.stack.pop().into(),
	});

	self.leak_memory_write(memory);
	self.code.push(data);
}

fn push_atomic_rmw_cmpxchg(&mut self, atomic_type: AtomicRmwCmpxchgType, memarg: MemArg) {
	let memory = memarg.memory.try_into().unwrap();
	let offset = memarg.offset.try_into().unwrap();

	let data = Statement::AtomicRmwCmpxchg(AtomicRmwCmpxchg {
		atomic_type,
		memory,
		offset,
		expected: self.stack.pop().into(),
		replacement: self.stack.pop().into(),
		pointer: self.stack.pop().into(),
	});

	self.leak_memory_write(memory);
	self.code.push(data);
}

fn push_atomic_wait(&mut self, atomic_type: AtomicWaitType, memarg: MemArg) {
	let memory = memarg.memory.try_into().unwrap();
	let offset = memarg.offset.try_into().unwrap();

	let data = Statement::AtomicWait(AtomicWait {
		atomic_type,
		memory,
		offset,
		expected: self.stack.pop().into(),
		timeout: self.stack.pop().into(),
		pointer: self.stack.pop().into(),
	});

	self.leak_memory_write(memory);
	self.code.push(data);
}

fn push_atomic_notify(&mut self, atomic_type: AtomicNotifyType, memarg: MemArg) {
	let memory = memarg.memory.try_into().unwrap();
	let offset = memarg.offset.try_into().unwrap();

	let data = Statement::AtomicNotify(AtomicNotify {
		atomic_type,
		memory,
		offset,
		count: self.stack.pop().into(),
		pointer: self.stack.pop().into(),
	});

	self.leak_memory_write(memory);
	self.code.push(data);
} i don't know if the atomic instructions are related to statement or expression.

@Rerumu
Copy link
Owner

Rerumu commented Dec 15, 2024

Due to the nature of Lua, I would honestly avoid making custom atomic statements in the AST altogether. Lua only really runs in one thread, and Wasynth doesn't support shared memories at all, so you might have better luck just making the atomic instruction codegen call the already existing code for construction non-atomic operations.

@JIMXGtamods
Copy link
Author

JIMXGtamods commented Dec 15, 2024

Due to the nature of Lua, I would honestly avoid making custom atomic statements in the AST altogether. Lua only really runs in one thread, and Wasynth doesn't support shared memories at all, so you might have better luck just making the atomic instruction codegen call the already existing code for construction non-atomic operations.

Thanks for the information but doing atomic instructions without implementing threads isn't what i want.
I think Wasynth can support shared memory, revamping the runtime.lua can resolve the problem.
For luajit i dont know cause i dont use this version of lua (i didn't do the atomic update for this version, it's useless for me), but in luau there is a little chance to be made.
The threads in luau seems to be correct, i already do the emscripten library in luau, it working.
But these taking me days, i will send a comment if i found a idea.
Thanks.

@JIMXGtamods
Copy link
Author

Due to the nature of Lua, I would honestly avoid making custom atomic statements in the AST altogether. Lua only really runs in one thread, and Wasynth doesn't support shared memories at all, so you might have better luck just making the atomic instruction codegen call the already existing code for construction non-atomic operations.

Good news, wasynth supports now passive data and thread. I have to test in roblox and upgrade my emscripten library to support threads!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants