Skip to content

Instantly share code, notes, and snippets.

@cookbrianj
Created May 30, 2012 20:45
Show Gist options
  • Save cookbrianj/2838841 to your computer and use it in GitHub Desktop.
Save cookbrianj/2838841 to your computer and use it in GitHub Desktop.
ARM NEON Helpers
//
// BCNeonImageUtils.h
// IRStudio
//
// Created by Brian Cook on 5/30/12.
// Copyright (c) 2012 All rights reserved.
//
#ifndef IRStudio_BCNeonImageUtils_h
#define IRStudio_BCNeonImageUtils_h
static void neon_BGRA_to_ARGB(unsigned char *src, int width, int height) {
int numPixels = width * height;
int iterations = numPixels / 8;
__asm__ __volatile__("1: \n"
"vld4.8 {d0-d3}, [%0] \n"
"vswp.8 d0, d3 \n" //swap Blue and Alpha
"vswp.8 d1, d2 \n" //swap Red and Green
"vst4.8 {d0-d3}, [%0]! \n"
"subs %1, %1, #1 \n"
"bne 1b \n"
:
: "r"(src), "r"(iterations)
: "memory"
);
}
static void neon_BGRA_to_RGBA(unsigned char *src, int width, int height) {
int numPixels = width * height;
int iterations = numPixels / 8;
__asm__ __volatile__("1: \n"
"vld4.8 {d0-d3}, [%0] \n"
"vswp.8 d0, d2 \n" //swap Red and Blue
"vst4.8 {d0-d3}, [%0]! \n"
"subs %1, %1, #1 \n"
"bne 1b \n"
:
: "r"(src), "r"(iterations)
: "memory"
);
}
static void neon_asm_switch_red_and_blue(unsigned char *src, int numPixels) {
__asm__ __volatile__("1: \n"
"vld4.8 {d0-d3}, [%0] \n"
"vswp.8 d1, d3 \n"
"vst4.8 {d0-d3}, [%0]! \n"
"subs %1, %1, #1 \n"
"bne 1b \n"
:
: "r"(src), "r"(numPixels)
: "memory"
);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment