mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Use faster clamping for Uint8ClampedArray (#422)
This commit is contained in:
parent
6a1ffb8e2f
commit
ed97672a8c
@ -15,6 +15,10 @@ import {
|
|||||||
COMPARATOR
|
COMPARATOR
|
||||||
} from "./internal/sort";
|
} from "./internal/sort";
|
||||||
|
|
||||||
|
function clampToByte(value: i32): i32 {
|
||||||
|
return ~(value >> 31) & (((255 - value) >> 31) | value); // & 255
|
||||||
|
}
|
||||||
|
|
||||||
export class Int8Array extends TypedArray<i8> {
|
export class Int8Array extends TypedArray<i8> {
|
||||||
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
|
@lazy static readonly BYTES_PER_ELEMENT: usize = sizeof<i8>();
|
||||||
|
|
||||||
@ -112,12 +116,12 @@ export class Uint8ClampedArray extends Uint8Array {
|
|||||||
|
|
||||||
@inline @operator("[]=")
|
@inline @operator("[]=")
|
||||||
protected __set(index: i32, value: i32): void {
|
protected __set(index: i32, value: i32): void {
|
||||||
super.__set(index, max(min(value, 255), 0));
|
super.__set(index, clampToByte(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@inline @operator("{}=")
|
@inline @operator("{}=")
|
||||||
protected __unchecked_set(index: i32, value: i32): void {
|
protected __unchecked_set(index: i32, value: i32): void {
|
||||||
super.__unchecked_set(index, max(min(value, 255), 0));
|
super.__unchecked_set(index, clampToByte(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {
|
fill(value: u32, start: i32 = 0, end: i32 = i32.MAX_VALUE): Uint8ClampedArray {
|
||||||
|
@ -1814,21 +1814,21 @@
|
|||||||
i32.store8 offset=8
|
i32.store8 offset=8
|
||||||
)
|
)
|
||||||
(func $~lib/typedarray/Uint8ClampedArray#__set (; 25 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32)
|
(func $~lib/typedarray/Uint8ClampedArray#__set (; 25 ;) (type $iii_) (param $0 i32) (param $1 i32) (param $2 i32)
|
||||||
(local $3 i32)
|
|
||||||
local.get $0
|
local.get $0
|
||||||
local.get $1
|
local.get $1
|
||||||
local.get $2
|
|
||||||
i32.const 255
|
i32.const 255
|
||||||
local.get $2
|
local.get $2
|
||||||
i32.const 255
|
i32.sub
|
||||||
i32.lt_s
|
i32.const 31
|
||||||
select
|
i32.shr_s
|
||||||
local.tee $3
|
local.get $2
|
||||||
i32.const 0
|
i32.or
|
||||||
local.get $3
|
local.get $2
|
||||||
i32.const 0
|
i32.const 31
|
||||||
i32.gt_s
|
i32.shr_s
|
||||||
select
|
i32.const -1
|
||||||
|
i32.xor
|
||||||
|
i32.and
|
||||||
call $~lib/internal/typedarray/TypedArray<u8>#__set
|
call $~lib/internal/typedarray/TypedArray<u8>#__set
|
||||||
)
|
)
|
||||||
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
(func $~lib/internal/typedarray/TypedArray<u8>#__get (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user