Skip to content

Fix code generation for SIMD types #444

@vecchiot-aws

Description

@vecchiot-aws

I'm not sure where in the translation process this should happen, but consider the following program:

#![feature(repr_simd)]

#[repr(simd)]
#[derive(PartialEq, Eq)]
pub struct A(i64, i64);

fn main() {
    let x = A(1, 2);
    let y = A(3, 4);
    assert!(x != y);
}

The generated C code from --gen-c does comparison like this:

_Bool _RNvXs_Csb7rQPrKk64Y_4mainNtB4_1ANtNtCs75dudyTCRYy_4core3cmp9PartialEq2neB4_(long int __attribute__((vector_size (2*sizeof(long int)))) *self, long int __attribute__((vector_size (2*sizeof(long int)))) *other)
{
  // ...
  long int *__self_1_0;
  long int *__self_1_1;
  long int *__self_0_0;
  long int *__self_0_1;
  // ...
  __self_1_0 = *other;
  __self_1_1 = &(*other)[1];
  __self_0_0 = *self;
  __self_0_1 = &(*self)[1];
  var_8 = *__self_0_0;
  var_9 = *__self_1_0;
  var_7 = var_8 != var_9;
  // ...
}

There are two main issues:

  1. __self_1_0 = *other;: the value *other is a vector type, while __self_1_0 is a long int*
  2. __self_1_1 = &(*other)[1];: this leads to "address of vector element requested"; you cannot take reference to a vector element in C.

No longer relevant: The --gen-c-runnable transformation handles this by casting the vector to a raw pointer and using array indexing, but long-term this should be fixed at the CBMC level.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions