[Beignet] [PATCH] Add the logic for pack/unpack long for scalar.

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jan 27 00:27:40 PST 2015


Rong, could you review this patch and verify it on your BDW machine. Thanks.

On Tue, Jan 27, 2015 at 10:53:22AM +0800, junyan.he at inbox.com wrote:
> From: Junyan He <junyan.he at linux.intel.com>
> 
> Sometimes, such as printf the kernel's long type
> parameter, the scalar register will also need to be
> pack/unpack.
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  backend/src/backend/gen8_context.cpp | 94 ++++++++++++++++++++++--------------
>  1 file changed, 59 insertions(+), 35 deletions(-)
> 
> diff --git a/backend/src/backend/gen8_context.cpp b/backend/src/backend/gen8_context.cpp
> index 07f8c47..cde87de 100644
> --- a/backend/src/backend/gen8_context.cpp
> +++ b/backend/src/backend/gen8_context.cpp
> @@ -618,60 +618,84 @@ namespace gbe
>  
>    void Gen8Context::packLongVec(GenRegister unpacked, GenRegister packed, uint32_t simd)
>    {
> +    bool isScalar = false;
> +    if (unpacked.hstride == GEN_HORIZONTAL_STRIDE_0)
> +      isScalar = true;
> +
>      GBE_ASSERT(packed.subnr == 0);
> -    GBE_ASSERT(unpacked.subnr == 0);
> +    GBE_ASSERT(packed.hstride != GEN_HORIZONTAL_STRIDE_0);
> +    GBE_ASSERT(unpacked.subnr == 0 || isScalar);
>  
>      unpacked = GenRegister::retype(unpacked, GEN_TYPE_UD);
>      packed = GenRegister::retype(packed, GEN_TYPE_UD);
>  
> -    if (simd == 16) {
> -      p->push();
> -      p->curr.execWidth = 8;
> -      p->MOV(GenRegister::h2(packed), unpacked);
> -      p->MOV(GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))),
> -             GenRegister::offset(unpacked, 2));
> -      p->curr.quarterControl = 1;
> -      p->MOV(GenRegister::h2(GenRegister::offset(packed, 2, 0)), GenRegister::offset(unpacked, 1));
> -      p->MOV(GenRegister::h2(GenRegister::offset(packed, 2, typeSize(GEN_TYPE_UD))),
> -             GenRegister::offset(unpacked, 3));
> -      p->pop();
> +    if (isScalar) {
> +      p->MOV(packed, unpacked);
>      } else {
> -      GBE_ASSERT(simd == 8);
> -      p->MOV(GenRegister::h2(packed), unpacked);
> -      p->MOV(GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))),
> -             GenRegister::offset(unpacked, 1));
> +      if (simd == 16) {
> +        p->push();
> +        p->curr.execWidth = 8;
> +        p->MOV(GenRegister::h2(packed), unpacked);
> +        p->MOV(GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))),
> +               GenRegister::offset(unpacked, 2));
> +        p->curr.quarterControl = 1;
> +        p->MOV(GenRegister::h2(GenRegister::offset(packed, 2, 0)), GenRegister::offset(unpacked, 1));
> +        p->MOV(GenRegister::h2(GenRegister::offset(packed, 2, typeSize(GEN_TYPE_UD))),
> +               GenRegister::offset(unpacked, 3));
> +        p->pop();
> +      } else {
> +        GBE_ASSERT(simd == 8);
> +        p->MOV(GenRegister::h2(packed), unpacked);
> +        p->MOV(GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))),
> +               GenRegister::offset(unpacked, 1));
> +      }
>      }
>    }
>  
>    void Gen8Context::unpackLongVec(GenRegister packed, GenRegister unpacked, uint32_t simd)
>    {
> -    GBE_ASSERT(packed.subnr == 0);
> +    bool isScalar = false;
> +    if (packed.hstride == GEN_HORIZONTAL_STRIDE_0)
> +      isScalar = true;
> +
> +    GBE_ASSERT(packed.subnr == 0 || isScalar);
> +    GBE_ASSERT(unpacked.hstride != GEN_HORIZONTAL_STRIDE_0);
>      GBE_ASSERT(unpacked.subnr == 0);
>  
>      unpacked = GenRegister::retype(unpacked, GEN_TYPE_UD);
>      packed = GenRegister::retype(packed, GEN_TYPE_UD);
>  
> -    packed.vstride = GEN_VERTICAL_STRIDE_8;
> -    packed.width = GEN_WIDTH_4;
> -
> -    p->push();
> -    p->curr.execWidth = 8;
> -    if (simd == 16) {
> -      p->MOV(unpacked, GenRegister::h2(packed));
> -      p->MOV(GenRegister::offset(unpacked, 2),
> -             GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))));
> +    if (isScalar) {
> +      p->MOV(unpacked, packed);
>  
> -      p->curr.quarterControl = 1;
> -      p->MOV(GenRegister::offset(unpacked, 1), GenRegister::h2(GenRegister::offset(packed, 2)));
> -      p->MOV(GenRegister::offset(unpacked, 3),
> -             GenRegister::h2(GenRegister::offset(packed, 2, typeSize(GEN_TYPE_UD))));
> +      if (simd == 16) {
> +        p->MOV(GenRegister::offset(unpacked, 2), GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD)));
> +      } else {
> +        p->MOV(GenRegister::offset(unpacked, 1), GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD)));
> +      }
>      } else {
> -      GBE_ASSERT(simd == 8);
> -      p->MOV(unpacked, GenRegister::h2(packed));
> -      p->MOV(GenRegister::offset(unpacked, 1),
> -             GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))));
> +      packed.vstride = GEN_VERTICAL_STRIDE_8;
> +      packed.width = GEN_WIDTH_4;
> +
> +      p->push();
> +      p->curr.execWidth = 8;
> +      if (simd == 16) {
> +        p->MOV(unpacked, GenRegister::h2(packed));
> +        p->MOV(GenRegister::offset(unpacked, 2),
> +               GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))));
> +
> +        p->curr.quarterControl = 1;
> +        p->MOV(GenRegister::offset(unpacked, 1), GenRegister::h2(GenRegister::offset(packed, 2)));
> +        p->MOV(GenRegister::offset(unpacked, 3),
> +               GenRegister::h2(GenRegister::offset(packed, 2, typeSize(GEN_TYPE_UD))));
> +      } else {
> +        GBE_ASSERT(simd == 8);
> +        p->MOV(unpacked, GenRegister::h2(packed));
> +        p->MOV(GenRegister::offset(unpacked, 1),
> +               GenRegister::h2(GenRegister::offset(packed, 0, typeSize(GEN_TYPE_UD))));
> +      }
> +      p->pop();
>      }
> -    p->pop();
>    }
>  
>    void Gen8Context::emitRead64Instruction(const SelectionInstruction &insn)
> -- 
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list