Skip to content

Commit

Permalink
Code review renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
EnderGnar committed Oct 4, 2023
1 parent efab1bf commit 4e72175
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions spec/lang/step/intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<M: Memory> Machine<M> {
// All integer sizes are powers of two.
let align = Align::from_bytes(size.bytes()).unwrap();
if size > M::T::MAX_ATOMIC_SIZE {
throw_ub!("invalid return type for `Intrinsic::AtomicCompareExchange`, size to big");
throw_ub!("invalid return type for `Intrinsic::AtomicCompareExchange`, size too big");
}

// The value at the location right now.
Expand Down Expand Up @@ -399,36 +399,36 @@ fn is_atomic_binop(op: BinOpInt) -> bool {
impl<M: Memory> Machine<M> {
fn eval_intrinsic(
&mut self,
Intrinsic::AtomicFetch(op): Intrinsic,
Intrinsic::AtomicFetchAndOp(op): Intrinsic,
arguments: List<(Value<M>, Type)>,
ret_ty: Type,
) -> NdResult<Value<M>> {
if arguments.len() != 2 {
throw_ub!("invalid number of arguments for `Intrinsic::AtomicFetch`");
throw_ub!("invalid number of arguments for `Intrinsic::AtomicFetchAndOp`");
}

let Value::Ptr(ptr) = arguments[0].0 else {
throw_ub!("invalid first argument to `Intrinsic::AtomicFetch`, not a pointer");
throw_ub!("invalid first argument to `Intrinsic::AtomicFetchAndOp`, not a pointer");
};

let (other, other_ty) = arguments[1];
if other_ty != ret_ty {
throw_ub!("invalid second argument to `Intrinsic::AtomicFetch`, not same type as return value");
throw_ub!("invalid second argument to `Intrinsic::AtomicFetchAndOp`, not same type as return value");
}

if !matches!(ret_ty, Type::Int(_)) {
throw_ub!("invalid return type for `Intrinis::AtomicFetch`, only works with integers");
throw_ub!("invalid return type for `Intrinis::AtomicFetchAndOp`, only works with integers");
}

let size = ret_ty.size::<M::T>();
// All integer sizes are powers of two.
let align = Align::from_bytes(size.bytes()).unwrap();
if size > M::T::MAX_ATOMIC_SIZE {
throw_ub!("invalid return type for `Intrinsic::AtomicFetch`, size to big");
throw_ub!("invalid return type for `Intrinsic::AtomicFetchAndOp`, size too big");
}

if !is_atomic_binop(op) {
throw_ub!("invalid bin op for `Intrinsic::AtomicFetch`");
throw_ub!("invalid bin op for `Intrinsic::AtomicFetchAndOp`");
}

// The value at the location right now.
Expand Down
2 changes: 1 addition & 1 deletion spec/lang/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub enum Intrinsic {
AtomicStore,
AtomicLoad,
AtomicCompareExchange,
AtomicFetch(BinOpInt),
AtomicFetchAndOp(BinOpInt),
Lock(LockIntrinsic),
}
```
Expand Down
4 changes: 2 additions & 2 deletions tooling/minimize/intrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ pub unsafe fn compare_exchange(ptr: *mut u32, current: u32, new: u32) -> u32 {
}
}

pub unsafe fn atomic_add(ptr: *mut u32, delta: u32) -> u32 {
pub unsafe fn atomic_fetch_add(ptr: *mut u32, delta: u32) -> u32 {
let atomic = AtomicU32::from_ptr(ptr);
atomic.fetch_add(delta, Ordering::SeqCst)
}

pub unsafe fn atomic_sub(ptr: *mut u32, delta: u32) -> u32 {
pub unsafe fn atomic_fetch_sub(ptr: *mut u32, delta: u32) -> u32 {
let atomic = AtomicU32::from_ptr(ptr);
atomic.fetch_sub(delta, Ordering::SeqCst)
}
4 changes: 2 additions & 2 deletions tooling/minimize/src/bb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ fn translate_call<'cx, 'tcx>(
"atomic_store" => Intrinsic::AtomicStore,
"atomic_load" => Intrinsic::AtomicLoad,
"compare_exchange" => Intrinsic::AtomicCompareExchange,
"atomic_add" => Intrinsic::AtomicFetch(BinOpInt::Add),
"atomic_sub" => Intrinsic::AtomicFetch(BinOpInt::Sub),
"atomic_fetch_add" => Intrinsic::AtomicFetchAndOp(BinOpInt::Add),
"atomic_fetch_sub" => Intrinsic::AtomicFetchAndOp(BinOpInt::Sub),
name => panic!("unsupported intrinsic `{}`", name),
};
Terminator::CallIntrinsic {
Expand Down
4 changes: 2 additions & 2 deletions tooling/minimize/tests/pass/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ fn main() {
print(x);
print(v);

let v = unsafe { atomic_add(ptr, 3) };
let v = unsafe { atomic_fetch_add(ptr, 3) };
print(x);
print(v);

let v = unsafe { atomic_sub(ptr, 4) };
let v = unsafe { atomic_fetch_sub(ptr, 4) };
print(x);
print(v);
}
16 changes: 8 additions & 8 deletions tooling/minitest/src/tests/atomic_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn atomic_fetch_arg_count() {

let b0 = block!(
Terminator::CallIntrinsic {
intrinsic: Intrinsic::AtomicFetch(BinOpInt::Add),
intrinsic: Intrinsic::AtomicFetchAndOp(BinOpInt::Add),
arguments: list!(),
ret: zst_place(),
next_block: Some(BbName(Name::from_internal(1)))
Expand All @@ -51,7 +51,7 @@ fn atomic_fetch_arg_count() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid number of arguments for `Intrinsic::AtomicFetch`");
assert_ub(p, "invalid number of arguments for `Intrinsic::AtomicFetchAndOp`");
}

#[test]
Expand All @@ -72,7 +72,7 @@ fn atomic_fetch_arg_1() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid first argument to `Intrinsic::AtomicFetch`, not a pointer");
assert_ub(p, "invalid first argument to `Intrinsic::AtomicFetchAndOp`, not a pointer");
}

#[test]
Expand All @@ -95,7 +95,7 @@ fn atomic_fetch_arg_2() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid second argument to `Intrinsic::AtomicFetch`, not same type as return value");
assert_ub(p, "invalid second argument to `Intrinsic::AtomicFetchAndOp`, not same type as return value");
}

#[test]
Expand All @@ -120,7 +120,7 @@ fn atomic_fetch_ret_ty() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid return type for `Intrinis::AtomicFetch`, only works with integers");
assert_ub(p, "invalid return type for `Intrinis::AtomicFetchAndOp`, only works with integers");
}

#[test]
Expand All @@ -143,7 +143,7 @@ fn atomic_fetch_int_size() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid return type for `Intrinsic::AtomicFetch`, size to big");
assert_ub(p, "invalid return type for `Intrinsic::AtomicFetchAndOp`, size too big");
}

#[test]
Expand All @@ -158,7 +158,7 @@ fn atomic_fetch_op() {
assign(local(0), const_int::<u32>(3)),

Terminator::CallIntrinsic {
intrinsic: Intrinsic::AtomicFetch(BinOpInt::Mul),
intrinsic: Intrinsic::AtomicFetchAndOp(BinOpInt::Mul),
arguments: list!( addr_of(local(0), ptr_ty), const_int::<u32>(1) ),
ret: local(1),
next_block: Some(BbName(Name::from_internal(1)))
Expand All @@ -171,5 +171,5 @@ fn atomic_fetch_op() {
let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);

assert_ub(p, "invalid bin op for `Intrinsic::AtomicFetch`");
assert_ub(p, "invalid bin op for `Intrinsic::AtomicFetchAndOp`");
}
2 changes: 1 addition & 1 deletion tooling/minitest/src/tests/compare_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,5 @@ fn compare_exchange_arg_size_max() {

let f = function(Ret::No, 0, &locals, &[b0, b1]);
let p = program(&[f]);
assert_ub(p, "invalid return type for `Intrinsic::AtomicCompareExchange`, size to big");
assert_ub(p, "invalid return type for `Intrinsic::AtomicCompareExchange`, size too big");
}
2 changes: 1 addition & 1 deletion tooling/miniutil/src/build/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn atomic_fetch(binop: FetchBinOp, dest: PlaceExpr, ptr: ValueExpr, other: V
};

Terminator::CallIntrinsic {
intrinsic: Intrinsic::AtomicFetch(binop),
intrinsic: Intrinsic::AtomicFetchAndOp(binop),
arguments: list!(ptr, other),
ret: dest,
next_block: Some(BbName(Name::from_internal(next)))
Expand Down
2 changes: 1 addition & 1 deletion tooling/miniutil/src/fmt/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn fmt_terminator(t: Terminator, comptypes: &mut Vec<CompType>) -> String {
Intrinsic::AtomicStore => "atomic_store",
Intrinsic::AtomicLoad => "atomic_load",
Intrinsic::AtomicCompareExchange => "atomic_compare_exchange",
Intrinsic::AtomicFetch(binop) => fmt_fetch(binop),
Intrinsic::AtomicFetchAndOp(binop) => fmt_fetch(binop),
Intrinsic::Lock(LockIntrinsic::Acquire) => "lock_acquire",
Intrinsic::Lock(LockIntrinsic::Create) => "lock_create",
Intrinsic::Lock(LockIntrinsic::Release) => "lock_release",
Expand Down

0 comments on commit 4e72175

Please sign in to comment.